Back to index

salome-med  6.5.0
FIELDcreate.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 using namespace std;
00024 #include "MEDMEM_Mesh.hxx"
00025 #include "MEDMEM_Field.hxx"
00026 
00027 using namespace MEDMEM;
00028 using namespace MED_EN ;
00029 
00030 int main (int argc, char ** argv) {
00031 
00032   const string MedFile = "pointe.med" ;
00033   const string MeshName = "maa1" ;
00034 
00035   /* read MESH */
00036   MESH * myMesh = new MESH(MED_DRIVER,MedFile,MeshName) ;
00037 
00038   // we need a support :
00039   const SUPPORT * mySupport = myMesh->getSupportOnAll(MED_CELL);
00040 
00041   /* create FIELD on mySupport, with 3 components */
00042   int NumberOfCompoennts = 3 ;
00043   FIELD<double> myField(mySupport,NumberOfCompoennts) ;
00044   const string FieldName = "fieldcelldouble" ;
00045   myField.setName(FieldName) ;
00046 
00047   // Components information
00048   string * ComponentsNames = new string[NumberOfCompoennts] ;
00049   ComponentsNames[0] = "Vx" ;
00050   ComponentsNames[1] = "Vy" ;
00051   ComponentsNames[2] = "Vz" ;
00052   myField.setComponentsNames(ComponentsNames) ;
00053 
00054   string * ComponentsDescriptions = new string[NumberOfCompoennts] ;
00055   ComponentsDescriptions[0] = "vitesse selon x" ;
00056   ComponentsDescriptions[1] = "vitesse selon y" ;
00057   ComponentsDescriptions[2] = "vitesse selon z" ;
00058   myField.setComponentsDescriptions(ComponentsDescriptions) ;
00059 
00060   string * ComponentsUnits = new string[NumberOfCompoennts] ;
00061   ComponentsUnits[0] = "m.s-1" ;
00062   ComponentsUnits[1] = "m.s-1" ;
00063   ComponentsUnits[2] = "m.s-1" ;
00064   myField.setMEDComponentsUnits(ComponentsUnits) ;
00065   
00066   // Iteration information :
00067   int IterationNumber = 10 ; // set value to MED_NOPDT if undefined (default)
00068   myField.setIterationNumber(IterationNumber) ;
00069 
00070   int OrderNumber = 1 ; // set value to MED_NONOR if undefined (default)
00071   myField.setOrderNumber(OrderNumber) ;
00072 
00073   double Time = 3.435678 ; // in second
00074   myField.setTime(Time) ;
00075 
00076   // Value :
00077   int NumberOfValue = mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
00078   for(int i=1; i<=NumberOfValue; i++) // i^th element
00079     for (int j=1; j<=NumberOfCompoennts; j++) { // j^th component
00080       double myValue = (i+j) * 0.1 ;
00081       myField.setValueIJ(i,j,myValue);
00082     }
00083   
00084   // save this new field
00085   myField.write(MED_DRIVER,filename) ;
00086 
00087   return 0 ;
00088 }