Salome HOME
MEDMEM suppression
[modules/med.git] / src / MEDMEMBinTest / test_MEDMEM_Meshing_poly.cxx
1 // Copyright (C) 2007-2013  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 #include "MEDMEM_Meshing.hxx"
23 #include "MEDMEM_DriverFactory.hxx"
24 #ifdef WIN32
25 #include <io.h>
26 #define access _access
27 #define W_OK 02
28 #endif
29
30 using namespace std;
31 using namespace MEDMEM;
32 using namespace MED_EN;
33 using namespace DRIVERFACTORY;
34
35 int main (int argc, char ** argv)
36 {
37     // Traitement arguments
38     if (argc > 2) 
39     {
40         cerr << "Usage : " << argv[0] 
41         << " filenameRoot" << endl << endl
42         << "-> creer un maillage et le sauve dans le fichier filenameRoot22.med sous le format Med Fichier V2.2 car il contient un polygon." << endl;
43         exit(-1);
44     }
45
46     string filenameRoot;
47     if (argc==2) 
48       filenameRoot= argv[1] ;
49     else {
50       if ( getenv("TMP") && access(getenv("TMP"),W_OK)==0 )
51         filenameRoot=getenv("TMP");
52       else if (getenv("TMPDIR") && access(getenv("TMPDIR"),W_OK)==0 )
53         filenameRoot=getenv("TMPDIR");
54       else
55         filenameRoot="/tmp";
56       filenameRoot+="/testMeshingPoly";
57     }
58
59     string medfilename  = filenameRoot + "22.med";
60
61     // Creation maillage
62     //***********************************************************************************
63
64       MESHING *myMeshing=new MESHING;
65       myMeshing->setName("myMeshing");
66
67       //   define coordinates
68
69       int SpaceDimension = 2;
70       int NumberOfNodes = 11;
71       double Coordinates[2*11] = {
72         0.0, 0.0,
73         0.5, 0.0,
74         1.0, 0.0,
75         0.25, 0.5,
76         0.5, 0.5,
77         0.75, 0.5,
78         0.0, 1.0,
79         0.5, 1.0,
80         1.0, 1.0,
81         1.5, 0.0,
82         1.5, 1.0,
83       };
84
85       myMeshing->setCoordinates(SpaceDimension,NumberOfNodes,Coordinates,"CARTESIAN",MED_FULL_INTERLACE);
86
87       string Names[3] = { "X","Y","Z" };
88       myMeshing->setCoordinatesNames(Names);
89
90       string Units[3] = { "cm","cm","cm" };
91       myMeshing->setCoordinatesUnits(Units);
92
93       //   define conectivities of classic types
94
95       //      cell part
96
97       const int NumberOfTypes = 3;
98       medGeometryElement Types[NumberOfTypes] = {MED_TRIA3,MED_QUAD4,MED_POLYGON};
99       const int NumberOfElements[NumberOfTypes] = {1,4,1};
100
101       myMeshing->setNumberOfTypes(NumberOfTypes,MED_CELL);
102       myMeshing->setTypes(Types,MED_CELL);
103       myMeshing->setNumberOfElements(NumberOfElements,MED_CELL);
104
105       int ConnectivityTria[1*3]=
106         {
107           7,4,1
108         };
109
110       myMeshing->setConnectivity(MED_CELL,MED_TRIA3,ConnectivityTria);
111
112       int ConnectivityQuad[4*4]=
113         {
114           4,5,2,1,
115           5,6,3,2,
116           7,8,5,4,
117           8,9,6,5
118         };
119   
120       myMeshing->setConnectivity(MED_CELL,MED_QUAD4,ConnectivityQuad);
121
122       // then define eventuel polygonal cells
123
124       int ConnectivityPolygon[1*5]=
125         {
126           9,11,10,3,6
127         };
128       int ConnectivityPolygonIndex[2]=
129         {
130           1,6
131         };
132
133       myMeshing->setConnectivity(MED_CELL,MED_POLYGON,ConnectivityPolygon,ConnectivityPolygonIndex);
134
135       // Ecriture fichier
136
137       int idMed22 = myMeshing->addDriver(MED_DRIVER,medfilename,myMeshing->getName());
138       myMeshing->write(idMed22) ;
139
140       //      int idVtk = myMeshing->addDriver(VTK_DRIVER,"toto.vtk",myMeshing->getName());
141       //      myMeshing->write(idVtk) ;
142       myMeshing->removeReference();
143
144   //************************************************************************************
145
146   // impression de controle
147   cout << endl;
148   cout << "Impression de MESHING : " << endl;
149   cout << myMeshing;
150
151   if (argc==1) {
152     cout << "Remove generated file" << endl;
153     remove( medfilename.c_str() );
154   }
155 }