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"
137 const char * fromFileName = "ResultatSyrthes.med";
138 const char * toFileName = "MaillageAster.med";
139 const char * resultFileName = "ResultatFlipback.med";
141 const char * fromFieldName = "THERDEP_TEMP____________________";
143 const char * fromMeshName = "MA";
144 const char * toMeshName = "MAILLAGE_IDEAS";
149 string flag="================[MAIN MESSAGES]================> ";
151 cout<<flag<<"Lecture de la structure MED : "<<flush;
152 MED fromMED (MED_DRIVER,fromFileName);
155 // Utilisation completement débile, on ne devrait pas avoir a faire l'appel suivant
156 fromMED.updateSupport();
158 cout<<flag<<"Lecture du Mailllage Cible : "<<flush;
159 MESH toMesh (MED_DRIVER,toFileName,toMeshName);
162 cout<<flag<<"Lecture des pas de temps : "<<flush;
163 deque<DT_IT_> pasDeTemps=fromMED.getFieldIteration (fromFieldName);
166 deque<DT_IT_>::const_iterator currentStep;
168 INTERPOLATION<3> * interFromTo ;
169 INTERPOLATION<3> * interToFrom ;
170 FIELD<double> * toField ;
171 FIELD<double> * toToField ;
172 int flagNewMappingFromTo = 0;
173 int flagNewMappingToFrom = 0;
175 for (currentStep=pasDeTemps.begin();currentStep!=pasDeTemps.end();currentStep++)
177 cout<<flag<<"Traitement du Step ( "<<flush<<(*currentStep).dt<<" ; "<<(*currentStep).it<<" ) : "<<endl;
179 cout<<flag<<"Lecture du FIELD_ "<<flush;
180 FIELD_ * fromField_ = fromMED.getField(fromFieldName,(*currentStep).dt,(*currentStep).it);
183 cout<<flag<<"Transtypage en FIELD : "<<flush;
184 FIELD<double> * fromField = dynamic_cast<FIELD<double> *>(fromField_);
187 if (currentStep==pasDeTemps.begin())
189 //Utilisation completement débile, on ne devrait pas avoir a faire l'appel suivant
190 RUN(fromField->getSupport()->getMesh()->read());
193 MESH * fromMesh = fromField->getSupport()->getMesh();
195 cout<<flag<<"Lecture des valeurs du FIELD : "<<flush;
196 RUN(fromField->read());
199 if (currentStep==pasDeTemps.begin())
201 cout<<flag<<"Préparation de l'interpolation DIRECTE pour le premier pas de temps : "<<flush;
202 RUN(interFromTo = new INTERPOLATION<3>(*fromField,toMesh));
204 cout<<flag<<"Interpolation effective DIRECTE du premier pas de temps : "<<flush;
205 RUN(toField = interFromTo->interpolate(1,1));
207 cout<<flag<<"Préparation de l'interpolation INVERSE pour le premier pas de temps : "<<flush;
208 RUN(interToFrom = new INTERPOLATION<3>(*toField,*fromMesh));
210 cout<<flag<<"Interpolation effective INVERSE du premier pas de temps : "<<flush;
211 RUN(toToField = interToFrom->interpolate(1,1));
216 cout<<flag<<"Interpolation nextStep DIRECTE : "<<flush;
217 RUN(toField = interFromTo->interpolateNextStep(*fromField,flagNewMappingFromTo));
219 cout<<flag<<"Interpolation nextStep INVERSE : "<<flush;
220 RUN(toToField = interToFrom->interpolateNextStep(*toField,flagNewMappingToFrom));
224 cout<<flag<<"Calcul du flip back : "<<flush;
225 Flipback(toToField,fromField);
228 cout<<flag<<"Creation du driver d'écriture Field : "<<flush;
229 toToField->addDriver(MED_DRIVER,resultFileName,toToField->getName());
232 cout<<flag<<"Ecriture du Field résultat : "<<flush;
236 if (flagNewMappingToFrom==1)
238 cout<<flag<<"Creation du driver d'écriture Mesh : "<<flush;
239 handle = fromMesh->addDriver(MED_DRIVER,resultFileName,fromMesh->getName()) ;
242 cout<<flag<<"Ecriture du Mesh résultat : "<<flush;
243 fromMesh->write(handle);
248 } catch (MEDEXCEPTION& ex){