xml_parser_elast.h

Go to the documentation of this file.
00001 /* ./continuum/libmesh/xml_parser_elast.h 
00002 **********************************
00003 Copyright INRIA and CEA 
00004 
00005 author : Guillaume ANCIAUX (anciaux@labri.fr, g.anciaux@laposte.net)
00006 
00007 The LibMultiScale is a C++ parallel framework for the multiscale
00008 coupling methods dedicated to material simulations. This framework
00009 provides an API which makes it possible to program coupled simulations
00010 and integration of already existing codes.
00011 
00012 This Project is done in a collaboration between INRIA Futurs Bordeaux
00013 within ScAlApplix team and CEA/DPTA Ile de France. 
00014 
00015 This software is governed by the CeCILL-C license under French law and
00016 abiding by the rules of distribution of free software.  You can  use, 
00017 modify and/ or redistribute the software under the terms of the CeCILL-C
00018 license as circulated by CEA, CNRS and INRIA at the following URL
00019 "http://www.cecill.info". 
00020 
00021 As a counterpart to the access to the source code and  rights to copy,
00022 modify and redistribute granted by the license, users are provided only
00023 with a limited warranty  and the software's author,  the holder of the
00024 economic rights,  and the successive licensors  have only  limited
00025 liability. 
00026 
00027 In this respect, the user's attention is drawn to the risks associated
00028 with loading,  using,  modifying and/or developing or reproducing the
00029 software by the user in light of its specific status of free software,
00030 that may mean  that it is complicated to manipulate,  and  that  also
00031 therefore means  that it is reserved for developers  and  experienced
00032 professionals having in-depth computer knowledge. Users are therefore
00033 encouraged to load and test the software's suitability as regards their
00034 requirements in conditions enabling the security of their systems and/or 
00035 data to be ensured and,  more generally, to use and operate it in the 
00036 same conditions as regards security. 
00037 
00038 The fact that you are presently reading this means that you have had
00039 knowledge of the CeCILL-C license and that you accept its terms.
00040 ***********************************/
00041 
00042 #ifndef XML_PARSER_ELAST_H
00043 #define XML_PARSER_ELAST_H
00044 
00045 #define NONE 0
00046 #define IDS 1
00047 #define P0S 2
00048 #define DEP 3
00049 #define VEL 4
00050 #define ACC 5
00051 
00052 class XMLElasticityParser : public XMLParser {
00053 
00054  public:
00055 
00056   XMLElasticityParser(DOFLibMesh & d,GhostedNumericVector<Number> & a):dofs(d),A(a){};
00057 
00058 
00059   virtual int ParseFile(char * name){
00060     XMLParser::ParseFile(name);
00061 
00062     DUMP("dimension read : " << Dim,DBG_INFO);
00063     DUMP("nbNodes read : " << nbNodes,DBG_INFO);
00064 
00065 /*     for (unsigned int i = 0 ; i < nbNodes ; ++i){ */
00066 /*       std::cout << tab_indexes[i] << " ";       */
00067 /*     } */
00068 /*     std::cout << std::endl; */
00069     return 0;
00070   }
00071 
00072  protected:
00073 
00074 
00075   void charHandler(const XML_Char * str,int len){
00076     char buf[512];
00077     
00078    
00079     if (len == 0)
00080       return;
00081 
00082     strncpy(buf,str,len);
00083     buf[len]='\0';
00084 
00085     if (buf[0] == '\n')
00086       return;
00087 
00088     //    DUMP("len = " << len);
00089     //DUMP("buf = " << buf);
00090 
00091     switch (current_field){
00092     case IDS: manageNodeIDs(buf);break;
00093     case P0S: manageP0(buf);break;
00094     case DEP: manageU(buf);break;
00095     case VEL: manageV(buf);break;
00096     case ACC: manageA(buf);break;
00097     }
00098   };
00099 
00100   void startElement(const char *name,const char **atts){
00101     int j;
00102     cpt=0;
00103 
00104     if (strcmp("meshData",name)==0){
00105       for (j=0; (j < 10  && atts[j] != NULL);++j){
00106         if (strcmp("dim",atts[j])==0){
00107           Dim = atoi(atts[j+1]);
00108           //    printf("Dim = %d\n",data.Dim);
00109           ++j;
00110         }
00111         if (strcmp("nbNodes",atts[j])==0){
00112           nbNodes = atoi(atts[j+1]);
00113           //printf("nbNodes = %d\n",data.nbNodes);
00114           ++j;
00115           tab_indexes = new int[nbNodes]; 
00116         }
00117       }
00118     }
00119     if (strcmp("nodeIDs",name)==0){
00120       current_field = IDS;
00121     }
00122     if (strcmp("P0",name)==0){
00123       current_field = P0S;
00124     }
00125     if (strcmp("V",name)==0){
00126       current_field = VEL;
00127     }
00128     if (strcmp("A",name)==0){
00129       current_field = ACC;
00130     }
00131 
00132     
00133   };
00134 
00135   void endElement(const char * name){
00136 
00137     char message[256];
00138     
00139     switch (current_field){
00140     case IDS: sprintf(message,"%s : in vector IDs ",name);break;
00141     case P0S: sprintf(message,"%s : in vector P0s ",name);break;
00142     case DEP: sprintf(message,"%s : in vector Us ",name);break;
00143     case VEL: sprintf(message,"%s : in vector Vs ",name);break;
00144     case ACC: sprintf(message,"%s : in vector As ",name);break;
00145     }
00146     current_field = NOONE;
00147 
00148     if (cpt != 0 && cpt != nbNodes)
00149       FATAL(message << ": values number do not concord (read " << cpt << " should be " << nbNodes << ")");
00150   };
00151   
00152 
00153  private:
00154   
00155   void manageNodeIDs(char * s){
00156     int id;
00157     
00158 
00159     std::istringstream str(s);
00160 
00161     while (str >> id){
00162       tab_indexes[cpt] = id;
00163       ++cpt;
00164       //      DUMP(id);
00165     }
00166 
00167   };
00168   void manageP0(char * s){
00169     double x=0,y=0,z=0;
00170     double xold=0,yold=0,zold=0;
00171     char tmp[256];
00172 
00173     std::istringstream str(s);
00174 
00175     GhostedNumericVector<Number> & P0 = dofs.P0();
00176     int start = P0.first_local_index();
00177     int last = P0.last_local_index();
00178 
00179     while (str >> tmp){
00180       
00181       int index = tab_indexes[cpt]*Dim;
00182       ++cpt;
00183 
00184       //      DUMP("index = " << index);
00185       xold = atof(tmp);
00186       if (Dim > 1 && str >> tmp) yold = atof(tmp);
00187       if (Dim == 3 && str >> tmp) zold = atof(tmp);
00188 
00189       if (index < start ||  index >= last) continue;
00190 
00191       x = P0[index];
00192       if (Dim > 1)
00193         y = P0[index+1];
00194       if (Dim == 3)
00195         z = P0[index+2];
00196 
00197       DUMP(x << " " << y << " " << z << " " << xold << " " << yold << " " << zold,DBG_ALL);
00198 
00199 /*       if (ipow(x - xold,2) + ipow(y - yold,2) + ipow(z - zold,2) > ) */
00200 /*      FATAL("there seems to have a trouble beetween restart file and loaded simulation (are they equivalent ?)"); */
00201 
00202     }
00203     
00204   };
00205   void manageU(char * s){
00206     double ux=0,uy=0,uz=0;
00207     double tmp;
00208 
00209     std::istringstream str(s);
00210 
00211     GhostedNumericVector<Number> & U = dofs.U();
00212     int start = U.first_local_index();
00213     int last = U.last_local_index();
00214 
00215     while (str >> tmp){
00216       
00217       int index = tab_indexes[cpt]*Dim;
00218 
00219       ++cpt;
00220 
00221       //      DUMP("index = " << index);
00222       ux = tmp;
00223       if (Dim > 1 && str >> tmp) uy = tmp;
00224       if (Dim == 3 && str >> tmp) uz = tmp;
00225 
00226       if (index < start ||  index >= last)
00227         continue;
00228 
00229       U.set(index,ux);
00230       if (Dim > 1)
00231         U.set(index+1,uy);
00232       if (Dim == 3)
00233         U.set(index+2,uz);
00234 
00235 
00236       DUMP(ux << " " << uy << " " << uz,DBG_ALL);
00237 
00238     }
00239 
00240     U.close();
00241   };
00242   void manageV(char * s){
00243     double vx=0,vy=0,vz=0;
00244     double tmp;
00245 
00246     std::istringstream str(s);
00247 
00248     GhostedNumericVector<Number> & V = dofs.V();
00249     int start = V.first_local_index();
00250     int last = V.last_local_index();
00251 
00252     while (str >> tmp){
00253       
00254       int index = tab_indexes[cpt]*Dim;
00255 
00256       DUMP("index = " << index,DBG_ALL);
00257 
00258       ++cpt;
00259 
00260       vx = tmp;
00261       if (Dim > 1 && str >> tmp) vy = tmp;
00262       if (Dim == 3 && str >> tmp) vz = tmp;
00263 
00264       if (index < start ||  index >= last)
00265         continue;
00266 
00267       V.set(index,vx);
00268       if (Dim > 1 )
00269         V.set(index+1,vy);
00270       if (Dim == 3) 
00271         V.set(index+2,vz);
00272 
00273       DUMP("setting v[" << index/Dim << "]" << vx << " " << vy << " " << vz,DBG_ALL);
00274 
00275     }
00276 
00277     V.close();
00278   };
00279   void manageA(char * s){
00280     double ax=0,ay=0,az=0;
00281     double tmp;
00282 
00283     std::istringstream str(s);
00284 
00285     int start = A.first_local_index();
00286     int last = A.last_local_index();
00287 
00288     while (str >> tmp){
00289       
00290       int index = tab_indexes[cpt]*Dim;
00291 
00292       ++cpt;
00293 
00294       //      DUMP("index = " << index);
00295       ax = tmp;
00296       if (Dim > 1 && str >> tmp) ay = tmp;
00297       if (Dim == 3 && str >> tmp) az = tmp;
00298 
00299       if (index < start ||  index >= last)
00300         continue;
00301 
00302       A.set(index,ax);
00303       if (Dim > 1 )
00304         A.set(index+1,ay);
00305       if (Dim == 3)
00306         A.set(index+2,az);
00307 
00308       DUMP(ax << " " << ay << " " << az,DBG_ALL);
00309 
00310     }
00311 
00312     A.close();
00313   };
00314   void manageMassMatrixX(char * s){
00315     *s = 0;
00316   };
00317   void manageMassMatrixY(char * s){
00318     *s = 0;
00319   };
00320   void manageMassMatrixZ(char * s){
00321     *s = 0;
00322   };
00323 
00324   unsigned int Dim;
00325   unsigned int nbNodes;
00326   int * tab_indexes;
00327 
00328   int current_field;
00329   unsigned int cpt;
00330 
00331   DOFLibMesh & dofs;
00332   GhostedNumericVector<Number> & A;  
00333 };
00334 
00335 #endif

Generated on Fri Sep 7 13:12:34 2007 for LibMultiScale by  doxygen 1.5.2