Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MEDMEM / test_MEDMEM_Meshing_poly.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #include "MEDMEM_Meshing.hxx"
21 #include "MEDMEM_DriverFactory.hxx"
22
23 using namespace std;
24 using namespace MEDMEM;
25 using namespace MED_EN;
26 using namespace DRIVERFACTORY;
27
28 int main (int argc, char ** argv)
29 {
30     // Traitement arguments
31     if (argc > 2) 
32     {
33         cerr << "Usage : " << argv[0] 
34         << " filenameRoot" << endl << endl
35         << "-> creer un maillage et le sauve dans le fichier filenameRoot22.med sous le format Med Fichier V2.2 car il contient un polygon." << endl;
36         exit(-1);
37     }
38
39     string filenameRoot;
40     if (argc==2) 
41       filenameRoot= argv[1] ;
42     else
43       filenameRoot="/tmp/testMeshingPoly";
44
45     string medfilename  = filenameRoot + "22.med";
46
47     // Creation maillage
48     //***********************************************************************************
49
50       MESHING myMeshing;
51       myMeshing.setName("myMeshing");
52
53       //   define coordinates
54
55       int SpaceDimension = 2;
56       int NumberOfNodes = 11;
57       double Coordinates[2*11] = {
58         0.0, 0.0,
59         0.5, 0.0,
60         1.0, 0.0,
61         0.25, 0.5,
62         0.5, 0.5,
63         0.75, 0.5,
64         0.0, 1.0,
65         0.5, 1.0,
66         1.0, 1.0,
67         1.5, 0.0,
68         1.5, 1.0,
69       };
70
71       myMeshing.setCoordinates(SpaceDimension,NumberOfNodes,Coordinates,"CARTESIAN",MED_FULL_INTERLACE);
72
73       string Names[3] = { "X","Y","Z" };
74       myMeshing.setCoordinatesNames(Names);
75
76       string Units[3] = { "cm","cm","cm" };
77       myMeshing.setCoordinatesUnits(Units);
78
79       //   define conectivities of classic types
80
81       //      cell part
82
83       const int NumberOfTypes = 2;
84       medGeometryElement Types[NumberOfTypes] = {MED_TRIA3,MED_QUAD4};
85       const int NumberOfElements[NumberOfTypes] = {1,4};
86
87       myMeshing.setNumberOfTypes(NumberOfTypes,MED_CELL);
88       myMeshing.setTypes(Types,MED_CELL);
89       myMeshing.setNumberOfElements(NumberOfElements,MED_CELL);
90
91       int ConnectivityTria[1*3]=
92         {
93           7,4,1
94         };
95
96       myMeshing.setConnectivity(ConnectivityTria,MED_CELL,MED_TRIA3);
97
98       int ConnectivityQuad[4*4]=
99         {
100           4,5,2,1,
101           5,6,3,2,
102           7,8,5,4,
103           8,9,6,5
104         };
105   
106       myMeshing.setConnectivity(ConnectivityQuad,MED_CELL,MED_QUAD4);
107
108       int MeshDimension = SpaceDimension ;
109       // because there are 2D cells in the mesh
110
111       myMeshing.setMeshDimension(MeshDimension) ;
112
113       // then define eventuel polygonal cells
114
115       int ConnectivityPolygon[1*5]=
116         {
117           9,11,10,3,6
118         };
119       int ConnectivityPolygonIndex[2]=
120         {
121           1,6
122         };
123
124       myMeshing.setPolygonsConnectivity(ConnectivityPolygonIndex,ConnectivityPolygon,1,MED_CELL);
125
126       // Ecriture fichier
127
128       medFileVersion version = getMedFileVersionForWriting();
129       if (version == V21)
130         setMedFileVersionForWriting(V22);
131
132       int idMed22 = myMeshing.addDriver(MED_DRIVER,medfilename,myMeshing.getName());
133       myMeshing.write(idMed22) ;
134
135       //      int idVtk = myMeshing.addDriver(VTK_DRIVER,"toto.vtk",myMeshing.getName());
136       //      myMeshing.write(idVtk) ;
137
138   //************************************************************************************
139
140   // impression de controle
141   cout << endl;
142   cout << "Impression de MESHING : " << endl;
143   cout << myMeshing;
144
145 }