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