Salome HOME
Building a version which will be tagged PreV2_0_0 working with KERNEL V1_4_0.
[modules/med.git] / src / MEDMEM / INTERPOLATION / test_MEDMEM_InterpolationTimeStep.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 main () {
14     
15   const char * fromFileName   = "ResultatSyrthes.med";
16   const char * toFileName     = "MaillageAster.med";
17   const char * resultFileName = "ResultatInterpolation.med";
18
19   const char * fromFieldName  = "THERDEP_TEMP____________________";
20
21   const char * fromMeshName   = "MA";
22   const char * toMeshName     = "MAILLAGE_IDEAS";
23   int handle;
24
25   try {
26     
27     string flag="================[MAIN MESSAGES]================> ";
28     
29     cout<<flag<<"Lecture de la structure MED               : "<<flush; 
30     MED             fromMED     (MED_DRIVER,fromFileName); 
31     cout<<"OK !"<<endl;
32     
33     // Utilisation completement débile, on ne devrait pas avoir a faire l'appel suivant
34     fromMED.updateSupport();
35
36     cout<<flag<<"Lecture du Mailllage Cible                : "<<flush; 
37     MESH            toMesh      (MED_DRIVER,toFileName,toMeshName); 
38     cout<<"OK !"<<endl;
39     
40     cout<<flag<<"Lecture des pas de temps                  : "<<flush; 
41     deque<DT_IT_> pasDeTemps=fromMED.getFieldIteration (fromFieldName); 
42     cout<<"OK !"<<endl;
43     
44     deque<DT_IT_>::const_iterator currentStep;
45     
46     INTERPOLATION<3>  * myInter ;
47     FIELD<double>   * toField   ;
48     int flagNewMapping = 1;
49
50     for (currentStep=pasDeTemps.begin();currentStep!=pasDeTemps.end();currentStep++)
51         {
52         cout<<flag<<"Traitement du Step ( "<<flush<<(*currentStep).dt<<" ; "<<(*currentStep).it<<" )  : "<<endl;
53         
54         cout<<flag<<"Lecture du FIELD_ "<<flush;
55         FIELD_ * fromField_ = fromMED.getField(fromFieldName,(*currentStep).dt,(*currentStep).it) ; 
56         cout<<"OK !"<<endl;
57     
58         cout<<flag<<"Transtypage en FIELD                      : "<<flush; 
59         FIELD<double> * fromField = dynamic_cast<FIELD<double> *>(fromField_); 
60         cout<<"OK !"<<endl;
61
62         // Utilisation completement débile, on ne devrait pas avoir a faire l'appel suivant
63         fromField->getSupport()->getMesh()->read();
64         
65         cout<<flag<<"Lecture des valeurs du FIELD              : "<<flush; fromField->read(); 
66         cout<<"OK !"<<endl;   
67         
68         if (currentStep==pasDeTemps.begin())
69                 {
70                 cout<<flag<<"Préparation de l'interpolation pour le premier pas de temps  : "<<flush;
71                 myInter = new INTERPOLATION<3>(*fromField,toMesh) ; 
72                 cout<<"OK !"<<endl;            
73
74                 cout<<flag<<"Interpolation effective du premier pas de temps              : "<<flush;
75                 toField = myInter->interpolate(1,1); 
76                 cout<<"OK !"<<endl;    
77                 }
78         else
79                 {
80                 cout<<flag<<"Interpolation nextStep              : "<<flush;
81                 toField = myInter->interpolateNextStep(*fromField,flagNewMapping); 
82                 cout<<"OK !"<<endl;    
83                 }
84     
85         cout<<flag<<"Creation du driver d'écriture Field       : "<<flush;
86         toField->addDriver(MED_DRIVER,resultFileName,toField->getName()); 
87         cout<<"OK !"<<endl;
88     
89         cout<<flag<<"Ecriture du Field résultat                : "<<flush;
90         toField->write(); 
91         cout<<"OK !"<<endl;
92     
93         if (flagNewMapping==1)
94                 {
95                 cout<<flag<<"Creation du driver d'écriture Mesh        : "<<flush; 
96                 handle = toMesh.addDriver(MED_DRIVER,resultFileName,toMesh.getName()) ; 
97                 cout<<"OK !"<<endl;
98     
99                 cout<<flag<<"Ecriture du Mesh résultat                 : "<<flush; 
100                 toMesh.write(handle); 
101                 cout<<"OK !"<<endl;
102                 }
103         }
104
105   } catch (MEDEXCEPTION& ex){
106     MESSAGE(ex.what()) ;
107   }
108 }