1 // Copyright (C) 2007-2012 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_Connectivity.hxx"
24 #include "MEDMEM_define.hxx"
25 #include "MEDMEM_MedMeshDriver.hxx"
26 #include "MEDMEM_Mesh.hxx"
27 #include "MEDMEM_Family.hxx"
32 // use this define to enable lines, execution of which leads to Segmentation Fault
33 //#define ENABLE_FAULTS
36 using namespace MEDMEM;
38 static void createOrCheck (CONNECTIVITY * theC, string msg, bool create = false)
40 // Preconditions: Entity and NumberOfTypes
41 CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, MED_EN::MED_CELL, theC->getEntity());
42 CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfTypes(MED_EN::MED_CELL));
46 theC->setEntityDimension(3);
52 theC->setNumberOfNodes(nbNodes);
56 MED_EN::medGeometryElement aCellTypes[2] = {MED_EN::MED_PYRA5, MED_EN::MED_HEXA8};
58 // this variable is needed in check mode (!create)
59 // because of bug with getGlobalNumberingIndex() method (see below)
62 theC->setGeometricTypes(aCellTypes, MED_EN::MED_CELL);
63 CPPUNIT_ASSERT_THROW(theC->setGeometricTypes(aCellTypes, MED_EN::MED_NODE), MEDEXCEPTION);
64 CPPUNIT_ASSERT_THROW(theC->setGeometricTypes(aCellTypes, MED_EN::MED_FACE), MEDEXCEPTION);
65 CPPUNIT_ASSERT_THROW(theC->setGeometricTypes(aCellTypes, MED_EN::MED_EDGE), MEDEXCEPTION);
68 // Nodal Connectivity for standard types
69 int countCells[3] = {1, 3, 4}; // 2 PYRA5 and 1 HEXA8
70 int nodesCells_PYRA5[10] = {2,3,4,5,1, 6,7,8,9,10};
71 int nodesCells_HEXA8[8] = {2,3,4,5, 6,7,8,9};
74 theC->setCount(countCells, MED_EN::MED_CELL);
75 theC->setNodal(nodesCells_PYRA5, MED_EN::MED_CELL, MED_EN::MED_PYRA5);
76 theC->setNodal(nodesCells_HEXA8, MED_EN::MED_CELL, MED_EN::MED_HEXA8);
79 CPPUNIT_ASSERT_THROW(theC->setCount(countCells, MED_EN::MED_NODE), MEDEXCEPTION);
80 CPPUNIT_ASSERT_THROW(theC->setCount(countCells, MED_EN::MED_EDGE), MEDEXCEPTION);
81 CPPUNIT_ASSERT_THROW(theC->setCount(countCells, MED_EN::MED_FACE), MEDEXCEPTION);
83 CPPUNIT_ASSERT_THROW(theC->setNodal(nodesCells_PYRA5, MED_EN::MED_FACE, MED_EN::MED_PYRA5), MEDEXCEPTION);
87 const int nbPolyhedron = 2;
88 const int nbPolyNodes = 52 + 14 - 2; // = 64
90 int aPolyhedronIndex[nbPolyhedron + 1] = {1,33, 65};
92 int aPolyhedronNodalConnectivity[nbPolyNodes] = {
93 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,
94 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};
97 theC->setNodal(aPolyhedronNodalConnectivity,
98 MED_EN::MED_CELL, MED_EN::MED_POLYHEDRA, aPolyhedronIndex);
103 // Polyhedron-specific methods
105 // invalid polyhedron Id
106 //#ifdef ENABLE_FAULTS
110 // (BUG) Segmentation fault instead of MEDEXCEPTION
111 CPPUNIT_ASSERT_THROW(theC->getNodesOfPolyhedron(1, lenPolyh3nodes), MEDEXCEPTION);
112 CPPUNIT_ASSERT_THROW(theC->getNodesOfPolyhedron(3+3, lenPolyh3nodes), MEDEXCEPTION);
113 CPPUNIT_ASSERT_THROW(theC->getNodesPerFaceOfPolyhedron
114 (/*polyhedronId*/1, nbFaces3, nbNodes3), MEDEXCEPTION);
115 CPPUNIT_ASSERT_THROW(theC->getNodesPerFaceOfPolyhedron
116 (/*polyhedronId*/3+3, nbFaces3, nbNodes3), MEDEXCEPTION);
118 } // Polyhedron-specific methods
123 // force _constituent computation
124 CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfTypes(MED_EN::MED_FACE));
128 int main (int argc, char** argv)
130 CONNECTIVITY * c1 = new CONNECTIVITY(/*numberOfTypes*/2, MED_EN::MED_CELL);
131 createOrCheck(c1, "Creation", /*create*/true);
132 createOrCheck(c1, "Check just created", /*create*/false);