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