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