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 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 CPPUNIT_ASSERT(types[0] == MED_QUAD4);
158 CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid->getNumberOfElements(MED_CELL,types[0]));
159 CPPUNIT_ASSERT(nbElem);
161 int nbNodes = myGrid->getNumberOfNodes();
162 CPPUNIT_ASSERT(nbNodes);
166 for (int nbNode = 1; nbNode <= nbNodes; nbNode++) {
167 CPPUNIT_ASSERT_NO_THROW(myGrid->getNodePosition(nbNode, ijkNode[0], ijkNode[1], ijkNode[2]));
168 CPPUNIT_ASSERT_NO_THROW(NodeNumber = myGrid->getNodeNumber(ijkNode[0], ijkNode[1], ijkNode[2]));
169 CPPUNIT_ASSERT(NodeNumber == nbNode);
172 int nbCells = myGrid->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS);
173 CPPUNIT_ASSERT(nbCells);
177 for (int nbCell = 1; nbCell <= nbCells; nbCell++) {
178 CPPUNIT_ASSERT_NO_THROW(myGrid->getCellPosition(nbCell, ijkCell[0], ijkCell[1], ijkCell[2]));
179 CPPUNIT_ASSERT_NO_THROW(CellNumber = myGrid->getCellNumber(ijkCell[0], ijkCell[1], ijkCell[2]));
180 CPPUNIT_ASSERT(CellNumber == nbCell);
183 int nbEdges = myGrid->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS);
184 CPPUNIT_ASSERT(nbEdges);
188 for (int nbEdge = 1; nbEdge <= nbEdges; nbEdge++) {
189 CPPUNIT_ASSERT_NO_THROW(myGrid->getEdgePosition(nbEdge, ijkAxisEdge[0], ijkAxisEdge[1],
190 ijkAxisEdge[2], ijkAxisEdge[3]));
191 CPPUNIT_ASSERT_NO_THROW(EdgeNumber = myGrid->getEdgeNumber(ijkAxisEdge[0], ijkAxisEdge[1],
192 ijkAxisEdge[2], ijkAxisEdge[3]));
193 CPPUNIT_ASSERT(EdgeNumber == nbEdge);
196 int nbFaces = myGrid->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS);
197 CPPUNIT_ASSERT(nbFaces == 0);
199 //#ifdef ENABLE_FORCED_FAILURES
200 // To remove getFacePosition() from API
201 //CPPUNIT_FAIL("ERROR: nbFaces == 0, but getFacePosition(AnyNumber, ...) - return position(i,j,k)");
204 CPPUNIT_ASSERT_NO_THROW(myGrid->getFacePosition(6, ijkAxisFace[0], ijkAxisFace[1],
205 ijkAxisFace[2], ijkAxisFace[3]));
206 CPPUNIT_ASSERT(ijkAxisFace[0]);
207 CPPUNIT_ASSERT(ijkAxisFace[1]);
208 CPPUNIT_ASSERT(ijkAxisFace[2]);
211 for(int nbFace = 1; nbFace <= nbFaces; nbFace++)
213 CPPUNIT_ASSERT_NO_THROW( myGrid->getFacePosition(nbFace, ijkAxisFace[0], ijkAxisFace[1],
214 ijkAxisFace[2], ijkAxisFace[3]));
215 CPPUNIT_ASSERT_NO_THROW( EdgeNumber = myGrid->getEdgeNumber(ijkAxisFace[0], ijkAxisFace[1],
216 ijkAxisFace[2], ijkAxisFace[3]));
217 CPPUNIT_ASSERT(FaceNumber == nbFace);
220 bool existConnect = false;
221 CPPUNIT_ASSERT_NO_THROW(existConnect = mesh->existConnectivity(MED_NODAL, MED_CELL));
223 CPPUNIT_ASSERT_NO_THROW(mesh->calculateConnectivity(MED_NODAL, MED_CELL));
224 CPPUNIT_ASSERT(mesh->existConnectivity(MED_NODAL, MED_CELL));
227 const int* Connectivity;
228 const int* connectivity_index;
229 CPPUNIT_ASSERT_NO_THROW(Connectivity = mesh->getConnectivity( MED_NODAL, MED_CELL, types[0]));
230 CPPUNIT_ASSERT_NO_THROW(connectivity_index = mesh->getConnectivityIndex(MED_NODAL, MED_CELL));
231 out << "Nodal connectivity" << endl;
232 for (int j = 0; j < nbElem; j++) {
233 out << "Element "<< j+1 << " : ";
234 for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++)
235 out << Connectivity[k-1] << " ";
239 const int * ReverseNodalConnectivity;
240 const int * ReverseConnectivityIndex;
241 CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivity = mesh->getReverseConnectivity(MED_NODAL));
242 CPPUNIT_ASSERT_NO_THROW(ReverseConnectivityIndex = mesh->getReverseConnectivityIndex(MED_NODAL));
243 for (int i = 0; i < nbNodes; i++) {
244 out << "Node "<< i+1 << " : ";
245 for (int j = ReverseConnectivityIndex[i]; j < ReverseConnectivityIndex[i+1]; j++)
246 out << ReverseNodalConnectivity[j-1] << " ";
250 const int* myGlobalNbIdx;
251 CPPUNIT_ASSERT_NO_THROW(myGlobalNbIdx = mesh->getGlobalNumberingIndex(MED_CELL));
252 for (int i = 0; i <= nbTypesCell; i++) {
253 if (i == nbTypesCell) {
254 CPPUNIT_ASSERT_THROW(myGrid->getElementType(MED_CELL, myGlobalNbIdx[i]), MEDEXCEPTION);
257 medGeometryElement aElem;
258 CPPUNIT_ASSERT_NO_THROW(aElem = myGrid->getElementType(MED_CELL, myGlobalNbIdx[i]));
259 CPPUNIT_ASSERT(types[0] == aElem);
262 CPPUNIT_ASSERT_NO_THROW(existConnect = mesh->existConnectivity(MED_DESCENDING, MED_CELL));
264 CPPUNIT_ASSERT_NO_THROW(mesh->calculateConnectivity( MED_DESCENDING, MED_CELL));
265 CPPUNIT_ASSERT(mesh->existConnectivity(MED_DESCENDING, MED_CELL));
268 const int* ConnectivityDes;
269 const int* connectivity_index_des;
270 CPPUNIT_ASSERT_NO_THROW(ConnectivityDes = mesh->getConnectivity(MED_DESCENDING,
271 MED_CELL, MED_ALL_ELEMENTS));
272 CPPUNIT_ASSERT_NO_THROW(connectivity_index_des =
273 mesh->getConnectivityIndex(MED_DESCENDING, MED_CELL));
274 out<<"Descending connectivity"<<endl;
275 for (int j = 0; j < nbElem; j++) {
276 out << "Element "<< j+1 << " : ";
277 for (int k = connectivity_index_des[j]; k < connectivity_index_des[j+1]; k++)
278 out << ConnectivityDes[k-1] << " ";
282 const int * ReverseDesConnectivity;
283 const int * ReverseConnectivityIndexDes;
284 CPPUNIT_ASSERT_NO_THROW(ReverseDesConnectivity = mesh->getReverseConnectivity(MED_DESCENDING));
285 CPPUNIT_ASSERT_NO_THROW(ReverseConnectivityIndexDes =
286 mesh->getReverseConnectivityIndex(MED_DESCENDING));
287 for (int i = 0; i < nbNodes; i++) {
288 out << "Node "<< i+1 << " : ";
289 for (int j = ReverseConnectivityIndexDes[i]; j < ReverseConnectivityIndexDes[i+1]; j++)
290 out << ReverseDesConnectivity[j-1] << " ";
293 mesh->removeReference();
297 //////////////////////////////
298 // test2 "MED_BODY_FITTED" //
299 //////////////////////////////
301 CPPUNIT_ASSERT_THROW( MESH(MED_DRIVER, myMed->getFileName(), mesh_names[1]), MEDEXCEPTION);
303 GMESH* myMesh1 = new GRID(MED_DRIVER,myMed->getFileName(),mesh_names[1]);
304 std::auto_ptr<GMESH> meshDeleter(myMesh1);
306 CPPUNIT_ASSERT(myMesh1 != NULL);
307 CPPUNIT_ASSERT(myMesh1->getIsAGrid());
309 GRID* myGrid1 = dynamic_cast<GRID*>(myMesh1);
310 CPPUNIT_ASSERT(myGrid1);
313 CPPUNIT_ASSERT_NO_THROW(I = myGrid1->getArrayLength(1));
314 CPPUNIT_ASSERT_NO_THROW(J = myGrid1->getArrayLength(2));
315 CPPUNIT_ASSERT_NO_THROW(K = myGrid1->getArrayLength(3));
317 CPPUNIT_ASSERT(I == 2);
318 CPPUNIT_ASSERT(J == 2);
320 med_grid_type grid_type = myGrid1->getGridType();
321 CPPUNIT_ASSERT_MESSAGE("Wrong grid type", grid_type == MED_BODY_FITTED);
323 int nbTypesCell = myGrid1->getNumberOfTypes(MED_CELL);
324 CPPUNIT_ASSERT(nbTypesCell == 1);
326 const medGeometryElement* types1;
327 CPPUNIT_ASSERT_NO_THROW( types1 = myGrid1->getTypes(MED_CELL) );
328 CPPUNIT_ASSERT( types1[0] == MED_QUAD4);
331 CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid1->getNumberOfElements(MED_CELL, types1[0]));
332 CPPUNIT_ASSERT(nbElem);
334 const int* BodyConnectivity;
335 const int* body_connectivity_index;
337 const MESH* mesh = myGrid1->convertInMESH();
338 CPPUNIT_ASSERT_NO_THROW(BodyConnectivity = mesh->getConnectivity( MED_NODAL, MED_CELL, types1[0]));
339 CPPUNIT_ASSERT_NO_THROW(body_connectivity_index = mesh->getConnectivityIndex(MED_NODAL, MED_CELL));
340 out<<"Nodal connectivity"<<endl;
341 for (int j = 0; j < nbElem; j++) {
342 out << "Element "<< j+1 << " : ";
343 for (int k = body_connectivity_index[j]; k < body_connectivity_index[j+1]; k++){
344 CPPUNIT_ASSERT_NO_THROW(myGrid1->getNodePosition(BodyConnectivity[k-1], ijkNodeBody[0],
345 ijkNodeBody[1], ijkNodeBody[2]));
346 out << BodyConnectivity[k-1] << " ";
350 mesh->removeReference();
353 ///////////////////////////////////////////////////
354 // test3 "maa1" which in fact is not a pure GRID //
355 ///////////////////////////////////////////////////
357 GMESH* myMesh2 = NULL;
359 CPPUNIT_ASSERT_THROW( myMesh2 = new GRID( MED_DRIVER,myMed->getFileName(),mesh_names[2]),
361 CPPUNIT_ASSERT_NO_THROW( myMesh2 = new MESH( MED_DRIVER,myMed->getFileName(),mesh_names[2]));
363 CPPUNIT_ASSERT(myMesh2 != NULL);
364 CPPUNIT_ASSERT(!(myMesh2->getIsAGrid()));
365 myMesh2->removeReference();
370 ////////////////////////////
371 // test4 create new GRID //
372 ////////////////////////////
374 // Default constructor and destructor
376 GRID* myGrid2 = new GRID();
377 CPPUNIT_ASSERT(myGrid2->getIsAGrid());
378 CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN);
379 CPPUNIT_ASSERT(!myGrid2->getArrayLength(1));
380 CPPUNIT_ASSERT(!myGrid2->getArrayLength(2));
381 CPPUNIT_ASSERT(!myGrid2->getArrayLength(3));
382 myGrid2->removeReference();
385 // Constructor with grid type, setGridType()
387 GRID* myGrid2 = new GRID(MED_POLAR);
388 CPPUNIT_ASSERT(myGrid2->getGridType() == MED_POLAR);
389 myGrid2->setGridType(MED_CARTESIAN);
390 CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN);
391 myGrid2->removeReference();
394 // Constructor with coordinate values, getArrayValue(), init()
396 vector<vector<double> > xyz;
397 const int nbCoords = 3;
398 xyz.resize(nbCoords);
399 for ( int i = 0; i < nbCoords; i++ )
401 xyz[i].resize(i + 2);
402 for ( int j = 0; j < i + 2; j++ )
405 vector<string> Coord_Names;
406 Coord_Names.resize(nbCoords);
407 Coord_Names[0] = "X";
408 Coord_Names[1] = "Y";
409 Coord_Names[2] = "Z";
411 vector<string> Coord_Units;
412 Coord_Units.resize(nbCoords);
413 for(int i = 0; i < 3; i++)
414 Coord_Units[i] = "cm";
419 myGrid2 = new GRID(xyz, Coord_Names, Coord_Units, MED_CARTESIAN);
421 catch (const std::exception &e)
423 CPPUNIT_FAIL(e.what());
427 CPPUNIT_FAIL("Unknown exception");
430 // testing convertInMESH()
431 // We fill a map of all possible coordinate triples.
432 // After iteration through all coordinates, this map should contain only "true" as data.
433 // "true" in some map element during iteration means duplicated node position.
434 // "false" in some map element after iteration means empty node position.
435 map<int, bool> found;
436 for ( unsigned i1 = 0; i1 < xyz[0].size(); i1++ )
437 for ( unsigned i2 = 0; i2 < xyz[1].size(); i2++ )
438 for ( unsigned i3 = 0; i3 < xyz[2].size(); i3++ )
439 found[int(xyz[0][i1] * 100 + xyz[1][i2] * 10 + xyz[2][i3])] = false;
441 const MESH* mesh = myGrid2->convertInMESH();
442 COORDINATE* coords = (COORDINATE*)mesh->getCoordinateptr();
443 CPPUNIT_ASSERT(coords);
444 for (int num = 0; num < myGrid2->getNumberOfNodes(); num++) {
445 int x = int(coords->getCoordinate(num + 1, 1));
446 int y = int(coords->getCoordinate(num + 1, 2));
447 int z = int(coords->getCoordinate(num + 1, 3));
448 CPPUNIT_ASSERT(!found[x * 100 + y * 10 + z]);
449 found[x * 100 + y * 10 + z] = true;
452 for ( map<int, bool>::iterator it = found.begin(); it != found.end(); it++ )
453 CPPUNIT_ASSERT((*it).second);
455 // Testing fillConnectivity() and getConnectivityptr()
456 // Basic testing: presence of connectivity arrays, element types and number of elements
457 CONNECTIVITY* conn = (CONNECTIVITY*)mesh->getConnectivityptr();
458 CPPUNIT_ASSERT(conn);
459 bool hasFaces = myGrid2->getArrayLength(3), hasEdges = myGrid2->getArrayLength(2);
460 medGeometryElement aCellGeometry;
461 if (hasFaces) aCellGeometry = MED_HEXA8;
462 else if (hasEdges) aCellGeometry = MED_QUAD4;
463 else aCellGeometry = MED_SEG2;
464 CPPUNIT_ASSERT(conn->getElementType(MED_CELL, 1) == aCellGeometry);
465 CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_CELL));
466 CPPUNIT_ASSERT(conn->existConnectivity(MED_DESCENDING, MED_CELL));
468 CELLMODEL* cellmodel = (CELLMODEL*)mesh->getCellsTypes(MED_CELL);
469 CPPUNIT_ASSERT(cellmodel);
471 int nbCells, nbFaces, nbEdges;
473 int iLen = myGrid2->getArrayLength(1);
474 int jLen = myGrid2->getArrayLength(2);
475 int kLen = myGrid2->getArrayLength(3);
476 int iLenMin1 = myGrid2->getArrayLength(1)-1;
477 int jLenMin1 = myGrid2->getArrayLength(2)-1;
478 int kLenMin1 = myGrid2->getArrayLength(3)-1;
479 const int* aCellCount = conn->getGlobalNumberingIndex(MED_CELL);
480 nbCells = iLenMin1 * jLenMin1 * kLenMin1;
481 CPPUNIT_ASSERT(aCellCount[1] - 1 == nbCells);
484 CPPUNIT_ASSERT(conn->getElementType(MED_FACE, 1) == MED_QUAD4);
485 nbFaces = iLen * jLenMin1 * kLenMin1;
486 nbFaces += jLen * kLenMin1 * iLenMin1;
487 nbFaces += kLen * iLenMin1 * jLenMin1;
488 const int* aFaceCount = conn->getGlobalNumberingIndex(MED_FACE);
489 CPPUNIT_ASSERT(aFaceCount[1] - 1 == nbFaces);
490 CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_FACE));
492 CELLMODEL* cellmodelF = (CELLMODEL*)mesh->getCellsTypes(MED_FACE);
493 CPPUNIT_ASSERT(cellmodelF);
496 CPPUNIT_ASSERT(conn->getElementType(MED_EDGE, 1) == MED_SEG2);
497 if (kLen) { // 3d grid
498 nbEdges = iLenMin1 * jLen * kLen;
499 nbEdges += jLenMin1 * kLen * iLen;
500 nbEdges += kLenMin1 * iLen * jLen;
502 else if (jLen) { // 2d
503 nbEdges = iLenMin1 * jLen;
504 nbEdges += jLenMin1 * iLen;
506 const int* anEdgeCount = conn->getGlobalNumberingIndex(MED_EDGE);
507 CPPUNIT_ASSERT(anEdgeCount[1] - 1 == nbEdges);
508 CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_EDGE));
510 CELLMODEL* cellmodelE = (CELLMODEL*)mesh->getCellsTypes(MED_EDGE);
511 CPPUNIT_ASSERT(cellmodelE);
515 // Testing getArrayValue()
516 for ( int ii = 1; ii <= nbCoords; ii++ )
517 for ( int jj = 0; jj < ii + 1; jj++ )
518 CPPUNIT_ASSERT(myGrid2->getArrayValue(ii, jj) == xyz[ii - 1][jj]);
520 CPPUNIT_ASSERT_THROW(myGrid2->getArrayValue(nbCoords + 1, 0), MEDEXCEPTION);
521 CPPUNIT_ASSERT_THROW(myGrid2->getArrayValue(1, myGrid2->getArrayLength(1) + 1), MEDEXCEPTION);
522 myGrid2->setGridType(MED_POLAR);
524 //testing read/write functions
531 idGridV21 = const_cast<MESH*>(mesh)->addDriver(MED_DRIVER,filenameout21);
533 catch(MEDEXCEPTION &e)
535 CPPUNIT_FAIL(e.what());
539 CPPUNIT_FAIL("Unknown exception");
542 // write this driver to file as an unstructured mesh
543 CPPUNIT_ASSERT_NO_THROW(mesh->write(idGridV21));
545 GRID* myGrid3 = new GRID();
546 // add new driver for myGrid3
548 CPPUNIT_ASSERT_NO_THROW(driver = myGrid3->addDriver(MED_DRIVER, filenameout21));
550 //#ifdef ENABLE_FORCED_FAILURES
551 // ? (BUG) ? "The mesh dimension |-1| seems to be incorrect for
552 // the mesh : |Default Mesh Name|"
553 // TO CHECK writing CAREFULLY
554 // !!!!!!!!! Mesh was written as UNSTRUCTURED
555 // changed on THROW accoding to EAP
556 CPPUNIT_ASSERT_THROW(myGrid3->read(driver),MEDEXCEPTION);
557 //CPPUNIT_ASSERT_NO_THROW(myGrid3->read(driver));
559 // Testing getArrayValue()
560 //for ( int ii = 1; ii <= nbCoords; ii++ )
561 // for ( int jj = 0; jj < ii + 1; jj++ )
562 // CPPUNIT_ASSERT(myGrid3->getArrayValue(ii, jj) == xyz[ii - 1][jj]);
564 //CPPUNIT_ASSERT(myGrid3->getGridType() == MED_POLAR);
567 myGrid3->removeReference();
570 CPPUNIT_ASSERT_NO_THROW(myGrid2->init());
571 CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN);
572 CPPUNIT_ASSERT(myGrid2->getArrayLength(1) == 0);
573 CPPUNIT_ASSERT(myGrid2->getArrayLength(2) == 0);
574 CPPUNIT_ASSERT(myGrid2->getArrayLength(3) == 0);
575 //#ifdef ENABLE_FAULTS
576 // (BUG) Segmentation Fault
577 //myGrid2->makeUnstructured();
579 //#ifdef ENABLE_FORCED_FAILURES
580 // TODO: fix it - unstructured mesh should be simply empty, actually useless
581 //CPPUNIT_FAIL("ERROR:makeUnstructured() - there is no check if grid is empty or not");
584 myGrid2->removeReference();
585 mesh->removeReference();
590 CPPUNIT_ASSERT_NO_THROW(myGrid2 = new GRID(MED_DRIVER, filename, mesh_names[1]));
592 // Check if something has been read - full mesh data testing is above
593 CPPUNIT_ASSERT(myGrid2->getSpaceDimension());
594 CPPUNIT_ASSERT(myGrid2->getNumberOfNodes());
595 CPPUNIT_ASSERT(myGrid2->getNumberOfTypes(MED_CELL) == 1);
596 const medGeometryElement* types2;
597 CPPUNIT_ASSERT_NO_THROW(types2 = myGrid2->getTypes(MED_CELL));
599 CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid2->getNumberOfElements(MED_CELL,types2[0]));
600 CPPUNIT_ASSERT(nbElem);
601 myGrid2->removeReference();
605 GRID* myGrid4 = new GRID();
606 filename = getResourceFile("pointe.med");
607 myGrid4->setName("maa1");
608 MED_MESH_RDONLY_DRIVER myMeshDriver(filename, myGrid4);
609 myMeshDriver.setMeshName("maa1");
611 // add new driver for myGrid4
613 CPPUNIT_ASSERT_NO_THROW(driver = myGrid4->addDriver(myMeshDriver));
615 // MED Exception : MED_MESH_RDONLY_DRIVER21::getGRID() : The number
616 // of nodes |-1| seems to be incorrect for the mesh : |maa1|
617 // But this exception seems to be correct reaction on attempt
618 // to read a grid from a file, which does not contain it.
619 CPPUNIT_ASSERT_THROW(myGrid4->read(driver), MEDEXCEPTION);
621 myGrid4->removeReference();