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