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