Salome HOME
Initiating medtool
[modules/med.git] / src / ParaMEDMEMTest / ParaMEDMEMTest_MEDLoader.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D
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, or (at your option) any later version.
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 "ParaMEDMEMTest.hxx"
21 #include "MEDLoader.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingFieldDouble.hxx"
24
25 #include <cppunit/TestAssert.h>
26
27 #include <algorithm>
28 #include <numeric>
29 #include <iostream>
30 #include <iterator>
31
32 using namespace std;
33 using namespace INTERP_KERNEL;
34 using namespace ParaMEDMEM;
35
36 void ParaMEDMEMTest::testMEDLoaderRead1()
37 {
38   string fileName=getResourceFile("pointe.med");
39   vector<string> meshNames=MEDLoader::GetMeshNames(fileName.c_str());
40   CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
41   MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
42   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
43   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
44   CPPUNIT_ASSERT_EQUAL(16,mesh->getNumberOfCells());
45   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
46   CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllGeoTypes().size());
47   for(int i=0;i<12;i++)
48     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i));
49   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(12));
50   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(13));
51   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(14));
52   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(15));
53   CPPUNIT_ASSERT_EQUAL((std::size_t)90,mesh->getNodalConnectivity()->getNbOfElems());
54   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+90,0));
55   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+17,0));
56   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
57   mesh->decrRef();
58   //
59   vector<string> families=MEDLoader::GetMeshFamiliesNames(fileName.c_str(),meshNames[0].c_str());
60   CPPUNIT_ASSERT_EQUAL(8,(int)families.size());
61   CPPUNIT_ASSERT(families[2]=="FAMILLE_ELEMENT_3");
62   //
63   vector<string> families2;
64   families2.push_back(families[2]);
65   mesh=MEDLoader::ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),0,families2);
66   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
67   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
68   CPPUNIT_ASSERT_EQUAL(2,mesh->getNumberOfCells());
69   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
70   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
71   CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(0));
72   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(1));
73   CPPUNIT_ASSERT_EQUAL((std::size_t)11,mesh->getNodalConnectivity()->getNbOfElems());
74   CPPUNIT_ASSERT_EQUAL(132,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+11,0));
75   CPPUNIT_ASSERT_EQUAL(16,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+3,0));
76   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
77   mesh->decrRef();
78   //
79   vector<string> groups=MEDLoader::GetMeshGroupsNames(fileName.c_str(),meshNames[0].c_str());
80   CPPUNIT_ASSERT_EQUAL(5,(int)groups.size());
81   CPPUNIT_ASSERT(groups[0]=="groupe1");
82   CPPUNIT_ASSERT(groups[1]=="groupe2");
83   CPPUNIT_ASSERT(groups[2]=="groupe3");
84   CPPUNIT_ASSERT(groups[3]=="groupe4");
85   CPPUNIT_ASSERT(groups[4]=="groupe5");
86   vector<string> groups2;
87   groups2.push_back(groups[0]);
88   mesh=MEDLoader::ReadUMeshFromGroups(fileName.c_str(),meshNames[0].c_str(),0,groups2);
89   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
90   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
91   CPPUNIT_ASSERT_EQUAL(7,mesh->getNumberOfCells());
92   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
93   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
94   for(int i=0;i<6;i++)
95     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i));
96   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(6));
97   CPPUNIT_ASSERT_EQUAL((std::size_t)36,mesh->getNodalConnectivity()->getNbOfElems());
98   CPPUNIT_ASSERT_EQUAL(254,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+36,0));
99   CPPUNIT_ASSERT_EQUAL(141,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+8,0));
100   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
101   mesh->decrRef();
102   //
103   std::vector<std::string> fieldsName=MEDLoader::GetCellFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
104   CPPUNIT_ASSERT_EQUAL(2,(int)fieldsName.size());
105   CPPUNIT_ASSERT(fieldsName[0]=="fieldcelldoublescalar");
106   CPPUNIT_ASSERT(fieldsName[1]=="fieldcelldoublevector");
107   std::vector<std::pair<int,int> > its0=MEDLoader::GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[0].c_str());
108   CPPUNIT_ASSERT_EQUAL(1,(int)its0.size());
109   CPPUNIT_ASSERT_EQUAL(-1,its0[0].first);
110   CPPUNIT_ASSERT_EQUAL(-1,its0[0].second);
111   std::vector<std::pair<int,int> > its1=MEDLoader::GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[1].c_str());
112   CPPUNIT_ASSERT_EQUAL(1,(int)its1.size());
113   CPPUNIT_ASSERT_EQUAL(-1,its1[0].first);
114   CPPUNIT_ASSERT_EQUAL(-1,its1[0].second);
115   //
116   MEDCouplingFieldDouble *field0=MEDLoader::ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[0].c_str(),its0[0].first,its0[0].second);
117   field0->checkCoherency();
118   CPPUNIT_ASSERT(field0->getName()==fieldsName[0]);
119   CPPUNIT_ASSERT_EQUAL(1,field0->getNumberOfComponents());
120   CPPUNIT_ASSERT_EQUAL(16,field0->getNumberOfTuples());
121   const double expectedValues[16]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,2.,3.,3.,2.};
122   double diffValue[16];
123   std::transform(field0->getArray()->getPointer(),field0->getArray()->getPointer()+16,expectedValues,diffValue,std::minus<double>());
124   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue,diffValue+16),1e-12);
125   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue,diffValue+16),1e-12);
126   const MEDCouplingUMesh *constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0->getMesh());
127   CPPUNIT_ASSERT(constMesh);
128   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
129   CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
130   CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells());
131   CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes());
132   CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
133   for(int i=0;i<12;i++)
134     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
135   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
136   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
137   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
138   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
139   CPPUNIT_ASSERT_EQUAL((std::size_t)90,constMesh->getNodalConnectivity()->getNbOfElems());
140   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
141   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
142   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
143   field0->decrRef();
144   //
145   MEDCouplingFieldDouble *field1=MEDLoader::ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[1].c_str(),its1[0].first,its1[0].second);
146   field1->checkCoherency();
147   CPPUNIT_ASSERT(field1->getName()==fieldsName[1]);
148   CPPUNIT_ASSERT_EQUAL(3,field1->getNumberOfComponents());
149   CPPUNIT_ASSERT_EQUAL(16,field1->getNumberOfTuples());
150   const double expectedValues2[48]={1.,0.,1.,1.,0.,1.,1.,0.,1.,2.,1.,0.,2.,1.,0.,2.,1.,0.,3.,0.,1.,3.,0.,1.,3.,0.,1.,4.,1.,0.,4.,1.,0.,4.,1.,0.,5.,0.,0.,6.,1.,1.,6.,0.,0.,5.,1.,1.};
151   double diffValue2[48];
152   std::transform(field1->getArray()->getPointer(),field1->getArray()->getPointer()+48,expectedValues2,diffValue2,std::minus<double>());
153   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue2,diffValue2+48),1e-12);
154   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue2,diffValue2+48),1e-12);
155   constMesh=dynamic_cast<const MEDCouplingUMesh *>(field1->getMesh());
156   CPPUNIT_ASSERT(constMesh);
157   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
158   CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
159   CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells());
160   CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes());
161   CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
162   for(int i=0;i<12;i++)
163     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
164   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
165   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
166   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
167   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
168   CPPUNIT_ASSERT_EQUAL((std::size_t)90,constMesh->getNodalConnectivity()->getNbOfElems());
169   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
170   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
171   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
172   field1->decrRef();
173   //fields on nodes
174   std::vector<std::string> fieldsNameNode=MEDLoader::GetNodeFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
175   CPPUNIT_ASSERT_EQUAL(2,(int)fieldsNameNode.size());
176   CPPUNIT_ASSERT(fieldsNameNode[0]=="fieldnodedouble");
177   CPPUNIT_ASSERT(fieldsNameNode[1]=="fieldnodeint");
178   std::vector<std::pair<int,int> > its0Node=MEDLoader::GetNodeFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsNameNode[0].c_str());
179   CPPUNIT_ASSERT_EQUAL(3,(int)its0Node.size());
180   CPPUNIT_ASSERT_EQUAL(-1,its0Node[0].first);
181   CPPUNIT_ASSERT_EQUAL(-1,its0Node[0].second);
182   CPPUNIT_ASSERT_EQUAL(1,its0Node[1].first);
183   CPPUNIT_ASSERT_EQUAL(-1,its0Node[1].second);
184   CPPUNIT_ASSERT_EQUAL(2,its0Node[2].first);
185   CPPUNIT_ASSERT_EQUAL(-1,its0Node[2].second);
186   MEDCouplingFieldDouble *field0Nodes=MEDLoader::ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[0].first,its0Node[0].second);
187   field0Nodes->checkCoherency();
188   CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
189   CPPUNIT_ASSERT_EQUAL(1,field0Nodes->getNumberOfComponents());
190   CPPUNIT_ASSERT_EQUAL(19,field0Nodes->getNumberOfTuples());
191   const double expectedValues3[19]={1.,1.,1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.};
192   double diffValue3[19];
193   std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues3,diffValue3,std::minus<double>());
194   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
195   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
196   constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
197   CPPUNIT_ASSERT(constMesh);
198   field0Nodes->decrRef();
199   //
200   field0Nodes=MEDLoader::ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[2].first,its0Node[2].second);
201   field0Nodes->checkCoherency();
202   CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
203   CPPUNIT_ASSERT_EQUAL(1,field0Nodes->getNumberOfComponents());
204   CPPUNIT_ASSERT_EQUAL(19,field0Nodes->getNumberOfTuples());
205   const double expectedValues4[19]={1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.,7.,7.};
206   std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues4,diffValue3,std::minus<double>());
207   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
208   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
209   constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
210   CPPUNIT_ASSERT(constMesh);
211   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
212   CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
213   CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells());
214   CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes());
215   CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
216   for(int i=0;i<12;i++)
217     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
218   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
219   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
220   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
221   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
222   CPPUNIT_ASSERT_EQUAL((std::size_t)90,constMesh->getNodalConnectivity()->getNbOfElems());
223   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
224   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
225   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
226   field0Nodes->decrRef();
227   //
228   field0Nodes=MEDLoader::ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[0].first,its0Node[0].second);
229   field0Nodes->checkCoherency();
230   CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
231   CPPUNIT_ASSERT_EQUAL(1,field0Nodes->getNumberOfComponents());
232   CPPUNIT_ASSERT_EQUAL(19,field0Nodes->getNumberOfTuples());
233   const double expectedValues5[19]={1.,1.,1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.};
234   std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues5,diffValue3,std::minus<double>());
235   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
236   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
237   constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
238   CPPUNIT_ASSERT(constMesh);
239   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
240   CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
241   CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells());
242   CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes());
243   CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
244   for(int i=0;i<12;i++)
245     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
246   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
247   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
248   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
249   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
250   CPPUNIT_ASSERT_EQUAL((std::size_t)90,constMesh->getNodalConnectivity()->getNbOfElems());
251   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
252   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
253   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
254   field0Nodes->decrRef();
255 }
256
257 void ParaMEDMEMTest::testMEDLoaderPolygonRead()
258 {
259   string fileName=getResourceFile("polygones.med");
260   vector<string> meshNames=MEDLoader::GetMeshNames(fileName.c_str());
261   CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
262   CPPUNIT_ASSERT(meshNames[0]=="Bord");
263   MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
264   mesh->checkCoherency();
265   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
266   CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
267   CPPUNIT_ASSERT_EQUAL(538,mesh->getNumberOfCells());
268   CPPUNIT_ASSERT_EQUAL(579,mesh->getNumberOfNodes());
269   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
270   for(int i=0;i<514;i++)
271     CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(i));
272   for(int i=514;i<538;i++)
273     CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(i));
274   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+1737,0),1e-12);
275   const double expectedVals1[12]={1.4851585216522212,-0.5,0.,1.4851585216522212,-0.4,0.,1.4851585216522212,-0.3,0., 1.5741585216522211, -0.5, 0. };
276   double diffValue1[12];
277   std::transform(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+12,expectedVals1,diffValue1,std::minus<double>());
278   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue1,diffValue1+12),1e-12);
279   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue1,diffValue1+12),1e-12);
280   CPPUNIT_ASSERT_EQUAL((std::size_t)2768,mesh->getNodalConnectivity()->getNbOfElems());
281   CPPUNIT_ASSERT_EQUAL(651050,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+2768,0));
282   CPPUNIT_ASSERT_EQUAL(725943,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+539,0));
283   mesh->decrRef();
284   //
285   std::vector<std::string> fieldsName=MEDLoader::GetCellFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
286   CPPUNIT_ASSERT_EQUAL(3,(int)fieldsName.size());
287   CPPUNIT_ASSERT(fieldsName[0]=="bord_:_distorsion");
288   CPPUNIT_ASSERT(fieldsName[1]=="bord_:_familles");
289   CPPUNIT_ASSERT(fieldsName[2]=="bord_:_non-ortho");
290   std::vector<std::pair<int,int> > its0=MEDLoader::GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[0].c_str());
291   CPPUNIT_ASSERT_EQUAL(1,(int)its0.size());
292   MEDCouplingFieldDouble *field=MEDLoader::ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[0].c_str(),its0[0].first,its0[0].second);
293   field->checkCoherency();
294   CPPUNIT_ASSERT(field->getName()==fieldsName[0]);
295   CPPUNIT_ASSERT_EQUAL(1,field->getNumberOfComponents());
296   CPPUNIT_ASSERT_EQUAL(538,field->getNumberOfTuples());
297   const MEDCouplingUMesh *constMesh=dynamic_cast<const MEDCouplingUMesh *>(field->getMesh());
298   CPPUNIT_ASSERT(constMesh);
299   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
300   CPPUNIT_ASSERT_EQUAL(2,constMesh->getMeshDimension());
301   CPPUNIT_ASSERT_EQUAL(538,constMesh->getNumberOfCells());
302   CPPUNIT_ASSERT_EQUAL(579,constMesh->getNumberOfNodes());
303   CPPUNIT_ASSERT_EQUAL(2,(int)constMesh->getAllGeoTypes().size());
304   for(int i=0;i<514;i++)
305     CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,constMesh->getTypeOfCell(i));
306   for(int i=514;i<538;i++)
307     CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,constMesh->getTypeOfCell(i));
308   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+1737,0),1e-12);
309   std::transform(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+12,expectedVals1,diffValue1,std::minus<double>());
310   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue1,diffValue1+12),1e-12);
311   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue1,diffValue1+12),1e-12);
312   CPPUNIT_ASSERT_EQUAL((std::size_t)2768,constMesh->getNodalConnectivity()->getNbOfElems());
313   CPPUNIT_ASSERT_EQUAL(651050,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+2768,0));
314   CPPUNIT_ASSERT_EQUAL(725943,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+539,0));
315   const double *values=field->getArray()->getPointer();
316   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.87214203182918,std::accumulate(values,values+538,0.),1e-12);
317   field->decrRef();
318 }
319
320 void ParaMEDMEMTest::testMEDLoaderPolyhedronRead()
321 {
322   string fileName=getResourceFile("poly3D.med");
323   vector<string> meshNames=MEDLoader::GetMeshNames(fileName.c_str());
324   CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
325   CPPUNIT_ASSERT(meshNames[0]=="poly3D");
326   MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
327   mesh->checkCoherency();
328   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
329   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
330   CPPUNIT_ASSERT_EQUAL(3,mesh->getNumberOfCells());
331   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
332   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
333   CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(0));
334   CPPUNIT_ASSERT_EQUAL(NORM_POLYHED,mesh->getTypeOfCell(1));
335   CPPUNIT_ASSERT_EQUAL(NORM_POLYHED,mesh->getTypeOfCell(2));
336   CPPUNIT_ASSERT_EQUAL((std::size_t)98,mesh->getNodalConnectivity()->getNbOfElems());
337   CPPUNIT_ASSERT_EQUAL(725,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+98,0));
338   CPPUNIT_ASSERT_DOUBLES_EQUAL(110.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
339   CPPUNIT_ASSERT_EQUAL(155,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+4,0));
340   mesh->decrRef();
341   //
342   mesh=MEDLoader::ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),-1);
343   mesh->checkCoherency();
344   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
345   CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
346   CPPUNIT_ASSERT_EQUAL(17,mesh->getNumberOfCells());
347   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
348   CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllGeoTypes().size());
349   CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(0));
350   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(1));
351   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(2));
352   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(3));
353   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(4));
354   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(5));
355   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(6));
356   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(7));
357   CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(8));
358   CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(9));
359   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(10));
360   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(11));
361   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(12));
362   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(13));
363   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(14));
364   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(15));
365   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(16));
366   CPPUNIT_ASSERT_DOUBLES_EQUAL(110.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
367   CPPUNIT_ASSERT_EQUAL((std::size_t)83,mesh->getNodalConnectivity()->getNbOfElems());
368   CPPUNIT_ASSERT_EQUAL(619,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+83,0));
369   mesh->decrRef();
370   //
371   vector<string> families=MEDLoader::GetMeshFamiliesNames(fileName.c_str(),meshNames[0].c_str());
372   CPPUNIT_ASSERT_EQUAL(4,(int)families.size());
373   CPPUNIT_ASSERT(families[0]=="FAMILLE_FACE_POLYGONS3");
374   CPPUNIT_ASSERT(families[1]=="FAMILLE_FACE_QUAD41");
375   CPPUNIT_ASSERT(families[2]=="FAMILLE_FACE_TRIA32");
376   CPPUNIT_ASSERT(families[3]=="FAMILLE_ZERO");
377   vector<string> families2;
378   families2.push_back(families[0]);
379   mesh=MEDLoader::ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),-1,families2);
380   mesh->checkCoherency();
381   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
382   CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
383   CPPUNIT_ASSERT_EQUAL(3,mesh->getNumberOfCells());
384   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
385   CPPUNIT_ASSERT_EQUAL(1,(int)mesh->getAllGeoTypes().size());
386   for(int i=0;i<3;i++)
387     CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(i));
388   CPPUNIT_ASSERT_EQUAL((std::size_t)19,mesh->getNodalConnectivity()->getNbOfElems());
389   CPPUNIT_ASSERT_EQUAL(117,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+19,0));
390   mesh->decrRef();
391   //
392   mesh=MEDLoader::ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),0,families2);
393   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
394   CPPUNIT_ASSERT_EQUAL(0,mesh->getNumberOfCells());
395   CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
396   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
397   CPPUNIT_ASSERT_EQUAL(0,(int)mesh->getAllGeoTypes().size());
398   mesh->decrRef();
399 }