Salome HOME
e82ee51a687f7e06b3e809ef18aeb0c7e304f928
[modules/med.git] / src / MEDMEMBinTest / test_MEDMEM_MeshingFlica.cxx
1 // Copyright (C) 2007-2012  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
23 #include "MEDMEM_Meshing.hxx"
24 #include "MEDMEM_Group.hxx"
25 #ifdef WNT
26 #include <io.h>
27 #define access _access
28 #define W_OK 02
29 #else
30 #include <unistd.h>
31 #endif
32
33 double coords[108]=
34   {0, 0.21504, 0.21504, 0, 0.43008, 
35    0.43008, 0.21504, 0, 0.43008, 0, 
36    0.21504, 0.21504, 0, 0.43008, 
37    0.43008, 0.21504, 0, 0.43008, 0, 
38    0.21504, 0.21504, 0, 0.43008, 
39    0.43008, 0.21504, 0, 0.43008, 0, 
40    0.21504, 0.21504, 0, 0.43008, 
41    0.43008, 0.21504, 0, 0.43008,
42    //coordY
43    0, 0, 0.21504, 0.21504, 0, 0.21504, 
44    0.43008, 0.43008, 0.43008, 0, 0, 
45    0.21504, 0.21504, 0, 0.21504, 
46    0.43008, 0.43008, 0.43008, 0, 0, 
47    0.21504, 0.21504, 0, 0.21504, 
48    0.43008, 0.43008, 0.43008, 0, 0, 
49    0.21504, 0.21504, 0, 0.21504, 
50    0.43008, 0.43008, 0.43008,
51    //coordZ
52    0, 0, 0, 0, 0, 0, 0, 0, 0, 0.15677, 0.15677, 
53    0.15677, 0.15677, 0.15677, 
54    0.15677, 0.15677, 0.15677, 
55    0.15677, 0.1934, 0.1934, 
56    0.1934, 0.1934, 0.1934, 
57    0.1934, 0.1934, 0.1934, 
58    0.1934, 0.3485, 0.3485, 
59    0.3485, 0.3485, 0.3485, 
60    0.3485, 0.3485, 0.3485, 
61    0.3485};
62
63 int connNodalCellClassical[48]=
64   { 1, 2, 3, 4, 10, 11, 12, 13, 
65     4, 3, 7, 8, 13, 12, 16, 17, 
66     10, 11, 12, 13, 19, 20, 21, 22, 
67     13, 12, 16, 17, 22, 21, 25, 26, 
68     19, 20, 21, 22, 28, 29, 30, 31,
69     22, 21, 25, 26, 31, 30, 34, 35 };
70
71 int polyHedraInd[7]={1, 30, 59, 88, 117, 146, 175};
72
73 int polyHedraConn[174]={ 
74   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, 
75   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, 
76   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, 
77   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, 
78   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, 
79   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 };
80
81 int connNodalFaceClassical[116]=
82   { 1, 2, 3, 4, 
83     10, 13, 12, 11, 
84     1, 2, 11, 10, 
85     2, 3, 12, 11, 
86     3, 4, 13, 12, 
87     4, 1, 10, 13, 
88     4, 3, 7, 8, 
89     13, 17, 16, 12, 
90     3, 7, 16, 12, 
91     7, 8, 17, 16, 
92     8, 4, 13, 17, 
93     19, 22, 21, 20, 
94     10, 11, 20, 19,
95     11, 12, 21, 20, 
96     12, 13, 22, 21, 
97     13, 10, 19, 22, 
98     22, 26, 25, 21, 
99     12, 16, 25, 21, 
100     16, 17, 26, 25, 
101     17, 13, 22, 26, 
102     28, 31, 30, 29, 
103     19, 20, 29, 28, 
104     20, 21, 30, 29, 
105     21, 22, 31, 30, 
106     22, 19, 28, 31, 
107     31, 35, 34, 30, 
108     21, 25, 34, 30, 
109     25, 26, 35, 34, 
110     26, 22, 31, 35};
111
112 int cpolygonsIndex[24]=
113   { 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 
114     73, 77, 81, 85, 89, 93};
115
116 int cpolygonsValue[92]=
117   {2, 5, 6, 3, 
118    11, 12, 15, 14, 
119    2, 5, 14, 11, 
120    5, 6, 15, 14, 
121    6, 3, 12, 15, 
122    3, 6, 9, 7, 
123    12, 16, 18, 15, 
124    6, 9, 18, 15, 
125    9, 7, 16, 18, 
126    20, 21, 24, 23, 
127    11, 14, 23, 20, 
128    14, 15, 24, 23, 
129    15, 12, 21, 24, 
130    21, 25, 27, 24, 
131    15, 18, 27, 24, 
132    18, 16, 25, 27, 
133    29, 30, 33, 32, 
134    20, 23, 32, 29, 
135    23, 24, 33, 32, 
136    24, 21, 30, 33, 
137    30, 34, 36, 33, 
138    24, 27, 36, 33, 
139    27, 25, 34, 36};
140
141 int bottom[4]={1,7,30,35};
142 MED_EN::medGeometryElement bottomTypes[2]={MED_EN::MED_QUAD4, MED_EN::MED_POLYGON };
143 int bottomIndex[3]={1,3,5};
144 int bottomNbOfElts[2]={2,2};
145 int top[4]={21,26,46,50};
146 MED_EN::medGeometryElement topTypes[2]={MED_EN::MED_QUAD4, MED_EN::MED_POLYGON };
147 int topIndex[3]={1,3,5};
148 int topNbOfElts[2]={2,2};
149 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};
150 MED_EN::medGeometryElement sideTypes[2]={MED_EN::MED_QUAD4, MED_EN::MED_POLYGON };
151 int sideIndex[3]={1,13,25};
152 int sideNbOfElts[2]={12,12};
153
154 using namespace MEDMEM;
155
156 static void addMedFacesGroup( MESHING& meshing, int nFaces, const int *groupValue,
157                        string groupName, const MED_EN::medGeometryElement *mytypes,  const int *index, const int *myNumberOfElements, int nbOfGeomTypes)
158   {
159     GROUP *faces=new GROUP;
160     faces->setName(groupName) ;
161     faces->setMesh(&meshing) ;
162     faces->setEntity(MED_EN::MED_FACE) ;
163     faces->setNumberOfGeometricType(nbOfGeomTypes) ;
164     faces->setGeometricType(mytypes);
165     faces->setNumberOfElements(myNumberOfElements) ;
166     faces->setNumber(index, groupValue) ;
167     meshing.addGroup(*faces) ;
168     faces->removeReference();
169   }
170
171 int main()
172 {
173   MESHING* meshing = new MESHING;
174   meshing->setName( "TESTMESH" );
175   const int nNodes=36;
176   meshing->setCoordinates(3, nNodes, coords, "CARTESIAN",
177                           MED_EN::MED_NO_INTERLACE);
178   string coordname[3] = { "x", "y", "z" };
179   meshing->setCoordinatesNames(coordname);
180   string coordunit[3] = { "m", "m", "m" };
181   meshing->setCoordinatesUnits(coordunit);
182   //Cell connectivity info for classical elts
183   const MED_EN::medGeometryElement classicalTypesCell[2]={MED_EN::MED_HEXA8,MED_EN::MED_POLYHEDRA};
184   const int nbOfCellElts[2]={6,6};
185   meshing->setNumberOfTypes(2,MED_EN::MED_CELL);
186   meshing->setTypes(classicalTypesCell,MED_EN::MED_CELL);
187   meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
188   //Face connectivity info for classical elts
189   const MED_EN::medGeometryElement classicalTypesFace[2]={MED_EN::MED_QUAD4,MED_EN::MED_POLYGON};
190   const int nbOfFaceElts[2]={29,23};
191   meshing->setNumberOfTypes(2,MED_EN::MED_FACE);
192   meshing->setTypes(classicalTypesFace,MED_EN::MED_FACE);
193   meshing->setNumberOfElements(nbOfFaceElts,MED_EN::MED_FACE);
194   //All cell conn
195   meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_HEXA8,connNodalCellClassical);
196   meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_POLYHEDRA,polyHedraConn,polyHedraInd);
197   //All face conn
198   meshing->setConnectivity(MED_EN::MED_FACE,MED_EN::MED_QUAD4,connNodalFaceClassical);
199   meshing->setConnectivity(MED_EN::MED_FACE,MED_EN::MED_POLYGON, cpolygonsValue,cpolygonsIndex);
200   //Adding some groups on faces
201   addMedFacesGroup( *meshing, 4,  bottom, "BottomFaces",bottomTypes,bottomIndex,bottomNbOfElts,2) ;
202   addMedFacesGroup( *meshing, 4,  top,    "TopFaces",topTypes,topIndex,topNbOfElts,2) ;
203   addMedFacesGroup( *meshing, 24, side,   "SideFaces",sideTypes,sideIndex,sideNbOfElts,2) ;
204   //writing...
205   string medfile = "/tmp";
206   if ( getenv("TMP") && access(getenv("TMP"),W_OK)==0 )
207     medfile=getenv("TMP");
208   else if (getenv("TMPDIR") && access(getenv("TMPDIR"),W_OK)==0 )
209     medfile=getenv("TMPDIR");
210   medfile += "/totoFlica_V22.med";
211   
212   int id=meshing->addDriver(MED_DRIVER,medfile.c_str());
213   meshing->write(id);
214   meshing->removeReference();
215
216   if ( getenv("srcdir") )
217     remove(medfile.c_str());
218
219   return 0;
220 }