Salome HOME
adding a new test for makeMesh method.
[modules/med.git] / src / INTERPOLATION / test_MEDMEM_InterpolationTimeStep.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "MEDMEM_Exception.hxx"
23 #include "MEDMEM_define.hxx"
24
25 #include "MEDMEM_Med.hxx"
26 #include "MEDMEM_Field.hxx"
27 #include "MEDMEM_Mesh.hxx"
28 #include "MEDMEM_Interpolation.hxx"
29
30 #include <deque>
31
32 #include "stdio.h"
33
34 using namespace MEDMEM;
35 using namespace MED_EN;
36
37 int main () {
38   const char * fromFileName   = "ResultatSyrthes.med";
39   const char * toFileName     = "MaillageAster.med";
40   const char * resultFileName = "ResultatInterpolation.med";
41
42   const char * fromFieldName  = "THERDEP_TEMP____________________";
43
44   const char * fromMeshName   = "MA";
45   const char * toMeshName     = "MAILLAGE_IDEAS";
46   int handle;
47
48   try {
49     
50     string flag="================[MAIN MESSAGE_MEDS]================> ";
51     
52     cout<<flag<<"Lecture de la structure MED               : "<<flush; 
53     MED             fromMED     (MED_DRIVER,fromFileName); 
54     cout<<"OK !"<<endl;
55     
56     // Utilisation completement débile, on ne devrait pas avoir a faire l'appel suivant
57     fromMED.updateSupport();
58
59     cout<<flag<<"Lecture du Mailllage Cible                : "<<flush; 
60     MESH            toMesh      (MED_DRIVER,toFileName,toMeshName); 
61     cout<<"OK !"<<endl;
62     
63     cout<<flag<<"Lecture des pas de temps                  : "<<flush; 
64     deque<DT_IT_> pasDeTemps=fromMED.getFieldIteration (fromFieldName); 
65     cout<<"OK !"<<endl;
66     
67     deque<DT_IT_>::const_iterator currentStep;
68     
69     INTERPOLATION<3>  * myInter ;
70     FIELD<double>   * toField   ;
71     int flagNewMapping = 1;
72
73     for (currentStep=pasDeTemps.begin();currentStep!=pasDeTemps.end();currentStep++)
74         {
75         cout<<flag<<"Traitement du Step ( "<<flush<<(*currentStep).dt<<" ; "<<(*currentStep).it<<" )  : "<<endl;
76         
77         cout<<flag<<"Lecture du FIELD_ "<<flush;
78         FIELD_ * fromField_ = fromMED.getField(fromFieldName,(*currentStep).dt,(*currentStep).it) ; 
79         cout<<"OK !"<<endl;
80     
81         cout<<flag<<"Transtypage en FIELD                      : "<<flush; 
82         FIELD<double> * fromField = dynamic_cast<FIELD<double> *>(fromField_); 
83         cout<<"OK !"<<endl;
84
85         // Utilisation completement débile, on ne devrait pas avoir a faire l'appel suivant
86         fromField->getSupport()->getMesh()->read();
87         
88         cout<<flag<<"Lecture des valeurs du FIELD              : "<<flush; fromField->read(); 
89         cout<<"OK !"<<endl;   
90         
91         if (currentStep==pasDeTemps.begin())
92                 {
93                 cout<<flag<<"Préparation de l'interpolation pour le premier pas de temps  : "<<flush;
94                 myInter = new INTERPOLATION<3>(*fromField,toMesh) ; 
95                 cout<<"OK !"<<endl;            
96
97                 cout<<flag<<"Interpolation effective du premier pas de temps              : "<<flush;
98                 toField = myInter->interpolate(1,1); 
99                 cout<<"OK !"<<endl;    
100                 }
101         else
102                 {
103                 cout<<flag<<"Interpolation nextStep              : "<<flush;
104                 toField = myInter->interpolateNextStep(*fromField,flagNewMapping); 
105                 cout<<"OK !"<<endl;    
106                 }
107     
108         cout<<flag<<"Creation du driver d'écriture Field       : "<<flush;
109         toField->addDriver(MED_DRIVER,resultFileName,toField->getName()); 
110         cout<<"OK !"<<endl;
111     
112         cout<<flag<<"Ecriture du Field résultat                : "<<flush;
113         toField->write(); 
114         cout<<"OK !"<<endl;
115     
116         if (flagNewMapping==1)
117                 {
118                 cout<<flag<<"Creation du driver d'écriture Mesh        : "<<flush; 
119                 handle = toMesh.addDriver(MED_DRIVER,resultFileName,toMesh.getName()) ; 
120                 cout<<"OK !"<<endl;
121     
122                 cout<<flag<<"Ecriture du Mesh résultat                 : "<<flush; 
123                 toMesh.write(handle); 
124                 cout<<"OK !"<<endl;
125                 }
126         }
127
128   } catch (MEDEXCEPTION& ex){
129     MESSAGE_MED(ex.what()) ;
130   }
131 }