]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/Test/MEDLoaderTest.cxx
Salome HOME
0d1add2c1b986b70f3c8fa7e2677a419947e9fdc
[tools/medcoupling.git] / src / MEDLoader / Test / MEDLoaderTest.cxx
1 // Copyright (C) 2007-2024  CEA, EDF
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 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDLoaderTest.hxx"
22 #include "MEDLoader.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDCouplingUMesh.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingFieldFloat.hxx"
27 #include "MEDCouplingFieldInt64.hxx"
28 #include "MEDCouplingMemArray.hxx"
29 #include "TestInterpKernelUtils.hxx"  // getResourceFile()
30
31 #include <cmath>
32 #include <numeric>
33
34 using namespace MEDCoupling;
35
36 void MEDLoaderTest::testMesh1DRW()
37 {
38   MEDCouplingUMesh *mesh=build1DMesh_1();
39   mesh->checkConsistencyLight();
40   WriteUMesh("file1.med",mesh,true);
41   MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile("file1.med",mesh->getName().c_str(),0);
42   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
43   mesh_rw->decrRef();
44   mesh->decrRef();
45 }
46
47 void MEDLoaderTest::testMesh2DCurveRW()
48 {
49   MEDCouplingUMesh *mesh=build2DCurveMesh_1();
50   mesh->checkConsistencyLight();
51   WriteUMesh("file2.med",mesh,true);
52   MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile("file2.med",mesh->getName().c_str(),0);
53   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
54   mesh_rw->decrRef();
55   mesh->decrRef();
56 }
57
58 void MEDLoaderTest::testMesh2DRW()
59 {
60   MEDCouplingUMesh *mesh=build2DMesh_1();
61   mesh->checkConsistencyLight();
62   WriteUMesh("file3.med",mesh,true);
63   MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile("file3.med",mesh->getName().c_str(),0);
64   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
65   mesh_rw->decrRef();
66   mesh->decrRef();
67 }
68
69 void MEDLoaderTest::testMesh3DSurfRW()
70 {
71   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
72   mesh->checkConsistencyLight();
73   WriteUMesh("file4.med",mesh,true);
74   MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile("file4.med",mesh->getName().c_str(),0);
75   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
76   mesh_rw->decrRef();
77   mesh->decrRef();
78 }
79
80 void MEDLoaderTest::testMesh3DRW()
81 {
82   MEDCouplingUMesh *mesh=build3DMesh_1();
83   mesh->checkConsistencyLight();
84   WriteUMesh("file5.med",mesh,true);
85   MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile("file5.med",mesh->getName().c_str(),0);
86   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
87   mesh_rw->decrRef();
88   mesh->decrRef();
89 }
90
91 /*!
92  * Most basic test : one and only one MEDCoupling field in a new file.
93  */
94 void MEDLoaderTest::testFieldRW1()
95 {
96   MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
97   WriteField("file6.med",f1,true);
98   MEDCouplingFieldDouble *f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell("file6.med",f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),0,1));
99   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
100   f1->decrRef();
101   f2->decrRef();
102   //
103   f1=buildVecFieldOnNodes_1();
104   WriteField("file7.med",f1,true);
105   f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode("file7.med",f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,3));
106   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
107   // testing kind message on error of field type.
108   CPPUNIT_ASSERT_THROW(ReadFieldCell("file7.med",f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,3),INTERP_KERNEL::Exception);
109   //
110   f1->decrRef();
111   f2->decrRef();
112 }
113
114 /*!
115  * Multi field writing in a same file.
116  */
117 void MEDLoaderTest::testFieldRW2()
118 {
119   const char fileName[]="file8.med";
120   static const double VAL1=12345.67890314;
121   static const double VAL2=-1111111111111.;
122   MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
123   MEDCouplingFieldInt *f1_int=buildIntVecFieldOnCells_1();
124   MEDCouplingFieldFloat *f1_fl=buildFloatVecFieldOnCells_1();
125   MEDCouplingFieldInt64 *f1_int64=buildInt64VecFieldOnCells_1();
126   WriteField(fileName,f1,true);
127   f1->setTime(10.,8,9);
128   f1_int->setTime(10.,8,9);
129   f1_fl->setTime(10.,8,9);
130   f1_int64->setTime(10.,8,9);
131   double *tmp=f1->getArray()->getPointer();
132   tmp[0]=VAL1;
133   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
134   f1->setTime(10.14,18,19);
135   tmp[0]=VAL2;
136   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
137   // Write int and float fields:
138   WriteFieldUsingAlreadyWrittenMesh(fileName,f1_int);
139   WriteFieldUsingAlreadyWrittenMesh(fileName,f1_int64);
140   WriteFieldUsingAlreadyWrittenMesh(fileName,f1_fl);
141   //retrieving time steps...
142   MEDCouplingFieldDouble *f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),8,9));
143   f1->setTime(10.,8,9);
144   tmp[0]=VAL1;
145   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
146   f2->decrRef();
147   f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),0,1));
148   MEDCouplingFieldDouble *f3=buildVecFieldOnCells_1();
149   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
150   f3->decrRef();
151   f2->decrRef();
152   f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),18,19));
153   f1->setTime(10.14,18,19);
154   tmp[0]=VAL2;
155   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
156   //test of throw on invalid (dt,it)
157   CPPUNIT_ASSERT_THROW(ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),28,19),INTERP_KERNEL::Exception);
158   f2->decrRef();
159   f1->decrRef();
160   // Reading Int and Float fields:
161   MEDCouplingFieldInt *f2_int=dynamic_cast<MEDCouplingFieldInt *>(ReadFieldCell(fileName,f1_int->getMesh()->getName().c_str(),0,f1_int->getName().c_str(),8,9));
162   CPPUNIT_ASSERT(f1_int->isEqual(f2_int,1e-12,0)); // exact equality for int values
163   f2_int->decrRef();
164   f1_int->decrRef();
165   MEDCouplingFieldInt64 *f2_int64=dynamic_cast<MEDCouplingFieldInt64 *>(ReadFieldCell(fileName,f1_int64->getMesh()->getName().c_str(),0,f1_int64->getName().c_str(),8,9));
166   CPPUNIT_ASSERT(f1_int64->isEqual(f2_int64,1e-12,0)); // exact equality for int values
167   f2_int64->decrRef();
168   f1_int64->decrRef();
169   MEDCouplingFieldFloat *f2_fl=dynamic_cast<MEDCouplingFieldFloat *>(ReadFieldCell(fileName,f1_fl->getMesh()->getName().c_str(),0,f1_fl->getName().c_str(),8,9));
170   CPPUNIT_ASSERT(f1_fl->isEqual(f2_fl,1e-12,1e-07f));  // float comparison
171   f2_fl->decrRef();
172   f1_fl->decrRef();
173   //ON NODES
174   f1=buildVecFieldOnNodes_1();
175   const char fileName2[]="file9.med";
176   WriteField(fileName2,f1,true);
177   f1->setTime(110.,108,109);
178   tmp=f1->getArray()->getPointer();
179   tmp[3]=VAL1;
180   WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
181   f1->setTime(210.,208,209);
182   tmp[3]=VAL2;
183   WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
184   f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName2,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),108,109));
185   f1->setTime(110.,108,109);
186   tmp[3]=VAL1;
187   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
188   f2->decrRef();
189   f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName2,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,3));
190   f3=buildVecFieldOnNodes_1();
191   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
192   f3->decrRef();
193   f2->decrRef();
194   f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName2,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),208,209));
195   f1->setTime(210.,208,209);
196   tmp[3]=VAL2;
197   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
198   f2->decrRef();
199   f1->decrRef();
200 }
201
202 /*!
203  * Multi field in a same file, but this field has several timesteps
204  */
205 void MEDLoaderTest::testFieldRW3()
206 {
207   const char fileName[]="file11.med";
208   static const double VAL1=12345.67890314;
209   static const double VAL2=-1111111111111.;
210   const char name1[]="AField";
211   const char name3[]="AMesh1";
212   MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
213   (const_cast<MEDCouplingMesh *>(f1->getMesh()))->setName(name3);
214   f1->setName(name1);
215   f1->setTime(10.,8,9);
216   double *tmp=f1->getArray()->getPointer();
217   tmp[0]=VAL1;
218   WriteField(fileName,f1,true);
219   f1->setTime(10.14,18,19);
220   tmp[0]=VAL2;
221   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
222   f1->setTime(10.55,28,29);
223   tmp[0]=3*VAL1;
224   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
225   f1->setTime(10.66,38,39);
226   tmp[0]=3*VAL2;
227   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
228   f1->setTime(10.77,48,49);
229   tmp[0]=4*VAL2;
230   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
231   //ON NODES
232   f1->decrRef();
233   f1=buildVecFieldOnNodes_1();
234   f1->setName(name1);
235   (const_cast<MEDCouplingMesh *>(f1->getMesh()))->setName(name3);
236   f1->setTime(110.,8,9);
237   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
238   f1->setTime(110.,108,109);
239   tmp=f1->getArray()->getPointer();
240   tmp[3]=VAL1;
241   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
242   f1->setTime(210.,208,209);
243   tmp[3]=VAL2;
244   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
245   //
246   std::vector< std::pair<int,int> > it1=GetCellFieldIterations(fileName,name3,name1);
247   CPPUNIT_ASSERT_EQUAL(5,(int)it1.size());
248   CPPUNIT_ASSERT_EQUAL(8,it1[0].first); CPPUNIT_ASSERT_EQUAL(9,it1[0].second);
249   CPPUNIT_ASSERT_EQUAL(18,it1[1].first); CPPUNIT_ASSERT_EQUAL(19,it1[1].second);
250   CPPUNIT_ASSERT_EQUAL(28,it1[2].first); CPPUNIT_ASSERT_EQUAL(29,it1[2].second);
251   CPPUNIT_ASSERT_EQUAL(38,it1[3].first); CPPUNIT_ASSERT_EQUAL(39,it1[3].second);
252   CPPUNIT_ASSERT_EQUAL(48,it1[4].first); CPPUNIT_ASSERT_EQUAL(49,it1[4].second);
253   std::vector< std::pair<int,int> > it3=GetNodeFieldIterations(fileName,name3,name1);
254   CPPUNIT_ASSERT_EQUAL(3,(int)it3.size());
255   CPPUNIT_ASSERT_EQUAL(8,it3[0].first); CPPUNIT_ASSERT_EQUAL(9,it3[0].second);
256   CPPUNIT_ASSERT_EQUAL(108,it3[1].first); CPPUNIT_ASSERT_EQUAL(109,it3[1].second);
257   CPPUNIT_ASSERT_EQUAL(208,it3[2].first); CPPUNIT_ASSERT_EQUAL(209,it3[2].second);
258   //
259   f1->decrRef();
260   //
261   f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,name3,0,name1,8,9));
262   CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[0],1e-13);
263   f1->decrRef();
264   f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,name3,0,name1,18,19));
265   CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[0],1e-13);
266   f1->decrRef();
267   f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,name3,0,name1,28,29));
268   CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL1,f1->getArray()->getConstPointer()[0],1e-13);
269   f1->decrRef();
270   f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,name3,0,name1,38,39));
271   CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
272   f1->decrRef();
273   f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,name3,0,name1,48,49));
274   CPPUNIT_ASSERT_DOUBLES_EQUAL(4*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
275   f1->decrRef();
276   //
277   f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName,name3,0,name1,8,9));
278   CPPUNIT_ASSERT_DOUBLES_EQUAL(71.,f1->getArray()->getConstPointer()[3],1e-13);
279   f1->decrRef();
280   f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName,name3,0,name1,108,109));
281   CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[3],1e-13);
282   f1->decrRef();
283   f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName,name3,0,name1,208,209));
284   CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[3],1e-13);
285   f1->decrRef();
286 }
287
288 void MEDLoaderTest::testMultiMeshRW1()
289 {
290   const char fileName[]="file10.med";
291   MEDCouplingUMesh *mesh1=build3DMesh_1();
292   const mcIdType part1[5]={1,2,4,13,15};
293   MEDCouplingUMesh *mesh2=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part1,part1+5,true);
294   mesh2->setName("mesh2");
295   const mcIdType part2[4]={3,4,13,14};
296   MEDCouplingUMesh *mesh3=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part2,part2+4,true);
297   mesh3->setName("mesh3");
298   MEDCouplingUMesh *mesh4=MEDCouplingUMesh::New();
299   mesh4->setName("mesh4");
300   mesh4->setMeshDimension(3);
301   mesh4->allocateCells(1);
302   mcIdType conn[4]={0,11,1,3};
303   mesh4->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,conn);
304   mesh4->finishInsertingCells();
305   mesh4->setCoords(mesh1->getCoords());
306   std::vector<const MEDCouplingUMesh *> meshes;
307   meshes.push_back(mesh1);
308   meshes.push_back(mesh2);
309   meshes.push_back(mesh3);
310   meshes.push_back(mesh4);
311   const char mnane[]="3DToto";
312   WriteUMeshesPartition(fileName,mnane,meshes,true);
313   //
314   MEDCouplingUMesh *mesh5=ReadUMeshFromFile(fileName,mnane);
315   mesh1->setName(mnane);
316   const mcIdType part3[18]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
317   MEDCouplingUMesh *mesh6=(MEDCouplingUMesh *)mesh5->buildPartOfMySelf(part3,part3+18,true);
318   mesh6->setName(mnane);
319   mesh5->decrRef();
320   CPPUNIT_ASSERT(mesh6->isEqual(mesh1,1e-12));
321   mesh6->decrRef();
322   std::vector<std::string> grps=GetMeshGroupsNames(fileName,mnane);
323   CPPUNIT_ASSERT_EQUAL(4,(int)grps.size());
324   CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh2"))!=grps.end());
325   CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh3"))!=grps.end());
326   CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh4"))!=grps.end());
327   CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("3DMesh_1"))!=grps.end());
328   //
329   std::vector<std::string> vec;
330   vec.push_back(std::string("mesh2"));
331   MEDCouplingUMesh *mesh2_2=ReadUMeshFromGroups(fileName,mnane,0,vec);
332   CPPUNIT_ASSERT(mesh2_2->isEqual(mesh2,1e-12));
333   mesh2_2->decrRef();
334   vec.clear(); vec.push_back(std::string("mesh3"));
335   MEDCouplingUMesh *mesh3_2=ReadUMeshFromGroups(fileName,mnane,0,vec);
336   CPPUNIT_ASSERT(mesh3_2->isEqual(mesh3,1e-12));
337   mesh3_2->decrRef();
338   vec.clear(); vec.push_back(std::string("mesh4"));
339   MEDCouplingUMesh *mesh4_2=ReadUMeshFromGroups(fileName,mnane,0,vec);
340   CPPUNIT_ASSERT(mesh4_2->isEqual(mesh4,1e-12));
341   mesh4_2->decrRef();
342   vec.clear(); vec.push_back(std::string("3DMesh_1"));
343   MEDCouplingUMesh *mesh1_2=ReadUMeshFromGroups(fileName,mnane,0,vec);
344   mesh1->setName("3DMesh_1");
345   CPPUNIT_ASSERT(mesh1_2->isEqual(mesh1,1e-12));
346   mesh1_2->decrRef();
347   //
348   vec.clear(); vec.push_back(std::string("Family_-3")); vec.push_back(std::string("Family_-5"));
349   mesh2_2=ReadUMeshFromFamilies(fileName,mnane,0,vec);
350   mesh2_2->setName("mesh2");
351   CPPUNIT_ASSERT(mesh2_2->isEqual(mesh2,1e-12));
352   mesh2_2->decrRef();
353   //
354   std::vector<std::string> ret(GetMeshFamiliesNamesOnGroup(fileName,"3DToto","3DMesh_1"));
355   std::set<std::string> s(ret.begin(),ret.end());
356   std::set<std::string> ref_s;
357   ref_s.insert("Family_-2");
358   ref_s.insert("Family_-3");
359   ref_s.insert("Family_-4");
360   ref_s.insert("Family_-5");
361   CPPUNIT_ASSERT_EQUAL(4,(int)ret.size());
362   CPPUNIT_ASSERT(s==ref_s);
363   //
364   std::vector<std::string> ret1=GetMeshGroupsNamesOnFamily(fileName,"3DToto","Family_-3");
365   CPPUNIT_ASSERT_EQUAL(2,(int)ret1.size());
366   CPPUNIT_ASSERT(ret1[0]=="3DMesh_1");
367   CPPUNIT_ASSERT(ret1[1]=="mesh2");
368   //
369   mesh4->decrRef();
370   mesh3->decrRef();
371   mesh2->decrRef();
372   mesh1->decrRef();
373 }
374
375 void MEDLoaderTest::testFieldProfilRW1()
376 {
377   const char fileName[]="file12.med";
378   MEDCouplingUMesh *mesh1=build3DMesh_1();
379   bool b;
380   mcIdType newNbOfNodes;
381   DataArrayIdType *da=mesh1->mergeNodes(1e-12,b,newNbOfNodes);
382   da->decrRef();
383   WriteUMesh(fileName,mesh1,true);
384   const mcIdType part1[5]={1,2,4,13,15};
385   MEDCouplingUMesh *mesh2=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part1,part1+5,true);
386   mesh2->setName(mesh1->getName().c_str());// <- important for the test
387   //
388   mcIdType nbOfCells=mesh2->getNumberOfCells();
389   CPPUNIT_ASSERT_EQUAL(ToIdType(5),nbOfCells);
390   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
391   f1->setName("VectorFieldOnCells");
392   f1->setMesh(mesh2);
393   DataArrayDouble *array=DataArrayDouble::New();
394   array->alloc(nbOfCells,2);
395   f1->setArray(array);
396   array->decrRef();
397   double *tmp=array->getPointer();
398   const double arr1[10]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.};
399   std::copy(arr1,arr1+10,tmp);
400   f1->setTime(3.14,2,7);
401   f1->checkConsistencyLight();
402   //
403   WriteField(fileName,f1,false);// <- false important for the test
404   //
405   MEDCouplingFieldDouble *f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,7));
406   std::vector<MEDCoupling::TypeOfField> types=GetTypesOfField(fileName,f1->getMesh()->getName().c_str(),f1->getName().c_str());
407   CPPUNIT_ASSERT_EQUAL(1,(int)types.size());
408   CPPUNIT_ASSERT(types[0]==ON_CELLS);
409   f2->checkConsistencyLight();
410   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
411   //
412   f2->decrRef();
413   f1->decrRef();
414   mesh1->decrRef();
415   mesh2->decrRef();
416 }
417
418 /*!
419  * Test MED file profiles.
420  */
421 void MEDLoaderTest::testFieldNodeProfilRW1()
422 {
423   const char fileName[]="file19.med";
424   const char fileName2[]="file20.med";
425   MEDCouplingUMesh *m=build2DMesh_1();
426   mcIdType nbOfNodes=m->getNumberOfNodes();
427   WriteUMesh(fileName,m,true);
428   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
429   f1->setName("VFieldOnNodes");
430   f1->setMesh(m);
431   DataArrayDouble *array=DataArrayDouble::New();
432   const double arr1[24]={1.,101.,2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.};
433   array->alloc(nbOfNodes,2);
434   std::copy(arr1,arr1+24,array->getPointer());
435   f1->setArray(array);
436   array->setInfoOnComponent(0,"tyty [mm]");
437   array->setInfoOnComponent(1,"uiop [MW]");
438   array->decrRef();
439   f1->setTime(3.14,2,7);
440   f1->checkConsistencyLight();
441   const mcIdType arr2[2]={1,4};//node ids are 2,4,5,3,6,7
442   MEDCouplingFieldDouble *f2=f1->buildSubPart(arr2,arr2+2);
443   (const_cast<MEDCouplingMesh *>(f2->getMesh()))->setName(f1->getMesh()->getName().c_str());
444   WriteField(fileName,f2,false);// <- false important for the test
445   //
446   MEDCouplingFieldDouble *f3=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName,f2->getMesh()->getName().c_str(),0,f2->getName().c_str(),2,7));
447   f3->checkConsistencyLight();
448   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
449   f3->decrRef();
450   //
451   const mcIdType arr3[6]={1,3,0,5,2,4};
452   f2->renumberNodes(arr3);
453   WriteUMesh(fileName2,m,true);
454   WriteField(fileName2,f2,false);// <- false important for the test
455   f3=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName2,f2->getMesh()->getName().c_str(),0,f2->getName().c_str(),2,7));
456   f3->checkConsistencyLight();
457   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
458   f3->decrRef();
459   f2->decrRef();
460   //
461   f1->decrRef();
462   m->decrRef();
463 }
464
465 void MEDLoaderTest::testFieldNodeProfilRW2()
466 {
467   const char fileName[]="file23.med";
468   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
469   WriteUMesh(fileName,mesh,true);
470   //
471   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
472   f1->setName("FieldMix");
473   f1->setMesh(mesh);
474   const double arr2[24]={
475     1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
476     1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
477   };
478   DataArrayDouble *array=DataArrayDouble::New();
479   array->alloc(12,2);
480   f1->setArray(array);
481   array->setInfoOnComponent(0,"plkj [mm]");
482   array->setInfoOnComponent(1,"pqqqss [mm]");
483   array->decrRef();
484   double *tmp=array->getPointer();
485   std::copy(arr2,arr2+24,tmp);
486   f1->setTime(3.17,2,7);
487   //
488   const mcIdType renumArr[12]={3,7,2,1,5,11,10,0,9,6,8,4};
489   f1->renumberNodes(renumArr);
490   f1->checkConsistencyLight();
491   WriteField(fileName,f1,false);// <- false important for the test
492   MEDCouplingFieldDouble *f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,7));
493   CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
494   //
495   f2->decrRef();
496   mesh->decrRef();
497   f1->decrRef();
498 }
499
500 void MEDLoaderTest::testFieldGaussRW1()
501 {
502   const char fileName[]="file13.med";
503   MEDCouplingFieldDouble *f1=buildVecFieldOnGauss_1();
504   WriteField(fileName,f1,true);
505   MCAuto<MEDCouplingField> f2Tmp(ReadField(ON_GAUSS_PT,fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),1,5));
506   MCAuto<MEDCouplingFieldDouble> f2(MEDCoupling::DynamicCast<MEDCouplingField,MEDCouplingFieldDouble>(f2Tmp));
507   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
508   f1->decrRef();
509 }
510
511 void MEDLoaderTest::testFieldGaussNERW1()
512 {
513   const char fileName[]="file14.med";
514   MEDCouplingFieldDouble *f1=buildVecFieldOnGaussNE_1();
515   WriteField(fileName,f1,true);
516   std::vector<MEDCoupling::TypeOfField> tof(GetTypesOfField(fileName,"2DMesh_2","MyFieldOnGaussNE"));
517   CPPUNIT_ASSERT_EQUAL(1,(int)tof.size());
518   CPPUNIT_ASSERT(ON_GAUSS_NE==tof[0]);
519   MCAuto<MEDCouplingField> f2Tmp(ReadField(ON_GAUSS_NE,fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),1,5));
520   MCAuto<MEDCouplingFieldDouble> f2(MEDCoupling::DynamicCast<MEDCouplingField,MEDCouplingFieldDouble>(f2Tmp));
521   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
522   f1->decrRef();
523 }
524
525 void MEDLoaderTest::testLittleStrings1()
526 {
527   std::string s("azeeeerrrtty");
528   MEDLoaderBase::zipEqualConsChar(s,3);
529   CPPUNIT_ASSERT(s=="azertty");
530 }
531
532 void MEDLoaderTest::testSplitIntoNameAndUnit1()
533 {
534   std::string s(" []");
535   std::string c,u;
536   MEDLoaderBase::splitIntoNameAndUnit(s,c,u);
537   CPPUNIT_ASSERT(c.empty());
538   CPPUNIT_ASSERT(u.empty());
539   s="   lmmm  kki jjj      ";
540   MEDLoaderBase::strip(s);
541   CPPUNIT_ASSERT(s=="lmmm  kki jjj");
542   s=" ";
543   MEDLoaderBase::strip(s);
544   CPPUNIT_ASSERT(s.empty());
545   s="";
546   MEDLoaderBase::strip(s);
547   CPPUNIT_ASSERT(s.empty());
548   s="      ";
549   MEDLoaderBase::strip(s);
550   CPPUNIT_ASSERT(s.empty());
551   s="     pp";
552   MEDLoaderBase::strip(s);
553   CPPUNIT_ASSERT(s=="pp");
554 }
555
556 void MEDLoaderTest::testMesh3DSurfShuffleRW()
557 {
558   const char fileName[]="file15.med";
559   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
560   const mcIdType renumber1[6]={2,5,1,0,3,4};
561   mesh->renumberCells(renumber1,false);
562   mesh->checkConsistencyLight();
563   WriteUMesh(fileName,mesh,true);
564   MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile(fileName,mesh->getName().c_str(),0);
565   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
566   mesh_rw->decrRef();
567   mesh->decrRef();
568 }
569
570 void MEDLoaderTest::testFieldShuffleRW1()
571 {
572   const char fileName[]="file16.med";
573   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
574   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
575   f1->setName("FieldOnCellsShuffle");
576   f1->setMesh(mesh);
577   DataArrayDouble *array=DataArrayDouble::New();
578   array->alloc(6,2);
579   f1->setArray(array);
580   array->decrRef();
581   double *tmp=array->getPointer();
582   const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
583   std::copy(arr1,arr1+12,tmp);
584   f1->setTime(3.14,2,7);
585   f1->checkConsistencyLight();
586   //
587   const mcIdType renumber1[6]={2,1,5,0,3,4};
588   f1->renumberCells(renumber1,false);
589   WriteField(fileName,f1,true);
590   MEDCouplingFieldDouble *f2=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldCell(fileName,mesh->getName().c_str(),0,f1->getName().c_str(),2,7));
591   CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
592   f2->decrRef();
593   //
594   mesh->decrRef();
595   f1->decrRef();
596 }
597
598 /*!
599  * Shuffle de cells but no profile. Like pointe.med
600  */
601 void MEDLoaderTest::testMultiFieldShuffleRW1()
602 {
603   const char fileName[]="file17.med";
604   MEDCouplingUMesh *m=build3DMesh_2();
605   CPPUNIT_ASSERT_EQUAL(20,(int)m->getNumberOfCells());
606   CPPUNIT_ASSERT_EQUAL(ToIdType(45),m->getNumberOfNodes());
607   const mcIdType polys[3]={1,4,6};
608   std::vector<mcIdType> poly2(polys,polys+3);
609   m->convertToPolyTypes(&poly2[0],&poly2[0]+poly2.size());
610   const mcIdType renum[20]={1,3,2,8,9,12,13,16,19,0,4,7,5,15,14,17,10,18,6,11};
611   m->renumberCells(renum,false);
612   m->orientCorrectlyPolyhedrons();
613   // Writing
614   WriteUMesh(fileName,m,true);
615   MEDCouplingFieldDouble *f1Tmp=m->getMeasureField(false);
616   MEDCouplingFieldDouble *f1=f1Tmp->buildNewTimeReprFromThis(ONE_TIME,false);
617   f1Tmp->decrRef();
618   f1->setTime(0.,1,2);
619   MEDCouplingFieldDouble *f_1=f1->cloneWithMesh(true);
620   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
621   f1->applyFunc("2*x");
622   f1->setTime(0.01,3,4);
623   MEDCouplingFieldDouble *f_2=f1->cloneWithMesh(true);
624   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
625   f1->applyFunc("2*x/3");
626   f1->setTime(0.02,5,6);
627   MEDCouplingFieldDouble *f_3=f1->cloneWithMesh(true);
628   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
629   f1->decrRef();
630   // Reading
631   std::vector<std::pair<int,int> > its;
632   its.push_back(std::pair<int,int>(1,2));
633   its.push_back(std::pair<int,int>(3,4));
634   its.push_back(std::pair<int,int>(5,6));
635   std::vector<MEDCouplingFieldDouble *> fs=ReadFieldsOnSameMesh(ON_CELLS,fileName,f_1->getMesh()->getName().c_str(),0,f_1->getName().c_str(),its);
636   CPPUNIT_ASSERT_EQUAL(3,(int)fs.size());
637   const MEDCouplingMesh *mm=fs[0]->getMesh();
638   CPPUNIT_ASSERT(fs[0]->isEqual(f_1,1e-12,1e-12));
639   CPPUNIT_ASSERT(fs[1]->isEqual(f_2,1e-12,1e-12));
640   CPPUNIT_ASSERT(fs[2]->isEqual(f_3,1e-12,1e-12));
641   CPPUNIT_ASSERT(mm==fs[1]->getMesh());// <- important for the test
642   CPPUNIT_ASSERT(mm==fs[2]->getMesh());// <- important for the test
643   for(std::vector<MEDCouplingFieldDouble *>::iterator iter=fs.begin();iter!=fs.end();iter++)
644     (*iter)->decrRef();
645   //
646   f_1->decrRef();
647   f_2->decrRef();
648   f_3->decrRef();
649   //
650   m->decrRef();
651 }
652
653 void MEDLoaderTest::testWriteUMeshesRW1()
654 {
655   const char fileName[]="file18.med";
656   MEDCouplingUMesh *m3d=build3DMesh_2();
657   const double pt[3]={0.,0.,-0.3};
658   const double vec[3]={0.,0.,1.};
659   std::vector<mcIdType> nodes;
660   m3d->findNodesOnPlane(pt,vec,1e-12,nodes);
661   MEDCouplingUMesh *m2d=(MEDCouplingUMesh *)m3d->buildFacePartOfMySelfNode(&nodes[0],&nodes[0]+nodes.size(),true);
662   const mcIdType renumber[5]={1,2,0,4,3};
663   m2d->renumberCells(renumber,false);
664   m2d->setName("ExampleOfMultiDimW");
665   std::vector<const MEDCouplingUMesh *> meshes;
666   meshes.push_back(m2d);
667   meshes.push_back(m3d);
668   WriteUMeshes(fileName,meshes,true);
669   MEDCouplingUMesh *m3d_bis=ReadUMeshFromFile(fileName,m2d->getName().c_str(),0);
670   CPPUNIT_ASSERT(!m3d_bis->isEqual(m3d,1e-12));
671   m3d_bis->setName(m3d->getName().c_str());
672   CPPUNIT_ASSERT(m3d_bis->isEqual(m3d,1e-12));
673   MEDCouplingUMesh *m2d_bis=ReadUMeshFromFile(fileName,m2d->getName().c_str(),-1);//-1 for faces
674   CPPUNIT_ASSERT(m2d_bis->isEqual(m2d,1e-12));
675   // Creation of a field on faces.
676   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
677   f1->setName("FieldOnFacesShuffle");
678   f1->setMesh(m2d);
679   DataArrayDouble *array=DataArrayDouble::New();
680   array->alloc(m2d->getNumberOfCells(),2);
681   array->setInfoOnComponent(0,"plkj [mm]");
682   array->setInfoOnComponent(1,"pqqqss [mm]");
683   f1->setArray(array);
684   array->decrRef();
685   double *tmp=array->getPointer();
686   const double arr1[10]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.};
687   std::copy(arr1,arr1+10,tmp);
688   f1->setTime(3.14,2,7);
689   f1->checkConsistencyLight();
690   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
691   MEDCouplingFieldDouble *f2=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),-1,f1->getName().c_str(),2,7));
692   CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
693   f1->decrRef();
694   f2->decrRef();
695   //
696   m2d_bis->decrRef();
697   m3d_bis->decrRef();
698   m2d->decrRef();
699   m3d->decrRef();
700 }
701
702 void MEDLoaderTest::testMixCellAndNodesFieldRW1()
703 {
704   const char fileName[]="file21.med";
705   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
706   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
707   f1->setName("FieldMix");
708   f1->setMesh(mesh);
709   DataArrayDouble *array=DataArrayDouble::New();
710   array->alloc(6,2);
711   f1->setArray(array);
712   array->setInfoOnComponent(0,"plkj [mm]");
713   array->setInfoOnComponent(1,"pqqqss [mm]");
714   array->decrRef();
715   double *tmp=array->getPointer();
716   const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
717   std::copy(arr1,arr1+12,tmp);
718   f1->setTime(3.14,2,7);
719   f1->checkConsistencyLight();
720   //
721   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
722   f2->setName("FieldMix");
723   f2->setMesh(mesh);
724   array=DataArrayDouble::New();
725   array->alloc(12,2);
726   f2->setArray(array);
727   array->setInfoOnComponent(0,"plkj [mm]");
728   array->setInfoOnComponent(1,"pqqqss [mm]");
729   array->decrRef();
730   tmp=array->getPointer();
731   const double arr2[24]={
732     1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
733     1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
734   };
735   std::copy(arr2,arr2+24,tmp);
736   f2->setTime(3.14,2,7);
737   f2->checkConsistencyLight();
738   //
739   WriteField(fileName,f1,true);
740   std::vector<MEDCoupling::TypeOfField> ts=GetTypesOfField(fileName,f1->getMesh()->getName().c_str(),f1->getName().c_str());
741   CPPUNIT_ASSERT_EQUAL(1,(int)ts.size());
742   CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[0]);
743   std::vector<std::string> fs=GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName().c_str());
744   CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
745   CPPUNIT_ASSERT(fs[0]=="FieldMix");
746   WriteFieldUsingAlreadyWrittenMesh(fileName,f2);
747   fs=GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName().c_str());
748   CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
749   CPPUNIT_ASSERT(fs[0]=="FieldMix");
750   //
751   ts=GetTypesOfField(fileName,f1->getMesh()->getName().c_str(),f1->getName().c_str());
752   CPPUNIT_ASSERT_EQUAL(2,(int)ts.size());
753   CPPUNIT_ASSERT_EQUAL(ON_NODES,ts[0]);
754   CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[1]);
755   //
756   MEDCouplingFieldDouble *f3=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldNode(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,7));
757   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
758   f3->decrRef();
759   f3=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,7));
760   CPPUNIT_ASSERT(f3->isEqual(f1,1e-12,1e-12));
761   f3->decrRef();
762   //
763   f1->decrRef();
764   f2->decrRef();
765   mesh->decrRef();
766 }
767
768 void MEDLoaderTest::testGetAllFieldNamesRW1()
769 {
770   const char fileName[]="file22.med";
771   MEDCouplingUMesh *mesh=build2DMesh_2();
772   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
773   f1->setName("Field1");
774   f1->setTime(3.44,5,6);
775   f1->setMesh(mesh);
776   f1->fillFromAnalytic(2,"x+y");
777   WriteField(fileName,f1,true);
778   f1->setTime(1002.3,7,8);
779   f1->fillFromAnalytic(2,"x+77.*y");
780   WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
781   f1->setName("Field2");
782   WriteField(fileName,f1,false);
783   f1->setName("Field3");
784   mesh->setName("2DMesh_2Bis");
785   WriteField(fileName,f1,false);
786   f1->decrRef();
787   f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
788   f1->setName("Field8");
789   f1->setTime(8.99,7,9);
790   f1->setMesh(mesh);
791   f1->fillFromAnalytic(3,"3*x+y");
792   WriteField(fileName,f1,false);
793   f1->decrRef();
794   std::vector<std::string> fs=GetAllFieldNames(fileName);
795   CPPUNIT_ASSERT_EQUAL(4,(int)fs.size());
796   CPPUNIT_ASSERT(fs[0]=="Field1");
797   CPPUNIT_ASSERT(fs[1]=="Field2");
798   CPPUNIT_ASSERT(fs[2]=="Field3");
799   CPPUNIT_ASSERT(fs[3]=="Field8");
800   mesh->decrRef();
801 }
802
803
804 void MEDLoaderTest::testMEDLoaderRead1()
805 {
806   using namespace std;
807   using namespace INTERP_KERNEL;
808
809   string fileName= INTERP_TEST::getResourceFile("pointe.med", 3);
810   vector<string> meshNames=GetMeshNames(fileName.c_str());
811   CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
812   MEDCouplingUMesh *mesh=ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
813   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
814   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
815   CPPUNIT_ASSERT_EQUAL(16,(int)mesh->getNumberOfCells());
816   CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
817   CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllGeoTypes().size());
818   for(int i=0;i<12;i++)
819     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i));
820   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(12));
821   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(13));
822   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(14));
823   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(15));
824   CPPUNIT_ASSERT_EQUAL(ToIdType(90),mesh->getNodalConnectivity()->getNbOfElems());
825   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+90,0));
826   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+17,0));
827   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
828   mesh->decrRef();
829   //
830   vector<string> families=GetMeshFamiliesNames(fileName.c_str(),meshNames[0].c_str());
831   CPPUNIT_ASSERT_EQUAL(8,(int)families.size());
832   CPPUNIT_ASSERT(families[2]=="FAMILLE_ELEMENT_3");
833   //
834   vector<string> families2;
835   families2.push_back(families[2]);
836   mesh=ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),0,families2);
837   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
838   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
839   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getNumberOfCells());
840   CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
841   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
842   CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(0));
843   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(1));
844   CPPUNIT_ASSERT_EQUAL(ToIdType(11),mesh->getNodalConnectivity()->getNbOfElems());
845   CPPUNIT_ASSERT_EQUAL(132,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+11,0));
846   CPPUNIT_ASSERT_EQUAL(16,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+3,0));
847   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
848   mesh->decrRef();
849   //
850   vector<string> groups=GetMeshGroupsNames(fileName.c_str(),meshNames[0].c_str());
851   CPPUNIT_ASSERT_EQUAL(5,(int)groups.size());
852   CPPUNIT_ASSERT(groups[0]=="groupe1");
853   CPPUNIT_ASSERT(groups[1]=="groupe2");
854   CPPUNIT_ASSERT(groups[2]=="groupe3");
855   CPPUNIT_ASSERT(groups[3]=="groupe4");
856   CPPUNIT_ASSERT(groups[4]=="groupe5");
857   vector<string> groups2;
858   groups2.push_back(groups[0]);
859   mesh=ReadUMeshFromGroups(fileName.c_str(),meshNames[0].c_str(),0,groups2);
860   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
861   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
862   CPPUNIT_ASSERT_EQUAL(7,(int)mesh->getNumberOfCells());
863   CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
864   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
865   for(int i=0;i<6;i++)
866     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i));
867   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(6));
868   CPPUNIT_ASSERT_EQUAL(ToIdType(36),mesh->getNodalConnectivity()->getNbOfElems());
869   CPPUNIT_ASSERT_EQUAL(254,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+36,0));
870   CPPUNIT_ASSERT_EQUAL(141,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+8,0));
871   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
872   mesh->decrRef();
873   //
874   std::vector<std::string> fieldsName=GetCellFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
875   CPPUNIT_ASSERT_EQUAL(2,(int)fieldsName.size());
876   CPPUNIT_ASSERT(fieldsName[0]=="fieldcelldoublescalar");
877   CPPUNIT_ASSERT(fieldsName[1]=="fieldcelldoublevector");
878   std::vector<std::pair<int,int> > its0=GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[0].c_str());
879   CPPUNIT_ASSERT_EQUAL(1,(int)its0.size());
880   CPPUNIT_ASSERT_EQUAL(-1,its0[0].first);
881   CPPUNIT_ASSERT_EQUAL(-1,its0[0].second);
882   std::vector<std::pair<int,int> > its1=GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[1].c_str());
883   CPPUNIT_ASSERT_EQUAL(1,(int)its1.size());
884   CPPUNIT_ASSERT_EQUAL(-1,its1[0].first);
885   CPPUNIT_ASSERT_EQUAL(-1,its1[0].second);
886   //
887   MEDCouplingFieldDouble *field0=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[0].c_str(),its0[0].first,its0[0].second));
888   field0->checkConsistencyLight();
889   CPPUNIT_ASSERT(field0->getName()==fieldsName[0]);
890  CPPUNIT_ASSERT_EQUAL(1,(int)field0->getNumberOfComponents());
891  CPPUNIT_ASSERT_EQUAL(16,(int)field0->getNumberOfTuples());
892   const double expectedValues[16]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,2.,3.,3.,2.};
893   double diffValue[16];
894   std::transform(field0->getArray()->getPointer(),field0->getArray()->getPointer()+16,expectedValues,diffValue,std::minus<double>());
895   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue,diffValue+16),1e-12);
896   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue,diffValue+16),1e-12);
897   const MEDCouplingUMesh *constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0->getMesh());
898   CPPUNIT_ASSERT(constMesh);
899   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
900   CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
901   CPPUNIT_ASSERT_EQUAL(16,(int)constMesh->getNumberOfCells());
902   CPPUNIT_ASSERT_EQUAL(ToIdType(19),constMesh->getNumberOfNodes());
903   CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
904   for(int i=0;i<12;i++)
905     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
906   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
907   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
908   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
909   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
910   CPPUNIT_ASSERT_EQUAL(ToIdType(90),constMesh->getNodalConnectivity()->getNbOfElems());
911   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
912   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
913   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
914   field0->decrRef();
915   //
916   MEDCouplingFieldDouble *field1=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[1].c_str(),its1[0].first,its1[0].second));
917   field1->checkConsistencyLight();
918   CPPUNIT_ASSERT(field1->getName()==fieldsName[1]);
919   CPPUNIT_ASSERT_EQUAL(3,(int)field1->getNumberOfComponents());
920   CPPUNIT_ASSERT_EQUAL(16,(int)field1->getNumberOfTuples());
921   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.};
922   double diffValue2[48];
923   std::transform(field1->getArray()->getPointer(),field1->getArray()->getPointer()+48,expectedValues2,diffValue2,std::minus<double>());
924   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue2,diffValue2+48),1e-12);
925   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue2,diffValue2+48),1e-12);
926   constMesh=dynamic_cast<const MEDCouplingUMesh *>(field1->getMesh());
927   CPPUNIT_ASSERT(constMesh);
928   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
929   CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
930   CPPUNIT_ASSERT_EQUAL(16,(int)constMesh->getNumberOfCells());
931   CPPUNIT_ASSERT_EQUAL(ToIdType(19),constMesh->getNumberOfNodes());
932   CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
933   for(int i=0;i<12;i++)
934     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
935   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
936   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
937   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
938   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
939   CPPUNIT_ASSERT_EQUAL(ToIdType(90),constMesh->getNodalConnectivity()->getNbOfElems());
940   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
941   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
942   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
943   field1->decrRef();
944   //fields on nodes
945   std::vector<std::string> fieldsNameNode=GetNodeFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
946   CPPUNIT_ASSERT_EQUAL(2,(int)fieldsNameNode.size());
947   CPPUNIT_ASSERT(fieldsNameNode[0]=="fieldnodedouble");
948   CPPUNIT_ASSERT(fieldsNameNode[1]=="fieldnodeint");
949   std::vector<std::pair<int,int> > its0Node=GetNodeFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsNameNode[0].c_str());
950   CPPUNIT_ASSERT_EQUAL(3,(int)its0Node.size());
951   CPPUNIT_ASSERT_EQUAL(-1,its0Node[0].first);
952   CPPUNIT_ASSERT_EQUAL(-1,its0Node[0].second);
953   CPPUNIT_ASSERT_EQUAL(1,its0Node[1].first);
954   CPPUNIT_ASSERT_EQUAL(-1,its0Node[1].second);
955   CPPUNIT_ASSERT_EQUAL(2,its0Node[2].first);
956   CPPUNIT_ASSERT_EQUAL(-1,its0Node[2].second);
957   MEDCouplingFieldDouble *field0Nodes=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[0].first,its0Node[0].second));
958   field0Nodes->checkConsistencyLight();
959   CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
960  CPPUNIT_ASSERT_EQUAL(1,(int)field0Nodes->getNumberOfComponents());
961  CPPUNIT_ASSERT_EQUAL(19,(int)field0Nodes->getNumberOfTuples());
962   const double expectedValues3[19]={1.,1.,1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.};
963   double diffValue3[19];
964   std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues3,diffValue3,std::minus<double>());
965   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
966   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
967   constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
968   CPPUNIT_ASSERT(constMesh);
969   field0Nodes->decrRef();
970   //
971   field0Nodes=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[2].first,its0Node[2].second));
972   field0Nodes->checkConsistencyLight();
973   CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
974  CPPUNIT_ASSERT_EQUAL(1,(int)field0Nodes->getNumberOfComponents());
975  CPPUNIT_ASSERT_EQUAL(19,(int)field0Nodes->getNumberOfTuples());
976   const double expectedValues4[19]={1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.,7.,7.};
977   std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues4,diffValue3,std::minus<double>());
978   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
979   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
980   constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
981   CPPUNIT_ASSERT(constMesh);
982   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
983   CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
984   CPPUNIT_ASSERT_EQUAL(16,(int)constMesh->getNumberOfCells());
985   CPPUNIT_ASSERT_EQUAL(ToIdType(19),constMesh->getNumberOfNodes());
986   CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
987   for(int i=0;i<12;i++)
988     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
989   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
990   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
991   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
992   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
993   CPPUNIT_ASSERT_EQUAL(ToIdType(90),constMesh->getNodalConnectivity()->getNbOfElems());
994   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
995   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
996   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
997   field0Nodes->decrRef();
998   //
999   field0Nodes=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[0].first,its0Node[0].second));
1000   field0Nodes->checkConsistencyLight();
1001   CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
1002  CPPUNIT_ASSERT_EQUAL(1,(int)field0Nodes->getNumberOfComponents());
1003  CPPUNIT_ASSERT_EQUAL(19,(int)field0Nodes->getNumberOfTuples());
1004   const double expectedValues5[19]={1.,1.,1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.};
1005   std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues5,diffValue3,std::minus<double>());
1006   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
1007   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
1008   constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
1009   CPPUNIT_ASSERT(constMesh);
1010   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
1011   CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
1012   CPPUNIT_ASSERT_EQUAL(16,(int)constMesh->getNumberOfCells());
1013   CPPUNIT_ASSERT_EQUAL(ToIdType(19),constMesh->getNumberOfNodes());
1014   CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
1015   for(int i=0;i<12;i++)
1016     CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
1017   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
1018   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
1019   CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
1020   CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
1021   CPPUNIT_ASSERT_EQUAL(ToIdType(90),constMesh->getNodalConnectivity()->getNbOfElems());
1022   CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
1023   CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
1024   CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
1025   field0Nodes->decrRef();
1026 }
1027
1028 void MEDLoaderTest::testMEDLoaderPolygonRead()
1029 {
1030   using namespace std;
1031   using namespace INTERP_KERNEL;
1032
1033   string fileName=INTERP_TEST::getResourceFile("polygones.med", 3);
1034   vector<string> meshNames=GetMeshNames(fileName.c_str());
1035   CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
1036   CPPUNIT_ASSERT(meshNames[0]=="Bord");
1037   MEDCouplingUMesh *mesh=ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
1038   mesh->checkConsistencyLight();
1039   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1040   CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
1041   CPPUNIT_ASSERT_EQUAL(538,(int)mesh->getNumberOfCells());
1042   CPPUNIT_ASSERT_EQUAL(ToIdType(579),mesh->getNumberOfNodes());
1043   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
1044   for(int i=0;i<514;i++)
1045     CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(i));
1046   for(int i=514;i<538;i++)
1047     CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(i));
1048   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+1737,0),1e-12);
1049   const double expectedVals1[12]={1.4851585216522212,-0.5,0.,1.4851585216522212,-0.4,0.,1.4851585216522212,-0.3,0., 1.5741585216522211, -0.5, 0. };
1050   double diffValue1[12];
1051   std::transform(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+12,expectedVals1,diffValue1,std::minus<double>());
1052   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue1,diffValue1+12),1e-12);
1053   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue1,diffValue1+12),1e-12);
1054   CPPUNIT_ASSERT_EQUAL(ToIdType(2768),mesh->getNodalConnectivity()->getNbOfElems());
1055   CPPUNIT_ASSERT_EQUAL(651050,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+2768,0));
1056   CPPUNIT_ASSERT_EQUAL(725943,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+539,0));
1057   mesh->decrRef();
1058   //
1059   std::vector<std::string> fieldsName=GetCellFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
1060   CPPUNIT_ASSERT_EQUAL(3,(int)fieldsName.size());
1061   CPPUNIT_ASSERT(fieldsName[0]=="bord_:_distorsion");
1062   CPPUNIT_ASSERT(fieldsName[1]=="bord_:_familles");
1063   CPPUNIT_ASSERT(fieldsName[2]=="bord_:_non-ortho");
1064   std::vector<std::pair<int,int> > its0=GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[0].c_str());
1065   CPPUNIT_ASSERT_EQUAL(1,(int)its0.size());
1066   MEDCouplingFieldDouble *field=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[0].c_str(),its0[0].first,its0[0].second));
1067   field->checkConsistencyLight();
1068   CPPUNIT_ASSERT(field->getName()==fieldsName[0]);
1069  CPPUNIT_ASSERT_EQUAL(1,(int)field->getNumberOfComponents());
1070  CPPUNIT_ASSERT_EQUAL(538,(int)field->getNumberOfTuples());
1071   const MEDCouplingUMesh *constMesh=dynamic_cast<const MEDCouplingUMesh *>(field->getMesh());
1072   CPPUNIT_ASSERT(constMesh);
1073   CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
1074   CPPUNIT_ASSERT_EQUAL(2,constMesh->getMeshDimension());
1075   CPPUNIT_ASSERT_EQUAL(538,(int)constMesh->getNumberOfCells());
1076   CPPUNIT_ASSERT_EQUAL(ToIdType(579),constMesh->getNumberOfNodes());
1077   CPPUNIT_ASSERT_EQUAL(2,(int)constMesh->getAllGeoTypes().size());
1078   for(int i=0;i<514;i++)
1079     CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,constMesh->getTypeOfCell(i));
1080   for(int i=514;i<538;i++)
1081     CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,constMesh->getTypeOfCell(i));
1082   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+1737,0),1e-12);
1083   std::transform(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+12,expectedVals1,diffValue1,std::minus<double>());
1084   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue1,diffValue1+12),1e-12);
1085   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue1,diffValue1+12),1e-12);
1086   CPPUNIT_ASSERT_EQUAL(ToIdType(2768),constMesh->getNodalConnectivity()->getNbOfElems());
1087   CPPUNIT_ASSERT_EQUAL(651050,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+2768,0));
1088   CPPUNIT_ASSERT_EQUAL(725943,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+539,0));
1089   const double *values=field->getArray()->getPointer();
1090   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.87214203182918,std::accumulate(values,values+538,0.),1e-12);
1091   field->decrRef();
1092 }
1093
1094 void MEDLoaderTest::testMEDLoaderPolyhedronRead()
1095 {
1096   using namespace std;
1097   using namespace INTERP_KERNEL;
1098
1099   string fileName=INTERP_TEST::getResourceFile("poly3D.med", 3);
1100   vector<string> meshNames=GetMeshNames(fileName.c_str());
1101   CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
1102   CPPUNIT_ASSERT(meshNames[0]=="poly3D");
1103   MEDCouplingUMesh *mesh=ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
1104   mesh->checkConsistencyLight();
1105   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1106   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
1107   CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getNumberOfCells());
1108   CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
1109   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
1110   CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(0));
1111   CPPUNIT_ASSERT_EQUAL(NORM_POLYHED,mesh->getTypeOfCell(1));
1112   CPPUNIT_ASSERT_EQUAL(NORM_POLYHED,mesh->getTypeOfCell(2));
1113   CPPUNIT_ASSERT_EQUAL(ToIdType(98),mesh->getNodalConnectivity()->getNbOfElems());
1114   CPPUNIT_ASSERT_EQUAL(725,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+98,0));
1115   CPPUNIT_ASSERT_DOUBLES_EQUAL(110.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
1116   CPPUNIT_ASSERT_EQUAL(155,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+4,0));
1117   mesh->decrRef();
1118   //
1119   mesh=ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),-1);
1120   mesh->checkConsistencyLight();
1121   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1122   CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
1123   CPPUNIT_ASSERT_EQUAL(17,(int)mesh->getNumberOfCells());
1124   CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
1125   CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllGeoTypes().size());
1126   CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(0));
1127   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(1));
1128   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(2));
1129   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(3));
1130   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(4));
1131   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(5));
1132   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(6));
1133   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(7));
1134   CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(8));
1135   CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(9));
1136   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(10));
1137   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(11));
1138   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(12));
1139   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(13));
1140   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(14));
1141   CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(15));
1142   CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(16));
1143   CPPUNIT_ASSERT_DOUBLES_EQUAL(110.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
1144   CPPUNIT_ASSERT_EQUAL(ToIdType(83),mesh->getNodalConnectivity()->getNbOfElems());
1145   CPPUNIT_ASSERT_EQUAL(619,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+83,0));
1146   mesh->decrRef();
1147   //
1148   vector<string> families=GetMeshFamiliesNames(fileName.c_str(),meshNames[0].c_str());
1149   CPPUNIT_ASSERT_EQUAL(4,(int)families.size());
1150   CPPUNIT_ASSERT(families[0]=="FAMILLE_FACE_POLYGONS3");
1151   CPPUNIT_ASSERT(families[1]=="FAMILLE_FACE_QUAD41");
1152   CPPUNIT_ASSERT(families[2]=="FAMILLE_FACE_TRIA32");
1153   CPPUNIT_ASSERT(families[3]=="FAMILLE_ZERO");
1154   vector<string> families2;
1155   families2.push_back(families[0]);
1156   mesh=ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),-1,families2);
1157   mesh->checkConsistencyLight();
1158   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1159   CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
1160   CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getNumberOfCells());
1161   CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
1162   CPPUNIT_ASSERT_EQUAL(1,(int)mesh->getAllGeoTypes().size());
1163   for(int i=0;i<3;i++)
1164     CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(i));
1165   CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNodalConnectivity()->getNbOfElems());
1166   CPPUNIT_ASSERT_EQUAL(117,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+19,0));
1167   mesh->decrRef();
1168   //
1169   mesh=ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),0,families2);
1170   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1171   CPPUNIT_ASSERT_EQUAL(0,(int)mesh->getNumberOfCells());
1172   CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
1173   CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
1174   CPPUNIT_ASSERT_EQUAL(0,(int)mesh->getAllGeoTypes().size());
1175   mesh->decrRef();
1176 }
1177
1178 MEDCouplingUMesh *MEDLoaderTest::build1DMesh_1()
1179 {
1180   double coords[6]={ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 };
1181   mcIdType conn[9]={ 0,1, 1,2, 2,3 , 3,4,5};
1182   MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
1183   mesh->setName("1DMesh_1");
1184   mesh->setMeshDimension(1);
1185   mesh->allocateCells(4);
1186   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
1187   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
1188   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
1189   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6);
1190   mesh->finishInsertingCells();
1191   DataArrayDouble *myCoords=DataArrayDouble::New();
1192   myCoords->alloc(6,1);
1193   myCoords->setInfoOnComponent(0,"tototototototot [m*m*m*m*m*m*m*m]");
1194   std::copy(coords,coords+6,myCoords->getPointer());
1195   mesh->setCoords(myCoords);
1196   myCoords->decrRef();
1197   return mesh;
1198 }
1199
1200 MEDCouplingUMesh *MEDLoaderTest::build2DCurveMesh_1()
1201 {
1202   double coords[12]={ 0.0,0.0, 0.3,0.3, 0.75,0.75, 1.0,1.0, 1.4,1.4, 1.3,1.3 };
1203   mcIdType conn[9]={ 0,1, 1,2, 2,3 , 3,4,5};
1204   MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
1205   mesh->setName("2DCurveMesh_1");
1206   mesh->setMeshDimension(1);
1207   mesh->allocateCells(4);
1208   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
1209   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
1210   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
1211   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6);
1212   mesh->finishInsertingCells();
1213   DataArrayDouble *myCoords=DataArrayDouble::New();
1214   myCoords->alloc(6,2);
1215   std::copy(coords,coords+12,myCoords->getPointer());
1216   mesh->setCoords(myCoords);
1217   myCoords->decrRef();
1218   return mesh;
1219 }
1220
1221 MEDCouplingUMesh *MEDLoaderTest::build2DMesh_1()
1222 {
1223   double targetCoords[24]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7, -0.05,0.95, 0.2,1.2, 0.45,0.95 };
1224   mcIdType targetConn[24]={1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4};
1225   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
1226   targetMesh->setMeshDimension(2);
1227   targetMesh->allocateCells(6);
1228   targetMesh->setName("2DMesh_1");
1229   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
1230   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
1231   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
1232   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
1233   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
1234   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POLYGON,4,targetConn+20);
1235   targetMesh->finishInsertingCells();
1236   DataArrayDouble *myCoords=DataArrayDouble::New();
1237   myCoords->alloc(12,2);
1238   myCoords->setInfoOnComponent(0,"tototototototot [m]");
1239   myCoords->setInfoOnComponent(1,"energie [kW]");
1240   std::copy(targetCoords,targetCoords+24,myCoords->getPointer());
1241   targetMesh->setCoords(myCoords);
1242   myCoords->decrRef();
1243   return targetMesh;
1244 }
1245
1246 MEDCouplingUMesh *MEDLoaderTest::build2DMesh_2()
1247 {
1248   double targetCoords[24]={
1249     -0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7,
1250     -0.05,0.95, 0.2,1.2, 0.45,0.95
1251   };
1252   mcIdType targetConn[24]={1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4};
1253   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
1254   targetMesh->setMeshDimension(2);
1255   targetMesh->allocateCells(5);
1256   targetMesh->setName("2DMesh_2");
1257   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
1258   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
1259   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
1260   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
1261   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
1262   targetMesh->finishInsertingCells();
1263   DataArrayDouble *myCoords=DataArrayDouble::New();
1264   myCoords->alloc(12,2);
1265   myCoords->setInfoOnComponent(0,"toto [m]");
1266   myCoords->setInfoOnComponent(1,"energie [kW]");
1267   std::copy(targetCoords,targetCoords+24,myCoords->getPointer());
1268   targetMesh->setCoords(myCoords);
1269   myCoords->decrRef();
1270   return targetMesh;
1271 }
1272
1273 MEDCouplingUMesh *MEDLoaderTest::build3DSurfMesh_1()
1274 {
1275   double targetCoords[36]={
1276     -0.3,-0.3,-0.3, 0.2,-0.3,-0.3, 0.7,-0.3,-0.3, -0.3,0.2,-0.3, 0.2,0.2,-0.3, 0.7,0.2,-0.3, -0.3,0.7,-0.3, 0.2,0.7,-0.3, 0.7,0.7,-0.3
1277     ,-0.05,0.95,-0.3, 0.2,1.2,-0.3, 0.45,0.95,-0.3
1278   };
1279   mcIdType targetConn[24]={1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4};
1280   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
1281   targetMesh->setMeshDimension(2);
1282   targetMesh->allocateCells(6);
1283   targetMesh->setName("3DSurfMesh_1");
1284   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
1285   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
1286   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
1287   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
1288   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
1289   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POLYGON,4,targetConn+20);
1290   targetMesh->finishInsertingCells();
1291   DataArrayDouble *myCoords=DataArrayDouble::New();
1292   myCoords->alloc(12,3);
1293   myCoords->setInfoOnComponent(0,"toto [m]");
1294   myCoords->setInfoOnComponent(2,"ff [km]");//component 1 is not set for test
1295   std::copy(targetCoords,targetCoords+36,myCoords->getPointer());
1296   targetMesh->setCoords(myCoords);
1297   myCoords->decrRef();
1298   return targetMesh;
1299 }
1300
1301 MEDCouplingUMesh *MEDLoaderTest::build3DMesh_1()
1302 {
1303   double coords[180]={
1304     0.,0.,0., 1.,1.,0., 1.,1.25,0., 0.,1.,0., 1.,1.5,0., 2.,0.,0., 2.,1.,0., 1.,2.,0., 0.,2.,0., 3.,1.,0.,
1305     3.,2.,0., 0.,1.,0., 1.,3.,0., 2.,2.,0., 2.,3.,0.,
1306     0.,0.,1., 1.,1.,1., 1.,1.25,1., 0.,1.,1., 1.,1.5,1., 2.,0.,1., 2.,1.,1., 1.,2.,1., 0.,2.,1., 3.,1.,1.,
1307     3.,2.,1., 0.,1.,1., 1.,3.,1., 2.,2.,1., 2.,3.,1.,
1308     0.,0.,2., 1.,1.,2., 1.,1.25,2., 0.,1.,2., 1.,1.5,2., 2.,0.,2., 2.,1.,2., 1.,2.,2., 0.,2.,2., 3.,1.,2.,
1309     3.,2.,2., 0.,1.,2., 1.,3.,2., 2.,2.,2., 2.,3.,2.,
1310     0.,0.,3., 1.,1.,3., 1.,1.25,3., 0.,1.,3., 1.,1.5,3., 2.,0.,3., 2.,1.,3., 1.,2.,3., 0.,2.,3., 3.,1.,3.,
1311     3.,2.,3., 0.,1.,3., 1.,3.,3., 2.,2.,3., 2.,3.,3.};
1312
1313   mcIdType conn[354]={
1314     // 0
1315     0,11,1,3,15,26,16,18,   1,2,4,7,13,6,-1,1,16,21,6,-1,6,21,28,13,-1,13,7,22,28,-1,7,4,19,22,-1,4,2,17,19,-1,2,1,16,17,-1,16,21,28,22,19,17,
1316     1,6,5,3,16,21,20,18,   13,10,9,6,28,25,24,21,
1317     11,8,7,4,2,1,-1,11,26,16,1,-1,1,16,17,2,-1,2,17,19,4,-1,4,19,22,7,-1,7,8,23,22,-1,8,11,26,23,-1,26,16,17,19,22,23,
1318     7,12,14,13,22,27,29,28,
1319     // 1
1320     15,26,16,18,30,41,31,33,   16,17,19,22,28,21,-1,16,31,36,21,-1,21,36,43,28,-1,28,22,37,43,-1,22,19,34,37,-1,19,17,32,34,-1,17,16,31,32,-1,31,36,43,37,34,32,
1321     16,21,20,18,31,36,35,33,   28,25,24,21,43,40,39,36,
1322     26,23,22,19,17,16,-1,26,41,31,16,-1,16,31,32,17,-1,17,32,34,19,-1,19,34,37,22,-1,22,23,38,37,-1,23,26,41,38,-1,41,31,32,34,37,38,
1323     22,27,29,28,37,42,44,43,
1324     // 2
1325     30,41,31,33,45,56,46,48,  31,32,34,37,43,36,-1,31,46,51,36,-1,36,51,58,43,-1,43,37,52,58,-1,37,34,49,52,-1,34,32,47,49,-1,32,31,46,47,-1,46,51,58,52,49,47,
1326     31,36,35,33,46,51,50,48,  43,40,39,36,58,55,54,51,
1327     41,38,37,34,32,31,-1,41,56,46,31,-1,31,46,47,32,-1,32,47,49,34,-1,34,49,52,37,-1,37,38,53,52,-1,38,41,56,53,-1,56,46,47,49,52,53,
1328     37,42,44,43,52,57,59,58
1329   };
1330   //
1331   MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
1332   ret->setName("3DMesh_1");
1333   ret->setMeshDimension(3);
1334   ret->allocateCells(18);
1335   //
1336   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
1337   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+51);
1338   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+59);
1339   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+110);
1340   //
1341   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+118);
1342   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+169);
1343   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+177);
1344   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+228);
1345   //
1346   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+236);
1347   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+287);
1348   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+295);
1349   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+346);
1350   //
1351   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+8);
1352   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+67);
1353   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+126);
1354   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+185);
1355   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+244);
1356   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+303);
1357   //
1358   ret->finishInsertingCells();
1359   DataArrayDouble *myCoords=DataArrayDouble::New();
1360   myCoords->alloc(60,3);
1361   myCoords->setInfoOnComponent(0,"titi [m]");
1362   myCoords->setInfoOnComponent(1,"density power [MW/m^3]");
1363   myCoords->setInfoOnComponent(2,"t [kW]");
1364   std::copy(coords,coords+180,myCoords->getPointer());
1365   ret->setCoords(myCoords);
1366   myCoords->decrRef();
1367   return ret;
1368 }
1369
1370 MEDCouplingUMesh *MEDLoaderTest::build3DMesh_2()
1371 {
1372   MEDCouplingUMesh *m3dsurfBase=build3DSurfMesh_1();
1373   mcIdType numbers[5]={0,1,2,3,5};
1374   MEDCouplingUMesh *m3dsurf=(MEDCouplingUMesh *)m3dsurfBase->buildPartOfMySelf(numbers,numbers+5,false);
1375   m3dsurfBase->decrRef();
1376   MEDCouplingUMesh *m1dBase=build1DMesh_1();
1377   mcIdType numbers2[4]={0,1,2,3};
1378   MEDCouplingUMesh *m1d=(MEDCouplingUMesh *)m1dBase->buildPartOfMySelf(numbers2,numbers2+4,false);
1379   m1dBase->decrRef();
1380   m1d->changeSpaceDimension(3);
1381   const double vec[3]={0.,1.,0.};
1382   const double pt[3]={0.,0.,0.};
1383   m1d->rotate(pt,vec,-M_PI/2.);
1384   MEDCouplingUMesh *ret=m3dsurf->buildExtrudedMesh(m1d,0);
1385   m1d->decrRef();
1386   m3dsurf->decrRef();
1387   return ret;
1388 }
1389
1390 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnCells_1()
1391 {
1392   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1393   mcIdType nbOfCells=mesh->getNumberOfCells();
1394   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1395   f1->setName("VectorFieldOnCells");
1396   f1->setMesh(mesh);
1397   DataArrayDouble *array=DataArrayDouble::New();
1398   array->alloc(nbOfCells,3);
1399   array->setInfoOnComponent(0,"power [MW/m^3]");
1400   array->setInfoOnComponent(1,"density [g/cm^3]");
1401   array->setInfoOnComponent(2,"temperature [K]");
1402   f1->setArray(array);
1403   array->decrRef();
1404   double *tmp=array->getPointer();
1405   const double arr1[18]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.};
1406   std::copy(arr1,arr1+18,tmp);
1407   f1->setTime(2.,0,1);
1408   f1->checkConsistencyLight();
1409   mesh->decrRef();
1410   return f1;
1411 }
1412
1413 MEDCouplingFieldInt *MEDLoaderTest::buildIntVecFieldOnCells_1()
1414 {
1415   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1416   mcIdType nbOfCells=mesh->getNumberOfCells();
1417   MEDCouplingFieldInt *f1=MEDCouplingFieldInt::New(ON_CELLS,ONE_TIME);
1418   f1->setName("IntVectorFieldOnCells");
1419   f1->setMesh(mesh);
1420   DataArrayInt32 *array=DataArrayInt32::New();
1421   array->alloc(nbOfCells,3);
1422   array->setInfoOnComponent(0,"val1 [MW/m^3]");
1423   array->setInfoOnComponent(1,"va2 [g/cm^3]");
1424   array->setInfoOnComponent(2,"val3 [K]");
1425   f1->setArray(array);
1426   array->decrRef();
1427   int *tmp=array->getPointer();
1428   const int arr1[18]={0,10,20,1,11,21,2,12,22,3,13,23,4,14,24,5,15,25};
1429   std::copy(arr1,arr1+18,tmp);
1430   f1->setTime(2.,0,1);
1431   f1->checkConsistencyLight();
1432   mesh->decrRef();
1433   return f1;
1434 }
1435
1436 MEDCouplingFieldInt64 *MEDLoaderTest::buildInt64VecFieldOnCells_1()
1437 {
1438   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1439   mcIdType nbOfCells=mesh->getNumberOfCells();
1440   MEDCouplingFieldInt64 *f1=MEDCouplingFieldInt64::New(ON_CELLS,ONE_TIME);
1441   f1->setName("Int64VectorFieldOnCells");
1442   f1->setMesh(mesh);
1443   DataArrayInt64 *array=DataArrayInt64::New();
1444   array->alloc(nbOfCells,3);
1445   array->setInfoOnComponent(0,"val1 [MW/m^3]");
1446   array->setInfoOnComponent(1,"va2 [g/cm^3]");
1447   array->setInfoOnComponent(2,"val3 [K]");
1448   f1->setArray(array);
1449   array->decrRef();
1450   int64_t *tmp=array->getPointer();
1451   const int64_t arr1[18]={0,10,20,1,11,21,2,12,22,3,13,23,4,14,24,5,15,25};
1452   std::copy(arr1,arr1+18,tmp);
1453   f1->setTime(2.,0,1);
1454   f1->checkConsistencyLight();
1455   mesh->decrRef();
1456   return f1;
1457 }
1458
1459 MEDCouplingFieldFloat *MEDLoaderTest::buildFloatVecFieldOnCells_1()
1460 {
1461   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1462   mcIdType nbOfCells=mesh->getNumberOfCells();
1463   MEDCouplingFieldFloat *f1=MEDCouplingFieldFloat::New(ON_CELLS,ONE_TIME);
1464   f1->setName("FloatVectorFieldOnCells");
1465   f1->setMesh(mesh);
1466   DataArrayFloat *array=DataArrayFloat::New();
1467   array->alloc(nbOfCells,3);
1468   array->setInfoOnComponent(0,"power [MW/m^3]");
1469   array->setInfoOnComponent(1,"density [g/cm^3]");
1470   array->setInfoOnComponent(2,"temperature [K]");
1471   f1->setArray(array);
1472   array->decrRef();
1473   float *tmp=array->getPointer();
1474   const float arr1[18]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.};
1475   std::copy(arr1,arr1+18,tmp);
1476   f1->setTime(2.,0,1);
1477   f1->checkConsistencyLight();
1478   mesh->decrRef();
1479   return f1;
1480 }
1481
1482
1483 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnNodes_1()
1484 {
1485   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1486   mcIdType nbOfNodes=mesh->getNumberOfNodes();
1487   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
1488   f1->setName("VectorFieldOnNodes");
1489   f1->setMesh(mesh);
1490   DataArrayDouble *array=DataArrayDouble::New();
1491   array->alloc(nbOfNodes,3);
1492   f1->setArray(array);
1493   array->setInfoOnComponent(0,"power [MW/m^3]");
1494   array->setInfoOnComponent(1,"density [g/cm^3]");
1495   array->setInfoOnComponent(2,"temperature [K]");
1496   array->decrRef();
1497   double *tmp=array->getPointer();
1498   const double arr1[36]={
1499     70.,80.,90.,71.,81.,91.,72.,82.,92.,73.,83.,93.,74.,84.,94.,75.,85.,95.,
1500     1000.,10010.,10020.,1001.,10011.,10021.,1002.,10012.,10022.,1003.,10013.,10023.,1004.,10014.,10024.,1005.,10015.,10025.,
1501   };
1502   std::copy(arr1,arr1+36,tmp);
1503   f1->setTime(2.12,2,3);
1504   f1->checkConsistencyLight();
1505   mesh->decrRef();
1506   return f1;
1507 }
1508
1509 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGauss_1()
1510 {
1511   const double _a=0.446948490915965;
1512   const double _b=0.091576213509771;
1513   const double _p1=0.11169079483905;
1514   const double _p2=0.0549758718227661;
1515   const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
1516   const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
1517                             2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
1518   const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
1519   std::vector<double> _refCoo1(refCoo1,refCoo1+6);
1520   std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
1521   std::vector<double> _wg1(wg1,wg1+6);
1522   MEDCouplingUMesh *m=build2DMesh_2();
1523   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,ONE_TIME);
1524   f->setTime(3.14,1,5);
1525   f->setMesh(m);
1526   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
1527   const double refCoo2[12]={-1.0,1.0, -1.0,-1.0, 1.0,-1.0, -1.0,0.0, 0.0,-1.0, 0.0,0.0 };
1528   std::vector<double> _refCoo2(refCoo2,refCoo2+12);
1529   std::vector<double> _gsCoo2(_gsCoo1);
1530   std::vector<double> _wg2(_wg1);
1531   _gsCoo2.resize(6); _wg2.resize(3);
1532   const double refCoo3[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
1533   std::vector<double> _refCoo3(refCoo3,refCoo3+8);
1534   _gsCoo1.resize(4); _wg1.resize(2);
1535   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo3,_gsCoo1,_wg1);
1536   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI6,_refCoo2,_gsCoo2,_wg2);
1537   DataArrayDouble *array=DataArrayDouble::New();
1538   array->alloc(19,2);
1539   double *ptr=array->getPointer();
1540   for(int i=0;i<19*2;i++)
1541     ptr[i]=(double)(i+7);
1542   f->setArray(array);
1543   f->setName("MyFirstFieldOnGaussPoint");
1544   array->setInfoOnComponent(0,"power [MW/m^3]");
1545   array->setInfoOnComponent(1,"density");
1546   array->decrRef();
1547   f->checkConsistencyLight();
1548   m->decrRef();
1549   return f;
1550 }
1551
1552 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGaussNE_1()
1553 {
1554   MEDCouplingUMesh *m=build2DMesh_2();
1555   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,ONE_TIME);
1556   f->setTime(3.14,1,5);
1557   f->setMesh(m);
1558   DataArrayDouble *array=DataArrayDouble::New();
1559   array->alloc(20,2);
1560   double *ptr=array->getPointer();
1561   for(int i=0;i<20*2;i++)
1562     ptr[i]=(double)(i+8);
1563   f->setArray(array);
1564   array->setInfoOnComponent(0,"power [W]");
1565   array->setInfoOnComponent(1,"temperature");
1566   f->setName("MyFieldOnGaussNE");
1567   array->decrRef();
1568   f->checkConsistencyLight();
1569   m->decrRef();
1570   return f;
1571 }
1572
1573
1574