Salome HOME
DCQ : Merge with Ecole Ete a6.
[modules/med.git] / src / MEDMEM / INTERPOLATION / test_MEDMEM_InterpolationRecopieMaillage.cxx
1 #include "MEDMEM_Exception.hxx"
2 #include "MEDMEM_define.hxx"
3
4 #include "MEDMEM_Med.hxx"
5 #include "MEDMEM_Field.hxx"
6 #include "MEDMEM_Mesh.hxx"
7 #include "MEDMEM_Interpolation.hxx"
8
9 #include <deque>
10
11 #include "stdio.h"
12
13
14
15 // pour gestion timings
16 #include "time.h"
17
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;}
20
21 double CPUtime()
22         {
23         #ifdef SYSTIMES
24         struct tms buf;
25         if (times(&buf)!=-1)
26                 return ((double)buf.tms_utime+(double)buf.tms_stime)/(long) sysconf(_SC_CLK_TCK);
27         else
28         #endif
29         return ((double) clock())/CLOCKS_PER_SEC;
30         }
31
32
33
34 #include "MEDMEM_WrapperCells.hxx"
35
36 main () {
37 /*
38 int taille=100;
39 int * liste = new int [taille] ;
40 int i,j;
41 int nbr_faces;
42 for (i=0;i<taille;i++) liste[i]=i;
43
44 Wrapper_Maille_Tria3   Tria3  ;Tria3  .positionne(liste);cout<<"Tria3  "<<endl;Tria3  .export_connectivite();
45 Wrapper_Maille_Tria6   Tria6  ;Tria6  .positionne(liste);cout<<"Tria6  "<<endl;Tria6  .export_connectivite();
46 Wrapper_Maille_Quad4   Quad4  ;Quad4  .positionne(liste);cout<<"Quad4  "<<endl;Quad4  .export_connectivite();
47 Wrapper_Maille_Quad8   Quad8  ;Quad8  .positionne(liste);cout<<"Quad8  "<<endl;Quad8  .export_connectivite();
48 Wrapper_Maille_Tetra4  Tetra4 ;Tetra4 .positionne(liste);cout<<"Tetra4 "<<endl;Tetra4 .export_connectivite();
49 Wrapper_Maille_Tetra10 Tetra10;Tetra10.positionne(liste);cout<<"Tetra10"<<endl;Tetra10.export_connectivite();
50 Wrapper_Maille_Hexa8   Hexa8  ;Hexa8  .positionne(liste);cout<<"Hexa8  "<<endl;Hexa8  .export_connectivite();
51 Wrapper_Maille_Hexa20  Hexa20 ;Hexa20 .positionne(liste);cout<<"Hexa20 "<<endl;Hexa20 .export_connectivite();
52 Wrapper_Maille_Pyra5   Pyra5  ;Pyra5  .positionne(liste);cout<<"Pyra5  "<<endl;Pyra5  .export_connectivite();
53 Wrapper_Maille_Pyra13  Pyra13 ;Pyra13 .positionne(liste);cout<<"Pyra13 "<<endl;Pyra13 .export_connectivite();
54 Wrapper_Maille_Penta6  Penta6 ;Penta6 .positionne(liste);cout<<"Penta6 "<<endl;Penta6 .export_connectivite();
55 Wrapper_Maille_Penta15 Penta15;Penta15.positionne(liste);cout<<"Penta15"<<endl;Penta15.export_connectivite();
56 //*/
57
58 //*    
59   const char * fromFileName   = "ResultatSyrthes.med";
60   const char * toFileName     = "MaillageAster.med";
61   const char * resultFileName = "ResultatInterpolation.med";
62
63   const char * fromFieldName  = "THERDEP_TEMP____________________";
64
65   const char * fromMeshName   = "MA";
66   const char * toMeshName     = "MAILLAGE_IDEAS";
67   int handle;
68
69   try {
70     
71     string flag="================[MAIN MESSAGES]================> ";
72     
73     cout<<flag<<"Lecture de la structure MED               : "<<flush; 
74     MED             fromMED     (MED_DRIVER,fromFileName); 
75     cout<<"OK !"<<endl;
76     
77     // Utilisation completement débile, on ne devrait pas avoir a faire l'appel suivant
78     fromMED.updateSupport();
79
80     cout<<flag<<"Lecture du Mailllage Cible                : "<<flush; 
81     MESH            toMesh      (MED_DRIVER,toFileName,toMeshName); 
82     cout<<"OK !"<<endl;
83     
84     cout<<flag<<"Lecture des pas de temps                  : "<<flush; 
85     deque<DT_IT_> pasDeTemps=fromMED.getFieldIteration (fromFieldName); 
86     cout<<"OK !"<<endl;
87     
88     deque<DT_IT_>::const_iterator currentStep;
89     
90     INTERPOLATION<3>  * myInter ;
91     FIELD<double>   * toField   ;
92     int flagNewMapping = 1;
93
94     for (currentStep=pasDeTemps.begin();currentStep!=pasDeTemps.end();currentStep++)
95         {
96         cout<<flag<<"Traitement du Step ( "<<flush<<(*currentStep).dt<<" ; "<<(*currentStep).it<<" )  : "<<endl;
97         
98         cout<<flag<<"Lecture du FIELD_ "<<flush;
99         FIELD_ * fromField_ = fromMED.getField(fromFieldName,(*currentStep).dt,(*currentStep).it);
100         cout<<"OK !"<<endl;
101     
102         cout<<flag<<"Transtypage en FIELD                      : "<<flush; 
103         FIELD<double> * fromField = dynamic_cast<FIELD<double> *>(fromField_);
104         cout<<"OK !"<<endl;
105         
106         if (currentStep==pasDeTemps.begin())
107                 {
108                 //Utilisation completement débile, on ne devrait pas avoir a faire l'appel suivant
109                 RUN(fromField->getSupport()->getMesh()->read());
110                 }
111                 
112         cout<<flag<<"Lecture des valeurs du FIELD              : "<<flush; 
113         RUN(fromField->read()); 
114         cout<<"OK !"<<endl;   
115         
116         if (currentStep==pasDeTemps.begin())
117                 {
118                 cout<<flag<<"Préparation de l'interpolation pour le premier pas de temps  : "<<flush;
119                 RUN(myInter = new INTERPOLATION<3>(*fromField,toMesh));
120                 cout<<"OK !"<<endl;            
121                 cout<<flag<<"Interpolation effective du premier pas de temps              : "<<flush;
122                 RUN(toField = myInter->interpolate(1,1));
123                 cout<<"OK !"<<endl;    
124                 }
125         else
126                 {
127                 cout<<flag<<"Interpolation nextStep              : "<<flush;
128                 RUN(toField = myInter->interpolateNextStep(*fromField,flagNewMapping));
129                 cout<<"OK !"<<endl;    
130                 }
131     
132         cout<<flag<<"Creation du driver d'écriture Field       : "<<flush;
133         toField->addDriver(MED_DRIVER,resultFileName,toField->getName()); 
134         cout<<"OK !"<<endl;
135     
136         cout<<flag<<"Ecriture du Field résultat                : "<<flush;
137         toField->write(); 
138         cout<<"OK !"<<endl;
139     
140         if (flagNewMapping==1)
141                 {
142                 cout<<flag<<"Creation du driver d'écriture Mesh        : "<<flush; 
143                 handle = toMesh.addDriver(MED_DRIVER,resultFileName,toMesh.getName()) ; 
144                 cout<<"OK !"<<endl;
145     
146                 cout<<flag<<"Ecriture du Mesh résultat                 : "<<flush; 
147                 toMesh.write(handle); 
148                 cout<<"OK !"<<endl;
149                 }
150         }
151
152   } catch (MEDEXCEPTION& ex){
153     MESSAGE(ex.what()) ;
154   }
155 //*/
156 }