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"
21 #include <cppunit/TestAssert.h>
23 #include "MEDMEM_define.hxx"
24 #include "MEDMEM_Grid.hxx"
25 #include "MEDMEM_Mesh.hxx"
26 #include "MEDMEM_MedFileBrowser.hxx"
27 #include "MEDMEM_MedMeshDriver.hxx"
32 // use this define to enable lines, execution of which leads to Segmentation Fault
33 //#define ENABLE_FAULTS
35 // use this define to enable CPPUNIT asserts and fails, showing bugs
36 //#define ENABLE_FORCED_FAILURES
39 using namespace MEDMEM;
40 using namespace MED_EN;
44 * Check methods (23), defined in MEDMEM_Grid.hxx:
45 * class GRID: public MESH {
47 * (+) GRID(const MED_EN::med_grid_type type);
48 * (BUG:operator=() not implemented but init() not called) GRID(const GRID &m);
49 * (+) GRID(driverTypes driverType, const string & fileName="",const string & meshName="");
50 * (+) GRID(const std::vector<std::vector<double> >& xyz_array,
51 * const std::vector<std::string>& coord_name,
52 * const std::vector<std::string>& coord_unit,
53 * const MED_EN::med_grid_type type=MED_EN::MED_CARTESIAN);
54 * (NOT IMPLEMENTED) GRID & operator=(const GRID &m);
55 * (+) virtual ~GRID();
56 * (+) virtual void init();
57 * (+) virtual const MESH * convertInMESH() const
58 * (+) inline int getNodeNumber(const int i, const int j=0, const int k=0) const;
59 * (+) inline int getCellNumber(const int i, const int j=0, const int k=0) const;
60 * (+) int getEdgeNumber
61 * (const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION);
62 * (+) int getFaceNumber
63 * (const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION);
64 * (+) void getNodePosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION);
65 * (+) void getCellPosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION);
66 * (+) void getEdgePosition
67 * (const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION);
68 * (+) void getFacePosition
69 * (const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION);
70 * (+) inline MED_EN::med_grid_type getGridType() const;
71 * (+) int getArrayLength(const int Axis) const throw (MEDEXCEPTION);
72 * (+) const double getArrayValue (const int Axis, const int i) const throw (MEDEXCEPTION);
73 * (+) inline int getNumberOfTypes(MED_EN::medEntityMesh Entity) const;
74 * (+) inline const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const;
75 * (+) inline int getNumberOfElements
76 * (MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type) const;
77 * (+) inline MED_EN::medGeometryElement getElementType
78 * (MED_EN::medEntityMesh Entity, int Number) const;
79 * (+) inline void setGridType(MED_EN::med_grid_type gridType);
82 static void MEDMEMTest_testGrid()
84 string filename = getResourceFile("test19.med") ;
85 string filenameout21 = makeTmpFile("myGridWrite_grid21.med");
88 // To remove tmp files from disk
89 MEDMEMTest_TmpFilesRemover aRemover;
90 aRemover.Register(filenameout21);
92 // Remove file in advance to ensure it does not exist at the moment of writing,
93 // because files are not removed by the MEDMEMTest_TmpFilesRemover in case of
94 // Segmentation Fault (in previous tests execution).
96 MEDMEMTest_TmpFilesRemover aRemover1;
97 aRemover1.Register(filenameout21);
100 MEDFILEBROWSER * myMed = new MEDFILEBROWSER(filename);
102 int nbMeshes = myMed->getNumberOfMeshes();
103 CPPUNIT_ASSERT(nbMeshes);
105 vector<string> mesh_names = myMed->getMeshNames();
106 CPPUNIT_ASSERT(mesh_names.size() != 0);
108 //////////////////////////////
109 // test1 "CARTESIAN GRID" //
110 //////////////////////////////
112 CPPUNIT_ASSERT(myMed->isStructuredMesh(mesh_names[0]));
114 CPPUNIT_ASSERT_THROW( MESH(MED_DRIVER, myMed->getFileName(), mesh_names[0]), MEDEXCEPTION);
116 GMESH* myMesh = new GRID(MED_DRIVER, myMed->getFileName(), mesh_names[0]);
117 std::auto_ptr<GMESH> meshDeleter(myMesh);
119 CPPUNIT_ASSERT(myMesh != NULL);
120 CPPUNIT_ASSERT(myMesh->getIsAGrid());
122 GRID* myGrid = dynamic_cast<GRID*>(myMesh);
123 CPPUNIT_ASSERT(myGrid);
125 CPPUNIT_ASSERT_THROW(myGrid->getArrayLength(0), MEDEXCEPTION);
128 CPPUNIT_ASSERT_NO_THROW(I = myGrid->getArrayLength(1));
129 CPPUNIT_ASSERT_NO_THROW(J = myGrid->getArrayLength(2));
130 CPPUNIT_ASSERT_NO_THROW(K = myGrid->getArrayLength(3));
135 med_grid_type grid_type = myGrid->getGridType();
136 CPPUNIT_ASSERT_MESSAGE("Wrong grid type", grid_type == MED_CARTESIAN);
138 const MESH* mesh = myGrid->convertInMESH();
139 const double * coordinates = mesh->getCoordinates(MED_FULL_INTERLACE);
140 int SpaceDimension = myGrid->getSpaceDimension();
141 for (int axe = 0; axe < SpaceDimension; axe++) {
142 for (int num = 0; num < myGrid->getNumberOfNodes(); num++) {
144 CPPUNIT_ASSERT_NO_THROW(coordinate = mesh->getCoordinate(num + 1, axe + 1));
145 //cout << "coordinate = " << coordinate << endl;
146 CPPUNIT_ASSERT(fabs(coordinate - coordinates[(num * SpaceDimension)+axe]) < 0.001);
150 int nbTypesCell = myGrid->getNumberOfTypes(MED_CELL);
151 CPPUNIT_ASSERT(nbTypesCell == 1);
153 const medGeometryElement* types;
154 CPPUNIT_ASSERT_NO_THROW(types = myGrid->getTypes(MED_CELL));
155 //#ifdef ENABLE_FORCED_FAILURES
156 // Compilation warning about GRID::getTypes():
158 // `virtual const MED_EN::medGeometryElement* MEDMEM::GRID::getTypes(MED_EN::medEntityMesh) const'
159 // used but never defined".
160 // In MEDMEM_Grid.hxx:
161 // inline const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const;
162 // But implemented in MEDMEM_Grid.cxx:
163 // const MED_EN::medGeometryElement * GRID::getTypes(MED_EN::medEntityMesh entity) const
164 // CPPUNIT_FAIL("Problem with GRID::getTypes() method implementation.");
166 CPPUNIT_ASSERT(types[0] == MED_QUAD4);
169 CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid->getNumberOfElements(MED_CELL,types[0]));
170 CPPUNIT_ASSERT(nbElem);
172 int nbNodes = myGrid->getNumberOfNodes();
173 CPPUNIT_ASSERT(nbNodes);
177 for (int nbNode = 1; nbNode <= nbNodes; nbNode++) {
178 CPPUNIT_ASSERT_NO_THROW(myGrid->getNodePosition(nbNode, ijkNode[0], ijkNode[1], ijkNode[2]));
179 CPPUNIT_ASSERT_NO_THROW(NodeNumber = myGrid->getNodeNumber(ijkNode[0], ijkNode[1], ijkNode[2]));
180 CPPUNIT_ASSERT(NodeNumber == nbNode);
183 int nbCells = myGrid->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS);
184 CPPUNIT_ASSERT(nbCells);
188 for (int nbCell = 1; nbCell <= nbCells; nbCell++) {
189 CPPUNIT_ASSERT_NO_THROW(myGrid->getCellPosition(nbCell, ijkCell[0], ijkCell[1], ijkCell[2]));
190 CPPUNIT_ASSERT_NO_THROW(CellNumber = myGrid->getCellNumber(ijkCell[0], ijkCell[1], ijkCell[2]));
191 CPPUNIT_ASSERT(CellNumber == nbCell);
194 int nbEdges = myGrid->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS);
195 CPPUNIT_ASSERT(nbEdges);
199 for (int nbEdge = 1; nbEdge <= nbEdges; nbEdge++) {
200 CPPUNIT_ASSERT_NO_THROW(myGrid->getEdgePosition(nbEdge, ijkAxisEdge[0], ijkAxisEdge[1],
201 ijkAxisEdge[2], ijkAxisEdge[3]));
202 CPPUNIT_ASSERT_NO_THROW(EdgeNumber = myGrid->getEdgeNumber(ijkAxisEdge[0], ijkAxisEdge[1],
203 ijkAxisEdge[2], ijkAxisEdge[3]));
204 CPPUNIT_ASSERT(EdgeNumber == nbEdge);
207 int nbFaces = myGrid->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS);
208 CPPUNIT_ASSERT(nbFaces == 0);
210 //#ifdef ENABLE_FORCED_FAILURES
211 CPPUNIT_FAIL("ERROR: nbFaces == 0, but getFacePosition(AnyNumber, ...) - return position(i,j,k)");
214 CPPUNIT_ASSERT_NO_THROW(myGrid->getFacePosition(6, ijkAxisFace[0], ijkAxisFace[1],
215 ijkAxisFace[2], ijkAxisFace[3]));
216 CPPUNIT_ASSERT(ijkAxisFace[0]);
217 CPPUNIT_ASSERT(ijkAxisFace[1]);
218 CPPUNIT_ASSERT(ijkAxisFace[2]);
221 for(int nbFace = 1; nbFace <= nbFaces; nbFace++)
223 CPPUNIT_ASSERT_NO_THROW( myGrid->getFacePosition(nbFace, ijkAxisFace[0], ijkAxisFace[1],
224 ijkAxisFace[2], ijkAxisFace[3]));
225 CPPUNIT_ASSERT_NO_THROW( EdgeNumber = myGrid->getEdgeNumber(ijkAxisFace[0], ijkAxisFace[1],
226 ijkAxisFace[2], ijkAxisFace[3]));
227 CPPUNIT_ASSERT(FaceNumber == nbFace);
230 bool existConnect = false;
231 CPPUNIT_ASSERT_NO_THROW(existConnect = mesh->existConnectivity(MED_NODAL, MED_CELL));
233 CPPUNIT_ASSERT_NO_THROW(mesh->calculateConnectivity( MED_NODAL, MED_CELL));
234 CPPUNIT_ASSERT(mesh->existConnectivity(MED_NODAL, MED_CELL));
237 const int* Connectivity;
238 const int* connectivity_index;
239 CPPUNIT_ASSERT_NO_THROW(Connectivity = mesh->getConnectivity( MED_NODAL,
240 MED_CELL, types[0]));
241 CPPUNIT_ASSERT_NO_THROW(connectivity_index = mesh->getConnectivityIndex(MED_NODAL, MED_CELL));
242 out << "Nodal connectivity" << endl;
243 for (int j = 0; j < nbElem; j++) {
244 out << "Element "<< j+1 << " : ";
245 for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++)
246 out << Connectivity[k-1] << " ";
250 const int * ReverseNodalConnectivity;
251 const int * ReverseConnectivityIndex;
252 CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivity = mesh->getReverseConnectivity(MED_NODAL));
253 CPPUNIT_ASSERT_NO_THROW(ReverseConnectivityIndex = mesh->getReverseConnectivityIndex(MED_NODAL));
254 for (int i = 0; i < nbNodes; i++) {
255 out << "Node "<< i+1 << " : ";
256 for (int j = ReverseConnectivityIndex[i]; j < ReverseConnectivityIndex[i+1]; j++)
257 out << ReverseNodalConnectivity[j-1] << " ";
261 const int* myGlobalNbIdx;
262 CPPUNIT_ASSERT_NO_THROW(myGlobalNbIdx = mesh->getGlobalNumberingIndex(MED_CELL));
263 for (int i = 0; i <= nbTypesCell; i++) {
264 if (i == nbTypesCell) {
265 CPPUNIT_ASSERT_THROW(myGrid->getElementType(MED_CELL, myGlobalNbIdx[i]), MEDEXCEPTION);
268 medGeometryElement aElem;
269 CPPUNIT_ASSERT_NO_THROW(aElem = myGrid->getElementType(MED_CELL, myGlobalNbIdx[i]));
270 CPPUNIT_ASSERT(types[0] == aElem);
273 CPPUNIT_ASSERT_NO_THROW(existConnect = mesh->existConnectivity(MED_DESCENDING, MED_CELL));
275 CPPUNIT_ASSERT_NO_THROW(mesh->calculateConnectivity( MED_DESCENDING, MED_CELL));
276 CPPUNIT_ASSERT(mesh->existConnectivity(MED_DESCENDING, MED_CELL));
279 const int* ConnectivityDes;
280 const int* connectivity_index_des;
281 CPPUNIT_ASSERT_NO_THROW(ConnectivityDes = mesh->getConnectivity( MED_DESCENDING,
282 MED_CELL, MED_ALL_ELEMENTS));
283 CPPUNIT_ASSERT_NO_THROW(connectivity_index_des =
284 mesh->getConnectivityIndex(MED_DESCENDING, MED_CELL));
285 out<<"Descending connectivity"<<endl;
286 for (int j = 0; j < nbElem; j++) {
287 out << "Element "<< j+1 << " : ";
288 for (int k = connectivity_index_des[j]; k < connectivity_index_des[j+1]; k++)
289 out << ConnectivityDes[k-1] << " ";
293 const int * ReverseDesConnectivity;
294 const int * ReverseConnectivityIndexDes;
295 CPPUNIT_ASSERT_NO_THROW(ReverseDesConnectivity = mesh->getReverseConnectivity(MED_DESCENDING));
296 CPPUNIT_ASSERT_NO_THROW(ReverseConnectivityIndexDes =
297 mesh->getReverseConnectivityIndex(MED_DESCENDING));
298 for (int i = 0; i < nbNodes; i++) {
299 out << "Node "<< i+1 << " : ";
300 for (int j = ReverseConnectivityIndexDes[i]; j < ReverseConnectivityIndexDes[i+1]; j++)
301 out << ReverseDesConnectivity[j-1] << " ";
304 mesh->removeReference();
308 //////////////////////////////
309 // test2 "MED_BODY_FITTED" //
310 //////////////////////////////
312 CPPUNIT_ASSERT_THROW( MESH(MED_DRIVER, myMed->getFileName(), mesh_names[1]), MEDEXCEPTION);
314 GMESH* myMesh1 = new GRID(MED_DRIVER,myMed->getFileName(),mesh_names[1]);
315 std::auto_ptr<GMESH> meshDeleter(myMesh1);
317 CPPUNIT_ASSERT(myMesh1 != NULL);
318 CPPUNIT_ASSERT(myMesh1->getIsAGrid());
320 GRID* myGrid1 = dynamic_cast<GRID*>(myMesh1);
321 CPPUNIT_ASSERT(myGrid1);
324 CPPUNIT_ASSERT_NO_THROW(I = myGrid1->getArrayLength(1));
325 CPPUNIT_ASSERT_NO_THROW(J = myGrid1->getArrayLength(2));
326 CPPUNIT_ASSERT_NO_THROW(K = myGrid1->getArrayLength(3));
328 CPPUNIT_ASSERT(I == 2);
329 CPPUNIT_ASSERT(J == 2);
331 med_grid_type grid_type = myGrid1->getGridType();
332 CPPUNIT_ASSERT_MESSAGE("Wrong grid type", grid_type == MED_BODY_FITTED);
334 int nbTypesCell = myGrid1->getNumberOfTypes(MED_CELL);
335 CPPUNIT_ASSERT(nbTypesCell == 1);
337 const medGeometryElement* types1;
338 CPPUNIT_ASSERT_NO_THROW( types1 = myGrid1->getTypes(MED_CELL) );
339 CPPUNIT_ASSERT( types1[0] == MED_QUAD4);
342 CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid1->getNumberOfElements(MED_CELL, types1[0]));
343 CPPUNIT_ASSERT(nbElem);
345 const int* BodyConnectivity;
346 const int* body_connectivity_index;
348 const MESH* mesh = myGrid1->convertInMESH();
349 CPPUNIT_ASSERT_NO_THROW(BodyConnectivity = mesh->getConnectivity( MED_NODAL,
350 MED_CELL, types1[0]));
351 CPPUNIT_ASSERT_NO_THROW(body_connectivity_index = mesh->getConnectivityIndex(MED_NODAL, MED_CELL));
352 out<<"Nodal connectivity"<<endl;
353 for (int j = 0; j < nbElem; j++) {
354 out << "Element "<< j+1 << " : ";
355 for (int k = body_connectivity_index[j]; k < body_connectivity_index[j+1]; k++){
356 CPPUNIT_ASSERT_NO_THROW(myGrid1->getNodePosition(BodyConnectivity[k-1], ijkNodeBody[0],
357 ijkNodeBody[1], ijkNodeBody[2]));
358 out << BodyConnectivity[k-1] << " ";
362 mesh->removeReference();
365 ///////////////////////////////////////////////////
366 // test3 "maa1" which in fact is not a pure GRID //
367 ///////////////////////////////////////////////////
369 GMESH* myMesh2 = NULL;
371 CPPUNIT_ASSERT_THROW( myMesh2 = new GRID( MED_DRIVER,myMed->getFileName(),mesh_names[2]),
373 CPPUNIT_ASSERT_NO_THROW( myMesh2 = new MESH( MED_DRIVER,myMed->getFileName(),mesh_names[2]));
375 CPPUNIT_ASSERT(myMesh2 != NULL);
376 CPPUNIT_ASSERT(!(myMesh2->getIsAGrid()));
377 myMesh2->removeReference();
382 ////////////////////////////
383 // test4 create new GRID //
384 ////////////////////////////
386 // Default constructor and destructor
388 GRID* myGrid2 = new GRID();
389 CPPUNIT_ASSERT(myGrid2->getIsAGrid());
390 CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN);
391 CPPUNIT_ASSERT(!myGrid2->getArrayLength(1));
392 CPPUNIT_ASSERT(!myGrid2->getArrayLength(2));
393 CPPUNIT_ASSERT(!myGrid2->getArrayLength(3));
394 myGrid2->removeReference();
397 // Constructor with grid type, setGridType()
399 GRID* myGrid2 = new GRID(MED_POLAR);
400 CPPUNIT_ASSERT(myGrid2->getGridType() == MED_POLAR);
401 myGrid2->setGridType(MED_CARTESIAN);
402 CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN);
403 myGrid2->removeReference();
406 // Constructor with coordinate values, getArrayValue(), init()
408 vector<vector<double> > xyz;
409 const int nbCoords = 3;
410 xyz.resize(nbCoords);
411 for ( int i = 0; i < nbCoords; i++ )
413 xyz[i].resize(i + 2);
414 for ( int j = 0; j < i + 2; j++ )
417 vector<string> Coord_Names;
418 Coord_Names.resize(nbCoords);
419 Coord_Names[0] = "X";
420 Coord_Names[1] = "Y";
421 Coord_Names[2] = "Z";
423 vector<string> Coord_Units;
424 Coord_Units.resize(nbCoords);
425 for(int i = 0; i < 3; i++)
426 Coord_Units[i] = "cm";
431 myGrid2 = new GRID(xyz, Coord_Names, Coord_Units, MED_CARTESIAN);
433 catch (const std::exception &e)
435 CPPUNIT_FAIL(e.what());
439 CPPUNIT_FAIL("Unknown exception");
442 // testing getCoordinateptr() and fillCoordinates()
443 // We fill a map of all possible coordinate triples.
444 // After iteration through all coordinates, this map should contain only "true" as data.
445 // "true" in some map element during iteration means duplicated node position.
446 // "false" in some map element after iteration means empty node position.
447 map<int, bool> found;
448 for ( unsigned i1 = 0; i1 < xyz[0].size(); i1++ )
449 for ( unsigned i2 = 0; i2 < xyz[1].size(); i2++ )
450 for ( unsigned i3 = 0; i3 < xyz[2].size(); i3++ )
451 found[ xyz[0][i1] * 100 + xyz[1][i2] * 10 + xyz[2][i3] ] = false;
453 const MESH* mesh = myGrid2->convertInMESH();
454 COORDINATE* coords = (COORDINATE*)mesh->getCoordinateptr();
455 CPPUNIT_ASSERT(coords);
456 for (int num = 0; num < myGrid2->getNumberOfNodes(); num++) {
457 int x = int(coords->getCoordinate(num + 1, 1));
458 int y = int(coords->getCoordinate(num + 1, 2));
459 int z = int(coords->getCoordinate(num + 1, 3));
460 CPPUNIT_ASSERT(!found[x * 100 + y * 10 + z]);
461 found[x * 100 + y * 10 + z] = true;
464 for ( map<int, bool>::iterator it = found.begin(); it != found.end(); it++ )
465 CPPUNIT_ASSERT((*it).second);
467 // Testing fillConnectivity() and getConnectivityptr()
468 // Basic testing: presence of connectivity arrays, element types and number of elements
469 CONNECTIVITY* conn = (CONNECTIVITY*)mesh->getConnectivityptr();
470 CPPUNIT_ASSERT(conn);
471 bool hasFaces = myGrid2->getArrayLength(3), hasEdges = myGrid2->getArrayLength(2);
472 medGeometryElement aCellGeometry;
473 if (hasFaces) aCellGeometry = MED_HEXA8;
474 else if (hasEdges) aCellGeometry = MED_QUAD4;
475 else aCellGeometry = MED_SEG2;
476 CPPUNIT_ASSERT(conn->getElementType(MED_CELL, 1) == aCellGeometry);
477 CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_CELL));
478 CPPUNIT_ASSERT(conn->existConnectivity(MED_DESCENDING, MED_CELL));
480 CELLMODEL* cellmodel = (CELLMODEL*)mesh->getCellsTypes(MED_CELL);
481 CPPUNIT_ASSERT(cellmodel);
483 int nbCells, nbFaces, nbEdges;
485 int iLen = myGrid2->getArrayLength(1);
486 int jLen = myGrid2->getArrayLength(2);
487 int kLen = myGrid2->getArrayLength(3);
488 int iLenMin1 = myGrid2->getArrayLength(1)-1;
489 int jLenMin1 = myGrid2->getArrayLength(2)-1;
490 int kLenMin1 = myGrid2->getArrayLength(3)-1;
491 const int* aCellCount = conn->getGlobalNumberingIndex(MED_CELL);
492 nbCells = iLenMin1 * jLenMin1 * kLenMin1;
493 CPPUNIT_ASSERT(aCellCount[1] - 1 == nbCells);
496 CPPUNIT_ASSERT(conn->getElementType(MED_FACE, 1) == MED_QUAD4);
497 nbFaces = iLen * jLenMin1 * kLenMin1;
498 nbFaces += jLen * kLenMin1 * iLenMin1;
499 nbFaces += kLen * iLenMin1 * jLenMin1;
500 const int* aFaceCount = conn->getGlobalNumberingIndex(MED_FACE);
501 CPPUNIT_ASSERT(aFaceCount[1] - 1 == nbFaces);
502 CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_FACE));
504 CELLMODEL* cellmodelF = (CELLMODEL*)mesh->getCellsTypes(MED_FACE);
505 CPPUNIT_ASSERT(cellmodelF);
508 CPPUNIT_ASSERT(conn->getElementType(MED_EDGE, 1) == MED_SEG2);
509 if (kLen) { // 3d grid
510 nbEdges = iLenMin1 * jLen * kLen;
511 nbEdges += jLenMin1 * kLen * iLen;
512 nbEdges += kLenMin1 * iLen * jLen;
514 else if (jLen) { // 2d
515 nbEdges = iLenMin1 * jLen;
516 nbEdges += jLenMin1 * iLen;
518 const int* anEdgeCount = conn->getGlobalNumberingIndex(MED_EDGE);
519 CPPUNIT_ASSERT(anEdgeCount[1] - 1 == nbEdges);
520 CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_EDGE));
522 CELLMODEL* cellmodelE = (CELLMODEL*)mesh->getCellsTypes(MED_EDGE);
523 CPPUNIT_ASSERT(cellmodelE);
527 // Testing getArrayValue()
528 for ( int ii = 1; ii <= nbCoords; ii++ )
529 for ( int jj = 0; jj < ii + 1; jj++ )
530 CPPUNIT_ASSERT(myGrid2->getArrayValue(ii, jj) == xyz[ii - 1][jj]);
532 CPPUNIT_ASSERT_THROW(myGrid2->getArrayValue(nbCoords + 1, 0), MEDEXCEPTION);
533 CPPUNIT_ASSERT_THROW(myGrid2->getArrayValue(1, myGrid2->getArrayLength(1) + 1), MEDEXCEPTION);
534 myGrid2->setGridType(MED_POLAR);
536 //testing read/write functions
543 idGridV21 = const_cast<MESH*>(mesh)->addDriver(MED_DRIVER,filenameout21);
545 catch(MEDEXCEPTION &e)
547 CPPUNIT_FAIL(e.what());
551 CPPUNIT_FAIL("Unknown exception");
554 // write this driver to file as an unstructured mesh
555 CPPUNIT_ASSERT_NO_THROW(mesh->write(idGridV21));
557 GRID* myGrid3 = new GRID();
558 // add new driver for myGrid3
560 CPPUNIT_ASSERT_NO_THROW(driver = myGrid3->addDriver(MED_DRIVER, filenameout21));
562 //#ifdef ENABLE_FORCED_FAILURES
563 // ? (BUG) ? "The mesh dimension |-1| seems to be incorrect for the mesh : |Default Mesh Name|"
564 CPPUNIT_ASSERT_NO_THROW(myGrid3->read(driver));
566 // Testing getArrayValue()
567 for ( int ii = 1; ii <= nbCoords; ii++ )
568 for ( int jj = 0; jj < ii + 1; jj++ )
569 CPPUNIT_ASSERT(myGrid3->getArrayValue(ii, jj) == xyz[ii - 1][jj]);
571 CPPUNIT_ASSERT(myGrid3->getGridType() == MED_POLAR);
574 myGrid3->removeReference();
577 CPPUNIT_ASSERT_NO_THROW(myGrid2->init());
578 CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN);
579 CPPUNIT_ASSERT(myGrid2->getArrayLength(1) == 0);
580 CPPUNIT_ASSERT(myGrid2->getArrayLength(2) == 0);
581 CPPUNIT_ASSERT(myGrid2->getArrayLength(3) == 0);
582 //#ifdef ENABLE_FAULTS
583 // (BUG) Segmentation Fault
584 //myGrid2->makeUnstructured();
586 //#ifdef ENABLE_FORCED_FAILURES
587 // CPPUNIT_FAIL("ERROR:makeUnstructured() - there is no check if grid is empty or not");
590 myGrid2->removeReference();
591 mesh->removeReference();
594 //#ifdef ENABLE_FORCED_FAILURES
597 // ? (BUG) ? MED Exception in /dn20/salome/jfa/V3/SRC/MED_SRC/src/MEDMEM/MEDMEM_MedM
598 //eshDriver21.cxx [430] : MED_MESH_RDONLY_DRIVER21::getCOORDINATE() : The number
599 //of nodes |0| seems to be incorrect for the mesh : |bodyfitted|
600 CPPUNIT_ASSERT_NO_THROW(myGrid2 = new GRID(MED_DRIVER, filename, mesh_names[1]));
602 // Check if something has been read - full mesh data testing is above
603 CPPUNIT_ASSERT(myGrid2->getSpaceDimension());
604 CPPUNIT_ASSERT(myGrid2->getNumberOfNodes());
605 CPPUNIT_ASSERT(myGrid2->getNumberOfTypes(MED_CELL) == 1);
606 const medGeometryElement* types2;
607 CPPUNIT_ASSERT_NO_THROW(types2 = myGrid2->getTypes(MED_CELL));
609 CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid2->getNumberOfElements(MED_CELL,types2[0]));
610 CPPUNIT_ASSERT(nbElem);
611 myGrid2->removeReference();
616 GRID* myGrid4 = new GRID();
617 filename = getResourceFile("pointe.med");
618 myGrid4->setName("maa1");
619 MED_MESH_RDONLY_DRIVER myMeshDriver(filename, myGrid4);
620 myMeshDriver.setMeshName("maa1");
622 // add new driver for myGrid4
624 CPPUNIT_ASSERT_NO_THROW(driver = myGrid4->addDriver(myMeshDriver));
626 // ??? ERROR:myGrid4->fillMeshAfterRead()- this method is incomplete:
627 // currently it only resets _is_coordinates_filled and _is_connectivity_filled
628 // flags that leads to grid reconstruction
630 // MED Exception : MED_MESH_RDONLY_DRIVER21::getGRID() : The number
631 // of nodes |-1| seems to be incorrect for the mesh : |maa1|
632 // But this exception seems to be correct reaction on attempt
633 // to read a grid from a file, which does not contain it.
634 CPPUNIT_ASSERT_THROW(myGrid4->read(driver), MEDEXCEPTION);
635 //CPPUNIT_ASSERT_NO_THROW(myGrid4->read(driver));
636 /*CPPUNIT_ASSERT(myGrid4->getArrayLength(1) == 0);
637 CPPUNIT_ASSERT(myGrid4->getArrayLength(2) == 0);
638 CPPUNIT_ASSERT(myGrid4->getArrayLength(3) == 0);
639 myGrid4->fillMeshAfterRead();
640 CPPUNIT_ASSERT(myGrid4->getArrayLength(1) != 0);
641 CPPUNIT_ASSERT(myGrid4->getArrayLength(2) != 0);
642 CPPUNIT_ASSERT(myGrid4->getArrayLength(3) != 0);*/
644 myGrid4->removeReference();
648 int main (int argc, char** argv)
650 MEDMEMTest_testGrid();