Back to index

salome-med  6.5.0
MESHINGexample.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 #include "MEDMEM_Meshing.hxx"
00024 #include "MEDMEM_Group.hxx"
00025 
00026 using namespace MEDMEM ;
00027 using namespace MED_EN ;
00028 
00029 using namespace std;
00030 
00031 int main (int argc, char ** argv) {
00032 
00033   // filename to save the generated MESH
00034   string filename = "meshing.med" ;
00035 
00036   MESHING* myMeshing = new MESHING;
00037   myMeshing->setName("meshing") ;
00038 
00039   // define coordinates
00040 
00041   int SpaceDimension = 3 ;
00042   int NumberOfNodes = 19 ;
00043   double Coordinates[57] = {
00044     0.0, 0.0, 0.0, 
00045     0.0, 0.0, 1.0, 
00046     2.0, 0.0, 1.0, 
00047     0.0, 2.0, 1.0, 
00048     -2.0, 0.0, 1.0, 
00049     0.0, -2.0, 1.0, 
00050     1.0, 1.0, 2.0, 
00051     -1.0, 1.0, 2.0, 
00052     -1.0, -1.0, 2.0, 
00053     1.0, -1.0, 2.0, 
00054     1.0, 1.0, 3.0, 
00055     -1.0, 1.0, 3.0, 
00056     -1.0, -1.0, 3.0, 
00057     1.0, -1.0, 3.0, 
00058     1.0, 1.0, 4.0, 
00059     -1.0, 1.0, 4.0, 
00060     -1.0, -1.0, 4.0, 
00061     1.0, -1.0, 4.0,
00062     0.0, 0.0, 5.0
00063   };
00064 
00065   myMeshing->setCoordinates(SpaceDimension,NumberOfNodes,Coordinates,"CARTESIAN",MED_FULL_INTERLACE);
00066 
00067   string Names[3] = { "X","Y","Z" } ;
00068   myMeshing->setCoordinatesNames(Names);
00069 
00070   string Units[3] = { "cm","cm","cm" } ;
00071   myMeshing->setCoordinatesUnits(Units) ;
00072 
00073   // define conectivities
00074 
00075   // cell part
00076   
00077   const int NumberOfTypes = 3 ;
00078   medGeometryElement Types[NumberOfTypes] = {MED_TETRA4,MED_PYRA5,MED_HEXA8} ;
00079   const int NumberOfElements[NumberOfTypes] = {12,2,2} ;
00080 
00081   myMeshing->setNumberOfTypes(NumberOfTypes,MED_CELL);
00082   myMeshing->setTypes(Types,MED_CELL);
00083   myMeshing->setNumberOfElements(NumberOfElements,MED_CELL);
00084 
00085   const int sizeTetra = 12*4 ;
00086   int ConnectivityTetra[sizeTetra]=
00087   {
00088     1,2,3,6,
00089     1,2,4,3,
00090     1,2,5,4,
00091     1,2,6,5,
00092     2,7,4,3,
00093     2,8,5,4,
00094     2,9,6,5,
00095     2,10,3,6,
00096     2,7,3,10,
00097     2,8,4,7,
00098     2,9,5,8,
00099     2,10,6,9
00100   };
00101   
00102   myMeshing->setConnectivity(MED_CELL,MED_TETRA4,ConnectivityTetra);
00103 
00104   int ConnectivityPyra[2*5]=
00105   {
00106     7,8,9,10,2,
00107     15,18,17,16,19
00108   };
00109 
00110   myMeshing->setConnectivity(MED_CELL,MED_PYRA5,ConnectivityPyra);
00111 
00112   int ConnectivityHexa[2*8]=
00113   {
00114     11,12,13,14,7,8,9,10,
00115     15,16,17,18,11,12,13,14
00116   };
00117 
00118   myMeshing->setConnectivity(MED_CELL,MED_HEXA8,ConnectivityHexa);
00119 
00120   // face part
00121 
00122   const int NumberOfFacesTypes = 2 ;
00123   medGeometryElement FacesTypes[NumberOfFacesTypes] = {MED_TRIA3,MED_QUAD4} ;
00124   const int NumberOfFacesElements[NumberOfFacesTypes] = {4,4} ;
00125 
00126   myMeshing->setNumberOfTypes(NumberOfFacesTypes,MED_FACE);
00127   myMeshing->setTypes(FacesTypes,MED_FACE);
00128   myMeshing->setNumberOfElements(NumberOfFacesElements,MED_FACE);
00129 
00130   const int sizeTria = 3*4 ;
00131   int ConnectivityTria[sizeTria]=
00132   {
00133     1,4,3,
00134     1,5,4,
00135     1,6,5,
00136     1,3,6
00137   };
00138   
00139   myMeshing->setConnectivity(MED_FACE,MED_TRIA3,ConnectivityTria);
00140 
00141   int ConnectivityQua[4*4]=
00142   {
00143     7,8,9,10,
00144     11,12,13,14,
00145     11,7,8,12,
00146     12,8,9,13
00147   };
00148 
00149   myMeshing->setConnectivity(MED_FACE,MED_QUAD4,ConnectivityQua);
00150 
00151   // edge part
00152 
00153   // not yet implemented : if set, results are unpredictable.
00154 
00155   // Some groups :
00156 
00157   // Node :
00158   {
00159     GROUP* myGroup = new GROUP;
00160     myGroup->setName("SomeNodes");
00161     myGroup->setMesh(myMeshing);
00162     myGroup->setEntity(MED_NODE);
00163     myGroup->setNumberOfGeometricType(1);
00164     medGeometryElement myTypes[1] = {MED_NONE};
00165     myGroup->setGeometricType(myTypes);
00166     const int myNumberOfElements[1] = {4} ;
00167     myGroup->setNumberOfElements(myNumberOfElements);
00168     const int index[1+1] = {1,5} ;
00169     const int value[4]= { 1,4,5,7} ;
00170     myGroup->setNumber(index,value);
00171     
00172     myMeshing->addGroup(*myGroup);
00173     myGroup->removeReference();
00174   }
00175   {
00176     GROUP* myGroup = new GROUP;
00177     myGroup->setName("OtherNodes");
00178     myGroup->setMesh(myMeshing);
00179     myGroup->setEntity(MED_NODE);
00180     myGroup->setNumberOfGeometricType(1);
00181     medGeometryElement myTypes[1] = {MED_NONE};
00182     myGroup->setGeometricType(myTypes);
00183     const int myNumberOfElements[1] = {3} ;
00184     myGroup->setNumberOfElements(myNumberOfElements);
00185     const int index[1+1] = {1,4} ;
00186     const int value[3]= { 2,3,6} ;
00187     myGroup->setNumber(index,value);
00188     
00189     myMeshing->addGroup(*myGroup);
00190     myGroup->removeReference();
00191   }
00192 
00193   // Cell :
00194   {
00195     GROUP* myGroup = new GROUP;
00196     myGroup->setName("SomeCells");
00197     myGroup->setMesh(myMeshing);
00198     myGroup->setEntity(MED_CELL);
00199     myGroup->setNumberOfGeometricType(3);
00200     medGeometryElement myTypes[3] = {MED_TETRA4,MED_PYRA5,MED_HEXA8};
00201     myGroup->setGeometricType(myTypes);
00202     const int myNumberOfElements[3] = {4,1,2} ;
00203     myGroup->setNumberOfElements(myNumberOfElements);
00204     const int index[3+1] = {1,5,6,8} ;
00205     const int value[4+1+2]=
00206     {
00207       2,7,8,12,
00208       13,
00209       15,16
00210     };
00211     myGroup->setNumber(index,value);
00212     
00213     myMeshing->addGroup(*myGroup);
00214     myGroup->removeReference();
00215   }
00216   {
00217     GROUP* myGroup = new GROUP;
00218     myGroup->setName("OtherCells");
00219     myGroup->setMesh(myMeshing);
00220     myGroup->setEntity(MED_CELL);
00221     myGroup->setNumberOfGeometricType(2);
00222     medGeometryElement myTypes[] = {MED_TETRA4,MED_PYRA5};
00223     myGroup->setGeometricType(myTypes);
00224     const int myNumberOfElements[] = {4,1} ;
00225     myGroup->setNumberOfElements(myNumberOfElements);
00226     const int index[3+1] = {1,5,6} ;
00227     const int value[4+1]=
00228     {
00229       3,4,5,9,
00230       14
00231     };
00232     myGroup->setNumber(index,value);
00233     
00234     myMeshing->addGroup(*myGroup);
00235     myGroup->removeReference();
00236   }
00237 
00238   // Face :
00239   {
00240     GROUP* myGroup = new GROUP;
00241     myGroup->setName("SomeFaces");
00242     myGroup->setMesh(myMeshing);
00243     myGroup->setEntity(MED_FACE);
00244     myGroup->setNumberOfGeometricType(2);
00245     medGeometryElement myTypes[2] = {MED_TRIA3,MED_QUAD4};
00246     myGroup->setGeometricType(myTypes);
00247     const int myNumberOfElements[2] = {2,3} ;
00248     myGroup->setNumberOfElements(myNumberOfElements);
00249     const int index[2+1] = {1,3,6} ;
00250     const int value[2+3]=
00251     {
00252       2,4,
00253       5,6,8
00254     } ;
00255     myGroup->setNumber(index,value);
00256     
00257     myMeshing->addGroup(*myGroup);
00258     myGroup->removeReference();
00259   }
00260   {
00261     GROUP* myGroup = new GROUP;
00262     myGroup->setName("OtherFaces");
00263     myGroup->setMesh(myMeshing);
00264     myGroup->setEntity(MED_FACE);
00265     myGroup->setNumberOfGeometricType(1);
00266     medGeometryElement myTypes[1] = {MED_TRIA3};
00267     myGroup->setGeometricType(myTypes);
00268     const int myNumberOfElements[1] = {2} ;
00269     myGroup->setNumberOfElements(myNumberOfElements);
00270     const int index[1+1] = {1,3} ;
00271     const int value[2]=
00272     {
00273       1,3
00274     } ;
00275     myGroup->setNumber(index,value);
00276     
00277     myMeshing->addGroup(*myGroup);
00278     myGroup->removeReference();
00279   }
00280 
00281   // all rigtht, we save it !
00282 
00283   int id = myMeshing->addDriver(MED_DRIVER,filename,myMeshing->getName());
00284   myMeshing->write(id) ;
00285   myMeshing->removeReference();
00286 }