Salome HOME
afa1cb7b6a0fbacf578b7181dab00c3b6dba0c8b
[modules/med.git] / src / MEDMEMCppTest / MEDMEMTest_GetVolumeAbs.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MEDMEMTest.hxx"
21
22 #include "MEDMEM_Mesh.hxx"
23 #include "MEDMEM_Group.hxx"
24 #include "MEDMEM_Meshing.hxx"
25 #include "MEDMEM_MedMeshDriver.hxx"
26 #include "MEDMEM_GibiMeshDriver.hxx"
27
28 #include <cppunit/Message.h>
29 #include <cppunit/TestAssert.h>
30
31 using namespace std;
32 using namespace MEDMEM;
33
34 void MEDMEMTest::testGetVolumeAbs()
35 {
36   double coords[63]=
37     {
38       0., 0., 0. 
39       ,2., 0., 0. 
40       ,2., 1., 0. 
41       ,1., 2., 0. 
42       ,0., 1., 0. 
43       ,2., 2., 0. 
44       , 0., 2., 0. 
45       , 0., 0., 1. 
46       , 2., 0., 1. 
47       , 2., 1., 1. 
48       , 1., 2., 1. 
49       , 0., 1., 1. 
50       , 2., 2., 1. 
51       , 0., 2., 1. 
52       , 0., 0., 2. 
53       , 2., 0., 2. 
54       , 2., 1., 2. 
55       , 1., 2., 2. 
56       , 0., 1., 2. 
57       , 2., 2., 2. 
58       , 0., 2., 2. 
59     };
60   int connNodalCellClassical[24]=
61     {
62       10, 11, 13, 17, 18, 20,
63       4,  5,  7, 11, 12, 14,
64       11, 12, 14, 18, 19, 21,
65       3,  4,  6, 10, 11, 13 
66     };
67   int polyHedraConn[60+12]=
68     {
69       8, 9, 10, 11, 12,   -1,
70       15, 16, 17, 18, 19, -1,
71       8, 9, 16, 15,       -1,
72       9,  10, 17, 16,     -1,
73       10, 11, 18, 17,     -1,
74       11, 12, 19, 18,     -1,
75       12, 8, 15, 19,
76       //cell2
77       1, 2, 3, 4, 5,      -1,
78       8, 9, 10, 11, 12,   -1,
79       1, 2, 9, 8,         -1,
80       2, 3, 10, 9,        -1,
81       3, 4, 11, 10,       -1,
82       4, 5, 12, 11,       -1,
83       5, 1, 8, 12 
84     };
85   int polyHedraInd[3]=
86     {
87       1,37,73
88     };
89   MESHING* meshing = new MESHING;
90   meshing->setName( "TESTMESH" );
91   const int nNodes=21;
92   meshing->setCoordinates(3, nNodes, coords, "CARTESIAN",
93                           MED_EN::MED_FULL_INTERLACE);
94   string coordname[3] = 
95     {
96       "x", "y", "z" 
97     };
98   meshing->setCoordinatesNames(coordname);
99   string coordunit[3] = 
100     {
101       "m", "m", "m" 
102     };
103   meshing->setCoordinatesUnits(coordunit);
104   //Cell connectivity info
105   const MED_EN::medGeometryElement classicalTypesCell[2]=
106     {
107       MED_EN::MED_PENTA6,MED_POLYHEDRA
108     };
109   const int nbOfCellElts[2]=
110     {
111       4,2
112     };
113   meshing->setNumberOfTypes(2,MED_EN::MED_CELL);
114   meshing->setTypes(classicalTypesCell,MED_EN::MED_CELL);
115   meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
116   //All cell conn
117   meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_PENTA6,connNodalCellClassical);
118   meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_POLYHEDRA, polyHedraConn,polyHedraInd);
119   //
120   const SUPPORT *sup=meshing->getSupportOnAll(MED_CELL);
121   FIELD<double> *volumes=meshing->getVolume(sup);
122   const double *vals=volumes->getValue();
123   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[0],1e-13);
124   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[1],1e-13);
125   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[2],1e-13);
126   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[3],1e-13);
127   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.,vals[4],1e-13);
128   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.,vals[5],1e-13);
129   volumes->removeReference();
130   volumes=meshing->getVolume(sup,false);
131   vals=volumes->getValue();
132   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[0],1e-13);
133   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[1],1e-13);
134   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[2],1e-13);
135   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,vals[3],1e-13);
136   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,vals[4],1e-13);
137   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,vals[5],1e-13);
138   //
139   volumes->removeReference();
140   meshing->removeReference();
141 }