Back to index

salome-med  6.5.0
test_MEDMEM_MeshingFlica.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 #ifdef WNT
00026 #include <io.h>
00027 #define access _access
00028 #define W_OK 02
00029 #endif
00030 
00031 double coords[108]=
00032   {0, 0.21504, 0.21504, 0, 0.43008, 
00033    0.43008, 0.21504, 0, 0.43008, 0, 
00034    0.21504, 0.21504, 0, 0.43008, 
00035    0.43008, 0.21504, 0, 0.43008, 0, 
00036    0.21504, 0.21504, 0, 0.43008, 
00037    0.43008, 0.21504, 0, 0.43008, 0, 
00038    0.21504, 0.21504, 0, 0.43008, 
00039    0.43008, 0.21504, 0, 0.43008,
00040    //coordY
00041    0, 0, 0.21504, 0.21504, 0, 0.21504, 
00042    0.43008, 0.43008, 0.43008, 0, 0, 
00043    0.21504, 0.21504, 0, 0.21504, 
00044    0.43008, 0.43008, 0.43008, 0, 0, 
00045    0.21504, 0.21504, 0, 0.21504, 
00046    0.43008, 0.43008, 0.43008, 0, 0, 
00047    0.21504, 0.21504, 0, 0.21504, 
00048    0.43008, 0.43008, 0.43008,
00049    //coordZ
00050    0, 0, 0, 0, 0, 0, 0, 0, 0, 0.15677, 0.15677, 
00051    0.15677, 0.15677, 0.15677, 
00052    0.15677, 0.15677, 0.15677, 
00053    0.15677, 0.1934, 0.1934, 
00054    0.1934, 0.1934, 0.1934, 
00055    0.1934, 0.1934, 0.1934, 
00056    0.1934, 0.3485, 0.3485, 
00057    0.3485, 0.3485, 0.3485, 
00058    0.3485, 0.3485, 0.3485, 
00059    0.3485};
00060 
00061 int connNodalCellClassical[48]=
00062   { 1, 2, 3, 4, 10, 11, 12, 13, 
00063     4, 3, 7, 8, 13, 12, 16, 17, 
00064     10, 11, 12, 13, 19, 20, 21, 22, 
00065     13, 12, 16, 17, 22, 21, 25, 26, 
00066     19, 20, 21, 22, 28, 29, 30, 31,
00067     22, 21, 25, 26, 31, 30, 34, 35 };
00068 
00069 int polyHedraInd[7]={1, 30, 59, 88, 117, 146, 175};
00070 
00071 int polyHedraConn[174]={ 
00072   2,  3,  6,  5,  -1, 11, 14, 15, 12, -1, 2,  5,  14, 11, -1, 5,  6,  15, 14, -1, 6,  3,  12, 15, -1, 3,  2,  11, 12, 
00073   3,  7,  9,  6,  -1, 12, 15, 18, 16, -1, 3,  6,  15, 12, -1, 6,  9,  18, 15, -1, 9,  7,  16, 18, -1, 7,  3,  12, 16, 
00074   11, 12, 15, 14, -1, 20, 23, 24, 21, -1, 11, 14, 23, 20, -1, 14, 15, 24, 23, -1, 15, 12, 21, 24, -1, 12, 11, 20, 21, 
00075   12, 16, 18, 15, -1, 21, 24, 27, 25, -1, 12, 15, 24, 21, -1, 15, 18, 27, 24, -1, 18, 16, 25, 27, -1, 16, 12, 21, 25, 
00076   20, 21, 24, 23, -1, 29, 32, 33, 30, -1, 20, 23, 32, 29, -1, 23, 24, 33, 32, -1, 24, 21, 30, 33, -1, 21, 20, 29, 30, 
00077   21, 25, 27, 24, -1, 30, 33, 36, 34, -1, 21, 24, 33, 30, -1, 24, 27, 36, 33, -1, 27, 25, 34, 36, -1, 25, 21, 30, 34 };
00078 
00079 int connNodalFaceClassical[116]=
00080   { 1, 2, 3, 4, 
00081     10, 13, 12, 11, 
00082     1, 2, 11, 10, 
00083     2, 3, 12, 11, 
00084     3, 4, 13, 12, 
00085     4, 1, 10, 13, 
00086     4, 3, 7, 8, 
00087     13, 17, 16, 12, 
00088     3, 7, 16, 12, 
00089     7, 8, 17, 16, 
00090     8, 4, 13, 17, 
00091     19, 22, 21, 20, 
00092     10, 11, 20, 19,
00093     11, 12, 21, 20, 
00094     12, 13, 22, 21, 
00095     13, 10, 19, 22, 
00096     22, 26, 25, 21, 
00097     12, 16, 25, 21, 
00098     16, 17, 26, 25, 
00099     17, 13, 22, 26, 
00100     28, 31, 30, 29, 
00101     19, 20, 29, 28, 
00102     20, 21, 30, 29, 
00103     21, 22, 31, 30, 
00104     22, 19, 28, 31, 
00105     31, 35, 34, 30, 
00106     21, 25, 34, 30, 
00107     25, 26, 35, 34, 
00108     26, 22, 31, 35};
00109 
00110 int cpolygonsIndex[24]=
00111   { 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 
00112     73, 77, 81, 85, 89, 93};
00113 
00114 int cpolygonsValue[92]=
00115   {2, 5, 6, 3, 
00116    11, 12, 15, 14, 
00117    2, 5, 14, 11, 
00118    5, 6, 15, 14, 
00119    6, 3, 12, 15, 
00120    3, 6, 9, 7, 
00121    12, 16, 18, 15, 
00122    6, 9, 18, 15, 
00123    9, 7, 16, 18, 
00124    20, 21, 24, 23, 
00125    11, 14, 23, 20, 
00126    14, 15, 24, 23, 
00127    15, 12, 21, 24, 
00128    21, 25, 27, 24, 
00129    15, 18, 27, 24, 
00130    18, 16, 25, 27, 
00131    29, 30, 33, 32, 
00132    20, 23, 32, 29, 
00133    23, 24, 33, 32, 
00134    24, 21, 30, 33, 
00135    30, 34, 36, 33, 
00136    24, 27, 36, 33, 
00137    27, 25, 34, 36};
00138 
00139 int bottom[4]={1,7,30,35};
00140 MED_EN::medGeometryElement bottomTypes[2]={MED_EN::MED_QUAD4, MED_EN::MED_POLYGON };
00141 int bottomIndex[3]={1,3,5};
00142 int bottomNbOfElts[2]={2,2};
00143 int top[4]={21,26,46,50};
00144 MED_EN::medGeometryElement topTypes[2]={MED_EN::MED_QUAD4, MED_EN::MED_POLYGON };
00145 int topIndex[3]={1,3,5};
00146 int topNbOfElts[2]={2,2};
00147 int side[24]={ 3, 6, 10, 11, 13, 16, 19, 20, 22, 25, 28, 29, 32, 33, 37, 38, 40, 41, 44, 45, 47, 48, 51, 52};
00148 MED_EN::medGeometryElement sideTypes[2]={MED_EN::MED_QUAD4, MED_EN::MED_POLYGON };
00149 int sideIndex[3]={1,13,25};
00150 int sideNbOfElts[2]={12,12};
00151 
00152 using namespace MEDMEM;
00153 
00154 static void addMedFacesGroup( MESHING& meshing, int nFaces, const int *groupValue,
00155                        string groupName, const MED_EN::medGeometryElement *mytypes,  const int *index, const int *myNumberOfElements, int nbOfGeomTypes)
00156   {
00157     GROUP *faces=new GROUP;
00158     faces->setName(groupName) ;
00159     faces->setMesh(&meshing) ;
00160     faces->setEntity(MED_EN::MED_FACE) ;
00161     faces->setNumberOfGeometricType(nbOfGeomTypes) ;
00162     faces->setGeometricType(mytypes);
00163     faces->setNumberOfElements(myNumberOfElements) ;
00164     faces->setNumber(index, groupValue) ;
00165     meshing.addGroup(*faces) ;
00166     faces->removeReference();
00167   }
00168 
00169 int main()
00170 {
00171   MESHING* meshing = new MESHING;
00172   meshing->setName( "TESTMESH" );
00173   const int nNodes=36;
00174   meshing->setCoordinates(3, nNodes, coords, "CARTESIAN",
00175                           MED_EN::MED_NO_INTERLACE);
00176   string coordname[3] = { "x", "y", "z" };
00177   meshing->setCoordinatesNames(coordname);
00178   string coordunit[3] = { "m", "m", "m" };
00179   meshing->setCoordinatesUnits(coordunit);
00180   //Cell connectivity info for classical elts
00181   const MED_EN::medGeometryElement classicalTypesCell[2]={MED_EN::MED_HEXA8,MED_EN::MED_POLYHEDRA};
00182   const int nbOfCellElts[2]={6,6};
00183   meshing->setNumberOfTypes(2,MED_EN::MED_CELL);
00184   meshing->setTypes(classicalTypesCell,MED_EN::MED_CELL);
00185   meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
00186   //Face connectivity info for classical elts
00187   const MED_EN::medGeometryElement classicalTypesFace[2]={MED_EN::MED_QUAD4,MED_EN::MED_POLYGON};
00188   const int nbOfFaceElts[2]={29,23};
00189   meshing->setNumberOfTypes(2,MED_EN::MED_FACE);
00190   meshing->setTypes(classicalTypesFace,MED_EN::MED_FACE);
00191   meshing->setNumberOfElements(nbOfFaceElts,MED_EN::MED_FACE);
00192   //All cell conn
00193   meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_HEXA8,connNodalCellClassical);
00194   meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_POLYHEDRA,polyHedraConn,polyHedraInd);
00195   //All face conn
00196   meshing->setConnectivity(MED_EN::MED_FACE,MED_EN::MED_QUAD4,connNodalFaceClassical);
00197   meshing->setConnectivity(MED_EN::MED_FACE,MED_EN::MED_POLYGON, cpolygonsValue,cpolygonsIndex);
00198   //Adding some groups on faces
00199   addMedFacesGroup( *meshing, 4,  bottom, "BottomFaces",bottomTypes,bottomIndex,bottomNbOfElts,2) ;
00200   addMedFacesGroup( *meshing, 4,  top,    "TopFaces",topTypes,topIndex,topNbOfElts,2) ;
00201   addMedFacesGroup( *meshing, 24, side,   "SideFaces",sideTypes,sideIndex,sideNbOfElts,2) ;
00202   //writing...
00203   string medfile = "/tmp";
00204   if ( getenv("TMP") && access(getenv("TMP"),W_OK)==0 )
00205     medfile=getenv("TMP");
00206   else if (getenv("TMPDIR") && access(getenv("TMPDIR"),W_OK)==0 )
00207     medfile=getenv("TMPDIR");
00208   medfile += "/totoFlica_V22.med";
00209   
00210   int id=meshing->addDriver(MED_DRIVER,medfile.c_str());
00211   meshing->write(id);
00212   meshing->removeReference();
00213 
00214   if ( getenv("srcdir") )
00215     remove(medfile.c_str());
00216 
00217   return 0;
00218 }