Back to index

salome-med  6.5.0
MEDMEMTest_Grid.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 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     CPPUNIT_ASSERT(types[0] == MED_QUAD4);
00156 
00157     int nbElem = 0;
00158     CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid->getNumberOfElements(MED_CELL,types[0]));
00159     CPPUNIT_ASSERT(nbElem);
00160 
00161     int nbNodes = myGrid->getNumberOfNodes();
00162     CPPUNIT_ASSERT(nbNodes);
00163 
00164     int ijkNode[3];
00165     int NodeNumber;
00166     for (int nbNode = 1; nbNode <= nbNodes; nbNode++) {
00167       CPPUNIT_ASSERT_NO_THROW(myGrid->getNodePosition(nbNode, ijkNode[0], ijkNode[1], ijkNode[2]));
00168       CPPUNIT_ASSERT_NO_THROW(NodeNumber = myGrid->getNodeNumber(ijkNode[0], ijkNode[1], ijkNode[2]));
00169       CPPUNIT_ASSERT(NodeNumber == nbNode);
00170     }
00171 
00172     int nbCells = myGrid->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS);
00173     CPPUNIT_ASSERT(nbCells);
00174 
00175     int ijkCell[3];
00176     int CellNumber;
00177     for (int nbCell = 1; nbCell <= nbCells; nbCell++) {
00178       CPPUNIT_ASSERT_NO_THROW(myGrid->getCellPosition(nbCell, ijkCell[0], ijkCell[1], ijkCell[2]));
00179       CPPUNIT_ASSERT_NO_THROW(CellNumber = myGrid->getCellNumber(ijkCell[0], ijkCell[1], ijkCell[2]));
00180       CPPUNIT_ASSERT(CellNumber == nbCell);
00181     }
00182 
00183     int nbEdges = myGrid->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS);
00184     CPPUNIT_ASSERT(nbEdges);
00185 
00186     int ijkAxisEdge[4];
00187     int EdgeNumber;
00188     for (int nbEdge = 1; nbEdge <= nbEdges; nbEdge++) {
00189       CPPUNIT_ASSERT_NO_THROW(myGrid->getEdgePosition(nbEdge, ijkAxisEdge[0], ijkAxisEdge[1],
00190                                                       ijkAxisEdge[2], ijkAxisEdge[3]));
00191       CPPUNIT_ASSERT_NO_THROW(EdgeNumber = myGrid->getEdgeNumber(ijkAxisEdge[0], ijkAxisEdge[1],
00192                                                                  ijkAxisEdge[2], ijkAxisEdge[3]));
00193       CPPUNIT_ASSERT(EdgeNumber == nbEdge);
00194     }
00195 
00196     int nbFaces = myGrid->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS);
00197     CPPUNIT_ASSERT(nbFaces == 0);
00198 
00199     //#ifdef ENABLE_FORCED_FAILURES
00200     // To remove getFacePosition() from API
00201     //CPPUNIT_FAIL("ERROR: nbFaces == 0, but getFacePosition(AnyNumber, ...) - return position(i,j,k)");
00202     //#endif
00203     int ijkAxisFace[4];
00204     CPPUNIT_ASSERT_NO_THROW(myGrid->getFacePosition(6, ijkAxisFace[0], ijkAxisFace[1],
00205                                                     ijkAxisFace[2], ijkAxisFace[3]));
00206     CPPUNIT_ASSERT(ijkAxisFace[0]);
00207     CPPUNIT_ASSERT(ijkAxisFace[1]);
00208     CPPUNIT_ASSERT(ijkAxisFace[2]);
00209 
00210     /*int FaceNumber;
00211     for(int nbFace = 1; nbFace <= nbFaces; nbFace++)
00212     {
00213       CPPUNIT_ASSERT_NO_THROW( myGrid->getFacePosition(nbFace, ijkAxisFace[0], ijkAxisFace[1],
00214                                                        ijkAxisFace[2], ijkAxisFace[3]));
00215       CPPUNIT_ASSERT_NO_THROW( EdgeNumber = myGrid->getEdgeNumber(ijkAxisFace[0], ijkAxisFace[1],
00216                                                                   ijkAxisFace[2], ijkAxisFace[3]));
00217       CPPUNIT_ASSERT(FaceNumber == nbFace);
00218     }*/
00219 
00220     bool existConnect = false;
00221     CPPUNIT_ASSERT_NO_THROW(existConnect = mesh->existConnectivity(MED_NODAL, MED_CELL));
00222     if (!existConnect) {
00223       CPPUNIT_ASSERT_NO_THROW(mesh->calculateConnectivity(MED_NODAL, MED_CELL));
00224       CPPUNIT_ASSERT(mesh->existConnectivity(MED_NODAL, MED_CELL));
00225     }
00226 
00227     const int* Connectivity;
00228     const int* connectivity_index;
00229     CPPUNIT_ASSERT_NO_THROW(Connectivity = mesh->getConnectivity( MED_NODAL, MED_CELL, types[0]));
00230     CPPUNIT_ASSERT_NO_THROW(connectivity_index = mesh->getConnectivityIndex(MED_NODAL, MED_CELL));
00231     out << "Nodal connectivity" << endl;
00232     for (int j = 0; j < nbElem; j++) {
00233       out << "Element "<< j+1 << " : ";
00234       for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++)
00235         out << Connectivity[k-1] << " ";
00236       out << endl;
00237     }
00238 
00239     const int * ReverseNodalConnectivity;
00240     const int * ReverseConnectivityIndex;
00241     CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivity = mesh->getReverseConnectivity(MED_NODAL));
00242     CPPUNIT_ASSERT_NO_THROW(ReverseConnectivityIndex = mesh->getReverseConnectivityIndex(MED_NODAL));
00243     for (int i = 0; i < nbNodes; i++) {
00244       out << "Node "<< i+1 << " : ";
00245       for (int j = ReverseConnectivityIndex[i]; j < ReverseConnectivityIndex[i+1]; j++)
00246         out << ReverseNodalConnectivity[j-1] << " ";
00247       out << endl;
00248     }
00249 
00250     const int* myGlobalNbIdx;
00251     CPPUNIT_ASSERT_NO_THROW(myGlobalNbIdx = mesh->getGlobalNumberingIndex(MED_CELL));
00252     for (int i = 0; i <= nbTypesCell; i++) {
00253       if (i == nbTypesCell) {
00254         CPPUNIT_ASSERT_THROW(myGrid->getElementType(MED_CELL, myGlobalNbIdx[i]), MEDEXCEPTION);
00255         break;
00256       }
00257       medGeometryElement aElem;
00258       CPPUNIT_ASSERT_NO_THROW(aElem = myGrid->getElementType(MED_CELL, myGlobalNbIdx[i]));
00259       CPPUNIT_ASSERT(types[0] == aElem);
00260     }
00261 
00262     CPPUNIT_ASSERT_NO_THROW(existConnect = mesh->existConnectivity(MED_DESCENDING, MED_CELL));
00263     if (!existConnect) {
00264       CPPUNIT_ASSERT_NO_THROW(mesh->calculateConnectivity( MED_DESCENDING, MED_CELL));
00265       CPPUNIT_ASSERT(mesh->existConnectivity(MED_DESCENDING, MED_CELL));
00266     }
00267 
00268     const int* ConnectivityDes;
00269     const int* connectivity_index_des;
00270     CPPUNIT_ASSERT_NO_THROW(ConnectivityDes = mesh->getConnectivity(MED_DESCENDING,
00271                                                                     MED_CELL, MED_ALL_ELEMENTS));
00272     CPPUNIT_ASSERT_NO_THROW(connectivity_index_des =
00273                             mesh->getConnectivityIndex(MED_DESCENDING, MED_CELL));
00274     out<<"Descending connectivity"<<endl;
00275     for (int j = 0; j < nbElem; j++) {
00276       out << "Element "<< j+1 << " : ";
00277       for (int k = connectivity_index_des[j]; k < connectivity_index_des[j+1]; k++)
00278         out << ConnectivityDes[k-1] << " ";
00279       out << endl;
00280     }
00281 
00282     const int * ReverseDesConnectivity;
00283     const int * ReverseConnectivityIndexDes;
00284     CPPUNIT_ASSERT_NO_THROW(ReverseDesConnectivity = mesh->getReverseConnectivity(MED_DESCENDING));
00285     CPPUNIT_ASSERT_NO_THROW(ReverseConnectivityIndexDes =
00286                             mesh->getReverseConnectivityIndex(MED_DESCENDING));
00287     for (int i = 0; i < nbNodes; i++) {
00288       out << "Node "<< i+1 << " : ";
00289       for (int j = ReverseConnectivityIndexDes[i]; j < ReverseConnectivityIndexDes[i+1]; j++)
00290         out << ReverseDesConnectivity[j-1] << " ";
00291       out << endl;
00292     }
00293     mesh->removeReference();
00294 
00295   }
00296 
00298   // test2 "MED_BODY_FITTED"  //
00300   {
00301     CPPUNIT_ASSERT_THROW( MESH(MED_DRIVER, myMed->getFileName(), mesh_names[1]), MEDEXCEPTION);
00302 
00303     GMESH* myMesh1 = new GRID(MED_DRIVER,myMed->getFileName(),mesh_names[1]);
00304     std::auto_ptr<GMESH> meshDeleter(myMesh1);
00305 
00306     CPPUNIT_ASSERT(myMesh1 != NULL);
00307     CPPUNIT_ASSERT(myMesh1->getIsAGrid());
00308 
00309     GRID* myGrid1 = dynamic_cast<GRID*>(myMesh1);
00310     CPPUNIT_ASSERT(myGrid1);
00311 
00312     int I, J, K;
00313     CPPUNIT_ASSERT_NO_THROW(I = myGrid1->getArrayLength(1));
00314     CPPUNIT_ASSERT_NO_THROW(J = myGrid1->getArrayLength(2));
00315     CPPUNIT_ASSERT_NO_THROW(K = myGrid1->getArrayLength(3));
00316 
00317     CPPUNIT_ASSERT(I == 2);
00318     CPPUNIT_ASSERT(J == 2);
00319 
00320     med_grid_type grid_type = myGrid1->getGridType();
00321     CPPUNIT_ASSERT_MESSAGE("Wrong grid type", grid_type == MED_BODY_FITTED);
00322 
00323     int nbTypesCell = myGrid1->getNumberOfTypes(MED_CELL);
00324     CPPUNIT_ASSERT(nbTypesCell == 1);
00325 
00326     const medGeometryElement* types1;
00327     CPPUNIT_ASSERT_NO_THROW( types1 = myGrid1->getTypes(MED_CELL) );
00328     CPPUNIT_ASSERT( types1[0] == MED_QUAD4);
00329 
00330     int nbElem;
00331     CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid1->getNumberOfElements(MED_CELL, types1[0]));
00332     CPPUNIT_ASSERT(nbElem);
00333 
00334     const int* BodyConnectivity;
00335     const int* body_connectivity_index;
00336     int ijkNodeBody[3];
00337     const MESH* mesh = myGrid1->convertInMESH();
00338     CPPUNIT_ASSERT_NO_THROW(BodyConnectivity = mesh->getConnectivity( MED_NODAL, MED_CELL, types1[0]));
00339     CPPUNIT_ASSERT_NO_THROW(body_connectivity_index = mesh->getConnectivityIndex(MED_NODAL, MED_CELL));
00340     out<<"Nodal connectivity"<<endl;
00341     for (int j = 0; j < nbElem; j++) {
00342       out << "Element "<< j+1 << " : ";
00343       for (int k = body_connectivity_index[j]; k < body_connectivity_index[j+1]; k++){
00344         CPPUNIT_ASSERT_NO_THROW(myGrid1->getNodePosition(BodyConnectivity[k-1], ijkNodeBody[0],
00345                                                          ijkNodeBody[1], ijkNodeBody[2]));
00346         out << BodyConnectivity[k-1] << " ";
00347       }
00348       out << endl;
00349     }
00350     mesh->removeReference();
00351   }
00352 
00354   // test3 "maa1" which in fact is not a pure GRID //
00356   {
00357     GMESH* myMesh2 = NULL;
00358 
00359     CPPUNIT_ASSERT_THROW( myMesh2 = new GRID( MED_DRIVER,myMed->getFileName(),mesh_names[2]),
00360                           MEDEXCEPTION );
00361     CPPUNIT_ASSERT_NO_THROW( myMesh2 = new MESH( MED_DRIVER,myMed->getFileName(),mesh_names[2]));
00362 
00363     CPPUNIT_ASSERT(myMesh2 != NULL);
00364     CPPUNIT_ASSERT(!(myMesh2->getIsAGrid()));
00365     myMesh2->removeReference();
00366   }
00367 
00368   delete myMed;
00369 
00371   // test4 create new GRID  //
00373 
00374   // Default constructor and destructor
00375   {
00376     GRID* myGrid2 = new GRID();
00377     CPPUNIT_ASSERT(myGrid2->getIsAGrid());
00378     CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN);
00379     CPPUNIT_ASSERT(!myGrid2->getArrayLength(1));
00380     CPPUNIT_ASSERT(!myGrid2->getArrayLength(2));
00381     CPPUNIT_ASSERT(!myGrid2->getArrayLength(3));
00382     myGrid2->removeReference();
00383   }
00384 
00385   // Constructor with grid type, setGridType()
00386   {
00387     GRID* myGrid2 = new GRID(MED_POLAR);
00388     CPPUNIT_ASSERT(myGrid2->getGridType() == MED_POLAR);
00389     myGrid2->setGridType(MED_CARTESIAN);
00390     CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN);
00391     myGrid2->removeReference();
00392   }
00393 
00394   // Constructor with coordinate values, getArrayValue(), init()
00395   {
00396     vector<vector<double> > xyz;
00397     const int nbCoords = 3;
00398     xyz.resize(nbCoords);
00399     for ( int i = 0; i < nbCoords; i++ )
00400     {
00401       xyz[i].resize(i + 2);
00402       for ( int j = 0; j < i + 2; j++ )
00403         xyz[i][j] = j;
00404     }
00405     vector<string> Coord_Names;
00406     Coord_Names.resize(nbCoords);
00407     Coord_Names[0] = "X";
00408     Coord_Names[1] = "Y";
00409     Coord_Names[2] = "Z";
00410 
00411     vector<string> Coord_Units;
00412     Coord_Units.resize(nbCoords);
00413     for(int i = 0; i < 3; i++)
00414       Coord_Units[i] = "cm";
00415 
00416     GRID* myGrid2;
00417 
00418     try{
00419       myGrid2 = new GRID(xyz, Coord_Names, Coord_Units, MED_CARTESIAN);
00420     }
00421     catch (const std::exception &e)
00422     {
00423       CPPUNIT_FAIL(e.what());
00424     }
00425     catch (...)
00426     {
00427       CPPUNIT_FAIL("Unknown exception");
00428     }
00429 
00430     // testing convertInMESH()
00431     // We fill a map of all possible coordinate triples.
00432     // After iteration through all coordinates, this map should contain only "true" as data.
00433     // "true" in some map element during iteration means duplicated node position.
00434     // "false" in some map element after iteration means empty node position.
00435     map<int, bool> found;
00436     for ( unsigned i1 = 0; i1 < xyz[0].size(); i1++ )
00437       for ( unsigned i2 = 0; i2 < xyz[1].size(); i2++ )
00438         for ( unsigned i3 = 0; i3 < xyz[2].size(); i3++ )
00439           found[int(xyz[0][i1] * 100 + xyz[1][i2] * 10 + xyz[2][i3])] = false;
00440 
00441     const MESH* mesh = myGrid2->convertInMESH();
00442     COORDINATE* coords = (COORDINATE*)mesh->getCoordinateptr();
00443     CPPUNIT_ASSERT(coords);
00444     for (int num = 0; num < myGrid2->getNumberOfNodes(); num++) {
00445       int x = int(coords->getCoordinate(num + 1, 1));
00446       int y = int(coords->getCoordinate(num + 1, 2));
00447       int z = int(coords->getCoordinate(num + 1, 3));
00448       CPPUNIT_ASSERT(!found[x * 100 + y * 10 + z]);
00449       found[x * 100 + y * 10 + z] = true;
00450     }
00451 
00452     for ( map<int, bool>::iterator it = found.begin(); it != found.end(); it++ )
00453       CPPUNIT_ASSERT((*it).second);
00454 
00455     // Testing fillConnectivity() and getConnectivityptr()
00456     // Basic testing: presence of connectivity arrays, element types and number of elements
00457     CONNECTIVITY* conn = (CONNECTIVITY*)mesh->getConnectivityptr();
00458     CPPUNIT_ASSERT(conn);
00459     bool hasFaces = myGrid2->getArrayLength(3), hasEdges = myGrid2->getArrayLength(2);
00460     medGeometryElement aCellGeometry;
00461     if (hasFaces)      aCellGeometry = MED_HEXA8;
00462     else if (hasEdges) aCellGeometry = MED_QUAD4;
00463     else               aCellGeometry = MED_SEG2;
00464     CPPUNIT_ASSERT(conn->getElementType(MED_CELL, 1) == aCellGeometry);
00465     CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL,      MED_CELL));
00466     CPPUNIT_ASSERT(conn->existConnectivity(MED_DESCENDING, MED_CELL));
00467     //test getCellsTypes
00468     CELLMODEL* cellmodel = (CELLMODEL*)mesh->getCellsTypes(MED_CELL);
00469     CPPUNIT_ASSERT(cellmodel);
00470 
00471     int nbCells, nbFaces, nbEdges;
00472 
00473     int iLen     = myGrid2->getArrayLength(1);
00474     int jLen     = myGrid2->getArrayLength(2);
00475     int kLen     = myGrid2->getArrayLength(3);
00476     int iLenMin1 = myGrid2->getArrayLength(1)-1;
00477     int jLenMin1 = myGrid2->getArrayLength(2)-1;
00478     int kLenMin1 = myGrid2->getArrayLength(3)-1;
00479     const int* aCellCount = conn->getGlobalNumberingIndex(MED_CELL);
00480     nbCells = iLenMin1 * jLenMin1 * kLenMin1;
00481     CPPUNIT_ASSERT(aCellCount[1] - 1 == nbCells);
00482 
00483     if (hasFaces){
00484       CPPUNIT_ASSERT(conn->getElementType(MED_FACE, 1) == MED_QUAD4);
00485       nbFaces  = iLen * jLenMin1 * kLenMin1;
00486       nbFaces += jLen * kLenMin1 * iLenMin1;
00487       nbFaces += kLen * iLenMin1 * jLenMin1;
00488       const int* aFaceCount = conn->getGlobalNumberingIndex(MED_FACE);
00489       CPPUNIT_ASSERT(aFaceCount[1] - 1 == nbFaces);
00490       CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_FACE));
00491       //test getCellsTypes
00492       CELLMODEL* cellmodelF = (CELLMODEL*)mesh->getCellsTypes(MED_FACE);
00493       CPPUNIT_ASSERT(cellmodelF);
00494     }
00495     if (hasEdges){
00496       CPPUNIT_ASSERT(conn->getElementType(MED_EDGE, 1) == MED_SEG2);
00497       if (kLen) { // 3d grid
00498         nbEdges  = iLenMin1 * jLen * kLen;
00499         nbEdges += jLenMin1 * kLen * iLen;
00500         nbEdges += kLenMin1 * iLen * jLen;
00501       }
00502       else if (jLen) { // 2d
00503         nbEdges  = iLenMin1 * jLen;
00504         nbEdges += jLenMin1 * iLen;
00505       }
00506       const int* anEdgeCount = conn->getGlobalNumberingIndex(MED_EDGE);
00507       CPPUNIT_ASSERT(anEdgeCount[1] - 1 == nbEdges);
00508       CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_EDGE));
00509       //test getCellsTypes
00510       CELLMODEL* cellmodelE = (CELLMODEL*)mesh->getCellsTypes(MED_EDGE);
00511       CPPUNIT_ASSERT(cellmodelE);
00512 
00513     }
00514 
00515     // Testing getArrayValue()
00516     for ( int ii = 1; ii <= nbCoords; ii++ )
00517       for ( int jj = 0; jj < ii + 1; jj++ )
00518         CPPUNIT_ASSERT(myGrid2->getArrayValue(ii, jj) == xyz[ii - 1][jj]);
00519 
00520     CPPUNIT_ASSERT_THROW(myGrid2->getArrayValue(nbCoords + 1, 0), MEDEXCEPTION);
00521     CPPUNIT_ASSERT_THROW(myGrid2->getArrayValue(1, myGrid2->getArrayLength(1) + 1), MEDEXCEPTION);
00522     myGrid2->setGridType(MED_POLAR);
00523 
00524     //testing read/write functions
00525 
00526     // add new driver
00527     int idGridV21;
00528 
00529     try
00530     {
00531       idGridV21 = const_cast<MESH*>(mesh)->addDriver(MED_DRIVER,filenameout21);
00532     }
00533     catch(MEDEXCEPTION &e)
00534     {
00535       CPPUNIT_FAIL(e.what());
00536     }
00537     catch( ... )
00538     {
00539       CPPUNIT_FAIL("Unknown exception");
00540     }
00541 
00542     // write this driver to file as an unstructured mesh
00543     CPPUNIT_ASSERT_NO_THROW(mesh->write(idGridV21));
00544 
00545     GRID* myGrid3 = new GRID();
00546     // add new driver for myGrid3
00547     int driver;
00548     CPPUNIT_ASSERT_NO_THROW(driver = myGrid3->addDriver(MED_DRIVER, filenameout21));
00549 
00550     //#ifdef ENABLE_FORCED_FAILURES
00551     // ? (BUG) ? "The mesh dimension |-1| seems to be incorrect for
00552     // the mesh : |Default Mesh Name|"
00553     // TO CHECK writing CAREFULLY
00554     // !!!!!!!!! Mesh was written as UNSTRUCTURED
00555     // changed on THROW accoding to EAP 
00556     CPPUNIT_ASSERT_THROW(myGrid3->read(driver),MEDEXCEPTION);
00557     //CPPUNIT_ASSERT_NO_THROW(myGrid3->read(driver));
00558 
00559     // Testing getArrayValue()
00560     //for ( int ii = 1; ii <= nbCoords; ii++ )
00561     //  for ( int jj = 0; jj < ii + 1; jj++ )
00562     //    CPPUNIT_ASSERT(myGrid3->getArrayValue(ii, jj) == xyz[ii - 1][jj]);
00563 
00564     //CPPUNIT_ASSERT(myGrid3->getGridType() == MED_POLAR);
00565     //#endif
00566 
00567     myGrid3->removeReference();
00568 
00569     //test init()
00570     CPPUNIT_ASSERT_NO_THROW(myGrid2->init());
00571     CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN);
00572     CPPUNIT_ASSERT(myGrid2->getArrayLength(1) == 0);
00573     CPPUNIT_ASSERT(myGrid2->getArrayLength(2) == 0);
00574     CPPUNIT_ASSERT(myGrid2->getArrayLength(3) == 0);
00575     //#ifdef ENABLE_FAULTS
00576     // (BUG) Segmentation Fault
00577     //myGrid2->makeUnstructured();
00578     //#endif
00579     //#ifdef ENABLE_FORCED_FAILURES
00580     // TODO: fix it - unstructured mesh should be simply empty, actually useless
00581     //CPPUNIT_FAIL("ERROR:makeUnstructured() - there is no check if grid is empty or not");
00582     //#endif
00583 
00584     myGrid2->removeReference();
00585     mesh->removeReference();
00586   }
00587 
00588   {
00589     GRID* myGrid2;
00590     CPPUNIT_ASSERT_NO_THROW(myGrid2 = new GRID(MED_DRIVER, filename, mesh_names[1]));
00591 
00592     // Check if something has been read - full mesh data testing is above
00593     CPPUNIT_ASSERT(myGrid2->getSpaceDimension());
00594     CPPUNIT_ASSERT(myGrid2->getNumberOfNodes());
00595     CPPUNIT_ASSERT(myGrid2->getNumberOfTypes(MED_CELL) == 1);
00596     const medGeometryElement* types2;
00597     CPPUNIT_ASSERT_NO_THROW(types2 = myGrid2->getTypes(MED_CELL));
00598     int nbElem;
00599     CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid2->getNumberOfElements(MED_CELL,types2[0]));
00600     CPPUNIT_ASSERT(nbElem);
00601     myGrid2->removeReference();
00602   }
00603 
00604   {
00605     GRID* myGrid4 = new GRID();
00606     filename = getResourceFile("pointe.med");
00607     myGrid4->setName("maa1");
00608     MED_MESH_RDONLY_DRIVER myMeshDriver(filename, myGrid4);
00609     myMeshDriver.setMeshName("maa1");
00610 
00611     // add new driver for myGrid4
00612     int driver;
00613     CPPUNIT_ASSERT_NO_THROW(driver = myGrid4->addDriver(myMeshDriver));
00614 
00615     // MED Exception : MED_MESH_RDONLY_DRIVER21::getGRID() : The number
00616     // of nodes |-1| seems to be incorrect for the mesh : |maa1|
00617     // But this exception seems to be correct reaction on attempt
00618     // to read a grid from a file, which does not contain it.
00619     CPPUNIT_ASSERT_THROW(myGrid4->read(driver), MEDEXCEPTION);
00620 
00621     myGrid4->removeReference();
00622   }
00623 }