1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDLoaderTest.hxx"
22 #include "MEDLoader.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDCouplingUMesh.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingMemArray.hxx"
30 using namespace ParaMEDMEM;
32 void MEDLoaderTest::testMesh1DRW()
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().c_str(),0);
38 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
43 void MEDLoaderTest::testMesh2DCurveRW()
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().c_str(),0);
49 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
54 void MEDLoaderTest::testMesh2DRW()
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().c_str(),0);
60 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
65 void MEDLoaderTest::testMesh3DSurfRW()
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().c_str(),0);
71 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
76 void MEDLoaderTest::testMesh3DRW()
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().c_str(),0);
82 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
88 * Most basic test : one and only one MEDCoupling field in a new file.
90 void MEDLoaderTest::testFieldRW1()
92 MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
93 MEDLoader::WriteField("file6.med",f1,true);
94 MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell("file6.med",f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),0,1);
95 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
99 f1=buildVecFieldOnNodes_1();
100 MEDLoader::WriteField("file7.med",f1,true);
101 f2=MEDLoader::ReadFieldNode("file7.med",f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),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().c_str(),0,f1->getName().c_str(),2,3),INTERP_KERNEL::Exception);
111 * Multi field writing in a same file.
113 void MEDLoaderTest::testFieldRW2()
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();
123 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
124 f1->setTime(10.14,18,19);
126 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
127 //retrieving time steps...
128 MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),8,9);
129 f1->setTime(10.,8,9);
131 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
133 f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),0,1);
134 MEDCouplingFieldDouble *f3=buildVecFieldOnCells_1();
135 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
138 f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),18,19);
139 f1->setTime(10.14,18,19);
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().c_str(),0,f1->getName().c_str(),28,19),INTERP_KERNEL::Exception);
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();
153 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
154 f1->setTime(210.,208,209);
156 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
157 f2=MEDLoader::ReadFieldNode(fileName2,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),108,109);
158 f1->setTime(110.,108,109);
160 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
162 f2=MEDLoader::ReadFieldNode(fileName2,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,3);
163 f3=buildVecFieldOnNodes_1();
164 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
167 f2=MEDLoader::ReadFieldNode(fileName2,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),208,209);
168 f1->setTime(210.,208,209);
170 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
176 * Multi field in a same file, but this field has several
178 void MEDLoaderTest::testFieldRW3()
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);
188 f1->setTime(10.,8,9);
189 double *tmp=f1->getArray()->getPointer();
191 MEDLoader::WriteField(fileName,f1,true);
192 f1->setTime(10.14,18,19);
194 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
195 f1->setTime(10.55,28,29);
197 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
198 f1->setTime(10.66,38,39);
200 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
201 f1->setTime(10.77,48,49);
203 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
206 f1=buildVecFieldOnNodes_1();
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();
214 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
215 f1->setTime(210.,208,209);
217 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
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);
234 f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,8,9);
235 CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[0],1e-13);
237 f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,18,19);
238 CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[0],1e-13);
240 f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,28,29);
241 CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL1,f1->getArray()->getConstPointer()[0],1e-13);
243 f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,38,39);
244 CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
246 f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,48,49);
247 CPPUNIT_ASSERT_DOUBLES_EQUAL(4*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
250 f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,8,9);
251 CPPUNIT_ASSERT_DOUBLES_EQUAL(71.,f1->getArray()->getConstPointer()[3],1e-13);
253 f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,108,109);
254 CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[3],1e-13);
256 f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,208,209);
257 CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[3],1e-13);
261 void MEDLoaderTest::testMultiMeshRW1()
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);
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);
293 CPPUNIT_ASSERT(mesh6->isEqual(mesh1,1e-12));
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());
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));
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));
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));
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));
321 vec.clear(); vec.push_back(std::string("Family_-3")); vec.push_back(std::string("Family_-5"));
322 mesh2_2=MEDLoader::ReadUMeshFromFamilies(fileName,mnane,0,vec);
323 mesh2_2->setName("mesh2");
324 CPPUNIT_ASSERT(mesh2_2->isEqual(mesh2,1e-12));
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_-2");
330 CPPUNIT_ASSERT(ret[1]=="Family_-3");
331 CPPUNIT_ASSERT(ret[2]=="Family_-4");
332 CPPUNIT_ASSERT(ret[3]=="Family_-5");
334 std::vector<std::string> ret1=MEDLoader::GetMeshGroupsNamesOnFamily(fileName,"3DToto","Family_-3");
335 CPPUNIT_ASSERT_EQUAL(2,(int)ret1.size());
336 CPPUNIT_ASSERT(ret1[0]=="3DMesh_1");
337 CPPUNIT_ASSERT(ret1[1]=="mesh2");
345 void MEDLoaderTest::testFieldProfilRW1()
347 const char fileName[]="file12.med";
348 MEDCouplingUMesh *mesh1=build3DMesh_1();
351 DataArrayInt *da=mesh1->mergeNodes(1e-12,b,newNbOfNodes);
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().c_str());//<- important for the test
358 int nbOfCells=mesh2->getNumberOfCells();
359 CPPUNIT_ASSERT_EQUAL(5,nbOfCells);
360 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
361 f1->setName("VectorFieldOnCells");
363 DataArrayDouble *array=DataArrayDouble::New();
364 array->alloc(nbOfCells,2);
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();
373 MEDLoader::WriteField(fileName,f1,false);//<- false important for the test
375 MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,7);
376 std::vector<ParaMEDMEM::TypeOfField> types=MEDLoader::GetTypesOfField(fileName,f1->getMesh()->getName().c_str(),f1->getName().c_str());
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));
389 * Test MED file profiles.
391 void MEDLoaderTest::testFieldNodeProfilRW1()
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");
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());
406 array->setInfoOnComponent(0,"tyty [mm]");
407 array->setInfoOnComponent(1,"uiop [MW]");
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().c_str());
414 MEDLoader::WriteField(fileName,f2,false);//<- false important for the test
416 MEDCouplingFieldDouble *f3=MEDLoader::ReadFieldNode(fileName,f2->getMesh()->getName().c_str(),0,f2->getName().c_str(),2,7);
417 f3->checkCoherency();
418 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
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().c_str(),0,f2->getName().c_str(),2,7);
426 f3->checkCoherency();
427 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
435 void MEDLoaderTest::testFieldNodeProfilRW2()
437 const char fileName[]="file23.med";
438 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
439 MEDLoader::WriteUMesh(fileName,mesh,true);
441 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
442 f1->setName("FieldMix");
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.
448 DataArrayDouble *array=DataArrayDouble::New();
451 array->setInfoOnComponent(0,"plkj [mm]");
452 array->setInfoOnComponent(1,"pqqqss [mm]");
454 double *tmp=array->getPointer();
455 std::copy(arr2,arr2+24,tmp);
456 f1->setTime(3.17,2,7);
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().c_str(),0,f1->getName().c_str(),2,7);
463 CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
470 void MEDLoaderTest::testFieldGaussRW1()
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().c_str(),0,f1->getName().c_str(),1,5);
476 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
481 void MEDLoaderTest::testFieldGaussNERW1()
483 const char fileName[]="file14.med";
484 MEDCouplingFieldDouble *f1=buildVecFieldOnGaussNE_1();
485 MEDLoader::WriteField(fileName,f1,true);
486 std::vector<ParaMEDMEM::TypeOfField> tof(MEDLoader::GetTypesOfField(fileName,"2DMesh_2","MyFieldOnGaussNE"));
487 CPPUNIT_ASSERT_EQUAL(1,(int)tof.size());
488 CPPUNIT_ASSERT(ON_GAUSS_NE==tof[0]);
489 MEDCouplingFieldDouble *f2=MEDLoader::ReadField(ON_GAUSS_NE,fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),1,5);
490 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
495 void MEDLoaderTest::testLittleStrings1()
497 std::string s("azeeeerrrtty");
498 MEDLoaderBase::zipEqualConsChar(s,3);
499 CPPUNIT_ASSERT(s=="azertty");
502 void MEDLoaderTest::testSplitIntoNameAndUnit1()
504 std::string s(" []");
506 MEDLoaderBase::splitIntoNameAndUnit(s,c,u);
507 CPPUNIT_ASSERT(c.empty());
508 CPPUNIT_ASSERT(u.empty());
510 MEDLoaderBase::strip(s);
511 CPPUNIT_ASSERT(s=="lmmm kki jjj");
513 MEDLoaderBase::strip(s);
514 CPPUNIT_ASSERT(s.empty());
516 MEDLoaderBase::strip(s);
517 CPPUNIT_ASSERT(s.empty());
519 MEDLoaderBase::strip(s);
520 CPPUNIT_ASSERT(s.empty());
522 MEDLoaderBase::strip(s);
523 CPPUNIT_ASSERT(s=="pp");
526 void MEDLoaderTest::testMesh3DSurfShuffleRW()
528 const char fileName[]="file15.med";
529 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
530 const int renumber1[6]={2,5,1,0,3,4};
531 mesh->renumberCells(renumber1,false);
532 mesh->checkCoherency();
533 MEDLoader::WriteUMesh(fileName,mesh,true);
534 MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile(fileName,mesh->getName().c_str(),0);
535 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
540 void MEDLoaderTest::testFieldShuffleRW1()
542 const char fileName[]="file16.med";
543 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
544 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
545 f1->setName("FieldOnCellsShuffle");
547 DataArrayDouble *array=DataArrayDouble::New();
551 double *tmp=array->getPointer();
552 const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
553 std::copy(arr1,arr1+12,tmp);
554 f1->setTime(3.14,2,7);
555 f1->checkCoherency();
557 const int renumber1[6]={2,1,5,0,3,4};
558 f1->renumberCells(renumber1,false);
559 MEDLoader::WriteField(fileName,f1,true);
560 MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,mesh->getName().c_str(),0,f1->getName().c_str(),2,7);
561 CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
569 * Shuffle de cells but no profile. Like pointe.med
571 void MEDLoaderTest::testMultiFieldShuffleRW1()
573 const char fileName[]="file17.med";
574 MEDCouplingUMesh *m=build3DMesh_2();
575 CPPUNIT_ASSERT_EQUAL(20,m->getNumberOfCells());
576 CPPUNIT_ASSERT_EQUAL(45,m->getNumberOfNodes());
577 const int polys[3]={1,4,6};
578 std::vector<int> poly2(polys,polys+3);
579 m->convertToPolyTypes(&poly2[0],&poly2[0]+poly2.size());
580 const int renum[20]={1,3,2,8,9,12,13,16,19,0,4,7,5,15,14,17,10,18,6,11};
581 m->renumberCells(renum,false);
582 m->orientCorrectlyPolyhedrons();
584 MEDLoader::WriteUMesh(fileName,m,true);
585 MEDCouplingFieldDouble *f1Tmp=m->getMeasureField(false);
586 MEDCouplingFieldDouble *f1=f1Tmp->buildNewTimeReprFromThis(ONE_TIME,false);
589 MEDCouplingFieldDouble *f_1=f1->cloneWithMesh(true);
590 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
591 f1->applyFunc("2*x");
592 f1->setTime(0.01,3,4);
593 MEDCouplingFieldDouble *f_2=f1->cloneWithMesh(true);
594 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
595 f1->applyFunc("2*x/3");
596 f1->setTime(0.02,5,6);
597 MEDCouplingFieldDouble *f_3=f1->cloneWithMesh(true);
598 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
601 std::vector<std::pair<int,int> > its;
602 its.push_back(std::pair<int,int>(1,2));
603 its.push_back(std::pair<int,int>(3,4));
604 its.push_back(std::pair<int,int>(5,6));
605 std::vector<MEDCouplingFieldDouble *> fs=MEDLoader::ReadFieldsOnSameMesh(ON_CELLS,fileName,f_1->getMesh()->getName().c_str(),0,f_1->getName().c_str(),its);
606 CPPUNIT_ASSERT_EQUAL(3,(int)fs.size());
607 const MEDCouplingMesh *mm=fs[0]->getMesh();
608 CPPUNIT_ASSERT(fs[0]->isEqual(f_1,1e-12,1e-12));
609 CPPUNIT_ASSERT(fs[1]->isEqual(f_2,1e-12,1e-12));
610 CPPUNIT_ASSERT(fs[2]->isEqual(f_3,1e-12,1e-12));
611 CPPUNIT_ASSERT(mm==fs[1]->getMesh());// <- important for the test
612 CPPUNIT_ASSERT(mm==fs[2]->getMesh());// <- important for the test
613 for(std::vector<MEDCouplingFieldDouble *>::iterator iter=fs.begin();iter!=fs.end();iter++)
623 void MEDLoaderTest::testWriteUMeshesRW1()
625 const char fileName[]="file18.med";
626 MEDCouplingUMesh *m3d=build3DMesh_2();
627 const double pt[3]={0.,0.,-0.3};
628 const double vec[3]={0.,0.,1.};
629 std::vector<int> nodes;
630 m3d->findNodesOnPlane(pt,vec,1e-12,nodes);
631 MEDCouplingUMesh *m2d=(MEDCouplingUMesh *)m3d->buildFacePartOfMySelfNode(&nodes[0],&nodes[0]+nodes.size(),true);
632 const int renumber[5]={1,2,0,4,3};
633 m2d->renumberCells(renumber,false);
634 m2d->setName("ExampleOfMultiDimW");
635 std::vector<const MEDCouplingUMesh *> meshes;
636 meshes.push_back(m2d);
637 meshes.push_back(m3d);
638 MEDLoader::WriteUMeshes(fileName,meshes,true);
639 MEDCouplingUMesh *m3d_bis=MEDLoader::ReadUMeshFromFile(fileName,m2d->getName().c_str(),0);
640 CPPUNIT_ASSERT(!m3d_bis->isEqual(m3d,1e-12));
641 m3d_bis->setName(m3d->getName().c_str());
642 CPPUNIT_ASSERT(m3d_bis->isEqual(m3d,1e-12));
643 MEDCouplingUMesh *m2d_bis=MEDLoader::ReadUMeshFromFile(fileName,m2d->getName().c_str(),-1);//-1 for faces
644 CPPUNIT_ASSERT(m2d_bis->isEqual(m2d,1e-12));
645 // Creation of a field on faces.
646 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
647 f1->setName("FieldOnFacesShuffle");
649 DataArrayDouble *array=DataArrayDouble::New();
650 array->alloc(m2d->getNumberOfCells(),2);
651 array->setInfoOnComponent(0,"plkj [mm]");
652 array->setInfoOnComponent(1,"pqqqss [mm]");
655 double *tmp=array->getPointer();
656 const double arr1[10]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.};
657 std::copy(arr1,arr1+10,tmp);
658 f1->setTime(3.14,2,7);
659 f1->checkCoherency();
660 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
661 MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),-1,f1->getName().c_str(),2,7);
662 CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
672 void MEDLoaderTest::testMixCellAndNodesFieldRW1()
674 const char fileName[]="file21.med";
675 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
676 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
677 f1->setName("FieldMix");
679 DataArrayDouble *array=DataArrayDouble::New();
682 array->setInfoOnComponent(0,"plkj [mm]");
683 array->setInfoOnComponent(1,"pqqqss [mm]");
685 double *tmp=array->getPointer();
686 const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
687 std::copy(arr1,arr1+12,tmp);
688 f1->setTime(3.14,2,7);
689 f1->checkCoherency();
691 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
692 f2->setName("FieldMix");
694 array=DataArrayDouble::New();
697 array->setInfoOnComponent(0,"plkj [mm]");
698 array->setInfoOnComponent(1,"pqqqss [mm]");
700 tmp=array->getPointer();
701 const double arr2[24]={
702 1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
703 1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
705 std::copy(arr2,arr2+24,tmp);
706 f2->setTime(3.14,2,7);
707 f2->checkCoherency();
709 MEDLoader::WriteField(fileName,f1,true);
710 std::vector<ParaMEDMEM::TypeOfField> ts=MEDLoader::GetTypesOfField(fileName,f1->getMesh()->getName().c_str(),f1->getName().c_str());
711 CPPUNIT_ASSERT_EQUAL(1,(int)ts.size());
712 CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[0]);
713 std::vector<std::string> fs=MEDLoader::GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName().c_str());
714 CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
715 CPPUNIT_ASSERT(fs[0]=="FieldMix");
716 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f2);
717 fs=MEDLoader::GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName().c_str());
718 CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
719 CPPUNIT_ASSERT(fs[0]=="FieldMix");
721 ts=MEDLoader::GetTypesOfField(fileName,f1->getMesh()->getName().c_str(),f1->getName().c_str());
722 CPPUNIT_ASSERT_EQUAL(2,(int)ts.size());
723 CPPUNIT_ASSERT_EQUAL(ON_NODES,ts[0]);
724 CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[1]);
726 MEDCouplingFieldDouble *f3=MEDLoader::ReadFieldNode(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,7);
727 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
729 f3=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,7);
730 CPPUNIT_ASSERT(f3->isEqual(f1,1e-12,1e-12));
738 void MEDLoaderTest::testGetAllFieldNamesRW1()
740 const char fileName[]="file22.med";
741 MEDCouplingUMesh *mesh=build2DMesh_2();
742 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
743 f1->setName("Field1");
744 f1->setTime(3.44,5,6);
746 f1->fillFromAnalytic(2,"x+y");
747 MEDLoader::WriteField(fileName,f1,true);
748 f1->setTime(1002.3,7,8);
749 f1->fillFromAnalytic(2,"x+77.*y");
750 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
751 f1->setName("Field2");
752 MEDLoader::WriteField(fileName,f1,false);
753 f1->setName("Field3");
754 mesh->setName("2DMesh_2Bis");
755 MEDLoader::WriteField(fileName,f1,false);
757 f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
758 f1->setName("Field8");
759 f1->setTime(8.99,7,9);
761 f1->fillFromAnalytic(3,"3*x+y");
762 MEDLoader::WriteField(fileName,f1,false);
764 std::vector<std::string> fs=MEDLoader::GetAllFieldNames(fileName);
765 CPPUNIT_ASSERT_EQUAL(4,(int)fs.size());
766 CPPUNIT_ASSERT(fs[0]=="Field1");
767 CPPUNIT_ASSERT(fs[1]=="Field2");
768 CPPUNIT_ASSERT(fs[2]=="Field3");
769 CPPUNIT_ASSERT(fs[3]=="Field8");
774 void MEDLoaderTest::testMEDLoaderRead1()
777 using namespace INTERP_KERNEL;
779 string fileName=getResourceFile("pointe.med");
780 vector<string> meshNames=MEDLoader::GetMeshNames(fileName.c_str());
781 CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
782 MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
783 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
784 CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
785 CPPUNIT_ASSERT_EQUAL(16,mesh->getNumberOfCells());
786 CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
787 CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllGeoTypes().size());
788 for(int i=0;i<12;i++)
789 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i));
790 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(12));
791 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(13));
792 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(14));
793 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(15));
794 CPPUNIT_ASSERT_EQUAL((std::size_t)90,mesh->getNodalConnectivity()->getNbOfElems());
795 CPPUNIT_ASSERT_EQUAL(701,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+90,0));
796 CPPUNIT_ASSERT_EQUAL(705,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+17,0));
797 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
800 vector<string> families=MEDLoader::GetMeshFamiliesNames(fileName.c_str(),meshNames[0].c_str());
801 CPPUNIT_ASSERT_EQUAL(8,(int)families.size());
802 CPPUNIT_ASSERT(families[2]=="FAMILLE_ELEMENT_3");
804 vector<string> families2;
805 families2.push_back(families[2]);
806 mesh=MEDLoader::ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),0,families2);
807 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
808 CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
809 CPPUNIT_ASSERT_EQUAL(2,mesh->getNumberOfCells());
810 CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
811 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
812 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(0));
813 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(1));
814 CPPUNIT_ASSERT_EQUAL((std::size_t)11,mesh->getNodalConnectivity()->getNbOfElems());
815 CPPUNIT_ASSERT_EQUAL(132,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+11,0));
816 CPPUNIT_ASSERT_EQUAL(16,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+3,0));
817 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
820 vector<string> groups=MEDLoader::GetMeshGroupsNames(fileName.c_str(),meshNames[0].c_str());
821 CPPUNIT_ASSERT_EQUAL(5,(int)groups.size());
822 CPPUNIT_ASSERT(groups[0]=="groupe1");
823 CPPUNIT_ASSERT(groups[1]=="groupe2");
824 CPPUNIT_ASSERT(groups[2]=="groupe3");
825 CPPUNIT_ASSERT(groups[3]=="groupe4");
826 CPPUNIT_ASSERT(groups[4]=="groupe5");
827 vector<string> groups2;
828 groups2.push_back(groups[0]);
829 mesh=MEDLoader::ReadUMeshFromGroups(fileName.c_str(),meshNames[0].c_str(),0,groups2);
830 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
831 CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
832 CPPUNIT_ASSERT_EQUAL(7,mesh->getNumberOfCells());
833 CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
834 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
836 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i));
837 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(6));
838 CPPUNIT_ASSERT_EQUAL((std::size_t)36,mesh->getNodalConnectivity()->getNbOfElems());
839 CPPUNIT_ASSERT_EQUAL(254,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+36,0));
840 CPPUNIT_ASSERT_EQUAL(141,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+8,0));
841 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
844 std::vector<std::string> fieldsName=MEDLoader::GetCellFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
845 CPPUNIT_ASSERT_EQUAL(2,(int)fieldsName.size());
846 CPPUNIT_ASSERT(fieldsName[0]=="fieldcelldoublescalar");
847 CPPUNIT_ASSERT(fieldsName[1]=="fieldcelldoublevector");
848 std::vector<std::pair<int,int> > its0=MEDLoader::GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[0].c_str());
849 CPPUNIT_ASSERT_EQUAL(1,(int)its0.size());
850 CPPUNIT_ASSERT_EQUAL(-1,its0[0].first);
851 CPPUNIT_ASSERT_EQUAL(-1,its0[0].second);
852 std::vector<std::pair<int,int> > its1=MEDLoader::GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[1].c_str());
853 CPPUNIT_ASSERT_EQUAL(1,(int)its1.size());
854 CPPUNIT_ASSERT_EQUAL(-1,its1[0].first);
855 CPPUNIT_ASSERT_EQUAL(-1,its1[0].second);
857 MEDCouplingFieldDouble *field0=MEDLoader::ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[0].c_str(),its0[0].first,its0[0].second);
858 field0->checkCoherency();
859 CPPUNIT_ASSERT(field0->getName()==fieldsName[0]);
860 CPPUNIT_ASSERT_EQUAL(1,field0->getNumberOfComponents());
861 CPPUNIT_ASSERT_EQUAL(16,field0->getNumberOfTuples());
862 const double expectedValues[16]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,2.,3.,3.,2.};
863 double diffValue[16];
864 std::transform(field0->getArray()->getPointer(),field0->getArray()->getPointer()+16,expectedValues,diffValue,std::minus<double>());
865 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue,diffValue+16),1e-12);
866 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue,diffValue+16),1e-12);
867 const MEDCouplingUMesh *constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0->getMesh());
868 CPPUNIT_ASSERT(constMesh);
869 CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
870 CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
871 CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells());
872 CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes());
873 CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
874 for(int i=0;i<12;i++)
875 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
876 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
877 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
878 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
879 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
880 CPPUNIT_ASSERT_EQUAL((std::size_t)90,constMesh->getNodalConnectivity()->getNbOfElems());
881 CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
882 CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
883 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
886 MEDCouplingFieldDouble *field1=MEDLoader::ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[1].c_str(),its1[0].first,its1[0].second);
887 field1->checkCoherency();
888 CPPUNIT_ASSERT(field1->getName()==fieldsName[1]);
889 CPPUNIT_ASSERT_EQUAL(3,field1->getNumberOfComponents());
890 CPPUNIT_ASSERT_EQUAL(16,field1->getNumberOfTuples());
891 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.};
892 double diffValue2[48];
893 std::transform(field1->getArray()->getPointer(),field1->getArray()->getPointer()+48,expectedValues2,diffValue2,std::minus<double>());
894 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue2,diffValue2+48),1e-12);
895 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue2,diffValue2+48),1e-12);
896 constMesh=dynamic_cast<const MEDCouplingUMesh *>(field1->getMesh());
897 CPPUNIT_ASSERT(constMesh);
898 CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
899 CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
900 CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells());
901 CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes());
902 CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
903 for(int i=0;i<12;i++)
904 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
905 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
906 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
907 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
908 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
909 CPPUNIT_ASSERT_EQUAL((std::size_t)90,constMesh->getNodalConnectivity()->getNbOfElems());
910 CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
911 CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
912 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
915 std::vector<std::string> fieldsNameNode=MEDLoader::GetNodeFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
916 CPPUNIT_ASSERT_EQUAL(2,(int)fieldsNameNode.size());
917 CPPUNIT_ASSERT(fieldsNameNode[0]=="fieldnodedouble");
918 CPPUNIT_ASSERT(fieldsNameNode[1]=="fieldnodeint");
919 std::vector<std::pair<int,int> > its0Node=MEDLoader::GetNodeFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsNameNode[0].c_str());
920 CPPUNIT_ASSERT_EQUAL(3,(int)its0Node.size());
921 CPPUNIT_ASSERT_EQUAL(-1,its0Node[0].first);
922 CPPUNIT_ASSERT_EQUAL(-1,its0Node[0].second);
923 CPPUNIT_ASSERT_EQUAL(1,its0Node[1].first);
924 CPPUNIT_ASSERT_EQUAL(-1,its0Node[1].second);
925 CPPUNIT_ASSERT_EQUAL(2,its0Node[2].first);
926 CPPUNIT_ASSERT_EQUAL(-1,its0Node[2].second);
927 MEDCouplingFieldDouble *field0Nodes=MEDLoader::ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[0].first,its0Node[0].second);
928 field0Nodes->checkCoherency();
929 CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
930 CPPUNIT_ASSERT_EQUAL(1,field0Nodes->getNumberOfComponents());
931 CPPUNIT_ASSERT_EQUAL(19,field0Nodes->getNumberOfTuples());
932 const double expectedValues3[19]={1.,1.,1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.};
933 double diffValue3[19];
934 std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues3,diffValue3,std::minus<double>());
935 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
936 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
937 constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
938 CPPUNIT_ASSERT(constMesh);
939 field0Nodes->decrRef();
941 field0Nodes=MEDLoader::ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[2].first,its0Node[2].second);
942 field0Nodes->checkCoherency();
943 CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
944 CPPUNIT_ASSERT_EQUAL(1,field0Nodes->getNumberOfComponents());
945 CPPUNIT_ASSERT_EQUAL(19,field0Nodes->getNumberOfTuples());
946 const double expectedValues4[19]={1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.,7.,7.};
947 std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues4,diffValue3,std::minus<double>());
948 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
949 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
950 constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
951 CPPUNIT_ASSERT(constMesh);
952 CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
953 CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
954 CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells());
955 CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes());
956 CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
957 for(int i=0;i<12;i++)
958 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
959 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
960 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
961 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
962 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
963 CPPUNIT_ASSERT_EQUAL((std::size_t)90,constMesh->getNodalConnectivity()->getNbOfElems());
964 CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
965 CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
966 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
967 field0Nodes->decrRef();
969 field0Nodes=MEDLoader::ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[0].first,its0Node[0].second);
970 field0Nodes->checkCoherency();
971 CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
972 CPPUNIT_ASSERT_EQUAL(1,field0Nodes->getNumberOfComponents());
973 CPPUNIT_ASSERT_EQUAL(19,field0Nodes->getNumberOfTuples());
974 const double expectedValues5[19]={1.,1.,1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.};
975 std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues5,diffValue3,std::minus<double>());
976 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
977 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
978 constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
979 CPPUNIT_ASSERT(constMesh);
980 CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
981 CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
982 CPPUNIT_ASSERT_EQUAL(16,constMesh->getNumberOfCells());
983 CPPUNIT_ASSERT_EQUAL(19,constMesh->getNumberOfNodes());
984 CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
985 for(int i=0;i<12;i++)
986 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
987 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
988 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
989 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
990 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
991 CPPUNIT_ASSERT_EQUAL((std::size_t)90,constMesh->getNodalConnectivity()->getNbOfElems());
992 CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
993 CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
994 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
995 field0Nodes->decrRef();
998 void MEDLoaderTest::testMEDLoaderPolygonRead()
1000 using namespace std;
1001 using namespace INTERP_KERNEL;
1003 string fileName=getResourceFile("polygones.med");
1004 vector<string> meshNames=MEDLoader::GetMeshNames(fileName.c_str());
1005 CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
1006 CPPUNIT_ASSERT(meshNames[0]=="Bord");
1007 MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
1008 mesh->checkCoherency();
1009 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1010 CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
1011 CPPUNIT_ASSERT_EQUAL(538,mesh->getNumberOfCells());
1012 CPPUNIT_ASSERT_EQUAL(579,mesh->getNumberOfNodes());
1013 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
1014 for(int i=0;i<514;i++)
1015 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(i));
1016 for(int i=514;i<538;i++)
1017 CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(i));
1018 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+1737,0),1e-12);
1019 const double expectedVals1[12]={1.4851585216522212,-0.5,0.,1.4851585216522212,-0.4,0.,1.4851585216522212,-0.3,0., 1.5741585216522211, -0.5, 0. };
1020 double diffValue1[12];
1021 std::transform(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+12,expectedVals1,diffValue1,std::minus<double>());
1022 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue1,diffValue1+12),1e-12);
1023 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue1,diffValue1+12),1e-12);
1024 CPPUNIT_ASSERT_EQUAL((std::size_t)2768,mesh->getNodalConnectivity()->getNbOfElems());
1025 CPPUNIT_ASSERT_EQUAL(651050,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+2768,0));
1026 CPPUNIT_ASSERT_EQUAL(725943,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+539,0));
1029 std::vector<std::string> fieldsName=MEDLoader::GetCellFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
1030 CPPUNIT_ASSERT_EQUAL(3,(int)fieldsName.size());
1031 CPPUNIT_ASSERT(fieldsName[0]=="bord_:_distorsion");
1032 CPPUNIT_ASSERT(fieldsName[1]=="bord_:_familles");
1033 CPPUNIT_ASSERT(fieldsName[2]=="bord_:_non-ortho");
1034 std::vector<std::pair<int,int> > its0=MEDLoader::GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[0].c_str());
1035 CPPUNIT_ASSERT_EQUAL(1,(int)its0.size());
1036 MEDCouplingFieldDouble *field=MEDLoader::ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[0].c_str(),its0[0].first,its0[0].second);
1037 field->checkCoherency();
1038 CPPUNIT_ASSERT(field->getName()==fieldsName[0]);
1039 CPPUNIT_ASSERT_EQUAL(1,field->getNumberOfComponents());
1040 CPPUNIT_ASSERT_EQUAL(538,field->getNumberOfTuples());
1041 const MEDCouplingUMesh *constMesh=dynamic_cast<const MEDCouplingUMesh *>(field->getMesh());
1042 CPPUNIT_ASSERT(constMesh);
1043 CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
1044 CPPUNIT_ASSERT_EQUAL(2,constMesh->getMeshDimension());
1045 CPPUNIT_ASSERT_EQUAL(538,constMesh->getNumberOfCells());
1046 CPPUNIT_ASSERT_EQUAL(579,constMesh->getNumberOfNodes());
1047 CPPUNIT_ASSERT_EQUAL(2,(int)constMesh->getAllGeoTypes().size());
1048 for(int i=0;i<514;i++)
1049 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,constMesh->getTypeOfCell(i));
1050 for(int i=514;i<538;i++)
1051 CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,constMesh->getTypeOfCell(i));
1052 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+1737,0),1e-12);
1053 std::transform(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+12,expectedVals1,diffValue1,std::minus<double>());
1054 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue1,diffValue1+12),1e-12);
1055 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue1,diffValue1+12),1e-12);
1056 CPPUNIT_ASSERT_EQUAL((std::size_t)2768,constMesh->getNodalConnectivity()->getNbOfElems());
1057 CPPUNIT_ASSERT_EQUAL(651050,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+2768,0));
1058 CPPUNIT_ASSERT_EQUAL(725943,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+539,0));
1059 const double *values=field->getArray()->getPointer();
1060 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.87214203182918,std::accumulate(values,values+538,0.),1e-12);
1064 void MEDLoaderTest::testMEDLoaderPolyhedronRead()
1066 using namespace std;
1067 using namespace INTERP_KERNEL;
1069 string fileName=getResourceFile("poly3D.med");
1070 vector<string> meshNames=MEDLoader::GetMeshNames(fileName.c_str());
1071 CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
1072 CPPUNIT_ASSERT(meshNames[0]=="poly3D");
1073 MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
1074 mesh->checkCoherency();
1075 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1076 CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
1077 CPPUNIT_ASSERT_EQUAL(3,mesh->getNumberOfCells());
1078 CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
1079 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
1080 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(0));
1081 CPPUNIT_ASSERT_EQUAL(NORM_POLYHED,mesh->getTypeOfCell(1));
1082 CPPUNIT_ASSERT_EQUAL(NORM_POLYHED,mesh->getTypeOfCell(2));
1083 CPPUNIT_ASSERT_EQUAL((std::size_t)98,mesh->getNodalConnectivity()->getNbOfElems());
1084 CPPUNIT_ASSERT_EQUAL(725,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+98,0));
1085 CPPUNIT_ASSERT_DOUBLES_EQUAL(110.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
1086 CPPUNIT_ASSERT_EQUAL(155,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+4,0));
1089 mesh=MEDLoader::ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),-1);
1090 mesh->checkCoherency();
1091 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1092 CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
1093 CPPUNIT_ASSERT_EQUAL(17,mesh->getNumberOfCells());
1094 CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
1095 CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllGeoTypes().size());
1096 CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(0));
1097 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(1));
1098 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(2));
1099 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(3));
1100 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(4));
1101 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(5));
1102 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(6));
1103 CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(7));
1104 CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(8));
1105 CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(9));
1106 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(10));
1107 CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(11));
1108 CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(12));
1109 CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(13));
1110 CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(14));
1111 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(15));
1112 CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(16));
1113 CPPUNIT_ASSERT_DOUBLES_EQUAL(110.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
1114 CPPUNIT_ASSERT_EQUAL((std::size_t)83,mesh->getNodalConnectivity()->getNbOfElems());
1115 CPPUNIT_ASSERT_EQUAL(619,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+83,0));
1118 vector<string> families=MEDLoader::GetMeshFamiliesNames(fileName.c_str(),meshNames[0].c_str());
1119 CPPUNIT_ASSERT_EQUAL(4,(int)families.size());
1120 CPPUNIT_ASSERT(families[0]=="FAMILLE_FACE_POLYGONS3");
1121 CPPUNIT_ASSERT(families[1]=="FAMILLE_FACE_QUAD41");
1122 CPPUNIT_ASSERT(families[2]=="FAMILLE_FACE_TRIA32");
1123 CPPUNIT_ASSERT(families[3]=="FAMILLE_ZERO");
1124 vector<string> families2;
1125 families2.push_back(families[0]);
1126 mesh=MEDLoader::ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),-1,families2);
1127 mesh->checkCoherency();
1128 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1129 CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
1130 CPPUNIT_ASSERT_EQUAL(3,mesh->getNumberOfCells());
1131 CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
1132 CPPUNIT_ASSERT_EQUAL(1,(int)mesh->getAllGeoTypes().size());
1133 for(int i=0;i<3;i++)
1134 CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(i));
1135 CPPUNIT_ASSERT_EQUAL((std::size_t)19,mesh->getNodalConnectivity()->getNbOfElems());
1136 CPPUNIT_ASSERT_EQUAL(117,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+19,0));
1139 mesh=MEDLoader::ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),0,families2);
1140 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1141 CPPUNIT_ASSERT_EQUAL(0,mesh->getNumberOfCells());
1142 CPPUNIT_ASSERT_EQUAL(19,mesh->getNumberOfNodes());
1143 CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
1144 CPPUNIT_ASSERT_EQUAL(0,(int)mesh->getAllGeoTypes().size());
1148 std::string MEDLoaderTest::getResourceFile( const std::string& filename ) const
1150 std::string resourceFile = "";
1152 if ( getenv("top_srcdir") ) {
1153 // we are in 'make test' step
1154 resourceFile = getenv("top_srcdir");
1155 resourceFile += "/resources/";
1157 else if ( getenv("MED_ROOT_DIR") ) {
1158 // use MED_ROOT_DIR env.var
1159 resourceFile = getenv("MED_ROOT_DIR");
1160 resourceFile += "/share/salome/resources/med/";
1162 resourceFile += filename;
1163 return resourceFile;
1167 MEDCouplingUMesh *MEDLoaderTest::build1DMesh_1()
1169 double coords[6]={ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 };
1170 int conn[9]={ 0,1, 1,2, 2,3 , 3,4,5};
1171 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
1172 mesh->setName("1DMesh_1");
1173 mesh->setMeshDimension(1);
1174 mesh->allocateCells(4);
1175 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
1176 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
1177 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
1178 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6);
1179 mesh->finishInsertingCells();
1180 DataArrayDouble *myCoords=DataArrayDouble::New();
1181 myCoords->alloc(6,1);
1182 myCoords->setInfoOnComponent(0,"tototototototot [m*m*m*m*m*m*m*m]");
1183 std::copy(coords,coords+6,myCoords->getPointer());
1184 mesh->setCoords(myCoords);
1185 myCoords->decrRef();
1189 MEDCouplingUMesh *MEDLoaderTest::build2DCurveMesh_1()
1191 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 };
1192 int conn[9]={ 0,1, 1,2, 2,3 , 3,4,5};
1193 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
1194 mesh->setName("2DCurveMesh_1");
1195 mesh->setMeshDimension(1);
1196 mesh->allocateCells(4);
1197 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
1198 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
1199 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
1200 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6);
1201 mesh->finishInsertingCells();
1202 DataArrayDouble *myCoords=DataArrayDouble::New();
1203 myCoords->alloc(6,2);
1204 std::copy(coords,coords+12,myCoords->getPointer());
1205 mesh->setCoords(myCoords);
1206 myCoords->decrRef();
1210 MEDCouplingUMesh *MEDLoaderTest::build2DMesh_1()
1212 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 };
1213 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};
1214 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
1215 targetMesh->setMeshDimension(2);
1216 targetMesh->allocateCells(6);
1217 targetMesh->setName("2DMesh_1");
1218 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
1219 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
1220 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
1221 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
1222 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
1223 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POLYGON,4,targetConn+20);
1224 targetMesh->finishInsertingCells();
1225 DataArrayDouble *myCoords=DataArrayDouble::New();
1226 myCoords->alloc(12,2);
1227 myCoords->setInfoOnComponent(0,"tototototototot [m]");
1228 myCoords->setInfoOnComponent(1,"energie [kW]");
1229 std::copy(targetCoords,targetCoords+24,myCoords->getPointer());
1230 targetMesh->setCoords(myCoords);
1231 myCoords->decrRef();
1235 MEDCouplingUMesh *MEDLoaderTest::build2DMesh_2()
1237 double targetCoords[24]={
1238 -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,
1239 -0.05,0.95, 0.2,1.2, 0.45,0.95
1241 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};
1242 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
1243 targetMesh->setMeshDimension(2);
1244 targetMesh->allocateCells(5);
1245 targetMesh->setName("2DMesh_2");
1246 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
1247 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
1248 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
1249 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
1250 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
1251 targetMesh->finishInsertingCells();
1252 DataArrayDouble *myCoords=DataArrayDouble::New();
1253 myCoords->alloc(12,2);
1254 myCoords->setInfoOnComponent(0,"toto [m]");
1255 myCoords->setInfoOnComponent(1,"energie [kW]");
1256 std::copy(targetCoords,targetCoords+24,myCoords->getPointer());
1257 targetMesh->setCoords(myCoords);
1258 myCoords->decrRef();
1262 MEDCouplingUMesh *MEDLoaderTest::build3DSurfMesh_1()
1264 double targetCoords[36]={
1265 -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
1266 ,-0.05,0.95,-0.3, 0.2,1.2,-0.3, 0.45,0.95,-0.3
1268 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};
1269 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
1270 targetMesh->setMeshDimension(2);
1271 targetMesh->allocateCells(6);
1272 targetMesh->setName("3DSurfMesh_1");
1273 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
1274 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
1275 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
1276 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
1277 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
1278 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POLYGON,4,targetConn+20);
1279 targetMesh->finishInsertingCells();
1280 DataArrayDouble *myCoords=DataArrayDouble::New();
1281 myCoords->alloc(12,3);
1282 myCoords->setInfoOnComponent(0,"toto [m]");
1283 myCoords->setInfoOnComponent(2,"ff [km]");//component 1 is not set for test
1284 std::copy(targetCoords,targetCoords+36,myCoords->getPointer());
1285 targetMesh->setCoords(myCoords);
1286 myCoords->decrRef();
1290 MEDCouplingUMesh *MEDLoaderTest::build3DMesh_1()
1292 double coords[180]={
1293 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.,
1294 3.,2.,0., 0.,1.,0., 1.,3.,0., 2.,2.,0., 2.,3.,0.,
1295 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.,
1296 3.,2.,1., 0.,1.,1., 1.,3.,1., 2.,2.,1., 2.,3.,1.,
1297 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.,
1298 3.,2.,2., 0.,1.,2., 1.,3.,2., 2.,2.,2., 2.,3.,2.,
1299 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.,
1300 3.,2.,3., 0.,1.,3., 1.,3.,3., 2.,2.,3., 2.,3.,3.};
1304 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,
1305 1,6,5,3,16,21,20,18, 13,10,9,6,28,25,24,21,
1306 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,
1307 7,12,14,13,22,27,29,28,
1309 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,
1310 16,21,20,18,31,36,35,33, 28,25,24,21,43,40,39,36,
1311 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,
1312 22,27,29,28,37,42,44,43,
1314 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,
1315 31,36,35,33,46,51,50,48, 43,40,39,36,58,55,54,51,
1316 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,
1317 37,42,44,43,52,57,59,58
1320 MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
1321 ret->setName("3DMesh_1");
1322 ret->setMeshDimension(3);
1323 ret->allocateCells(18);
1325 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
1326 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+51);
1327 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+59);
1328 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+110);
1330 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+118);
1331 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+169);
1332 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+177);
1333 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+228);
1335 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+236);
1336 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+287);
1337 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+295);
1338 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+346);
1340 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+8);
1341 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+67);
1342 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+126);
1343 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+185);
1344 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+244);
1345 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+303);
1347 ret->finishInsertingCells();
1348 DataArrayDouble *myCoords=DataArrayDouble::New();
1349 myCoords->alloc(60,3);
1350 myCoords->setInfoOnComponent(0,"titi [m]");
1351 myCoords->setInfoOnComponent(1,"density power [MW/m^3]");
1352 myCoords->setInfoOnComponent(2,"t [kW]");
1353 std::copy(coords,coords+180,myCoords->getPointer());
1354 ret->setCoords(myCoords);
1355 myCoords->decrRef();
1359 MEDCouplingUMesh *MEDLoaderTest::build3DMesh_2()
1361 MEDCouplingUMesh *m3dsurfBase=build3DSurfMesh_1();
1362 int numbers[5]={0,1,2,3,5};
1363 MEDCouplingUMesh *m3dsurf=(MEDCouplingUMesh *)m3dsurfBase->buildPartOfMySelf(numbers,numbers+5,false);
1364 m3dsurfBase->decrRef();
1365 MEDCouplingUMesh *m1dBase=build1DMesh_1();
1366 int numbers2[4]={0,1,2,3};
1367 MEDCouplingUMesh *m1d=(MEDCouplingUMesh *)m1dBase->buildPartOfMySelf(numbers2,numbers2+4,false);
1369 m1d->changeSpaceDimension(3);
1370 const double vec[3]={0.,1.,0.};
1371 const double pt[3]={0.,0.,0.};
1372 m1d->rotate(pt,vec,-M_PI/2.);
1373 MEDCouplingUMesh *ret=m3dsurf->buildExtrudedMesh(m1d,0);
1379 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnCells_1()
1381 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1382 int nbOfCells=mesh->getNumberOfCells();
1383 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1384 f1->setName("VectorFieldOnCells");
1386 DataArrayDouble *array=DataArrayDouble::New();
1387 array->alloc(nbOfCells,3);
1388 array->setInfoOnComponent(0,"power [MW/m^3]");
1389 array->setInfoOnComponent(1,"density [g/cm^3]");
1390 array->setInfoOnComponent(2,"temperature [K]");
1391 f1->setArray(array);
1393 double *tmp=array->getPointer();
1394 const double arr1[18]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.};
1395 std::copy(arr1,arr1+18,tmp);
1396 f1->setTime(2.,0,1);
1397 f1->checkCoherency();
1402 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnNodes_1()
1404 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1405 int nbOfNodes=mesh->getNumberOfNodes();
1406 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
1407 f1->setName("VectorFieldOnNodes");
1409 DataArrayDouble *array=DataArrayDouble::New();
1410 array->alloc(nbOfNodes,3);
1411 f1->setArray(array);
1412 array->setInfoOnComponent(0,"power [MW/m^3]");
1413 array->setInfoOnComponent(1,"density [g/cm^3]");
1414 array->setInfoOnComponent(2,"temperature [K]");
1416 double *tmp=array->getPointer();
1417 const double arr1[36]={
1418 70.,80.,90.,71.,81.,91.,72.,82.,92.,73.,83.,93.,74.,84.,94.,75.,85.,95.,
1419 1000.,10010.,10020.,1001.,10011.,10021.,1002.,10012.,10022.,1003.,10013.,10023.,1004.,10014.,10024.,1005.,10015.,10025.,
1421 std::copy(arr1,arr1+36,tmp);
1422 f1->setTime(2.12,2,3);
1423 f1->checkCoherency();
1428 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGauss_1()
1430 const double _a=0.446948490915965;
1431 const double _b=0.091576213509771;
1432 const double _p1=0.11169079483905;
1433 const double _p2=0.0549758718227661;
1434 const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
1435 const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
1436 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
1437 const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
1438 std::vector<double> _refCoo1(refCoo1,refCoo1+6);
1439 std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
1440 std::vector<double> _wg1(wg1,wg1+6);
1441 MEDCouplingUMesh *m=build2DMesh_2();
1442 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,ONE_TIME);
1443 f->setTime(3.14,1,5);
1445 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
1446 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 };
1447 std::vector<double> _refCoo2(refCoo2,refCoo2+12);
1448 std::vector<double> _gsCoo2(_gsCoo1);
1449 std::vector<double> _wg2(_wg1);
1450 _gsCoo2.resize(6); _wg2.resize(3);
1451 const double refCoo3[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
1452 std::vector<double> _refCoo3(refCoo3,refCoo3+8);
1453 _gsCoo1.resize(4); _wg1.resize(2);
1454 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo3,_gsCoo1,_wg1);
1455 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI6,_refCoo2,_gsCoo2,_wg2);
1456 DataArrayDouble *array=DataArrayDouble::New();
1458 double *ptr=array->getPointer();
1459 for(int i=0;i<19*2;i++)
1460 ptr[i]=(double)(i+7);
1462 f->setName("MyFirstFieldOnGaussPoint");
1463 array->setInfoOnComponent(0,"power [MW/m^3]");
1464 array->setInfoOnComponent(1,"density");
1466 f->checkCoherency();
1471 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGaussNE_1()
1473 MEDCouplingUMesh *m=build2DMesh_2();
1474 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,ONE_TIME);
1475 f->setTime(3.14,1,5);
1477 DataArrayDouble *array=DataArrayDouble::New();
1479 double *ptr=array->getPointer();
1480 for(int i=0;i<20*2;i++)
1481 ptr[i]=(double)(i+8);
1483 array->setInfoOnComponent(0,"power [W]");
1484 array->setInfoOnComponent(1,"temperature");
1485 f->setName("MyFieldOnGaussNE");
1487 f->checkCoherency();