Back to index

salome-med  6.5.0
MEDMEMTest_PartialDescendingConnectivity.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 
00022 #include "MEDMEM_Meshing.hxx"
00023 #include "MEDMEM_Group.hxx"
00024 #include "MEDMEM_Field.hxx"
00025 
00026 #include <numeric>
00027 
00028 void MEDMEMTest::testPartialDescendingConnectivity()
00029 {
00030   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.};
00031 
00032   const int connNodalCellClassical[8]={2, 6, 5, 1, 4, 8, 7, 3};
00033 
00034   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};
00035 
00036   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};
00037   //
00038 
00039   MESHING* myMesh = new MESHING;
00040   myMesh->setName( "TESTMESH" );
00041   const int nNodes=8;
00042   myMesh->setCoordinates(3, nNodes, coords, "CARTESIAN", MED_EN::MED_FULL_INTERLACE);
00043   string coordname[3] = { "x", "y", "z" };
00044   myMesh->setCoordinatesNames(coordname);
00045   string coordunit[3] = { "m", "m", "m" };
00046   myMesh->setCoordinatesUnits(coordunit);
00047   //Cell connectivity info for classical elts
00048   const MED_EN::medGeometryElement classicalTypesCell[1]={MED_EN::MED_HEXA8};
00049   const int nbOfCellElts[1]={1};
00050   myMesh->setNumberOfTypes(1,MED_EN::MED_CELL);
00051   myMesh->setTypes(classicalTypesCell,MED_EN::MED_CELL);
00052   myMesh->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
00053   //Face connectivity info for classical elts
00054   const MED_EN::medGeometryElement classicalTypesFace[1]={MED_EN::MED_QUAD4};
00055   const int nbOfFaceElts[1]={6};
00056   myMesh->setNumberOfTypes(1,MED_EN::MED_FACE);
00057   myMesh->setTypes(classicalTypesFace,MED_EN::MED_FACE);
00058   myMesh->setNumberOfElements(nbOfFaceElts,MED_EN::MED_FACE);
00059   //
00060   const MED_EN::medGeometryElement classicalTypesEdge[1]={MED_EN::MED_SEG2};
00061   const int nbOfEdgeElts[1]={12};
00062   myMesh->setNumberOfTypes(1,MED_EN::MED_EDGE);
00063   myMesh->setTypes(classicalTypesEdge,MED_EN::MED_EDGE);
00064   myMesh->setNumberOfElements(nbOfEdgeElts,MED_EN::MED_EDGE);
00065   //All cell conn
00066   myMesh->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_HEXA8,connNodalCellClassical);
00067   //All face conn
00068   myMesh->setConnectivity(MED_EN::MED_FACE,MED_EN::MED_QUAD4,connNodalFaceClassical);
00069   //All edge conn
00070   myMesh->setConnectivity(MED_EN::MED_EDGE,MED_EN::MED_SEG2,connNodalEdgeClassical);
00071   //
00072   /*const int *ConnNodal = */myMesh->getConnectivity(MED_NODAL,MED_CELL,MED_ALL_ELEMENTS);
00073   /*const int *ConnNodalIndex = */myMesh->getConnectivityIndex(MED_NODAL,MED_CELL);
00074 
00075   const int *Conn      = myMesh->getConnectivity(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS);
00076   const int *ConnIndex = myMesh->getConnectivityIndex(MED_DESCENDING,MED_CELL);
00077   int lgth=myMesh->getConnectivityLength(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS);
00078   CPPUNIT_ASSERT_EQUAL(6,lgth);
00079   CPPUNIT_ASSERT_EQUAL(1,ConnIndex[0]);
00080   CPPUNIT_ASSERT_EQUAL(7,ConnIndex[1]);
00081   int ConnTmp[6];
00082   copy(Conn,Conn+6,ConnTmp);
00083   for(int i=0;i<6;i++)
00084     ConnTmp[i]=abs(ConnTmp[i]);
00085   int sum=accumulate(ConnTmp,ConnTmp+6,0);
00086   CPPUNIT_ASSERT_EQUAL(21,sum);//1+2+3+4+5+6
00087   CPPUNIT_ASSERT_EQUAL(6, *max_element(ConnTmp,ConnTmp+6));
00088   CPPUNIT_ASSERT_EQUAL(1, *min_element(ConnTmp,ConnTmp+6));
00089   //
00090   const int *ConnFaceNodal = myMesh->getConnectivity(MED_NODAL,MED_FACE,MED_ALL_ELEMENTS);
00091   const int *ConnFaceNodalIndex = myMesh->getConnectivityIndex(MED_NODAL,MED_FACE);
00092   const int expected3[7]={1,5,9,13,17,21,25};
00093   int i;
00094   for(i=0;i<24;i++)
00095     CPPUNIT_ASSERT_EQUAL(connNodalFaceClassical[i],ConnFaceNodal[i]);
00096   for(i=0;i<7;i++)
00097     CPPUNIT_ASSERT_EQUAL(expected3[i],ConnFaceNodalIndex[i]);
00098   //
00099   myMesh->removeReference();
00100 }