Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / doc / MEDMEM / FIELDcreate.cxx
1 // Copyright (C) 2007-2012  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
23 using namespace std;
24 #include "MEDMEM_Mesh.hxx"
25 #include "MEDMEM_Field.hxx"
26
27 using namespace MEDMEM;
28 using namespace MED_EN ;
29
30 int main (int argc, char ** argv) {
31
32   const string MedFile = "pointe.med" ;
33   const string MeshName = "maa1" ;
34
35   /* read MESH */
36   MESH * myMesh = new MESH(MED_DRIVER,MedFile,MeshName) ;
37
38   // we need a support :
39   const SUPPORT * mySupport = myMesh->getSupportOnAll(MED_CELL);
40
41   /* create FIELD on mySupport, with 3 components */
42   int NumberOfCompoennts = 3 ;
43   FIELD<double> myField(mySupport,NumberOfCompoennts) ;
44   const string FieldName = "fieldcelldouble" ;
45   myField.setName(FieldName) ;
46
47   // Components information
48   string * ComponentsNames = new string[NumberOfCompoennts] ;
49   ComponentsNames[0] = "Vx" ;
50   ComponentsNames[1] = "Vy" ;
51   ComponentsNames[2] = "Vz" ;
52   myField.setComponentsNames(ComponentsNames) ;
53
54   string * ComponentsDescriptions = new string[NumberOfCompoennts] ;
55   ComponentsDescriptions[0] = "vitesse selon x" ;
56   ComponentsDescriptions[1] = "vitesse selon y" ;
57   ComponentsDescriptions[2] = "vitesse selon z" ;
58   myField.setComponentsDescriptions(ComponentsDescriptions) ;
59
60   string * ComponentsUnits = new string[NumberOfCompoennts] ;
61   ComponentsUnits[0] = "m.s-1" ;
62   ComponentsUnits[1] = "m.s-1" ;
63   ComponentsUnits[2] = "m.s-1" ;
64   myField.setMEDComponentsUnits(ComponentsUnits) ;
65   
66   // Iteration information :
67   int IterationNumber = 10 ; // set value to MED_NOPDT if undefined (default)
68   myField.setIterationNumber(IterationNumber) ;
69
70   int OrderNumber = 1 ; // set value to MED_NONOR if undefined (default)
71   myField.setOrderNumber(OrderNumber) ;
72
73   double Time = 3.435678 ; // in second
74   myField.setTime(Time) ;
75
76   // Value :
77   int NumberOfValue = mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
78   for(int i=1; i<=NumberOfValue; i++) // i^th element
79     for (int j=1; j<=NumberOfCompoennts; j++) { // j^th component
80       double myValue = (i+j) * 0.1 ;
81       myField.setValueIJ(i,j,myValue);
82     }
83   
84   // save this new field
85   myField.write(MED_DRIVER,filename) ;
86
87   return 0 ;
88 }