Back to index

salome-med  6.5.0
MEDMEMTest_Connectivity_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_Connectivity.hxx"
00024 #include "MEDMEM_define.hxx"
00025 #include "MEDMEM_MedMeshDriver.hxx"
00026 #include "MEDMEM_Mesh.hxx"
00027 #include "MEDMEM_Family.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 using namespace std;
00036 using namespace MEDMEM;
00037 
00038 static void createOrCheck (CONNECTIVITY * theC, string msg, bool create = false)
00039 {
00040   // Preconditions: Entity and NumberOfTypes
00041   CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, MED_EN::MED_CELL, theC->getEntity());
00042   CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfTypes(MED_EN::MED_CELL));
00043 
00044   // EntityDimension
00045   if (create)
00046     theC->setEntityDimension(3);
00047 
00048   // NumberOfNodes
00049   int nbNodes = 20;
00050 
00051   if (create) {
00052     theC->setNumberOfNodes(nbNodes);
00053   }
00054 
00055   // GeometricTypes
00056   MED_EN::medGeometryElement aCellTypes[2] = {MED_EN::MED_PYRA5, MED_EN::MED_HEXA8};
00057 
00058   // this variable is needed in check mode (!create)
00059   // because of bug with getGlobalNumberingIndex() method (see below)
00060 
00061   if (create) {
00062     theC->setGeometricTypes(aCellTypes, MED_EN::MED_CELL);
00063     CPPUNIT_ASSERT_THROW(theC->setGeometricTypes(aCellTypes, MED_EN::MED_NODE), MEDEXCEPTION);
00064     CPPUNIT_ASSERT_THROW(theC->setGeometricTypes(aCellTypes, MED_EN::MED_FACE), MEDEXCEPTION);
00065     CPPUNIT_ASSERT_THROW(theC->setGeometricTypes(aCellTypes, MED_EN::MED_EDGE), MEDEXCEPTION);
00066   }
00067 
00068   // Nodal Connectivity for standard types
00069   int countCells[3] = {1, 3, 4}; // 2 PYRA5 and 1 HEXA8
00070   int nodesCells_PYRA5[10] = {2,3,4,5,1, 6,7,8,9,10};
00071   int nodesCells_HEXA8[8] = {2,3,4,5, 6,7,8,9};
00072 
00073   if (create) {
00074     theC->setCount(countCells, MED_EN::MED_CELL);
00075     theC->setNodal(nodesCells_PYRA5, MED_EN::MED_CELL, MED_EN::MED_PYRA5);
00076     theC->setNodal(nodesCells_HEXA8, MED_EN::MED_CELL, MED_EN::MED_HEXA8);
00077 
00078     // Invalid cases
00079     CPPUNIT_ASSERT_THROW(theC->setCount(countCells, MED_EN::MED_NODE), MEDEXCEPTION);
00080     CPPUNIT_ASSERT_THROW(theC->setCount(countCells, MED_EN::MED_EDGE), MEDEXCEPTION);
00081     CPPUNIT_ASSERT_THROW(theC->setCount(countCells, MED_EN::MED_FACE), MEDEXCEPTION);
00082 
00083     CPPUNIT_ASSERT_THROW(theC->setNodal(nodesCells_PYRA5, MED_EN::MED_FACE, MED_EN::MED_PYRA5), MEDEXCEPTION);
00084   }
00085 
00086   // 2 POLYHEDRA
00087   const int nbPolyhedron = 2;
00088   const int nbPolyNodes = 52 + 14 - 2; // = 64
00089 
00090   int aPolyhedronIndex[nbPolyhedron + 1] = {1,33, 65};
00091 
00092   int aPolyhedronNodalConnectivity[nbPolyNodes] = {
00093     11,15,19,20,17,13,-1, 11,13,14,-1,  14,13,17,18,-1,  18,17,20,-1,  11,14,15,-1,  15,14,18,19,-1,  19,18,20,
00094     11,13,17,20,19,15,-1, 11,12,13,-1,  13,12,16,17,-1,  17,16,20,-1,  11,15,12,-1,  12,15,19,16,-1,  16,19,20};
00095 
00096   if (create) {
00097     theC->setNodal(aPolyhedronNodalConnectivity,
00098                    MED_EN::MED_CELL, MED_EN::MED_POLYHEDRA, aPolyhedronIndex);
00099   }
00100   else {
00101     // CELLS(3D): theC
00102     {
00103       // Polyhedron-specific methods
00104       {
00105         // invalid polyhedron Id
00106 //#ifdef ENABLE_FAULTS
00107         int lenPolyh3nodes;
00108         int nbFaces3;
00109         int *nbNodes3;
00110         // (BUG) Segmentation fault instead of MEDEXCEPTION
00111         CPPUNIT_ASSERT_THROW(theC->getNodesOfPolyhedron(1, lenPolyh3nodes), MEDEXCEPTION);
00112         CPPUNIT_ASSERT_THROW(theC->getNodesOfPolyhedron(3+3, lenPolyh3nodes), MEDEXCEPTION);
00113         CPPUNIT_ASSERT_THROW(theC->getNodesPerFaceOfPolyhedron
00114                              (/*polyhedronId*/1, nbFaces3, nbNodes3), MEDEXCEPTION);
00115         CPPUNIT_ASSERT_THROW(theC->getNodesPerFaceOfPolyhedron
00116                              (/*polyhedronId*/3+3, nbFaces3, nbNodes3), MEDEXCEPTION);
00117 //#endif
00118       } // Polyhedron-specific methods
00119     } // CELLS: theC
00120   }
00121 
00122   if (create) {
00123     // force _constituent computation
00124     CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfTypes(MED_EN::MED_FACE));
00125   }
00126 }
00127 
00128 int main (int argc, char** argv)
00129 {
00130   CONNECTIVITY * c1 = new CONNECTIVITY(/*numberOfTypes*/2, MED_EN::MED_CELL);
00131   createOrCheck(c1, "Creation", /*create*/true);
00132   createOrCheck(c1, "Check just created", /*create*/false);
00133 }