00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #define LOCAL_MODULE MOD_PARSER
00043
00044 #include "../common/common.h"
00045 #include <sstream>
00046 #include "xml_parser_restart.h"
00047
00048 bool Triplet::domainSizeIsSet;
00049 Cube Triplet::geom(3);
00050 double Triplet::tx = 0;
00051 double Triplet::ty = 0;
00052 double Triplet::tz = 0;
00053
00054
00055 inline void truncate(double * a){
00056
00057
00058 unsigned int * temp = (unsigned int *)a;
00059 *temp = 0;
00060
00061
00062
00063
00064
00065
00066
00067 }
00068
00069
00070 void Triplet::Truncate(){
00071
00072
00073
00074
00075 x += tx;
00076 y += ty;
00077 z += tz;
00078
00079 truncate(&x);
00080 truncate(&y);
00081 truncate(&z);
00082 };
00083
00084 void Triplet::SetDomainSize(Geometrie & g){
00085 domainSizeIsSet = true;
00086 geom = GeomTools::GetBoundingBox(g);
00087 };
00088
00089
00090
00091 void XMLRestartParser::charHandler(const XML_Char * str,int len){
00092 char * buf;
00093
00094 DUMP("read a line of size " << len,DBG_ALL);
00095 if (len == 0)
00096 return;
00097
00098 buf = new char[len+1];
00099
00100 strncpy(buf,str,len);
00101
00102 if (type == TEXT)
00103 buf[len]='\0';
00104 else
00105 b64.SetStream(buf,len);
00106
00107 if (buf[0] == '\n')
00108 return;
00109
00110
00111
00112
00113 switch (current_field){
00114 case P0S: manageP0(buf);break;
00115 case DEP: manageU(buf);break;
00116 case VEL: manageV(buf);break;
00117 case ACC: manageA(buf);break;
00118 }
00119
00120 delete [] buf;
00121 };
00122
00123
00124 void XMLRestartParser::startElement(const char *name,const char **atts){
00125 int j;
00126 cpt=0;
00127
00128 if (strcmp("SimulationData",name)==0){
00129 for (j=0; (j < 10 && atts[j] != NULL);++j){
00130 if (strcmp("dim",atts[j])==0){
00131 Dim = atoi(atts[j+1]);
00132
00133 ++j;
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 if (strcmp("dataType",atts[j])==0){
00145 if (strcmp("TEXT",atts[j+1])==0){
00146 type = TEXT;
00147 }
00148 else type = BINARY;
00149 ++j;
00150 }
00151 if (strcmp("nbDofs",atts[j])==0){
00152 nbDofs = atoi(atts[j+1]);
00153
00154 ++j;
00155 tab_indexes = new int[nbDofs];
00156 }
00157 if (strcmp("savedTime",atts[j])==0){
00158 savedTime = atoi(atts[j+1]);
00159
00160 ++j;
00161 }
00162 }
00163 }
00164 if (strcmp("P0",name)==0){
00165 current_field = P0S;
00166 DUMP("reading intial positions",DBG_INFO);
00167 }
00168 if (strcmp("U",name)==0){
00169 current_field = DEP;
00170 DUMP("reading displacements",DBG_INFO);
00171 }
00172 if (strcmp("V",name)==0){
00173 current_field = VEL;
00174 DUMP("reading velocities",DBG_INFO);
00175 }
00176 if (strcmp("A",name)==0){
00177 current_field = ACC;
00178 DUMP("reading accelerations",DBG_INFO);
00179 }
00180
00181
00182 };
00183
00184
00185 void XMLRestartParser::endElement(const char * name){
00186
00187 char message[256];
00188
00189 switch (current_field){
00190 case P0S: sprintf(message,"%s : in vector P0s ",name);break;
00191 case DEP: sprintf(message,"%s : in vector Us ",name);break;
00192 case VEL: sprintf(message,"%s : in vector Vs ",name);break;
00193 case ACC: sprintf(message,"%s : in vector As ",name);break;
00194 }
00195 current_field = NONE;
00196
00197 if (cpt != 0 && cpt != nbDofs)
00198 FATAL(message << ": values number do not concord (read " << cpt << " should be " << nbDofs << ")");
00199 };
00200
00201 int XMLRestartParser::readTriplet(Triplet & C,char * s){
00202 if (type == TEXT){
00203 std::istringstream str(s);
00204 char tmp[256];
00205 if (triplet.getRead() == 0 && str >> tmp) {
00206 triplet(0) = atof(tmp);
00207 triplet.getRead()++;
00208 }
00209 else return 0;
00210 if (triplet.getRead() == 1 && str >> tmp) {
00211 triplet(1) = atof(tmp);
00212 triplet.getRead()++;
00213 }
00214 else return 0;
00215 if (triplet.getRead() == 2 && str >> tmp) {
00216 triplet(2) = atof(tmp);
00217 triplet.getRead()++;
00218 }
00219 else return 0;
00220 }
00221
00222 if (type == BINARY){
00223 for (int i = triplet.getRead() ; i < 3 ; ++i){
00224 DUMP("read " << triplet.getRead() << " " << i,DBG_ALL);
00225 triplet.getRead() += b64.PopDoubleInBase64(triplet(i));
00226 DUMP("read " << triplet.getRead() << " " << i,DBG_ALL);
00227 if (i+1 != triplet.getRead()) {DUMP("already red " << triplet.getRead() << " components of the triplet",DBG_ALL);return 0;}
00228 }
00229 }
00230
00231 C = triplet;
00232 triplet.getRead() = 0;
00233
00234 return 1;
00235 }
00236
00237
00238 void XMLRestartParser::manageP0(char * s){
00239 Triplet C;
00240 while (readTriplet(C,s) && cpt < nbDofs){
00241 C.Truncate();
00242 mapP0[cpt] = C;
00243 DUMP(C(0) << " " << C(1) << " " << C(2) << " " << cpt,DBG_ALL);
00244 ++cpt;
00245 }
00246 };
00247
00248
00249 void XMLRestartParser::manageU(char * s){
00250 Triplet u;
00251 while (readTriplet(u,s) && cpt < nbDofs){
00252 mapU[mapP0[cpt]] = u;
00253 DUMP(u(0) << " + " << u(1) << " + " << u(2) << " + " << cpt,DBG_ALL);
00254 ++cpt;
00255 }
00256 };
00257
00258 void XMLRestartParser::manageV(char * s){
00259 Triplet v;
00260 while (readTriplet(v,s) && cpt < nbDofs){
00261 mapV[mapP0[cpt]] = v;
00262 DUMP(v(0) << " + " << v(1) << " + " << v(2) << " + " << cpt,DBG_ALL);
00263 ++cpt;
00264 }
00265 };
00266
00267 void XMLRestartParser::manageA(char * s){
00268 Triplet a;
00269 while (readTriplet(a,s) && cpt < nbDofs){
00270 mapA[mapP0[cpt]] = a;
00271 DUMP(a(0) << " + " << a(1) << " + " << a(2) << " + " << cpt,DBG_ALL);
00272 ++cpt;
00273 }
00274 };
00275
00276
00277 bool XMLRestartParser::IsDofRegistered(double x,double y, double z){
00278 double epsilon2 = .8e-10*.8e-10;
00279
00280 if (Dim < 3) z = 0;
00281 if (Dim == 1) y = 0;
00282 Triplet a(x,y,z);
00283 a.Truncate();
00284 if (mapU.count(a) == 0) {
00285 std::map<Triplet,Triplet>::iterator pos;
00286 DUMP("testing if already registered with the position " << a,DBG_ALL);
00287 pos = find_if(mapU.begin(),mapU.end(),close_enough(a));
00288
00289 if(pos != mapU.end()){
00290 Triplet found = pos->first;
00291 double dx = a(0) - found(0);
00292 double dy = a(1) - found(1);
00293 double dz = a(2) - found(2);
00294
00295 double rmin = dx*dx + dy*dy +dz*dz;
00296 DUMP("minimal distance = " << FORMATREAL(rmin) << " " << found(0) << " " << found(1) << " " << found(2),DBG_ALL);
00297 if ( rmin > epsilon2 ) return false;
00298 Triplet::tx = found(0) - x;Triplet::ty=found(1) - y;Triplet::tz=found(2) -z;
00299 DUMP("translation " << FORMATREAL(Triplet::tx) << " " << Triplet::ty << " " << Triplet::tz,DBG_ALL);
00300
00301 return true;
00302 }
00303 DUMP("Triplet not found : " << a,DBG_ALL);
00304 return false;
00305 }
00306 return true;
00307 };
00308
00309
00310 void XMLRestartParser::AssignDispField(double x,double y, double z,double & ux, double & uy,double & uz){
00311 if (Dim < 3) z = 0;
00312 if (Dim == 1) y = 0;
00313 Triplet a(x,y,z);
00314 a.Truncate();
00315 Triplet &b = mapU[a];
00316 ux = b(0);
00317 uy = b(1);
00318 uz = b(2);
00319 };
00320
00321 void XMLRestartParser::AssignVelField(double x,double y, double z,double & ux, double & uy,double & uz){
00322 if (Dim < 3) z = 0;
00323 if (Dim == 1) y = 0;
00324 Triplet a(x,y,z);
00325 a.Truncate();
00326 Triplet &b = mapV[a];
00327 ux = b(0);
00328 uy = b(1);
00329 uz = b(2);
00330 };
00331
00332 void XMLRestartParser::AssignForceField(double x,double y, double z,double & ux, double & uy,double & uz){
00333 if (Dim < 3) z = 0;
00334 if (Dim == 1) y = 0;
00335 Triplet a(x,y,z);
00336 a.Truncate();
00337 Triplet &b = mapA[a];
00338 ux = b(0);
00339 uy = b(1);
00340 uz = b(2);
00341 };
00342