Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / MEDMEMCppTest / MEDMEMTest_DesactivateFacesComputation.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MEDMEMTest.hxx"
21
22 #include "MEDMEM_Mesh.hxx"
23 #include "MEDMEM_Group.hxx"
24 #include "MEDMEM_Meshing.hxx"
25 #include "MEDMEM_MedMeshDriver.hxx"
26 #include "MEDMEM_GibiMeshDriver.hxx"
27
28 #include <cppunit/Message.h>
29 #include <cppunit/TestAssert.h>
30
31 #ifdef WIN32
32 #include <windows.h>
33 #endif
34
35 using namespace std;
36 using namespace MEDMEM;
37
38 static void addMedFacesGroup2( MESHING& meshing, int nFaces, const int *groupValue,
39                         string groupName, const MED_EN::medGeometryElement *mytypes,  const int *index, const int *myNumberOfElements, int nbOfGeomTypes)
40   {
41     GROUP *faces=new GROUP;
42     faces->setName(groupName) ;
43     faces->setMesh(&meshing) ;
44     faces->setEntity(MED_EN::MED_FACE) ;
45     faces->setNumberOfGeometricType(nbOfGeomTypes) ;
46     faces->setGeometricType(mytypes);
47     faces->setNumberOfElements(myNumberOfElements) ;
48     faces->setNumber(index, groupValue) ;
49     meshing.addGroup(*faces) ;
50     faces->removeReference();
51   }
52
53 void MEDMEMTest::testDesactivateFacesComputation()
54 {
55   double coords[108]=
56     {0, 0.21504, 0.21504, 0, 0.43008, 
57      0.43008, 0.21504, 0, 0.43008, 0, 
58      0.21504, 0.21504, 0, 0.43008, 
59      0.43008, 0.21504, 0, 0.43008, 0, 
60      0.21504, 0.21504, 0, 0.43008, 
61      0.43008, 0.21504, 0, 0.43008, 0, 
62      0.21504, 0.21504, 0, 0.43008, 
63      0.43008, 0.21504, 0, 0.43008,
64      //coordY
65      0, 0, 0.21504, 0.21504, 0, 0.21504, 
66      0.43008, 0.43008, 0.43008, 0, 0, 
67      0.21504, 0.21504, 0, 0.21504, 
68      0.43008, 0.43008, 0.43008, 0, 0, 
69      0.21504, 0.21504, 0, 0.21504, 
70      0.43008, 0.43008, 0.43008, 0, 0, 
71      0.21504, 0.21504, 0, 0.21504, 
72      0.43008, 0.43008, 0.43008,
73      //coordZ
74      0, 0, 0, 0, 0, 0, 0, 0, 0, 0.15677, 0.15677, 
75      0.15677, 0.15677, 0.15677, 
76      0.15677, 0.15677, 0.15677, 
77      0.15677, 0.1934, 0.1934, 
78      0.1934, 0.1934, 0.1934, 
79      0.1934, 0.1934, 0.1934, 
80      0.1934, 0.3485, 0.3485, 
81      0.3485, 0.3485, 0.3485, 
82      0.3485, 0.3485, 0.3485, 
83      0.3485};
84
85   int connNodalCellClassical[48]=
86     { 1, 2, 3, 4, 10, 11, 12, 13, 
87       4, 3, 7, 8, 13, 12, 16, 17, 
88       10, 11, 12, 13, 19, 20, 21, 22, 
89       13, 12, 16, 17, 22, 21, 25, 26, 
90       19, 20, 21, 22, 28, 29, 30, 31,
91       22, 21, 25, 26, 31, 30, 34, 35 };
92
93   int connNodalFaceClassical[116]=
94     { 1, 2, 3, 4, 
95       10, 13, 12, 11, 
96       1, 2, 11, 10, 
97       2, 3, 12, 11, 
98       3, 4, 13, 12, 
99       4, 1, 10, 13, 
100       4, 3, 7, 8, 
101       13, 17, 16, 12, 
102       3, 7, 16, 12, 
103       7, 8, 17, 16, 
104       8, 4, 13, 17, 
105       19, 22, 21, 20, 
106       10, 11, 20, 19,
107       11, 12, 21, 20, 
108       12, 13, 22, 21, 
109       13, 10, 19, 22, 
110       22, 26, 25, 21, 
111       12, 16, 25, 21, 
112       16, 17, 26, 25, 
113       17, 13, 22, 26, 
114       28, 31, 30, 29, 
115       19, 20, 29, 28, 
116       20, 21, 30, 29, 
117       21, 22, 31, 30, 
118       22, 19, 28, 31, 
119       31, 35, 34, 30, 
120       21, 25, 34, 30, 
121       25, 26, 35, 34, 
122       26, 22, 31, 35};
123
124   int bottom[2]={1,7};
125   MED_EN::medGeometryElement bottomTypes[1]={MED_EN::MED_QUAD4};
126   int bottomIndex[2]={1,3};
127   int bottomNbOfElts[1]={2};
128   int top[4]={8,9,10,11};
129   MED_EN::medGeometryElement topTypes[1]={MED_EN::MED_QUAD4};
130   int topIndex[3]={1,5};
131   int topNbOfElts[1]={4};
132   int side[5]={ 3, 6, 10, 11, 13};
133   MED_EN::medGeometryElement sideTypes[1]={MED_EN::MED_QUAD4};
134   int sideIndex[2]={1,6};
135   int sideNbOfElts[1]={5};
136   //
137   string tmp_dir=getTmpDirectory();
138   string tmpfile=tmp_dir+"/toto3434535.med";
139   string tmpGibiFile=tmp_dir+"/TET4.sauv";
140   MEDMEMTest_TmpFilesRemover aRemover;
141   aRemover.Register(tmpfile);
142   aRemover.Register(tmpGibiFile);
143   //
144
145   MESHING* meshing = new MESHING;
146   meshing->setName( "TESTMESH" );
147   const int nNodes=36;
148   meshing->setCoordinates(3, nNodes, coords, "CARTESIAN",
149                           MED_EN::MED_NO_INTERLACE);
150   string coordname[3] = { "x", "y", "z" };
151   meshing->setCoordinatesNames(coordname);
152   string coordunit[3] = { "m", "m", "m" };
153   meshing->setCoordinatesUnits(coordunit);
154   //Cell connectivity info for classical elts
155   const MED_EN::medGeometryElement classicalTypesCell[1]={MED_EN::MED_HEXA8};
156   const int nbOfCellElts[1]={6};
157   meshing->setNumberOfTypes(1,MED_EN::MED_CELL);
158   meshing->setTypes(classicalTypesCell,MED_EN::MED_CELL);
159   meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
160   //Face connectivity info for classical elts
161   const MED_EN::medGeometryElement classicalTypesFace[1]={MED_EN::MED_QUAD4};
162   const int nbOfFaceElts[1]={14};
163   meshing->setNumberOfTypes(1,MED_EN::MED_FACE);
164   meshing->setTypes(classicalTypesFace,MED_EN::MED_FACE);
165   meshing->setNumberOfElements(nbOfFaceElts,MED_EN::MED_FACE);
166   //All cell conn
167   meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_HEXA8,connNodalCellClassical);
168   //All face conn
169   meshing->setConnectivity(MED_EN::MED_FACE,MED_EN::MED_QUAD4,connNodalFaceClassical);
170   int nbOfTypes=meshing->getNumberOfTypes(MED_EN::MED_EDGE);
171   addMedFacesGroup2( *meshing, 2,  bottom, "Bottom",bottomTypes,bottomIndex,bottomNbOfElts,1) ;
172   addMedFacesGroup2( *meshing, 4,  top,    "TopFace",topTypes,topIndex,topNbOfElts,1) ;
173   addMedFacesGroup2( *meshing, 5, side,   "SideFace",sideTypes,sideIndex,sideNbOfElts,1) ;
174   //
175   int id=meshing->addDriver(MED_DRIVER,tmpfile,meshing->getName());
176   meshing->write(id);
177   //
178   MESH *mesh=new MESH;
179   mesh->setName(meshing->getName());
180   MEDMEM::MED_MESH_RDONLY_DRIVER *driver=new MEDMEM::MED_MESH_RDONLY_DRIVER(tmpfile,mesh);
181   driver->desactivateFacesComputation();
182   id=mesh->addDriver(*driver);
183   mesh->read(id);
184   CPPUNIT_ASSERT_NO_THROW(nbOfTypes=mesh->getNumberOfTypes(MED_EN::MED_EDGE));
185   CPPUNIT_ASSERT_EQUAL(0,nbOfTypes);
186   MEDMEM::GIBI_MESH_WRONLY_DRIVER *gibidriver=new MEDMEM::GIBI_MESH_WRONLY_DRIVER(tmpGibiFile,mesh );
187   id=mesh->addDriver(*gibidriver);
188   mesh->write(id);
189 #ifdef WIN32
190   CPPUNIT_ASSERT( GetFileAttributes(tmpGibiFile.c_str()) != INVALID_FILE_ATTRIBUTES );
191 #else
192   CPPUNIT_ASSERT( access(tmpGibiFile.c_str(), F_OK) == 0 );
193 #endif
194
195   delete gibidriver;
196   delete driver;
197   //
198   meshing->removeReference();
199   mesh->removeReference();
200 }