Salome HOME
Merge from V6_main (04/10/2012)
[modules/med.git] / src / MEDLoader / Test / MEDLoaderTest.cxx
1 // Copyright (C) 2007-2012  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.
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
30 using namespace ParaMEDMEM;
31
32 void MEDLoaderTest::testMesh1DRW()
33 {
34   MEDCouplingUMesh *mesh=build1DMesh_1();
35   mesh->checkCoherency();
36   MEDLoader::WriteUMesh("file1.med",mesh,true);
37   MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file1.med",mesh->getName(),0);
38   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
39   mesh_rw->decrRef();
40   mesh->decrRef();
41 }
42
43 void MEDLoaderTest::testMesh2DCurveRW()
44 {
45   MEDCouplingUMesh *mesh=build2DCurveMesh_1();
46   mesh->checkCoherency();
47   MEDLoader::WriteUMesh("file2.med",mesh,true);
48   MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file2.med",mesh->getName(),0);
49   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
50   mesh_rw->decrRef();
51   mesh->decrRef();
52 }
53
54 void MEDLoaderTest::testMesh2DRW()
55 {
56   MEDCouplingUMesh *mesh=build2DMesh_1();
57   mesh->checkCoherency();
58   MEDLoader::WriteUMesh("file3.med",mesh,true);
59   MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file3.med",mesh->getName(),0);
60   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
61   mesh_rw->decrRef();
62   mesh->decrRef();
63 }
64
65 void MEDLoaderTest::testMesh3DSurfRW()
66 {
67   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
68   mesh->checkCoherency();
69   MEDLoader::WriteUMesh("file4.med",mesh,true);
70   MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file4.med",mesh->getName(),0);
71   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
72   mesh_rw->decrRef();
73   mesh->decrRef();
74 }
75
76 void MEDLoaderTest::testMesh3DRW()
77 {
78   MEDCouplingUMesh *mesh=build3DMesh_1();
79   mesh->checkCoherency();
80   MEDLoader::WriteUMesh("file5.med",mesh,true);
81   MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file5.med",mesh->getName(),0);
82   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
83   mesh_rw->decrRef();
84   mesh->decrRef();
85 }
86
87 /*!
88  * Most basic test : one and only one MEDCoupling field in a new file.
89  */
90 void MEDLoaderTest::testFieldRW1()
91 {
92   MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
93   MEDLoader::WriteField("file6.med",f1,true);
94   MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell("file6.med",f1->getMesh()->getName(),0,f1->getName(),0,1);
95   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
96   f1->decrRef();
97   f2->decrRef();
98   //
99   f1=buildVecFieldOnNodes_1();
100   MEDLoader::WriteField("file7.med",f1,true);
101   f2=MEDLoader::ReadFieldNode("file7.med",f1->getMesh()->getName(),0,f1->getName(),2,3);
102   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
103   // testing kind message on error of field type.
104   CPPUNIT_ASSERT_THROW(MEDLoader::ReadFieldCell("file7.med",f1->getMesh()->getName(),0,f1->getName(),2,3),INTERP_KERNEL::Exception);
105   //
106   f1->decrRef();
107   f2->decrRef();
108 }
109
110 /*!
111  * Multi field writing in a same file.
112  */
113 void MEDLoaderTest::testFieldRW2()
114 {
115   const char fileName[]="file8.med";
116   static const double VAL1=12345.67890314;
117   static const double VAL2=-1111111111111.;
118   MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
119   MEDLoader::WriteField(fileName,f1,true);
120   f1->setTime(10.,8,9);
121   double *tmp=f1->getArray()->getPointer();
122   tmp[0]=VAL1;
123   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
124   f1->setTime(10.14,18,19);
125   tmp[0]=VAL2;
126   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
127   //retrieving time steps...
128   MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),8,9);
129   f1->setTime(10.,8,9);
130   tmp[0]=VAL1;
131   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
132   f2->decrRef();
133   f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),0,1);
134   MEDCouplingFieldDouble *f3=buildVecFieldOnCells_1();
135   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
136   f3->decrRef();
137   f2->decrRef();
138   f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),18,19);
139   f1->setTime(10.14,18,19);
140   tmp[0]=VAL2;
141   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
142   //test of throw on invalid (dt,it)
143   CPPUNIT_ASSERT_THROW(MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),28,19),INTERP_KERNEL::Exception);
144   f2->decrRef();
145   f1->decrRef();
146   //ON NODES
147   f1=buildVecFieldOnNodes_1();
148   const char fileName2[]="file9.med";
149   MEDLoader::WriteField(fileName2,f1,true);
150   f1->setTime(110.,108,109);
151   tmp=f1->getArray()->getPointer();
152   tmp[3]=VAL1;
153   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
154   f1->setTime(210.,208,209);
155   tmp[3]=VAL2;
156   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
157   f2=MEDLoader::ReadFieldNode(fileName2,f1->getMesh()->getName(),0,f1->getName(),108,109);
158   f1->setTime(110.,108,109);
159   tmp[3]=VAL1;
160   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
161   f2->decrRef();
162   f2=MEDLoader::ReadFieldNode(fileName2,f1->getMesh()->getName(),0,f1->getName(),2,3);
163   f3=buildVecFieldOnNodes_1();
164   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
165   f3->decrRef();
166   f2->decrRef();
167   f2=MEDLoader::ReadFieldNode(fileName2,f1->getMesh()->getName(),0,f1->getName(),208,209);
168   f1->setTime(210.,208,209);
169   tmp[3]=VAL2;
170   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
171   f2->decrRef();
172   f1->decrRef();
173 }
174
175 /*!
176  * Multi field in a same file, but this field has several
177  */
178 void MEDLoaderTest::testFieldRW3()
179 {
180   const char fileName[]="file11.med";
181   static const double VAL1=12345.67890314;
182   static const double VAL2=-1111111111111.;
183   const char name1[]="AField";
184   const char name3[]="AMesh1";
185   MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
186   (const_cast<MEDCouplingMesh *>(f1->getMesh()))->setName(name3);
187   f1->setName(name1);
188   f1->setTime(10.,8,9);
189   double *tmp=f1->getArray()->getPointer();
190   tmp[0]=VAL1;
191   MEDLoader::WriteField(fileName,f1,true);
192   f1->setTime(10.14,18,19);
193   tmp[0]=VAL2;
194   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
195   f1->setTime(10.55,28,29);
196   tmp[0]=3*VAL1;
197   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
198   f1->setTime(10.66,38,39);
199   tmp[0]=3*VAL2;
200   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
201   f1->setTime(10.77,48,49);
202   tmp[0]=4*VAL2;
203   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
204   //ON NODES
205   f1->decrRef();
206   f1=buildVecFieldOnNodes_1();
207   f1->setName(name1);
208   (const_cast<MEDCouplingMesh *>(f1->getMesh()))->setName(name3);
209   f1->setTime(110.,8,9);
210   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
211   f1->setTime(110.,108,109);
212   tmp=f1->getArray()->getPointer();
213   tmp[3]=VAL1;
214   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
215   f1->setTime(210.,208,209);
216   tmp[3]=VAL2;
217   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
218   //
219   std::vector< std::pair<int,int> > it1=MEDLoader::GetCellFieldIterations(fileName,name3,name1);
220   CPPUNIT_ASSERT_EQUAL(5,(int)it1.size());
221   CPPUNIT_ASSERT_EQUAL(8,it1[0].first); CPPUNIT_ASSERT_EQUAL(9,it1[0].second);
222   CPPUNIT_ASSERT_EQUAL(18,it1[1].first); CPPUNIT_ASSERT_EQUAL(19,it1[1].second);
223   CPPUNIT_ASSERT_EQUAL(28,it1[2].first); CPPUNIT_ASSERT_EQUAL(29,it1[2].second);
224   CPPUNIT_ASSERT_EQUAL(38,it1[3].first); CPPUNIT_ASSERT_EQUAL(39,it1[3].second);
225   CPPUNIT_ASSERT_EQUAL(48,it1[4].first); CPPUNIT_ASSERT_EQUAL(49,it1[4].second);
226   std::vector< std::pair<int,int> > it3=MEDLoader::GetNodeFieldIterations(fileName,name3,name1);
227   CPPUNIT_ASSERT_EQUAL(3,(int)it3.size());
228   CPPUNIT_ASSERT_EQUAL(8,it3[0].first); CPPUNIT_ASSERT_EQUAL(9,it3[0].second);
229   CPPUNIT_ASSERT_EQUAL(108,it3[1].first); CPPUNIT_ASSERT_EQUAL(109,it3[1].second);
230   CPPUNIT_ASSERT_EQUAL(208,it3[2].first); CPPUNIT_ASSERT_EQUAL(209,it3[2].second);
231   //
232   f1->decrRef();
233   //
234   f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,8,9);
235   CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[0],1e-13);
236   f1->decrRef();
237   f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,18,19);
238   CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[0],1e-13);
239   f1->decrRef();
240   f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,28,29);
241   CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL1,f1->getArray()->getConstPointer()[0],1e-13);
242   f1->decrRef();
243   f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,38,39);
244   CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
245   f1->decrRef();
246   f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,48,49);
247   CPPUNIT_ASSERT_DOUBLES_EQUAL(4*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
248   f1->decrRef();
249   //
250   f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,8,9);
251   CPPUNIT_ASSERT_DOUBLES_EQUAL(71.,f1->getArray()->getConstPointer()[3],1e-13);
252   f1->decrRef();
253   f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,108,109);
254   CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[3],1e-13);
255   f1->decrRef();
256   f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,208,209);
257   CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[3],1e-13);
258   f1->decrRef();
259 }
260
261 void MEDLoaderTest::testMultiMeshRW1()
262 {
263   const char fileName[]="file10.med";
264   MEDCouplingUMesh *mesh1=build3DMesh_1();
265   const int part1[5]={1,2,4,13,15};
266   MEDCouplingUMesh *mesh2=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part1,part1+5,true);
267   mesh2->setName("mesh2");
268   const int part2[4]={3,4,13,14};
269   MEDCouplingUMesh *mesh3=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part2,part2+4,true);
270   mesh3->setName("mesh3");
271   MEDCouplingUMesh *mesh4=MEDCouplingUMesh::New();
272   mesh4->setName("mesh4");
273   mesh4->setMeshDimension(3);
274   mesh4->allocateCells(1);
275   int conn[4]={0,11,1,3};
276   mesh4->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,conn);
277   mesh4->finishInsertingCells();
278   mesh4->setCoords(mesh1->getCoords());
279   std::vector<const MEDCouplingUMesh *> meshes;
280   meshes.push_back(mesh1);
281   meshes.push_back(mesh2);
282   meshes.push_back(mesh3);
283   meshes.push_back(mesh4);
284   const char mnane[]="3DToto";
285   MEDLoader::WriteUMeshesPartition(fileName,mnane,meshes,true);
286   //
287   MEDCouplingUMesh *mesh5=MEDLoader::ReadUMeshFromFile(fileName,mnane);
288   mesh1->setName(mnane);
289   const int part3[18]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
290   MEDCouplingUMesh *mesh6=(MEDCouplingUMesh *)mesh5->buildPartOfMySelf(part3,part3+18,true);
291   mesh6->setName(mnane);
292   mesh5->decrRef();
293   CPPUNIT_ASSERT(mesh6->isEqual(mesh1,1e-12));
294   mesh6->decrRef();
295   std::vector<std::string> grps=MEDLoader::GetMeshGroupsNames(fileName,mnane);
296   CPPUNIT_ASSERT_EQUAL(4,(int)grps.size());
297   CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh2"))!=grps.end());
298   CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh3"))!=grps.end());
299   CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh4"))!=grps.end());
300   CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("3DMesh_1"))!=grps.end());
301   //
302   std::vector<std::string> vec;
303   vec.push_back(std::string("mesh2"));
304   MEDCouplingUMesh *mesh2_2=MEDLoader::ReadUMeshFromGroups(fileName,mnane,0,vec);
305   CPPUNIT_ASSERT(mesh2_2->isEqual(mesh2,1e-12));
306   mesh2_2->decrRef();
307   vec.clear(); vec.push_back(std::string("mesh3"));
308   MEDCouplingUMesh *mesh3_2=MEDLoader::ReadUMeshFromGroups(fileName,mnane,0,vec);
309   CPPUNIT_ASSERT(mesh3_2->isEqual(mesh3,1e-12));
310   mesh3_2->decrRef();
311   vec.clear(); vec.push_back(std::string("mesh4"));
312   MEDCouplingUMesh *mesh4_2=MEDLoader::ReadUMeshFromGroups(fileName,mnane,0,vec);
313   CPPUNIT_ASSERT(mesh4_2->isEqual(mesh4,1e-12));
314   mesh4_2->decrRef();
315   vec.clear(); vec.push_back(std::string("3DMesh_1"));
316   MEDCouplingUMesh *mesh1_2=MEDLoader::ReadUMeshFromGroups(fileName,mnane,0,vec);
317   mesh1->setName("3DMesh_1");
318   CPPUNIT_ASSERT(mesh1_2->isEqual(mesh1,1e-12));
319   mesh1_2->decrRef();
320   //
321   vec.clear(); vec.push_back(std::string("Family_4")); vec.push_back(std::string("Family_2"));
322   mesh2_2=MEDLoader::ReadUMeshFromFamilies(fileName,mnane,0,vec);
323   mesh2_2->setName("mesh2");
324   CPPUNIT_ASSERT(mesh2_2->isEqual(mesh2,1e-12));
325   mesh2_2->decrRef();
326   //
327   std::vector<std::string> ret=MEDLoader::GetMeshFamiliesNamesOnGroup(fileName,"3DToto","3DMesh_1");
328   CPPUNIT_ASSERT_EQUAL(4,(int)ret.size());
329   CPPUNIT_ASSERT(ret[0]=="Family_1");
330   CPPUNIT_ASSERT(ret[1]=="Family_2");
331   CPPUNIT_ASSERT(ret[2]=="Family_3");
332   CPPUNIT_ASSERT(ret[3]=="Family_4");
333   //
334   std::vector<std::string> ret1=MEDLoader::GetMeshGroupsNamesOnFamily(fileName,"3DToto","Family_2");
335   CPPUNIT_ASSERT_EQUAL(2,(int)ret1.size());
336   CPPUNIT_ASSERT(ret1[0]=="3DMesh_1");
337   CPPUNIT_ASSERT(ret1[1]=="mesh2");
338   //
339   mesh4->decrRef();
340   mesh3->decrRef();
341   mesh2->decrRef();
342   mesh1->decrRef();
343 }
344
345 void MEDLoaderTest::testFieldProfilRW1()
346 {
347   const char fileName[]="file12.med";
348   MEDCouplingUMesh *mesh1=build3DMesh_1();
349   bool b;
350   int newNbOfNodes;
351   DataArrayInt *da=mesh1->mergeNodes(1e-12,b,newNbOfNodes);
352   da->decrRef();
353   MEDLoader::WriteUMesh(fileName,mesh1,true);
354   const int part1[5]={1,2,4,13,15};
355   MEDCouplingUMesh *mesh2=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part1,part1+5,true);
356   mesh2->setName(mesh1->getName());//<- important for the test
357   //
358   int nbOfCells=mesh2->getNumberOfCells();
359   CPPUNIT_ASSERT_EQUAL(5,nbOfCells);
360   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
361   f1->setName("VectorFieldOnCells");
362   f1->setMesh(mesh2);
363   DataArrayDouble *array=DataArrayDouble::New();
364   array->alloc(nbOfCells,2);
365   f1->setArray(array);
366   array->decrRef();
367   double *tmp=array->getPointer();
368   const double arr1[10]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.};
369   std::copy(arr1,arr1+10,tmp);
370   f1->setTime(3.14,2,7);
371   f1->checkCoherency();
372   //
373   MEDLoader::WriteField(fileName,f1,false);//<- false important for the test
374   //
375   MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
376   std::vector<ParaMEDMEM::TypeOfField> types=MEDLoader::GetTypesOfField(fileName,f1->getMesh()->getName(),f1->getName());
377   CPPUNIT_ASSERT_EQUAL(1,(int)types.size());
378   CPPUNIT_ASSERT(types[0]==ON_CELLS);
379   f2->checkCoherency();
380   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
381   //
382   f2->decrRef();
383   f1->decrRef();
384   mesh1->decrRef();
385   mesh2->decrRef();
386 }
387
388 /*!
389  * Test MED file profiles.
390  */
391 void MEDLoaderTest::testFieldNodeProfilRW1()
392 {
393   const char fileName[]="file19.med";
394   const char fileName2[]="file20.med";
395   MEDCouplingUMesh *m=build2DMesh_1();
396   int nbOfNodes=m->getNumberOfNodes();
397   MEDLoader::WriteUMesh(fileName,m,true);
398   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
399   f1->setName("VFieldOnNodes");
400   f1->setMesh(m);
401   DataArrayDouble *array=DataArrayDouble::New();
402   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.};
403   array->alloc(nbOfNodes,2);
404   std::copy(arr1,arr1+24,array->getPointer());
405   f1->setArray(array);
406   array->setInfoOnComponent(0,"tyty [mm]");
407   array->setInfoOnComponent(1,"uiop [MW]");
408   array->decrRef();
409   f1->setTime(3.14,2,7);
410   f1->checkCoherency();
411   const int arr2[2]={1,4};//node ids are 2,4,5,3,6,7
412   MEDCouplingFieldDouble *f2=f1->buildSubPart(arr2,arr2+2);
413   (const_cast<MEDCouplingMesh *>(f2->getMesh()))->setName(f1->getMesh()->getName());
414   MEDLoader::WriteField(fileName,f2,false);//<- false important for the test
415   //
416   MEDCouplingFieldDouble *f3=MEDLoader::ReadFieldNode(fileName,f2->getMesh()->getName(),0,f2->getName(),2,7);
417   f3->checkCoherency();
418   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
419   f3->decrRef();
420   //
421   const int arr3[6]={1,3,0,5,2,4};
422   f2->renumberNodes(arr3);
423   MEDLoader::WriteUMesh(fileName2,m,true);
424   MEDLoader::WriteField(fileName2,f2,false);//<- false important for the test
425   f3=MEDLoader::ReadFieldNode(fileName2,f2->getMesh()->getName(),0,f2->getName(),2,7);
426   f3->checkCoherency();
427   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
428   f3->decrRef();
429   f2->decrRef();
430   //
431   f1->decrRef();
432   m->decrRef();
433 }
434
435 void MEDLoaderTest::testFieldNodeProfilRW2()
436 {
437   const char fileName[]="file23.med";
438   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
439   MEDLoader::WriteUMesh(fileName,mesh,true);
440   //
441   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
442   f1->setName("FieldMix");
443   f1->setMesh(mesh);
444   const double arr2[24]={
445     1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
446     1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
447   };
448   DataArrayDouble *array=DataArrayDouble::New();
449   array->alloc(12,2);
450   f1->setArray(array);
451   array->setInfoOnComponent(0,"plkj [mm]");
452   array->setInfoOnComponent(1,"pqqqss [mm]");
453   array->decrRef();
454   double *tmp=array->getPointer();
455   std::copy(arr2,arr2+24,tmp);
456   f1->setTime(3.17,2,7);
457   //
458   const int renumArr[12]={3,7,2,1,5,11,10,0,9,6,8,4};
459   f1->renumberNodes(renumArr);
460   f1->checkCoherency();
461   MEDLoader::WriteField(fileName,f1,false);//<- false important for the test
462   MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldNode(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
463   CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
464   //
465   f2->decrRef();
466   mesh->decrRef();
467   f1->decrRef();
468 }
469
470 void MEDLoaderTest::testFieldGaussRW1()
471 {
472   const char fileName[]="file13.med";
473   MEDCouplingFieldDouble *f1=buildVecFieldOnGauss_1();
474   MEDLoader::WriteField(fileName,f1,true);
475   MEDCouplingFieldDouble *f2=MEDLoader::ReadField(ON_GAUSS_PT,fileName,f1->getMesh()->getName(),0,f1->getName(),1,5);
476   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
477   f2->decrRef();
478   f1->decrRef();
479 }
480
481 void MEDLoaderTest::testFieldGaussNERW1()
482 {
483   const char fileName[]="file14.med";
484   MEDCouplingFieldDouble *f1=buildVecFieldOnGaussNE_1();
485   MEDLoader::WriteField(fileName,f1,true);
486   MEDCouplingFieldDouble *f2=MEDLoader::ReadField(ON_GAUSS_NE,fileName,f1->getMesh()->getName(),0,f1->getName(),1,5);
487   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
488   f2->decrRef();
489   f1->decrRef();
490 }
491
492 void MEDLoaderTest::testLittleStrings1()
493 {
494   std::string s("azeeeerrrtty");
495   MEDLoaderBase::zipEqualConsChar(s,3);
496   CPPUNIT_ASSERT(s=="azertty");
497 }
498
499 void MEDLoaderTest::testSplitIntoNameAndUnit1()
500 {
501   std::string s(" []");
502   std::string c,u;
503   MEDLoaderBase::splitIntoNameAndUnit(s,c,u);
504   CPPUNIT_ASSERT(c.empty());
505   CPPUNIT_ASSERT(u.empty());
506   s="   lmmm  kki jjj      ";
507   MEDLoaderBase::strip(s);
508   CPPUNIT_ASSERT(s=="lmmm  kki jjj");
509   s=" ";
510   MEDLoaderBase::strip(s);
511   CPPUNIT_ASSERT(s.empty());
512   s="";
513   MEDLoaderBase::strip(s);
514   CPPUNIT_ASSERT(s.empty());
515   s="      ";
516   MEDLoaderBase::strip(s);
517   CPPUNIT_ASSERT(s.empty());
518   s="     pp";
519   MEDLoaderBase::strip(s);
520   CPPUNIT_ASSERT(s=="pp");
521 }
522
523 void MEDLoaderTest::testMesh3DSurfShuffleRW()
524 {
525   const char fileName[]="file15.med";
526   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
527   const int renumber1[6]={2,5,1,0,3,4};
528   mesh->renumberCells(renumber1,false);
529   mesh->checkCoherency();
530   MEDLoader::WriteUMesh(fileName,mesh,true);
531   MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile(fileName,mesh->getName(),0);
532   CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
533   mesh_rw->decrRef();
534   mesh->decrRef();
535 }
536
537 void MEDLoaderTest::testFieldShuffleRW1()
538 {
539   const char fileName[]="file16.med";
540   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
541   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
542   f1->setName("FieldOnCellsShuffle");
543   f1->setMesh(mesh);
544   DataArrayDouble *array=DataArrayDouble::New();
545   array->alloc(6,2);
546   f1->setArray(array);
547   array->decrRef();
548   double *tmp=array->getPointer();
549   const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
550   std::copy(arr1,arr1+12,tmp);
551   f1->setTime(3.14,2,7);
552   f1->checkCoherency();
553   //
554   const int renumber1[6]={2,1,5,0,3,4};
555   f1->renumberCells(renumber1,false);
556   MEDLoader::WriteField(fileName,f1,true);
557   MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,mesh->getName(),0,f1->getName(),2,7);
558   CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
559   f2->decrRef();
560   //
561   mesh->decrRef();
562   f1->decrRef();
563 }
564
565 /*!
566  * Shuffle de cells but no profile. Like pointe.med
567  */
568 void MEDLoaderTest::testMultiFieldShuffleRW1()
569 {
570   const char fileName[]="file17.med";
571   MEDCouplingUMesh *m=build3DMesh_2();
572   CPPUNIT_ASSERT_EQUAL(20,m->getNumberOfCells());
573   CPPUNIT_ASSERT_EQUAL(45,m->getNumberOfNodes());
574   const int polys[3]={1,4,6};
575   std::vector<int> poly2(polys,polys+3);
576   m->convertToPolyTypes(&poly2[0],&poly2[0]+poly2.size());
577   const int renum[20]={1,3,2,8,9,12,13,16,19,0,4,7,5,15,14,17,10,18,6,11};
578   m->renumberCells(renum,false);
579   m->orientCorrectlyPolyhedrons();
580   // Writing
581   MEDLoader::WriteUMesh(fileName,m,true);
582   MEDCouplingFieldDouble *f1Tmp=m->getMeasureField(false);
583   MEDCouplingFieldDouble *f1=f1Tmp->buildNewTimeReprFromThis(ONE_TIME,false);
584   f1Tmp->decrRef();
585   f1->setTime(0.,1,2);
586   MEDCouplingFieldDouble *f_1=f1->cloneWithMesh(true);
587   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
588   f1->applyFunc("2*x");
589   f1->setTime(0.01,3,4);
590   MEDCouplingFieldDouble *f_2=f1->cloneWithMesh(true);
591   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
592   f1->applyFunc("2*x/3");
593   f1->setTime(0.02,5,6);
594   MEDCouplingFieldDouble *f_3=f1->cloneWithMesh(true);
595   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
596   f1->decrRef();
597   // Reading
598   std::vector<std::pair<int,int> > its;
599   its.push_back(std::pair<int,int>(1,2));
600   its.push_back(std::pair<int,int>(3,4));
601   its.push_back(std::pair<int,int>(5,6));
602   std::vector<MEDCouplingFieldDouble *> fs=MEDLoader::ReadFieldsOnSameMesh(ON_CELLS,fileName,f_1->getMesh()->getName(),0,f_1->getName(),its);
603   CPPUNIT_ASSERT_EQUAL(3,(int)fs.size());
604   const MEDCouplingMesh *mm=fs[0]->getMesh();
605   CPPUNIT_ASSERT(fs[0]->isEqual(f_1,1e-12,1e-12));
606   CPPUNIT_ASSERT(fs[1]->isEqual(f_2,1e-12,1e-12));
607   CPPUNIT_ASSERT(fs[2]->isEqual(f_3,1e-12,1e-12));
608   CPPUNIT_ASSERT(mm==fs[1]->getMesh());// <- important for the test
609   CPPUNIT_ASSERT(mm==fs[2]->getMesh());// <- important for the test
610   for(std::vector<MEDCouplingFieldDouble *>::iterator iter=fs.begin();iter!=fs.end();iter++)
611     (*iter)->decrRef();
612   //
613   f_1->decrRef();
614   f_2->decrRef();
615   f_3->decrRef();
616   //
617   m->decrRef();
618 }
619
620 void MEDLoaderTest::testWriteUMeshesRW1()
621 {
622   const char fileName[]="file18.med";
623   MEDCouplingUMesh *m3d=build3DMesh_2();
624   const double pt[3]={0.,0.,-0.3};
625   const double vec[3]={0.,0.,1.};
626   std::vector<int> nodes;
627   m3d->findNodesOnPlane(pt,vec,1e-12,nodes);
628   MEDCouplingUMesh *m2d=(MEDCouplingUMesh *)m3d->buildFacePartOfMySelfNode(&nodes[0],&nodes[0]+nodes.size(),true);
629   const int renumber[5]={1,2,0,4,3};
630   m2d->renumberCells(renumber,false);
631   m2d->setName("ExampleOfMultiDimW");
632   std::vector<const MEDCouplingUMesh *> meshes;
633   meshes.push_back(m2d);
634   meshes.push_back(m3d);
635   MEDLoader::WriteUMeshes(fileName,meshes,true);
636   MEDCouplingUMesh *m3d_bis=MEDLoader::ReadUMeshFromFile(fileName,m2d->getName(),0);
637   CPPUNIT_ASSERT(!m3d_bis->isEqual(m3d,1e-12));
638   m3d_bis->setName(m3d->getName());
639   CPPUNIT_ASSERT(m3d_bis->isEqual(m3d,1e-12));
640   MEDCouplingUMesh *m2d_bis=MEDLoader::ReadUMeshFromFile(fileName,m2d->getName(),-1);//-1 for faces
641   CPPUNIT_ASSERT(m2d_bis->isEqual(m2d,1e-12));
642   // Creation of a field on faces.
643   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
644   f1->setName("FieldOnFacesShuffle");
645   f1->setMesh(m2d);
646   DataArrayDouble *array=DataArrayDouble::New();
647   array->alloc(m2d->getNumberOfCells(),2);
648   array->setInfoOnComponent(0,"plkj [mm]");
649   array->setInfoOnComponent(1,"pqqqss [mm]");
650   f1->setArray(array);
651   array->decrRef();
652   double *tmp=array->getPointer();
653   const double arr1[10]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.};
654   std::copy(arr1,arr1+10,tmp);
655   f1->setTime(3.14,2,7);
656   f1->checkCoherency();
657   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
658   MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),-1,f1->getName(),2,7);
659   CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
660   f1->decrRef();
661   f2->decrRef();
662   //
663   m2d_bis->decrRef();
664   m3d_bis->decrRef();
665   m2d->decrRef();
666   m3d->decrRef();
667 }
668
669 void MEDLoaderTest::testMixCellAndNodesFieldRW1()
670 {
671   const char fileName[]="file21.med";
672   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
673   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
674   f1->setName("FieldMix");
675   f1->setMesh(mesh);
676   DataArrayDouble *array=DataArrayDouble::New();
677   array->alloc(6,2);
678   f1->setArray(array);
679   array->setInfoOnComponent(0,"plkj [mm]");
680   array->setInfoOnComponent(1,"pqqqss [mm]");
681   array->decrRef();
682   double *tmp=array->getPointer();
683   const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
684   std::copy(arr1,arr1+12,tmp);
685   f1->setTime(3.14,2,7);
686   f1->checkCoherency();
687   //
688   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
689   f2->setName("FieldMix");
690   f2->setMesh(mesh);
691   array=DataArrayDouble::New();
692   array->alloc(12,2);
693   f2->setArray(array);
694   array->setInfoOnComponent(0,"plkj [mm]");
695   array->setInfoOnComponent(1,"pqqqss [mm]");
696   array->decrRef();
697   tmp=array->getPointer();
698   const double arr2[24]={
699     1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
700     1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
701   };
702   std::copy(arr2,arr2+24,tmp);
703   f2->setTime(3.14,2,7);
704   f2->checkCoherency();
705   //
706   MEDLoader::WriteField(fileName,f1,true);
707   std::vector<ParaMEDMEM::TypeOfField> ts=MEDLoader::GetTypesOfField(fileName,f1->getMesh()->getName(),f1->getName());
708   CPPUNIT_ASSERT_EQUAL(1,(int)ts.size());
709   CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[0]);
710   std::vector<std::string> fs=MEDLoader::GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName());
711   CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
712   CPPUNIT_ASSERT(fs[0]=="FieldMix");
713   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f2);
714   fs=MEDLoader::GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName());
715   CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
716   CPPUNIT_ASSERT(fs[0]=="FieldMix");
717   //
718   ts=MEDLoader::GetTypesOfField(fileName,f1->getMesh()->getName(),f1->getName());
719   CPPUNIT_ASSERT_EQUAL(2,(int)ts.size());
720   CPPUNIT_ASSERT_EQUAL(ON_NODES,ts[0]);
721   CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[1]);
722   //
723   MEDCouplingFieldDouble *f3=MEDLoader::ReadFieldNode(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
724   CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
725   f3->decrRef();
726   f3=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
727   CPPUNIT_ASSERT(f3->isEqual(f1,1e-12,1e-12));
728   f3->decrRef();
729   //
730   f1->decrRef();
731   f2->decrRef();
732   mesh->decrRef();
733 }
734
735 void MEDLoaderTest::testGetAllFieldNamesRW1()
736 {
737   const char fileName[]="file22.med";
738   MEDCouplingUMesh *mesh=build2DMesh_2();
739   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
740   f1->setName("Field1");
741   f1->setTime(3.44,5,6);
742   f1->setMesh(mesh);
743   f1->fillFromAnalytic(2,"x+y");
744   MEDLoader::WriteField(fileName,f1,true);
745   f1->setTime(1002.3,7,8);
746   f1->fillFromAnalytic(2,"x+77.*y");
747   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
748   f1->setName("Field2");
749   MEDLoader::WriteField(fileName,f1,false);
750   f1->setName("Field3");
751   mesh->setName("2DMesh_2Bis");
752   MEDLoader::WriteField(fileName,f1,false);
753   f1->decrRef();
754   f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
755   f1->setName("Field8");
756   f1->setTime(8.99,7,9);
757   f1->setMesh(mesh);
758   f1->fillFromAnalytic(3,"3*x+y");
759   MEDLoader::WriteField(fileName,f1,false);
760   f1->decrRef();
761   std::vector<std::string> fs=MEDLoader::GetAllFieldNames(fileName);
762   CPPUNIT_ASSERT_EQUAL(4,(int)fs.size());
763   CPPUNIT_ASSERT(fs[0]=="Field1");
764   CPPUNIT_ASSERT(fs[1]=="Field2");
765   CPPUNIT_ASSERT(fs[2]=="Field3");
766   CPPUNIT_ASSERT(fs[3]=="Field8");
767   mesh->decrRef();
768 }
769
770 MEDCouplingUMesh *MEDLoaderTest::build1DMesh_1()
771 {
772   double coords[6]={ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 };
773   int conn[9]={ 0,1, 1,2, 2,3 , 3,4,5};
774   MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
775   mesh->setName("1DMesh_1");
776   mesh->setMeshDimension(1);
777   mesh->allocateCells(4);
778   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
779   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
780   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
781   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6);
782   mesh->finishInsertingCells();
783   DataArrayDouble *myCoords=DataArrayDouble::New();
784   myCoords->alloc(6,1);
785   myCoords->setInfoOnComponent(0,"tototototototot [m*m*m*m*m*m*m*m]");
786   std::copy(coords,coords+6,myCoords->getPointer());
787   mesh->setCoords(myCoords);
788   myCoords->decrRef();
789   return mesh;
790 }
791
792 MEDCouplingUMesh *MEDLoaderTest::build2DCurveMesh_1()
793 {
794   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 };
795   int conn[9]={ 0,1, 1,2, 2,3 , 3,4,5};
796   MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
797   mesh->setName("2DCurveMesh_1");
798   mesh->setMeshDimension(1);
799   mesh->allocateCells(4);
800   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
801   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
802   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
803   mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6);
804   mesh->finishInsertingCells();
805   DataArrayDouble *myCoords=DataArrayDouble::New();
806   myCoords->alloc(6,2);
807   std::copy(coords,coords+12,myCoords->getPointer());
808   mesh->setCoords(myCoords);
809   myCoords->decrRef();
810   return mesh;
811 }
812
813 MEDCouplingUMesh *MEDLoaderTest::build2DMesh_1()
814 {
815   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 };
816   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};
817   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
818   targetMesh->setMeshDimension(2);
819   targetMesh->allocateCells(6);
820   targetMesh->setName("2DMesh_1");
821   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
822   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
823   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
824   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
825   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
826   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POLYGON,4,targetConn+20);
827   targetMesh->finishInsertingCells();
828   DataArrayDouble *myCoords=DataArrayDouble::New();
829   myCoords->alloc(12,2);
830   myCoords->setInfoOnComponent(0,"tototototototot [m]");
831   myCoords->setInfoOnComponent(1,"energie [kW]");
832   std::copy(targetCoords,targetCoords+24,myCoords->getPointer());
833   targetMesh->setCoords(myCoords);
834   myCoords->decrRef();
835   return targetMesh;
836 }
837
838 MEDCouplingUMesh *MEDLoaderTest::build2DMesh_2()
839 {
840   double targetCoords[24]={
841     -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,
842     -0.05,0.95, 0.2,1.2, 0.45,0.95
843   };
844   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};
845   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
846   targetMesh->setMeshDimension(2);
847   targetMesh->allocateCells(5);
848   targetMesh->setName("2DMesh_2");
849   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
850   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
851   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
852   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
853   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
854   targetMesh->finishInsertingCells();
855   DataArrayDouble *myCoords=DataArrayDouble::New();
856   myCoords->alloc(12,2);
857   myCoords->setInfoOnComponent(0,"toto [m]");
858   myCoords->setInfoOnComponent(1,"energie [kW]");
859   std::copy(targetCoords,targetCoords+24,myCoords->getPointer());
860   targetMesh->setCoords(myCoords);
861   myCoords->decrRef();
862   return targetMesh;
863 }
864
865 MEDCouplingUMesh *MEDLoaderTest::build3DSurfMesh_1()
866 {
867   double targetCoords[36]={
868     -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
869     ,-0.05,0.95,-0.3, 0.2,1.2,-0.3, 0.45,0.95,-0.3
870   };
871   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};
872   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
873   targetMesh->setMeshDimension(2);
874   targetMesh->allocateCells(6);
875   targetMesh->setName("3DSurfMesh_1");
876   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
877   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
878   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
879   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
880   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
881   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POLYGON,4,targetConn+20);
882   targetMesh->finishInsertingCells();
883   DataArrayDouble *myCoords=DataArrayDouble::New();
884   myCoords->alloc(12,3);
885   myCoords->setInfoOnComponent(0,"toto [m]");
886   myCoords->setInfoOnComponent(2,"ff [km]");//component 1 is not set for test
887   std::copy(targetCoords,targetCoords+36,myCoords->getPointer());
888   targetMesh->setCoords(myCoords);
889   myCoords->decrRef();
890   return targetMesh;
891 }
892
893 MEDCouplingUMesh *MEDLoaderTest::build3DMesh_1()
894 {
895   double coords[180]={
896     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.,
897     3.,2.,0., 0.,1.,0., 1.,3.,0., 2.,2.,0., 2.,3.,0.,
898     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.,
899     3.,2.,1., 0.,1.,1., 1.,3.,1., 2.,2.,1., 2.,3.,1.,
900     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.,
901     3.,2.,2., 0.,1.,2., 1.,3.,2., 2.,2.,2., 2.,3.,2.,
902     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.,
903     3.,2.,3., 0.,1.,3., 1.,3.,3., 2.,2.,3., 2.,3.,3.};
904
905   int conn[354]={
906     // 0
907     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,
908     1,6,5,3,16,21,20,18,   13,10,9,6,28,25,24,21,
909     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,
910     7,12,14,13,22,27,29,28,
911     // 1
912     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,
913     16,21,20,18,31,36,35,33,   28,25,24,21,43,40,39,36,
914     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,
915     22,27,29,28,37,42,44,43,
916     // 2
917     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,
918     31,36,35,33,46,51,50,48,  43,40,39,36,58,55,54,51,
919     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,
920     37,42,44,43,52,57,59,58
921   };
922   //
923   MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
924   ret->setName("3DMesh_1");
925   ret->setMeshDimension(3);
926   ret->allocateCells(18);
927   //
928   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
929   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+51);
930   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+59);
931   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+110);
932   //
933   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+118);
934   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+169);
935   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+177);
936   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+228);
937   //
938   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+236);
939   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+287);
940   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+295);
941   ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+346);
942   //
943   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+8);
944   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+67);
945   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+126);
946   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+185);
947   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+244);
948   ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+303);
949   //
950   ret->finishInsertingCells();
951   DataArrayDouble *myCoords=DataArrayDouble::New();
952   myCoords->alloc(60,3);
953   myCoords->setInfoOnComponent(0,"titi [m]");
954   myCoords->setInfoOnComponent(1,"density power [MW/m^3]");
955   myCoords->setInfoOnComponent(2,"t [kW]");
956   std::copy(coords,coords+180,myCoords->getPointer());
957   ret->setCoords(myCoords);
958   myCoords->decrRef();
959   return ret;
960 }
961
962 MEDCouplingUMesh *MEDLoaderTest::build3DMesh_2()
963 {
964   MEDCouplingUMesh *m3dsurfBase=build3DSurfMesh_1();
965   int numbers[5]={0,1,2,3,5};
966   MEDCouplingUMesh *m3dsurf=(MEDCouplingUMesh *)m3dsurfBase->buildPartOfMySelf(numbers,numbers+5,false);
967   m3dsurfBase->decrRef();
968   MEDCouplingUMesh *m1dBase=build1DMesh_1();
969   int numbers2[4]={0,1,2,3};
970   MEDCouplingUMesh *m1d=(MEDCouplingUMesh *)m1dBase->buildPartOfMySelf(numbers2,numbers2+4,false);
971   m1dBase->decrRef();
972   m1d->changeSpaceDimension(3);
973   const double vec[3]={0.,1.,0.};
974   const double pt[3]={0.,0.,0.};
975   m1d->rotate(pt,vec,-M_PI/2.);
976   MEDCouplingUMesh *ret=m3dsurf->buildExtrudedMesh(m1d,0);
977   m1d->decrRef();
978   m3dsurf->decrRef();
979   return ret;
980 }
981
982 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnCells_1()
983 {
984   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
985   int nbOfCells=mesh->getNumberOfCells();
986   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
987   f1->setName("VectorFieldOnCells");
988   f1->setMesh(mesh);
989   DataArrayDouble *array=DataArrayDouble::New();
990   array->alloc(nbOfCells,3);
991   array->setInfoOnComponent(0,"power [MW/m^3]");
992   array->setInfoOnComponent(1,"density [g/cm^3]");
993   array->setInfoOnComponent(2,"temperature [K]");
994   f1->setArray(array);
995   array->decrRef();
996   double *tmp=array->getPointer();
997   const double arr1[18]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.};
998   std::copy(arr1,arr1+18,tmp);
999   f1->setTime(2.,0,1);
1000   f1->checkCoherency();
1001   mesh->decrRef();
1002   return f1;
1003 }
1004
1005 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnNodes_1()
1006 {
1007   MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1008   int nbOfNodes=mesh->getNumberOfNodes();
1009   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
1010   f1->setName("VectorFieldOnNodes");
1011   f1->setMesh(mesh);
1012   DataArrayDouble *array=DataArrayDouble::New();
1013   array->alloc(nbOfNodes,3);
1014   f1->setArray(array);
1015   array->setInfoOnComponent(0,"power [MW/m^3]");
1016   array->setInfoOnComponent(1,"density [g/cm^3]");
1017   array->setInfoOnComponent(2,"temperature [K]");
1018   array->decrRef();
1019   double *tmp=array->getPointer();
1020   const double arr1[36]={
1021     70.,80.,90.,71.,81.,91.,72.,82.,92.,73.,83.,93.,74.,84.,94.,75.,85.,95.,
1022     1000.,10010.,10020.,1001.,10011.,10021.,1002.,10012.,10022.,1003.,10013.,10023.,1004.,10014.,10024.,1005.,10015.,10025.,
1023   };
1024   std::copy(arr1,arr1+36,tmp);
1025   f1->setTime(2.12,2,3);
1026   f1->checkCoherency();
1027   mesh->decrRef();
1028   return f1;
1029 }
1030
1031 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGauss_1()
1032 {
1033   const double _a=0.446948490915965;
1034   const double _b=0.091576213509771;
1035   const double _p1=0.11169079483905;
1036   const double _p2=0.0549758718227661;
1037   const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
1038   const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
1039                             2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
1040   const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
1041   std::vector<double> _refCoo1(refCoo1,refCoo1+6);
1042   std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
1043   std::vector<double> _wg1(wg1,wg1+6);
1044   MEDCouplingUMesh *m=build2DMesh_2();
1045   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,ONE_TIME);
1046   f->setTime(3.14,1,5);
1047   f->setMesh(m);
1048   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
1049   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 };
1050   std::vector<double> _refCoo2(refCoo2,refCoo2+12);
1051   std::vector<double> _gsCoo2(_gsCoo1);
1052   std::vector<double> _wg2(_wg1);
1053   _gsCoo2.resize(6); _wg2.resize(3);
1054   const double refCoo3[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
1055   std::vector<double> _refCoo3(refCoo3,refCoo3+8);
1056   _gsCoo1.resize(4); _wg1.resize(2);
1057   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo3,_gsCoo1,_wg1);
1058   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI6,_refCoo2,_gsCoo2,_wg2);
1059   DataArrayDouble *array=DataArrayDouble::New();
1060   array->alloc(19,2);
1061   double *ptr=array->getPointer();
1062   for(int i=0;i<19*2;i++)
1063     ptr[i]=(double)(i+7);
1064   f->setArray(array);
1065   f->setName("MyFirstFieldOnGaussPoint");
1066   array->setInfoOnComponent(0,"power [MW/m^3]");
1067   array->setInfoOnComponent(1,"density");
1068   array->decrRef();
1069   f->checkCoherency();
1070   m->decrRef();
1071   return f;
1072 }
1073
1074 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGaussNE_1()
1075 {
1076   MEDCouplingUMesh *m=build2DMesh_2();
1077   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,ONE_TIME);
1078   f->setTime(3.14,1,5);
1079   f->setMesh(m);
1080   DataArrayDouble *array=DataArrayDouble::New();
1081   array->alloc(20,2);
1082   double *ptr=array->getPointer();
1083   for(int i=0;i<20*2;i++)
1084     ptr[i]=(double)(i+8);
1085   f->setArray(array);
1086   array->setInfoOnComponent(0,"power [W]");
1087   array->setInfoOnComponent(1,"temperature");
1088   f->setName("MyFieldOnGaussNE");
1089   array->decrRef();
1090   f->checkCoherency();
1091   m->decrRef();
1092   return f;
1093 }
1094