Back to index

salome-med  6.5.0
test_MEDMEM_Meshing_poly.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 #include "MEDMEM_Meshing.hxx"
00023 #include "MEDMEM_DriverFactory.hxx"
00024 #ifdef WNT
00025 #include <io.h>
00026 #define access _access
00027 #define W_OK 02
00028 #endif
00029 
00030 using namespace std;
00031 using namespace MEDMEM;
00032 using namespace MED_EN;
00033 using namespace DRIVERFACTORY;
00034 
00035 int main (int argc, char ** argv)
00036 {
00037     // Traitement arguments
00038     if (argc > 2) 
00039     {
00040         cerr << "Usage : " << argv[0] 
00041         << " filenameRoot" << endl << endl
00042         << "-> creer un maillage et le sauve dans le fichier filenameRoot22.med sous le format Med Fichier V2.2 car il contient un polygon." << endl;
00043         exit(-1);
00044     }
00045 
00046     string filenameRoot;
00047     if (argc==2) 
00048       filenameRoot= argv[1] ;
00049     else {
00050       if ( getenv("TMP") && access(getenv("TMP"),W_OK)==0 )
00051         filenameRoot=getenv("TMP");
00052       else if (getenv("TMPDIR") && access(getenv("TMPDIR"),W_OK)==0 )
00053         filenameRoot=getenv("TMPDIR");
00054       else
00055         filenameRoot="/tmp";
00056       filenameRoot+="/testMeshingPoly";
00057     }
00058 
00059     string medfilename  = filenameRoot + "22.med";
00060 
00061     // Creation maillage
00062     //***********************************************************************************
00063 
00064       MESHING *myMeshing=new MESHING;
00065       myMeshing->setName("myMeshing");
00066 
00067       //   define coordinates
00068 
00069       int SpaceDimension = 2;
00070       int NumberOfNodes = 11;
00071       double Coordinates[2*11] = {
00072         0.0, 0.0,
00073         0.5, 0.0,
00074         1.0, 0.0,
00075         0.25, 0.5,
00076         0.5, 0.5,
00077         0.75, 0.5,
00078         0.0, 1.0,
00079         0.5, 1.0,
00080         1.0, 1.0,
00081         1.5, 0.0,
00082         1.5, 1.0,
00083       };
00084 
00085       myMeshing->setCoordinates(SpaceDimension,NumberOfNodes,Coordinates,"CARTESIAN",MED_FULL_INTERLACE);
00086 
00087       string Names[3] = { "X","Y","Z" };
00088       myMeshing->setCoordinatesNames(Names);
00089 
00090       string Units[3] = { "cm","cm","cm" };
00091       myMeshing->setCoordinatesUnits(Units);
00092 
00093       //   define conectivities of classic types
00094 
00095       //      cell part
00096 
00097       const int NumberOfTypes = 3;
00098       medGeometryElement Types[NumberOfTypes] = {MED_TRIA3,MED_QUAD4,MED_POLYGON};
00099       const int NumberOfElements[NumberOfTypes] = {1,4,1};
00100 
00101       myMeshing->setNumberOfTypes(NumberOfTypes,MED_CELL);
00102       myMeshing->setTypes(Types,MED_CELL);
00103       myMeshing->setNumberOfElements(NumberOfElements,MED_CELL);
00104 
00105       int ConnectivityTria[1*3]=
00106         {
00107           7,4,1
00108         };
00109 
00110       myMeshing->setConnectivity(MED_CELL,MED_TRIA3,ConnectivityTria);
00111 
00112       int ConnectivityQuad[4*4]=
00113         {
00114           4,5,2,1,
00115           5,6,3,2,
00116           7,8,5,4,
00117           8,9,6,5
00118         };
00119   
00120       myMeshing->setConnectivity(MED_CELL,MED_QUAD4,ConnectivityQuad);
00121 
00122       // then define eventuel polygonal cells
00123 
00124       int ConnectivityPolygon[1*5]=
00125         {
00126           9,11,10,3,6
00127         };
00128       int ConnectivityPolygonIndex[2]=
00129         {
00130           1,6
00131         };
00132 
00133       myMeshing->setConnectivity(MED_CELL,MED_POLYGON,ConnectivityPolygon,ConnectivityPolygonIndex);
00134 
00135       // Ecriture fichier
00136 
00137       int idMed22 = myMeshing->addDriver(MED_DRIVER,medfilename,myMeshing->getName());
00138       myMeshing->write(idMed22) ;
00139 
00140       //      int idVtk = myMeshing->addDriver(VTK_DRIVER,"toto.vtk",myMeshing->getName());
00141       //      myMeshing->write(idVtk) ;
00142       myMeshing->removeReference();
00143 
00144   //************************************************************************************
00145 
00146   // impression de controle
00147   cout << endl;
00148   cout << "Impression de MESHING : " << endl;
00149   cout << myMeshing;
00150 
00151   if (argc==1) {
00152     cout << "Remove generated file" << endl;
00153     remove( medfilename.c_str() );
00154   }
00155 }