Back to index

salome-med  6.5.0
MEDMEMTest_GetVolumeAbs.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_Mesh.hxx"
00023 #include "MEDMEM_Group.hxx"
00024 #include "MEDMEM_Meshing.hxx"
00025 #include "MEDMEM_MedMeshDriver.hxx"
00026 #include "MEDMEM_GibiMeshDriver.hxx"
00027 
00028 #include <cppunit/Message.h>
00029 #include <cppunit/TestAssert.h>
00030 
00031 using namespace std;
00032 using namespace MEDMEM;
00033 
00034 void MEDMEMTest::testGetVolumeAbs()
00035 {
00036   double coords[63]=
00037     {
00038       0., 0., 0. 
00039       ,2., 0., 0. 
00040       ,2., 1., 0. 
00041       ,1., 2., 0. 
00042       ,0., 1., 0. 
00043       ,2., 2., 0. 
00044       , 0., 2., 0. 
00045       , 0., 0., 1. 
00046       , 2., 0., 1. 
00047       , 2., 1., 1. 
00048       , 1., 2., 1. 
00049       , 0., 1., 1. 
00050       , 2., 2., 1. 
00051       , 0., 2., 1. 
00052       , 0., 0., 2. 
00053       , 2., 0., 2. 
00054       , 2., 1., 2. 
00055       , 1., 2., 2. 
00056       , 0., 1., 2. 
00057       , 2., 2., 2. 
00058       , 0., 2., 2. 
00059     };
00060   int connNodalCellClassical[24]=
00061     {
00062       10, 11, 13, 17, 18, 20,
00063       4,  5,  7, 11, 12, 14,
00064       11, 12, 14, 18, 19, 21,
00065       3,  4,  6, 10, 11, 13 
00066     };
00067   int polyHedraConn[60+12]=
00068     {
00069       8, 9, 10, 11, 12,   -1,
00070       15, 16, 17, 18, 19, -1,
00071       8, 9, 16, 15,       -1,
00072       9,  10, 17, 16,     -1,
00073       10, 11, 18, 17,     -1,
00074       11, 12, 19, 18,     -1,
00075       12, 8, 15, 19,
00076       //cell2
00077       1, 2, 3, 4, 5,      -1,
00078       8, 9, 10, 11, 12,   -1,
00079       1, 2, 9, 8,         -1,
00080       2, 3, 10, 9,        -1,
00081       3, 4, 11, 10,       -1,
00082       4, 5, 12, 11,       -1,
00083       5, 1, 8, 12 
00084     };
00085   int polyHedraInd[3]=
00086     {
00087       1,37,73
00088     };
00089   MESHING* meshing = new MESHING;
00090   meshing->setName( "TESTMESH" );
00091   const int nNodes=21;
00092   meshing->setCoordinates(3, nNodes, coords, "CARTESIAN",
00093                           MED_EN::MED_FULL_INTERLACE);
00094   string coordname[3] = 
00095     {
00096       "x", "y", "z" 
00097     };
00098   meshing->setCoordinatesNames(coordname);
00099   string coordunit[3] = 
00100     {
00101       "m", "m", "m" 
00102     };
00103   meshing->setCoordinatesUnits(coordunit);
00104   //Cell connectivity info
00105   const MED_EN::medGeometryElement classicalTypesCell[2]=
00106     {
00107       MED_EN::MED_PENTA6,MED_POLYHEDRA
00108     };
00109   const int nbOfCellElts[2]=
00110     {
00111       4,2
00112     };
00113   meshing->setNumberOfTypes(2,MED_EN::MED_CELL);
00114   meshing->setTypes(classicalTypesCell,MED_EN::MED_CELL);
00115   meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
00116   //All cell conn
00117   meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_PENTA6,connNodalCellClassical);
00118   meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_POLYHEDRA, polyHedraConn,polyHedraInd);
00119   //
00120   const SUPPORT *sup=meshing->getSupportOnAll(MED_CELL);
00121   FIELD<double> *volumes=meshing->getVolume(sup);
00122   const double *vals=volumes->getValue();
00123   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[0],1e-13);
00124   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[1],1e-13);
00125   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[2],1e-13);
00126   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[3],1e-13);
00127   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.,vals[4],1e-13);
00128   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.,vals[5],1e-13);
00129   volumes->removeReference();
00130   volumes=meshing->getVolume(sup,false);
00131   vals=volumes->getValue();
00132   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[0],1e-13);
00133   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[1],1e-13);
00134   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[2],1e-13);
00135   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[3],1e-13);
00136   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,vals[4],1e-13);
00137   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,vals[5],1e-13);
00138   //
00139   volumes->removeReference();
00140   meshing->removeReference();
00141 }