1 #include "MEDMEM_Exception.hxx"
2 #include "MEDMEM_define.hxx"
4 #include "MEDMEM_Med.hxx"
5 #include "MEDMEM_Field.hxx"
6 #include "MEDMEM_Mesh.hxx"
7 #include "MEDMEM_Interpolation.hxx"
13 using namespace MEDMEM;
15 // pour gestion timings
18 #define RUN(procedure) {double t0,t1;cout<<"# =============> TEMPS D'EXECUTION A PARTIR D'ICI "<<endl<<#procedure<<endl;t0=CPUtime();procedure;t1=CPUtime();cout<<"# ================> TEMPS D'EXECUTION : "<<t1-t0<<endl;}
19 #define TIMORIZE(procedure,t) {double t0,t1;t0=CPUtime();procedure;t1=CPUtime();t=t1-t0;}
26 return ((double)buf.tms_utime+(double)buf.tms_stime)/(long) sysconf(_SC_CLK_TCK);
29 return ((double) clock())/CLOCKS_PER_SEC;
32 double ABS(Valeur<double> v)
36 for (i=0;i<v.SIZE();i++) tmp+=fabs(v[i]);
40 double ABS(Valeur<double> v1,Valeur<double> v2)
44 for (i=0;i<v1.SIZE();i++) tmp+=fabs(v1[i]-v2[i]);
50 // effectue la soustraction du premier moins le second et stocke le résultat dans le premier
51 void Flipback(FIELD<double> * firstField, FIELD<double> * secondField)
53 Wrapper_MED_Field first ( firstField);
54 Wrapper_MED_Field second (secondField);
55 int nbr_valeurs_first = first.Get_Nbr_Valeurs();
56 int nbr_valeurs_second = second.Get_Nbr_Valeurs();
61 double min1 = ABS(first[0]);
62 double min2 = ABS(second[0]);
73 if (nbr_valeurs_first!=nbr_valeurs_second)
75 cerr<<"Les champs à soustraire n'ont pas le meme nombre de valeurs"<<endl;
80 for (i=0;i<nbr_valeurs_first;i++)
83 //cout<<"tmp 1 ["<<i<<"] = "<<tmp<<endl;
89 if (tmp<min1) min1=tmp;
93 for (i=0;i<nbr_valeurs_first;i++)
101 if (tmp<min2) min2=tmp;
104 for (i=0;i<nbr_valeurs_first;i++)
106 first[i]=ABS(first[i],second[i]);
109 double maxdiff=ABS(first[0]);
110 double mindiff=ABS(first[0]);
112 for (i=0;i<nbr_valeurs_first;i++)
115 if (tmp>maxdiff) maxdiff=tmp;
116 if (tmp<mindiff) mindiff=tmp;
120 cout<<"/////////////////////////////////////////////////////////////////////////"<<endl;
121 cout<<"/////// max1 = "<<max1<<endl;
122 cout<<"/////// min1 = "<<min1<<endl;
123 cout<<"/////// Maximum First atteint pour i = "<<imax1<<endl;
124 cout<<"/////// max2 = "<<max2<<endl;
125 cout<<"/////// min2 = "<<min2<<endl;
126 cout<<"/////// Maximum Second atteint pour i = "<<imax2<<endl;
127 cout<<"/////// maxdiff = "<<maxdiff<<endl;
128 cout<<"/////// mindiff = "<<mindiff<<endl;
129 cout<<"/////////////////////////////////////////////////////////////////////////"<<endl;
134 #include "MEDMEM_WrapperCells.hxx"
138 const char * fromFileName = "ResultatSyrthes.med";
139 const char * toFileName = "MaillageAster.med";
140 const char * resultFileName = "ResultatFlipback.med";
142 const char * fromFieldName = "THERDEP_TEMP____________________";
144 const char * fromMeshName = "MA";
145 const char * toMeshName = "MAILLAGE_IDEAS";
150 string flag="================[MAIN MESSAGES]================> ";
152 cout<<flag<<"Lecture de la structure MED : "<<flush;
153 MED fromMED (MED_DRIVER,fromFileName);
156 // Utilisation completement débile, on ne devrait pas avoir a faire l'appel suivant
157 fromMED.updateSupport();
159 cout<<flag<<"Lecture du Mailllage Cible : "<<flush;
160 MESH toMesh (MED_DRIVER,toFileName,toMeshName);
163 cout<<flag<<"Lecture des pas de temps : "<<flush;
164 deque<DT_IT_> pasDeTemps=fromMED.getFieldIteration (fromFieldName);
167 deque<DT_IT_>::const_iterator currentStep;
169 INTERPOLATION<3> * interFromTo ;
170 INTERPOLATION<3> * interToFrom ;
171 FIELD<double> * toField ;
172 FIELD<double> * toToField ;
173 int flagNewMappingFromTo = 0;
174 int flagNewMappingToFrom = 0;
176 for (currentStep=pasDeTemps.begin();currentStep!=pasDeTemps.end();currentStep++)
178 cout<<flag<<"Traitement du Step ( "<<flush<<(*currentStep).dt<<" ; "<<(*currentStep).it<<" ) : "<<endl;
180 cout<<flag<<"Lecture du FIELD_ "<<flush;
181 FIELD_ * fromField_ = fromMED.getField(fromFieldName,(*currentStep).dt,(*currentStep).it);
184 cout<<flag<<"Transtypage en FIELD : "<<flush;
185 FIELD<double> * fromField = dynamic_cast<FIELD<double> *>(fromField_);
188 if (currentStep==pasDeTemps.begin())
190 //Utilisation completement débile, on ne devrait pas avoir a faire l'appel suivant
191 RUN(fromField->getSupport()->getMesh()->read());
194 MESH * fromMesh = fromField->getSupport()->getMesh();
196 cout<<flag<<"Lecture des valeurs du FIELD : "<<flush;
197 RUN(fromField->read());
200 if (currentStep==pasDeTemps.begin())
202 cout<<flag<<"Préparation de l'interpolation DIRECTE pour le premier pas de temps : "<<flush;
203 RUN(interFromTo = new INTERPOLATION<3>(*fromField,toMesh));
205 cout<<flag<<"Interpolation effective DIRECTE du premier pas de temps : "<<flush;
206 RUN(toField = interFromTo->interpolate(1,1));
208 cout<<flag<<"Préparation de l'interpolation INVERSE pour le premier pas de temps : "<<flush;
209 RUN(interToFrom = new INTERPOLATION<3>(*toField,*fromMesh));
211 cout<<flag<<"Interpolation effective INVERSE du premier pas de temps : "<<flush;
212 RUN(toToField = interToFrom->interpolate(1,1));
217 cout<<flag<<"Interpolation nextStep DIRECTE : "<<flush;
218 RUN(toField = interFromTo->interpolateNextStep(*fromField,flagNewMappingFromTo));
220 cout<<flag<<"Interpolation nextStep INVERSE : "<<flush;
221 RUN(toToField = interToFrom->interpolateNextStep(*toField,flagNewMappingToFrom));
225 cout<<flag<<"Calcul du flip back : "<<flush;
226 Flipback(toToField,fromField);
229 cout<<flag<<"Creation du driver d'écriture Field : "<<flush;
230 toToField->addDriver(MED_DRIVER,resultFileName,toToField->getName());
233 cout<<flag<<"Ecriture du Field résultat : "<<flush;
237 if (flagNewMappingToFrom==1)
239 cout<<flag<<"Creation du driver d'écriture Mesh : "<<flush;
240 handle = fromMesh->addDriver(MED_DRIVER,resultFileName,fromMesh->getName()) ;
243 cout<<flag<<"Ecriture du Mesh résultat : "<<flush;
244 fromMesh->write(handle);
249 } catch (MEDEXCEPTION& ex){