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"
22 #include "MEDMEM_Meshing.hxx"
23 #include "MEDMEM_Group.hxx"
24 #include "MEDMEM_Field.hxx"
28 void MEDMEMTest::testPartialDescendingConnectivity()
30 double coords[24]= {0., 0., 3., 0., 0., 0., 0., 3., 3., 0., 3., 0., 3., 0., 3., 3., 0., 0., 3., 3., 3., 3., 3., 0.};
32 const int connNodalCellClassical[8]={2, 6, 5, 1, 4, 8, 7, 3};
34 const int connNodalFaceClassical[24]={3, 1, 5, 7, 5, 6, 8, 7, 2, 1, 3, 4, 2, 4, 8, 6, 8, 4, 3, 7, 2, 6, 5, 1};
36 const int connNodalEdgeClassical[24]={4,8,8,7,2,1,1,3,5,7,2,6,1,5,6,8,6,5,4,3,3,7,2,4};
39 MESHING* myMesh = new MESHING;
40 myMesh->setName( "TESTMESH" );
42 myMesh->setCoordinates(3, nNodes, coords, "CARTESIAN", MED_EN::MED_FULL_INTERLACE);
43 string coordname[3] = { "x", "y", "z" };
44 myMesh->setCoordinatesNames(coordname);
45 string coordunit[3] = { "m", "m", "m" };
46 myMesh->setCoordinatesUnits(coordunit);
47 //Cell connectivity info for classical elts
48 const MED_EN::medGeometryElement classicalTypesCell[1]={MED_EN::MED_HEXA8};
49 const int nbOfCellElts[1]={1};
50 myMesh->setNumberOfTypes(1,MED_EN::MED_CELL);
51 myMesh->setTypes(classicalTypesCell,MED_EN::MED_CELL);
52 myMesh->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
53 //Face connectivity info for classical elts
54 const MED_EN::medGeometryElement classicalTypesFace[1]={MED_EN::MED_QUAD4};
55 const int nbOfFaceElts[1]={6};
56 myMesh->setNumberOfTypes(1,MED_EN::MED_FACE);
57 myMesh->setTypes(classicalTypesFace,MED_EN::MED_FACE);
58 myMesh->setNumberOfElements(nbOfFaceElts,MED_EN::MED_FACE);
60 const MED_EN::medGeometryElement classicalTypesEdge[1]={MED_EN::MED_SEG2};
61 const int nbOfEdgeElts[1]={12};
62 myMesh->setNumberOfTypes(1,MED_EN::MED_EDGE);
63 myMesh->setTypes(classicalTypesEdge,MED_EN::MED_EDGE);
64 myMesh->setNumberOfElements(nbOfEdgeElts,MED_EN::MED_EDGE);
66 myMesh->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_HEXA8,connNodalCellClassical);
68 myMesh->setConnectivity(MED_EN::MED_FACE,MED_EN::MED_QUAD4,connNodalFaceClassical);
70 myMesh->setConnectivity(MED_EN::MED_EDGE,MED_EN::MED_SEG2,connNodalEdgeClassical);
72 /*const int *ConnNodal = */myMesh->getConnectivity(MED_NODAL,MED_CELL,MED_ALL_ELEMENTS);
73 /*const int *ConnNodalIndex = */myMesh->getConnectivityIndex(MED_NODAL,MED_CELL);
75 const int *Conn = myMesh->getConnectivity(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS);
76 const int *ConnIndex = myMesh->getConnectivityIndex(MED_DESCENDING,MED_CELL);
77 int lgth=myMesh->getConnectivityLength(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS);
78 CPPUNIT_ASSERT_EQUAL(6,lgth);
79 CPPUNIT_ASSERT_EQUAL(1,ConnIndex[0]);
80 CPPUNIT_ASSERT_EQUAL(7,ConnIndex[1]);
82 copy(Conn,Conn+6,ConnTmp);
84 ConnTmp[i]=abs(ConnTmp[i]);
85 int sum=accumulate(ConnTmp,ConnTmp+6,0);
86 CPPUNIT_ASSERT_EQUAL(21,sum);//1+2+3+4+5+6
87 CPPUNIT_ASSERT_EQUAL(6, *max_element(ConnTmp,ConnTmp+6));
88 CPPUNIT_ASSERT_EQUAL(1, *min_element(ConnTmp,ConnTmp+6));
90 const int *ConnFaceNodal = myMesh->getConnectivity(MED_NODAL,MED_FACE,MED_ALL_ELEMENTS);
91 const int *ConnFaceNodalIndex = myMesh->getConnectivityIndex(MED_NODAL,MED_FACE);
92 const int expected3[7]={1,5,9,13,17,21,25};
95 CPPUNIT_ASSERT_EQUAL(connNodalFaceClassical[i],ConnFaceNodal[i]);
97 CPPUNIT_ASSERT_EQUAL(expected3[i],ConnFaceNodalIndex[i]);
99 myMesh->removeReference();