1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDMEMTest.hxx"
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"
28 #include <cppunit/Message.h>
29 #include <cppunit/TestAssert.h>
36 using namespace MEDMEM;
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)
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();
53 void MEDMEMTest::testDesactivateFacesComputation()
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,
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,
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,
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 };
93 int connNodalFaceClassical[116]=
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};
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);
145 MESHING* meshing = new MESHING;
146 meshing->setName( "TESTMESH" );
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);
167 meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_HEXA8,connNodalCellClassical);
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) ;
175 int id=meshing->addDriver(MED_DRIVER,tmpfile,meshing->getName());
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);
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);
190 CPPUNIT_ASSERT( GetFileAttributes(tmpGibiFile.c_str()) != INVALID_FILE_ATTRIBUTES );
192 CPPUNIT_ASSERT( access(tmpGibiFile.c_str(), F_OK) == 0 );
198 meshing->removeReference();
199 mesh->removeReference();