Back to index

salome-med  6.5.0
MEDMEMTest_Grid_fault.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDMEMTest.hxx"
00021 #include <cppunit/TestAssert.h>
00022 
00023 #include "MEDMEM_define.hxx"
00024 #include "MEDMEM_Grid.hxx"
00025 #include "MEDMEM_Mesh.hxx"
00026 #include "MEDMEM_MedFileBrowser.hxx"
00027 #include "MEDMEM_MedMeshDriver.hxx"
00028 
00029 #include <sstream>
00030 #include <cmath>
00031 
00032 // use this define to enable lines, execution of which leads to Segmentation Fault
00033 //#define ENABLE_FAULTS
00034 
00035 // use this define to enable CPPUNIT asserts and fails, showing bugs
00036 //#define ENABLE_FORCED_FAILURES
00037 
00038 using namespace std;
00039 using namespace MEDMEM;
00040 using namespace MED_EN;
00041 
00042 
00082 static void MEDMEMTest_testGrid()
00083 {
00084   string filename      = getResourceFile("test19.med") ;
00085   string filenameout21 = makeTmpFile("myGridWrite_grid21.med");
00086   ostringstream out;
00087 
00088   // To remove tmp files from disk
00089   MEDMEMTest_TmpFilesRemover aRemover;
00090   aRemover.Register(filenameout21);
00091 
00092   // Remove file in advance to ensure it does not exist at the moment of writing,
00093   // because files are not removed by the MEDMEMTest_TmpFilesRemover in case of
00094   // Segmentation Fault (in previous tests execution).
00095   {
00096     MEDMEMTest_TmpFilesRemover aRemover1;
00097     aRemover1.Register(filenameout21);
00098   }
00099 
00100   MEDFILEBROWSER * myMed = new MEDFILEBROWSER(filename);
00101 
00102   int nbMeshes = myMed->getNumberOfMeshes();
00103   CPPUNIT_ASSERT(nbMeshes);
00104 
00105   vector<string> mesh_names = myMed->getMeshNames();
00106   CPPUNIT_ASSERT(mesh_names.size() != 0);
00107 
00109   // test1 "CARTESIAN GRID"   //
00111   {
00112     CPPUNIT_ASSERT(myMed->isStructuredMesh(mesh_names[0]));
00113 
00114     CPPUNIT_ASSERT_THROW( MESH(MED_DRIVER, myMed->getFileName(), mesh_names[0]), MEDEXCEPTION);
00115 
00116     GMESH* myMesh = new GRID(MED_DRIVER, myMed->getFileName(), mesh_names[0]);
00117     std::auto_ptr<GMESH> meshDeleter(myMesh);
00118 
00119     CPPUNIT_ASSERT(myMesh != NULL);
00120     CPPUNIT_ASSERT(myMesh->getIsAGrid());
00121 
00122     GRID* myGrid = dynamic_cast<GRID*>(myMesh);
00123     CPPUNIT_ASSERT(myGrid);
00124 
00125     CPPUNIT_ASSERT_THROW(myGrid->getArrayLength(0), MEDEXCEPTION);
00126 
00127     int I, J, K;
00128     CPPUNIT_ASSERT_NO_THROW(I = myGrid->getArrayLength(1));
00129     CPPUNIT_ASSERT_NO_THROW(J = myGrid->getArrayLength(2));
00130     CPPUNIT_ASSERT_NO_THROW(K = myGrid->getArrayLength(3));
00131 
00132     CPPUNIT_ASSERT(I);
00133     CPPUNIT_ASSERT(J);
00134 
00135     med_grid_type grid_type = myGrid->getGridType();
00136     CPPUNIT_ASSERT_MESSAGE("Wrong grid type", grid_type == MED_CARTESIAN);
00137 
00138     const MESH* mesh = myGrid->convertInMESH();
00139     const double * coordinates = mesh->getCoordinates(MED_FULL_INTERLACE);
00140     int SpaceDimension = myGrid->getSpaceDimension();
00141     for (int axe = 0; axe < SpaceDimension; axe++) {
00142       for (int num = 0; num < myGrid->getNumberOfNodes(); num++) {
00143         double coordinate;
00144         CPPUNIT_ASSERT_NO_THROW(coordinate = mesh->getCoordinate(num + 1, axe + 1));
00145         //cout << "coordinate = " << coordinate << endl;
00146         CPPUNIT_ASSERT(fabs(coordinate - coordinates[(num * SpaceDimension)+axe]) < 0.001);
00147       }
00148     }
00149 
00150     int nbTypesCell = myGrid->getNumberOfTypes(MED_CELL);
00151     CPPUNIT_ASSERT(nbTypesCell == 1);
00152 
00153     const medGeometryElement* types;
00154     CPPUNIT_ASSERT_NO_THROW(types = myGrid->getTypes(MED_CELL));
00155 //#ifdef ENABLE_FORCED_FAILURES
00156     // Compilation warning about GRID::getTypes():
00157     // "inline function
00158     // `virtual const MED_EN::medGeometryElement* MEDMEM::GRID::getTypes(MED_EN::medEntityMesh) const'
00159     // used but never defined".
00160     // In MEDMEM_Grid.hxx:
00161     // inline const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const;
00162     // But implemented in MEDMEM_Grid.cxx:
00163     //        const MED_EN::medGeometryElement * GRID::getTypes(MED_EN::medEntityMesh entity) const
00164 //    CPPUNIT_FAIL("Problem with GRID::getTypes() method implementation.");
00165 //#endif
00166     CPPUNIT_ASSERT(types[0] == MED_QUAD4);
00167 
00168     int nbElem = 0;
00169     CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid->getNumberOfElements(MED_CELL,types[0]));
00170     CPPUNIT_ASSERT(nbElem);
00171 
00172     int nbNodes = myGrid->getNumberOfNodes();
00173     CPPUNIT_ASSERT(nbNodes);
00174 
00175     int ijkNode[3];
00176     int NodeNumber;
00177     for (int nbNode = 1; nbNode <= nbNodes; nbNode++) {
00178       CPPUNIT_ASSERT_NO_THROW(myGrid->getNodePosition(nbNode, ijkNode[0], ijkNode[1], ijkNode[2]));
00179       CPPUNIT_ASSERT_NO_THROW(NodeNumber = myGrid->getNodeNumber(ijkNode[0], ijkNode[1], ijkNode[2]));
00180       CPPUNIT_ASSERT(NodeNumber == nbNode);
00181     }
00182 
00183     int nbCells = myGrid->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS);
00184     CPPUNIT_ASSERT(nbCells);
00185 
00186     int ijkCell[3];
00187     int CellNumber;
00188     for (int nbCell = 1; nbCell <= nbCells; nbCell++) {
00189       CPPUNIT_ASSERT_NO_THROW(myGrid->getCellPosition(nbCell, ijkCell[0], ijkCell[1], ijkCell[2]));
00190       CPPUNIT_ASSERT_NO_THROW(CellNumber = myGrid->getCellNumber(ijkCell[0], ijkCell[1], ijkCell[2]));
00191       CPPUNIT_ASSERT(CellNumber == nbCell);
00192     }
00193 
00194     int nbEdges = myGrid->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS);
00195     CPPUNIT_ASSERT(nbEdges);
00196 
00197     int ijkAxisEdge[4];
00198     int EdgeNumber;
00199     for (int nbEdge = 1; nbEdge <= nbEdges; nbEdge++) {
00200       CPPUNIT_ASSERT_NO_THROW(myGrid->getEdgePosition(nbEdge, ijkAxisEdge[0], ijkAxisEdge[1],
00201                                                       ijkAxisEdge[2], ijkAxisEdge[3]));
00202       CPPUNIT_ASSERT_NO_THROW(EdgeNumber = myGrid->getEdgeNumber(ijkAxisEdge[0], ijkAxisEdge[1],
00203                                                                  ijkAxisEdge[2], ijkAxisEdge[3]));
00204       CPPUNIT_ASSERT(EdgeNumber == nbEdge);
00205     }
00206 
00207     int nbFaces = myGrid->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS);
00208     CPPUNIT_ASSERT(nbFaces == 0);
00209 
00210 //#ifdef ENABLE_FORCED_FAILURES
00211     CPPUNIT_FAIL("ERROR: nbFaces == 0, but getFacePosition(AnyNumber, ...) - return position(i,j,k)");
00212 //#endif
00213     int ijkAxisFace[4];
00214     CPPUNIT_ASSERT_NO_THROW(myGrid->getFacePosition(6, ijkAxisFace[0], ijkAxisFace[1],
00215                                                     ijkAxisFace[2], ijkAxisFace[3]));
00216     CPPUNIT_ASSERT(ijkAxisFace[0]);
00217     CPPUNIT_ASSERT(ijkAxisFace[1]);
00218     CPPUNIT_ASSERT(ijkAxisFace[2]);
00219 
00220     /*int FaceNumber;
00221     for(int nbFace = 1; nbFace <= nbFaces; nbFace++)
00222     {
00223       CPPUNIT_ASSERT_NO_THROW( myGrid->getFacePosition(nbFace, ijkAxisFace[0], ijkAxisFace[1],
00224                                                        ijkAxisFace[2], ijkAxisFace[3]));
00225       CPPUNIT_ASSERT_NO_THROW( EdgeNumber = myGrid->getEdgeNumber(ijkAxisFace[0], ijkAxisFace[1],
00226                                                                   ijkAxisFace[2], ijkAxisFace[3]));
00227       CPPUNIT_ASSERT(FaceNumber == nbFace);
00228     }*/
00229 
00230     bool existConnect = false;
00231     CPPUNIT_ASSERT_NO_THROW(existConnect = mesh->existConnectivity(MED_NODAL, MED_CELL));
00232     if (!existConnect) {
00233       CPPUNIT_ASSERT_NO_THROW(mesh->calculateConnectivity( MED_NODAL, MED_CELL));
00234       CPPUNIT_ASSERT(mesh->existConnectivity(MED_NODAL, MED_CELL));
00235     }
00236 
00237     const int* Connectivity;
00238     const int* connectivity_index;
00239     CPPUNIT_ASSERT_NO_THROW(Connectivity = mesh->getConnectivity( MED_NODAL,
00240                                                                  MED_CELL, types[0]));
00241     CPPUNIT_ASSERT_NO_THROW(connectivity_index = mesh->getConnectivityIndex(MED_NODAL, MED_CELL));
00242     out << "Nodal connectivity" << endl;
00243     for (int j = 0; j < nbElem; j++) {
00244       out << "Element "<< j+1 << " : ";
00245       for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++)
00246         out << Connectivity[k-1] << " ";
00247       out << endl;
00248     }
00249 
00250     const int * ReverseNodalConnectivity;
00251     const int * ReverseConnectivityIndex;
00252     CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivity = mesh->getReverseConnectivity(MED_NODAL));
00253     CPPUNIT_ASSERT_NO_THROW(ReverseConnectivityIndex = mesh->getReverseConnectivityIndex(MED_NODAL));
00254     for (int i = 0; i < nbNodes; i++) {
00255       out << "Node "<< i+1 << " : ";
00256       for (int j = ReverseConnectivityIndex[i]; j < ReverseConnectivityIndex[i+1]; j++)
00257         out << ReverseNodalConnectivity[j-1] << " ";
00258       out << endl;
00259     }
00260 
00261     const int* myGlobalNbIdx;
00262     CPPUNIT_ASSERT_NO_THROW(myGlobalNbIdx = mesh->getGlobalNumberingIndex(MED_CELL));
00263     for (int i = 0; i <= nbTypesCell; i++) {
00264       if (i == nbTypesCell) {
00265         CPPUNIT_ASSERT_THROW(myGrid->getElementType(MED_CELL, myGlobalNbIdx[i]), MEDEXCEPTION);
00266         break;
00267       }
00268       medGeometryElement aElem;
00269       CPPUNIT_ASSERT_NO_THROW(aElem = myGrid->getElementType(MED_CELL, myGlobalNbIdx[i]));
00270       CPPUNIT_ASSERT(types[0] == aElem);
00271     }
00272 
00273     CPPUNIT_ASSERT_NO_THROW(existConnect = mesh->existConnectivity(MED_DESCENDING, MED_CELL));
00274     if (!existConnect) {
00275       CPPUNIT_ASSERT_NO_THROW(mesh->calculateConnectivity( MED_DESCENDING, MED_CELL));
00276       CPPUNIT_ASSERT(mesh->existConnectivity(MED_DESCENDING, MED_CELL));
00277     }
00278 
00279     const int* ConnectivityDes;
00280     const int* connectivity_index_des;
00281     CPPUNIT_ASSERT_NO_THROW(ConnectivityDes = mesh->getConnectivity( MED_DESCENDING,
00282                                                                     MED_CELL, MED_ALL_ELEMENTS));
00283     CPPUNIT_ASSERT_NO_THROW(connectivity_index_des =
00284                             mesh->getConnectivityIndex(MED_DESCENDING, MED_CELL));
00285     out<<"Descending connectivity"<<endl;
00286     for (int j = 0; j < nbElem; j++) {
00287       out << "Element "<< j+1 << " : ";
00288       for (int k = connectivity_index_des[j]; k < connectivity_index_des[j+1]; k++)
00289         out << ConnectivityDes[k-1] << " ";
00290       out << endl;
00291     }
00292 
00293     const int * ReverseDesConnectivity;
00294     const int * ReverseConnectivityIndexDes;
00295     CPPUNIT_ASSERT_NO_THROW(ReverseDesConnectivity = mesh->getReverseConnectivity(MED_DESCENDING));
00296     CPPUNIT_ASSERT_NO_THROW(ReverseConnectivityIndexDes =
00297                             mesh->getReverseConnectivityIndex(MED_DESCENDING));
00298     for (int i = 0; i < nbNodes; i++) {
00299       out << "Node "<< i+1 << " : ";
00300       for (int j = ReverseConnectivityIndexDes[i]; j < ReverseConnectivityIndexDes[i+1]; j++)
00301         out << ReverseDesConnectivity[j-1] << " ";
00302       out << endl;
00303     }
00304     mesh->removeReference();
00305 
00306   }
00307 
00309   // test2 "MED_BODY_FITTED"  //
00311   {
00312     CPPUNIT_ASSERT_THROW( MESH(MED_DRIVER, myMed->getFileName(), mesh_names[1]), MEDEXCEPTION);
00313 
00314     GMESH* myMesh1 = new GRID(MED_DRIVER,myMed->getFileName(),mesh_names[1]);
00315     std::auto_ptr<GMESH> meshDeleter(myMesh1);
00316 
00317     CPPUNIT_ASSERT(myMesh1 != NULL);
00318     CPPUNIT_ASSERT(myMesh1->getIsAGrid());
00319 
00320     GRID* myGrid1 = dynamic_cast<GRID*>(myMesh1);
00321     CPPUNIT_ASSERT(myGrid1);
00322 
00323     int I, J, K;
00324     CPPUNIT_ASSERT_NO_THROW(I = myGrid1->getArrayLength(1));
00325     CPPUNIT_ASSERT_NO_THROW(J = myGrid1->getArrayLength(2));
00326     CPPUNIT_ASSERT_NO_THROW(K = myGrid1->getArrayLength(3));
00327 
00328     CPPUNIT_ASSERT(I == 2);
00329     CPPUNIT_ASSERT(J == 2);
00330 
00331     med_grid_type grid_type = myGrid1->getGridType();
00332     CPPUNIT_ASSERT_MESSAGE("Wrong grid type", grid_type == MED_BODY_FITTED);
00333 
00334     int nbTypesCell = myGrid1->getNumberOfTypes(MED_CELL);
00335     CPPUNIT_ASSERT(nbTypesCell == 1);
00336 
00337     const medGeometryElement* types1;
00338     CPPUNIT_ASSERT_NO_THROW( types1 = myGrid1->getTypes(MED_CELL) );
00339     CPPUNIT_ASSERT( types1[0] == MED_QUAD4);
00340 
00341     int nbElem;
00342     CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid1->getNumberOfElements(MED_CELL, types1[0]));
00343     CPPUNIT_ASSERT(nbElem);
00344 
00345     const int* BodyConnectivity;
00346     const int* body_connectivity_index;
00347     int ijkNodeBody[3];
00348     const MESH* mesh = myGrid1->convertInMESH();
00349     CPPUNIT_ASSERT_NO_THROW(BodyConnectivity = mesh->getConnectivity( MED_NODAL,
00350                                                                      MED_CELL, types1[0]));
00351     CPPUNIT_ASSERT_NO_THROW(body_connectivity_index = mesh->getConnectivityIndex(MED_NODAL, MED_CELL));
00352     out<<"Nodal connectivity"<<endl;
00353     for (int j = 0; j < nbElem; j++) {
00354       out << "Element "<< j+1 << " : ";
00355       for (int k = body_connectivity_index[j]; k < body_connectivity_index[j+1]; k++){
00356         CPPUNIT_ASSERT_NO_THROW(myGrid1->getNodePosition(BodyConnectivity[k-1], ijkNodeBody[0],
00357                                                          ijkNodeBody[1], ijkNodeBody[2]));
00358         out << BodyConnectivity[k-1] << " ";
00359       }
00360       out << endl;
00361     }
00362     mesh->removeReference();
00363   }
00364 
00366   // test3 "maa1" which in fact is not a pure GRID //
00368   {
00369     GMESH* myMesh2 = NULL;
00370 
00371     CPPUNIT_ASSERT_THROW( myMesh2 = new GRID( MED_DRIVER,myMed->getFileName(),mesh_names[2]),
00372                           MEDEXCEPTION );
00373     CPPUNIT_ASSERT_NO_THROW( myMesh2 = new MESH( MED_DRIVER,myMed->getFileName(),mesh_names[2]));
00374 
00375     CPPUNIT_ASSERT(myMesh2 != NULL);
00376     CPPUNIT_ASSERT(!(myMesh2->getIsAGrid()));
00377     myMesh2->removeReference();
00378   }
00379 
00380   delete myMed;
00381 
00383   // test4 create new GRID  //
00385 
00386   // Default constructor and destructor
00387   {
00388     GRID* myGrid2 = new GRID();
00389     CPPUNIT_ASSERT(myGrid2->getIsAGrid());
00390     CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN);
00391     CPPUNIT_ASSERT(!myGrid2->getArrayLength(1));
00392     CPPUNIT_ASSERT(!myGrid2->getArrayLength(2));
00393     CPPUNIT_ASSERT(!myGrid2->getArrayLength(3));
00394     myGrid2->removeReference();
00395   }
00396 
00397   // Constructor with grid type, setGridType()
00398   {
00399     GRID* myGrid2 = new GRID(MED_POLAR);
00400     CPPUNIT_ASSERT(myGrid2->getGridType() == MED_POLAR);
00401     myGrid2->setGridType(MED_CARTESIAN);
00402     CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN);
00403     myGrid2->removeReference();
00404   }
00405 
00406   // Constructor with coordinate values, getArrayValue(), init()
00407   {
00408     vector<vector<double> > xyz;
00409     const int nbCoords = 3;
00410     xyz.resize(nbCoords);
00411     for ( int i = 0; i < nbCoords; i++ )
00412     {
00413       xyz[i].resize(i + 2);
00414       for ( int j = 0; j < i + 2; j++ )
00415         xyz[i][j] = j;
00416     }
00417     vector<string> Coord_Names;
00418     Coord_Names.resize(nbCoords);
00419     Coord_Names[0] = "X";
00420     Coord_Names[1] = "Y";
00421     Coord_Names[2] = "Z";
00422 
00423     vector<string> Coord_Units;
00424     Coord_Units.resize(nbCoords);
00425     for(int i = 0; i < 3; i++)
00426       Coord_Units[i] = "cm";
00427 
00428     GRID* myGrid2;
00429 
00430     try{
00431       myGrid2 = new GRID(xyz, Coord_Names, Coord_Units, MED_CARTESIAN);
00432     }
00433     catch (const std::exception &e)
00434     {
00435       CPPUNIT_FAIL(e.what());
00436     }
00437     catch (...)
00438     {
00439       CPPUNIT_FAIL("Unknown exception");
00440     }
00441 
00442     // testing getCoordinateptr() and fillCoordinates()
00443     // We fill a map of all possible coordinate triples.
00444     // After iteration through all coordinates, this map should contain only "true" as data.
00445     // "true" in some map element during iteration means duplicated node position.
00446     // "false" in some map element after iteration means empty node position.
00447     map<int, bool> found;
00448     for ( unsigned i1 = 0; i1 < xyz[0].size(); i1++ )
00449       for ( unsigned i2 = 0; i2 < xyz[1].size(); i2++ )
00450         for ( unsigned i3 = 0; i3 < xyz[2].size(); i3++ )
00451           found[ xyz[0][i1] * 100 + xyz[1][i2] * 10 + xyz[2][i3] ] = false;
00452 
00453     const MESH* mesh = myGrid2->convertInMESH();
00454     COORDINATE* coords = (COORDINATE*)mesh->getCoordinateptr();
00455     CPPUNIT_ASSERT(coords);
00456     for (int num = 0; num < myGrid2->getNumberOfNodes(); num++) {
00457       int x = int(coords->getCoordinate(num + 1, 1));
00458       int y = int(coords->getCoordinate(num + 1, 2));
00459       int z = int(coords->getCoordinate(num + 1, 3));
00460       CPPUNIT_ASSERT(!found[x * 100 + y * 10 + z]);
00461       found[x * 100 + y * 10 + z] = true;
00462     }
00463 
00464     for ( map<int, bool>::iterator it = found.begin(); it != found.end(); it++ )
00465       CPPUNIT_ASSERT((*it).second);
00466 
00467     // Testing fillConnectivity() and getConnectivityptr()
00468     // Basic testing: presence of connectivity arrays, element types and number of elements
00469     CONNECTIVITY* conn = (CONNECTIVITY*)mesh->getConnectivityptr();
00470     CPPUNIT_ASSERT(conn);
00471     bool hasFaces = myGrid2->getArrayLength(3), hasEdges = myGrid2->getArrayLength(2);
00472     medGeometryElement aCellGeometry;
00473     if (hasFaces)      aCellGeometry = MED_HEXA8;
00474     else if (hasEdges) aCellGeometry = MED_QUAD4;
00475     else               aCellGeometry = MED_SEG2;
00476     CPPUNIT_ASSERT(conn->getElementType(MED_CELL, 1) == aCellGeometry);
00477     CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL,      MED_CELL));
00478     CPPUNIT_ASSERT(conn->existConnectivity(MED_DESCENDING, MED_CELL));
00479     //test getCellsTypes
00480     CELLMODEL* cellmodel = (CELLMODEL*)mesh->getCellsTypes(MED_CELL);
00481     CPPUNIT_ASSERT(cellmodel);
00482 
00483     int nbCells, nbFaces, nbEdges;
00484 
00485     int iLen     = myGrid2->getArrayLength(1);
00486     int jLen     = myGrid2->getArrayLength(2);
00487     int kLen     = myGrid2->getArrayLength(3);
00488     int iLenMin1 = myGrid2->getArrayLength(1)-1;
00489     int jLenMin1 = myGrid2->getArrayLength(2)-1;
00490     int kLenMin1 = myGrid2->getArrayLength(3)-1;
00491     const int* aCellCount = conn->getGlobalNumberingIndex(MED_CELL);
00492     nbCells = iLenMin1 * jLenMin1 * kLenMin1;
00493     CPPUNIT_ASSERT(aCellCount[1] - 1 == nbCells);
00494 
00495     if (hasFaces){
00496       CPPUNIT_ASSERT(conn->getElementType(MED_FACE, 1) == MED_QUAD4);
00497       nbFaces  = iLen * jLenMin1 * kLenMin1;
00498       nbFaces += jLen * kLenMin1 * iLenMin1;
00499       nbFaces += kLen * iLenMin1 * jLenMin1;
00500       const int* aFaceCount = conn->getGlobalNumberingIndex(MED_FACE);
00501       CPPUNIT_ASSERT(aFaceCount[1] - 1 == nbFaces);
00502       CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_FACE));
00503       //test getCellsTypes
00504       CELLMODEL* cellmodelF = (CELLMODEL*)mesh->getCellsTypes(MED_FACE);
00505       CPPUNIT_ASSERT(cellmodelF);
00506     }
00507     if (hasEdges){
00508       CPPUNIT_ASSERT(conn->getElementType(MED_EDGE, 1) == MED_SEG2);
00509       if (kLen) { // 3d grid
00510         nbEdges  = iLenMin1 * jLen * kLen;
00511         nbEdges += jLenMin1 * kLen * iLen;
00512         nbEdges += kLenMin1 * iLen * jLen;
00513       }
00514       else if (jLen) { // 2d
00515         nbEdges  = iLenMin1 * jLen;
00516         nbEdges += jLenMin1 * iLen;
00517       }
00518       const int* anEdgeCount = conn->getGlobalNumberingIndex(MED_EDGE);
00519       CPPUNIT_ASSERT(anEdgeCount[1] - 1 == nbEdges);
00520       CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_EDGE));
00521       //test getCellsTypes
00522       CELLMODEL* cellmodelE = (CELLMODEL*)mesh->getCellsTypes(MED_EDGE);
00523       CPPUNIT_ASSERT(cellmodelE);
00524 
00525     }
00526 
00527     // Testing getArrayValue()
00528     for ( int ii = 1; ii <= nbCoords; ii++ )
00529       for ( int jj = 0; jj < ii + 1; jj++ )
00530         CPPUNIT_ASSERT(myGrid2->getArrayValue(ii, jj) == xyz[ii - 1][jj]);
00531 
00532     CPPUNIT_ASSERT_THROW(myGrid2->getArrayValue(nbCoords + 1, 0), MEDEXCEPTION);
00533     CPPUNIT_ASSERT_THROW(myGrid2->getArrayValue(1, myGrid2->getArrayLength(1) + 1), MEDEXCEPTION);
00534     myGrid2->setGridType(MED_POLAR);
00535 
00536     //testing read/write functions
00537 
00538     // add new driver
00539     int idGridV21;
00540 
00541     try
00542     {
00543       idGridV21 = const_cast<MESH*>(mesh)->addDriver(MED_DRIVER,filenameout21);
00544     }
00545     catch(MEDEXCEPTION &e)
00546     {
00547       CPPUNIT_FAIL(e.what());
00548     }
00549     catch( ... )
00550     {
00551       CPPUNIT_FAIL("Unknown exception");
00552     }
00553 
00554     // write this driver to file as an unstructured mesh
00555     CPPUNIT_ASSERT_NO_THROW(mesh->write(idGridV21));
00556 
00557     GRID* myGrid3 = new GRID();
00558     // add new driver for myGrid3
00559     int driver;
00560     CPPUNIT_ASSERT_NO_THROW(driver = myGrid3->addDriver(MED_DRIVER, filenameout21));
00561 
00562 //#ifdef ENABLE_FORCED_FAILURES
00563     // ? (BUG) ? "The mesh dimension |-1| seems to be incorrect for the mesh : |Default Mesh Name|"
00564     CPPUNIT_ASSERT_NO_THROW(myGrid3->read(driver));
00565 
00566     // Testing getArrayValue()
00567     for ( int ii = 1; ii <= nbCoords; ii++ )
00568       for ( int jj = 0; jj < ii + 1; jj++ )
00569         CPPUNIT_ASSERT(myGrid3->getArrayValue(ii, jj) == xyz[ii - 1][jj]);
00570 
00571     CPPUNIT_ASSERT(myGrid3->getGridType() == MED_POLAR);
00572 //#endif
00573 
00574     myGrid3->removeReference();
00575 
00576     //test init()
00577     CPPUNIT_ASSERT_NO_THROW(myGrid2->init());
00578     CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN);
00579     CPPUNIT_ASSERT(myGrid2->getArrayLength(1) == 0);
00580     CPPUNIT_ASSERT(myGrid2->getArrayLength(2) == 0);
00581     CPPUNIT_ASSERT(myGrid2->getArrayLength(3) == 0);
00582 //#ifdef ENABLE_FAULTS
00583     // (BUG) Segmentation Fault
00584     //myGrid2->makeUnstructured();
00585 //#endif
00586 //#ifdef ENABLE_FORCED_FAILURES
00587 //    CPPUNIT_FAIL("ERROR:makeUnstructured() - there is no check if grid is empty or not");
00588 //#endif
00589 
00590     myGrid2->removeReference();
00591     mesh->removeReference();
00592   }
00593 
00594 //#ifdef ENABLE_FORCED_FAILURES
00595   {
00596     GRID* myGrid2;
00597     // ? (BUG) ? MED Exception in /dn20/salome/jfa/V3/SRC/MED_SRC/src/MEDMEM/MEDMEM_MedM
00598     //eshDriver21.cxx [430] : MED_MESH_RDONLY_DRIVER21::getCOORDINATE() : The number 
00599     //of nodes |0| seems to be incorrect for the mesh : |bodyfitted|
00600     CPPUNIT_ASSERT_NO_THROW(myGrid2 = new GRID(MED_DRIVER, filename, mesh_names[1]));
00601 
00602     // Check if something has been read - full mesh data testing is above
00603     CPPUNIT_ASSERT(myGrid2->getSpaceDimension());
00604     CPPUNIT_ASSERT(myGrid2->getNumberOfNodes());
00605     CPPUNIT_ASSERT(myGrid2->getNumberOfTypes(MED_CELL) == 1);
00606     const medGeometryElement* types2;
00607     CPPUNIT_ASSERT_NO_THROW(types2 = myGrid2->getTypes(MED_CELL));
00608     int nbElem;
00609     CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid2->getNumberOfElements(MED_CELL,types2[0]));
00610     CPPUNIT_ASSERT(nbElem);
00611     myGrid2->removeReference();
00612   }
00613 //#endif
00614 
00615   {
00616     GRID* myGrid4 = new GRID();
00617     filename = getResourceFile("pointe.med");
00618     myGrid4->setName("maa1");
00619     MED_MESH_RDONLY_DRIVER myMeshDriver(filename, myGrid4);
00620     myMeshDriver.setMeshName("maa1");
00621 
00622     // add new driver for myGrid4
00623     int driver;
00624     CPPUNIT_ASSERT_NO_THROW(driver = myGrid4->addDriver(myMeshDriver));
00625 
00626     // ??? ERROR:myGrid4->fillMeshAfterRead()- this method is incomplete:
00627     // currently it only resets _is_coordinates_filled and _is_connectivity_filled
00628     // flags that leads to grid reconstruction
00629 
00630     // MED Exception : MED_MESH_RDONLY_DRIVER21::getGRID() : The number
00631     // of nodes |-1| seems to be incorrect for the mesh : |maa1|
00632     // But this exception seems to be correct reaction on attempt
00633     // to read a grid from a file, which does not contain it.
00634     CPPUNIT_ASSERT_THROW(myGrid4->read(driver), MEDEXCEPTION);
00635     //CPPUNIT_ASSERT_NO_THROW(myGrid4->read(driver));
00636     /*CPPUNIT_ASSERT(myGrid4->getArrayLength(1) == 0);
00637     CPPUNIT_ASSERT(myGrid4->getArrayLength(2) == 0);
00638     CPPUNIT_ASSERT(myGrid4->getArrayLength(3) == 0);
00639     myGrid4->fillMeshAfterRead();
00640     CPPUNIT_ASSERT(myGrid4->getArrayLength(1) != 0);
00641     CPPUNIT_ASSERT(myGrid4->getArrayLength(2) != 0);
00642     CPPUNIT_ASSERT(myGrid4->getArrayLength(3) != 0);*/
00643 
00644     myGrid4->removeReference();
00645   }
00646 }
00647 
00648 int main (int argc, char** argv)
00649 {
00650   MEDMEMTest_testGrid();
00651 }