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