1 // Copyright (C) 2007-2024 CEA, EDF
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 "MEDCouplingCMesh.hxx"
23 #include "MEDLoader.hxx"
24 #include "MEDLoaderBase.hxx"
25 #include "MEDCouplingUMesh.hxx"
26 #include "MEDCouplingFieldDouble.hxx"
27 #include "MEDCouplingFieldFloat.hxx"
28 #include "MEDCouplingFieldInt64.hxx"
29 #include "MEDCouplingMemArray.hxx"
30 #include "TestInterpKernelUtils.hxx" // getResourceFile()
31 #include "MEDFileMesh.hxx"
36 using namespace MEDCoupling;
38 void MEDLoaderTest::testMesh1DRW()
40 MEDCouplingUMesh *mesh=build1DMesh_1();
41 mesh->checkConsistencyLight();
42 WriteUMesh("file1.med",mesh,true);
43 MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile("file1.med",mesh->getName().c_str(),0);
44 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
49 void MEDLoaderTest::testMesh2DCurveRW()
51 MEDCouplingUMesh *mesh=build2DCurveMesh_1();
52 mesh->checkConsistencyLight();
53 WriteUMesh("file2.med",mesh,true);
54 MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile("file2.med",mesh->getName().c_str(),0);
55 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
60 void MEDLoaderTest::testMesh2DRW()
62 MEDCouplingUMesh *mesh=build2DMesh_1();
63 mesh->checkConsistencyLight();
64 WriteUMesh("file3.med",mesh,true);
65 MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile("file3.med",mesh->getName().c_str(),0);
66 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
71 void MEDLoaderTest::testMesh3DSurfRW()
73 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
74 mesh->checkConsistencyLight();
75 WriteUMesh("file4.med",mesh,true);
76 MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile("file4.med",mesh->getName().c_str(),0);
77 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
82 void MEDLoaderTest::testMesh3DRW()
84 MEDCouplingUMesh *mesh=build3DMesh_1();
85 mesh->checkConsistencyLight();
86 WriteUMesh("file5.med",mesh,true);
87 MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile("file5.med",mesh->getName().c_str(),0);
88 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
94 * Most basic test : one and only one MEDCoupling field in a new file.
96 void MEDLoaderTest::testFieldRW1()
98 MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
99 WriteField("file6.med",f1,true);
100 MEDCouplingFieldDouble *f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell("file6.med",f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),0,1));
101 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
105 f1=buildVecFieldOnNodes_1();
106 WriteField("file7.med",f1,true);
107 f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode("file7.med",f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,3));
108 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
109 // testing kind message on error of field type.
110 CPPUNIT_ASSERT_THROW(ReadFieldCell("file7.med",f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,3),INTERP_KERNEL::Exception);
117 * Multi field writing in a same file.
119 void MEDLoaderTest::testFieldRW2()
121 const char fileName[]="file8.med";
122 static const double VAL1=12345.67890314;
123 static const double VAL2=-1111111111111.;
124 MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
125 MEDCouplingFieldInt *f1_int=buildIntVecFieldOnCells_1();
126 MEDCouplingFieldFloat *f1_fl=buildFloatVecFieldOnCells_1();
127 MEDCouplingFieldInt64 *f1_int64=buildInt64VecFieldOnCells_1();
128 WriteField(fileName,f1,true);
129 f1->setTime(10.,8,9);
130 f1_int->setTime(10.,8,9);
131 f1_fl->setTime(10.,8,9);
132 f1_int64->setTime(10.,8,9);
133 double *tmp=f1->getArray()->getPointer();
135 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
136 f1->setTime(10.14,18,19);
138 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
139 // Write int and float fields:
140 WriteFieldUsingAlreadyWrittenMesh(fileName,f1_int);
141 WriteFieldUsingAlreadyWrittenMesh(fileName,f1_int64);
142 WriteFieldUsingAlreadyWrittenMesh(fileName,f1_fl);
143 //retrieving time steps...
144 MEDCouplingFieldDouble *f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),8,9));
145 f1->setTime(10.,8,9);
147 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
149 f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),0,1));
150 MEDCouplingFieldDouble *f3=buildVecFieldOnCells_1();
151 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
154 f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),18,19));
155 f1->setTime(10.14,18,19);
157 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
158 //test of throw on invalid (dt,it)
159 CPPUNIT_ASSERT_THROW(ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),28,19),INTERP_KERNEL::Exception);
162 // Reading Int and Float fields:
163 MEDCouplingFieldInt *f2_int=dynamic_cast<MEDCouplingFieldInt *>(ReadFieldCell(fileName,f1_int->getMesh()->getName().c_str(),0,f1_int->getName().c_str(),8,9));
164 CPPUNIT_ASSERT(f1_int->isEqual(f2_int,1e-12,0)); // exact equality for int values
167 MEDCouplingFieldInt64 *f2_int64=dynamic_cast<MEDCouplingFieldInt64 *>(ReadFieldCell(fileName,f1_int64->getMesh()->getName().c_str(),0,f1_int64->getName().c_str(),8,9));
168 CPPUNIT_ASSERT(f1_int64->isEqual(f2_int64,1e-12,0)); // exact equality for int values
171 MEDCouplingFieldFloat *f2_fl=dynamic_cast<MEDCouplingFieldFloat *>(ReadFieldCell(fileName,f1_fl->getMesh()->getName().c_str(),0,f1_fl->getName().c_str(),8,9));
172 CPPUNIT_ASSERT(f1_fl->isEqual(f2_fl,1e-12,1e-07f)); // float comparison
176 f1=buildVecFieldOnNodes_1();
177 const char fileName2[]="file9.med";
178 WriteField(fileName2,f1,true);
179 f1->setTime(110.,108,109);
180 tmp=f1->getArray()->getPointer();
182 WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
183 f1->setTime(210.,208,209);
185 WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
186 f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName2,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),108,109));
187 f1->setTime(110.,108,109);
189 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
191 f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName2,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,3));
192 f3=buildVecFieldOnNodes_1();
193 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
196 f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName2,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),208,209));
197 f1->setTime(210.,208,209);
199 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
205 * Multi field in a same file, but this field has several timesteps
207 void MEDLoaderTest::testFieldRW3()
209 const char fileName[]="file11.med";
210 static const double VAL1=12345.67890314;
211 static const double VAL2=-1111111111111.;
212 const char name1[]="AField";
213 const char name3[]="AMesh1";
214 MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
215 (const_cast<MEDCouplingMesh *>(f1->getMesh()))->setName(name3);
217 f1->setTime(10.,8,9);
218 double *tmp=f1->getArray()->getPointer();
220 WriteField(fileName,f1,true);
221 f1->setTime(10.14,18,19);
223 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
224 f1->setTime(10.55,28,29);
226 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
227 f1->setTime(10.66,38,39);
229 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
230 f1->setTime(10.77,48,49);
232 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
235 f1=buildVecFieldOnNodes_1();
237 (const_cast<MEDCouplingMesh *>(f1->getMesh()))->setName(name3);
238 f1->setTime(110.,8,9);
239 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
240 f1->setTime(110.,108,109);
241 tmp=f1->getArray()->getPointer();
243 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
244 f1->setTime(210.,208,209);
246 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
248 std::vector< std::pair<int,int> > it1=GetCellFieldIterations(fileName,name3,name1);
249 CPPUNIT_ASSERT_EQUAL(5,(int)it1.size());
250 CPPUNIT_ASSERT_EQUAL(8,it1[0].first); CPPUNIT_ASSERT_EQUAL(9,it1[0].second);
251 CPPUNIT_ASSERT_EQUAL(18,it1[1].first); CPPUNIT_ASSERT_EQUAL(19,it1[1].second);
252 CPPUNIT_ASSERT_EQUAL(28,it1[2].first); CPPUNIT_ASSERT_EQUAL(29,it1[2].second);
253 CPPUNIT_ASSERT_EQUAL(38,it1[3].first); CPPUNIT_ASSERT_EQUAL(39,it1[3].second);
254 CPPUNIT_ASSERT_EQUAL(48,it1[4].first); CPPUNIT_ASSERT_EQUAL(49,it1[4].second);
255 std::vector< std::pair<int,int> > it3=GetNodeFieldIterations(fileName,name3,name1);
256 CPPUNIT_ASSERT_EQUAL(3,(int)it3.size());
257 CPPUNIT_ASSERT_EQUAL(8,it3[0].first); CPPUNIT_ASSERT_EQUAL(9,it3[0].second);
258 CPPUNIT_ASSERT_EQUAL(108,it3[1].first); CPPUNIT_ASSERT_EQUAL(109,it3[1].second);
259 CPPUNIT_ASSERT_EQUAL(208,it3[2].first); CPPUNIT_ASSERT_EQUAL(209,it3[2].second);
263 f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,name3,0,name1,8,9));
264 CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[0],1e-13);
266 f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,name3,0,name1,18,19));
267 CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[0],1e-13);
269 f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,name3,0,name1,28,29));
270 CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL1,f1->getArray()->getConstPointer()[0],1e-13);
272 f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,name3,0,name1,38,39));
273 CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
275 f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,name3,0,name1,48,49));
276 CPPUNIT_ASSERT_DOUBLES_EQUAL(4*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
279 f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName,name3,0,name1,8,9));
280 CPPUNIT_ASSERT_DOUBLES_EQUAL(71.,f1->getArray()->getConstPointer()[3],1e-13);
282 f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName,name3,0,name1,108,109));
283 CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[3],1e-13);
285 f1=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName,name3,0,name1,208,209));
286 CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[3],1e-13);
290 void MEDLoaderTest::testMultiMeshRW1()
292 const char fileName[]="file10.med";
293 MEDCouplingUMesh *mesh1=build3DMesh_1();
294 const mcIdType part1[5]={1,2,4,13,15};
295 MEDCouplingUMesh *mesh2=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part1,part1+5,true);
296 mesh2->setName("mesh2");
297 const mcIdType part2[4]={3,4,13,14};
298 MEDCouplingUMesh *mesh3=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part2,part2+4,true);
299 mesh3->setName("mesh3");
300 MEDCouplingUMesh *mesh4=MEDCouplingUMesh::New();
301 mesh4->setName("mesh4");
302 mesh4->setMeshDimension(3);
303 mesh4->allocateCells(1);
304 mcIdType conn[4]={0,11,1,3};
305 mesh4->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,conn);
306 mesh4->finishInsertingCells();
307 mesh4->setCoords(mesh1->getCoords());
308 std::vector<const MEDCouplingUMesh *> meshes;
309 meshes.push_back(mesh1);
310 meshes.push_back(mesh2);
311 meshes.push_back(mesh3);
312 meshes.push_back(mesh4);
313 const char mnane[]="3DToto";
314 WriteUMeshesPartition(fileName,mnane,meshes,true);
316 MEDCouplingUMesh *mesh5=ReadUMeshFromFile(fileName,mnane);
317 mesh1->setName(mnane);
318 const mcIdType part3[18]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
319 MEDCouplingUMesh *mesh6=(MEDCouplingUMesh *)mesh5->buildPartOfMySelf(part3,part3+18,true);
320 mesh6->setName(mnane);
322 CPPUNIT_ASSERT(mesh6->isEqual(mesh1,1e-12));
324 std::vector<std::string> grps=GetMeshGroupsNames(fileName,mnane);
325 CPPUNIT_ASSERT_EQUAL(4,(int)grps.size());
326 CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh2"))!=grps.end());
327 CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh3"))!=grps.end());
328 CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh4"))!=grps.end());
329 CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("3DMesh_1"))!=grps.end());
331 std::vector<std::string> vec;
332 vec.push_back(std::string("mesh2"));
333 MEDCouplingUMesh *mesh2_2=ReadUMeshFromGroups(fileName,mnane,0,vec);
334 CPPUNIT_ASSERT(mesh2_2->isEqual(mesh2,1e-12));
336 vec.clear(); vec.push_back(std::string("mesh3"));
337 MEDCouplingUMesh *mesh3_2=ReadUMeshFromGroups(fileName,mnane,0,vec);
338 CPPUNIT_ASSERT(mesh3_2->isEqual(mesh3,1e-12));
340 vec.clear(); vec.push_back(std::string("mesh4"));
341 MEDCouplingUMesh *mesh4_2=ReadUMeshFromGroups(fileName,mnane,0,vec);
342 CPPUNIT_ASSERT(mesh4_2->isEqual(mesh4,1e-12));
344 vec.clear(); vec.push_back(std::string("3DMesh_1"));
345 MEDCouplingUMesh *mesh1_2=ReadUMeshFromGroups(fileName,mnane,0,vec);
346 mesh1->setName("3DMesh_1");
347 CPPUNIT_ASSERT(mesh1_2->isEqual(mesh1,1e-12));
350 vec.clear(); vec.push_back(std::string("Family_-3")); vec.push_back(std::string("Family_-5"));
351 mesh2_2=ReadUMeshFromFamilies(fileName,mnane,0,vec);
352 mesh2_2->setName("mesh2");
353 CPPUNIT_ASSERT(mesh2_2->isEqual(mesh2,1e-12));
356 std::vector<std::string> ret(GetMeshFamiliesNamesOnGroup(fileName,"3DToto","3DMesh_1"));
357 std::set<std::string> s(ret.begin(),ret.end());
358 std::set<std::string> ref_s;
359 ref_s.insert("Family_-2");
360 ref_s.insert("Family_-3");
361 ref_s.insert("Family_-4");
362 ref_s.insert("Family_-5");
363 CPPUNIT_ASSERT_EQUAL(4,(int)ret.size());
364 CPPUNIT_ASSERT(s==ref_s);
366 std::vector<std::string> ret1=GetMeshGroupsNamesOnFamily(fileName,"3DToto","Family_-3");
367 CPPUNIT_ASSERT_EQUAL(2,(int)ret1.size());
368 CPPUNIT_ASSERT(ret1[0]=="3DMesh_1");
369 CPPUNIT_ASSERT(ret1[1]=="mesh2");
377 void MEDLoaderTest::testFieldProfilRW1()
379 const char fileName[]="file12.med";
380 MEDCouplingUMesh *mesh1=build3DMesh_1();
382 mcIdType newNbOfNodes;
383 DataArrayIdType *da=mesh1->mergeNodes(1e-12,b,newNbOfNodes);
385 WriteUMesh(fileName,mesh1,true);
386 const mcIdType part1[5]={1,2,4,13,15};
387 MEDCouplingUMesh *mesh2=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part1,part1+5,true);
388 mesh2->setName(mesh1->getName().c_str());// <- important for the test
390 mcIdType nbOfCells=mesh2->getNumberOfCells();
391 CPPUNIT_ASSERT_EQUAL(ToIdType(5),nbOfCells);
392 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
393 f1->setName("VectorFieldOnCells");
395 DataArrayDouble *array=DataArrayDouble::New();
396 array->alloc(nbOfCells,2);
399 double *tmp=array->getPointer();
400 const double arr1[10]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.};
401 std::copy(arr1,arr1+10,tmp);
402 f1->setTime(3.14,2,7);
403 f1->checkConsistencyLight();
405 WriteField(fileName,f1,false);// <- false important for the test
407 MEDCouplingFieldDouble *f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,7));
408 std::vector<MEDCoupling::TypeOfField> types=GetTypesOfField(fileName,f1->getMesh()->getName().c_str(),f1->getName().c_str());
409 CPPUNIT_ASSERT_EQUAL(1,(int)types.size());
410 CPPUNIT_ASSERT(types[0]==ON_CELLS);
411 f2->checkConsistencyLight();
412 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
421 * Test MED file profiles.
423 void MEDLoaderTest::testFieldNodeProfilRW1()
425 const char fileName[]="file19.med";
426 const char fileName2[]="file20.med";
427 MEDCouplingUMesh *m=build2DMesh_1();
428 mcIdType nbOfNodes=m->getNumberOfNodes();
429 WriteUMesh(fileName,m,true);
430 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
431 f1->setName("VFieldOnNodes");
433 DataArrayDouble *array=DataArrayDouble::New();
434 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.};
435 array->alloc(nbOfNodes,2);
436 std::copy(arr1,arr1+24,array->getPointer());
438 array->setInfoOnComponent(0,"tyty [mm]");
439 array->setInfoOnComponent(1,"uiop [MW]");
441 f1->setTime(3.14,2,7);
442 f1->checkConsistencyLight();
443 const mcIdType arr2[2]={1,4};//node ids are 2,4,5,3,6,7
444 MEDCouplingFieldDouble *f2=f1->buildSubPart(arr2,arr2+2);
445 (const_cast<MEDCouplingMesh *>(f2->getMesh()))->setName(f1->getMesh()->getName().c_str());
446 WriteField(fileName,f2,false);// <- false important for the test
448 MEDCouplingFieldDouble *f3=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName,f2->getMesh()->getName().c_str(),0,f2->getName().c_str(),2,7));
449 f3->checkConsistencyLight();
450 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
453 const mcIdType arr3[6]={1,3,0,5,2,4};
454 f2->renumberNodes(arr3);
455 WriteUMesh(fileName2,m,true);
456 WriteField(fileName2,f2,false);// <- false important for the test
457 f3=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName2,f2->getMesh()->getName().c_str(),0,f2->getName().c_str(),2,7));
458 f3->checkConsistencyLight();
459 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
467 void MEDLoaderTest::testFieldNodeProfilRW2()
469 const char fileName[]="file23.med";
470 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
471 WriteUMesh(fileName,mesh,true);
473 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
474 f1->setName("FieldMix");
476 const double arr2[24]={
477 1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
478 1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
480 DataArrayDouble *array=DataArrayDouble::New();
483 array->setInfoOnComponent(0,"plkj [mm]");
484 array->setInfoOnComponent(1,"pqqqss [mm]");
486 double *tmp=array->getPointer();
487 std::copy(arr2,arr2+24,tmp);
488 f1->setTime(3.17,2,7);
490 const mcIdType renumArr[12]={3,7,2,1,5,11,10,0,9,6,8,4};
491 f1->renumberNodes(renumArr);
492 f1->checkConsistencyLight();
493 WriteField(fileName,f1,false);// <- false important for the test
494 MEDCouplingFieldDouble *f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldNode(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,7));
495 CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
502 void MEDLoaderTest::testFieldGaussRW1()
504 const char fileName[]="file13.med";
505 MEDCouplingFieldDouble *f1=buildVecFieldOnGauss_1();
506 WriteField(fileName,f1,true);
507 MCAuto<MEDCouplingField> f2Tmp(ReadField(ON_GAUSS_PT,fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),1,5));
508 MCAuto<MEDCouplingFieldDouble> f2(MEDCoupling::DynamicCast<MEDCouplingField,MEDCouplingFieldDouble>(f2Tmp));
509 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
513 void MEDLoaderTest::testFieldGaussNERW1()
515 const char fileName[]="file14.med";
516 MEDCouplingFieldDouble *f1=buildVecFieldOnGaussNE_1();
517 WriteField(fileName,f1,true);
518 std::vector<MEDCoupling::TypeOfField> tof(GetTypesOfField(fileName,"2DMesh_2","MyFieldOnGaussNE"));
519 CPPUNIT_ASSERT_EQUAL(1,(int)tof.size());
520 CPPUNIT_ASSERT(ON_GAUSS_NE==tof[0]);
521 MCAuto<MEDCouplingField> f2Tmp(ReadField(ON_GAUSS_NE,fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),1,5));
522 MCAuto<MEDCouplingFieldDouble> f2(MEDCoupling::DynamicCast<MEDCouplingField,MEDCouplingFieldDouble>(f2Tmp));
523 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
527 void MEDLoaderTest::testLittleStrings1()
529 std::string s("azeeeerrrtty");
530 MEDLoaderBase::zipEqualConsChar(s,3);
531 CPPUNIT_ASSERT(s=="azertty");
534 void MEDLoaderTest::testSplitIntoNameAndUnit1()
536 std::string s(" []");
538 MEDLoaderBase::splitIntoNameAndUnit(s,c,u);
539 CPPUNIT_ASSERT(c.empty());
540 CPPUNIT_ASSERT(u.empty());
542 MEDLoaderBase::strip(s);
543 CPPUNIT_ASSERT(s=="lmmm kki jjj");
545 MEDLoaderBase::strip(s);
546 CPPUNIT_ASSERT(s.empty());
548 MEDLoaderBase::strip(s);
549 CPPUNIT_ASSERT(s.empty());
551 MEDLoaderBase::strip(s);
552 CPPUNIT_ASSERT(s.empty());
554 MEDLoaderBase::strip(s);
555 CPPUNIT_ASSERT(s=="pp");
558 void MEDLoaderTest::testMesh3DSurfShuffleRW()
560 const char fileName[]="file15.med";
561 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
562 const mcIdType renumber1[6]={2,5,1,0,3,4};
563 mesh->renumberCells(renumber1,false);
564 mesh->checkConsistencyLight();
565 WriteUMesh(fileName,mesh,true);
566 MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile(fileName,mesh->getName().c_str(),0);
567 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
572 void MEDLoaderTest::testFieldShuffleRW1()
574 const char fileName[]="file16.med";
575 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
576 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
577 f1->setName("FieldOnCellsShuffle");
579 DataArrayDouble *array=DataArrayDouble::New();
583 double *tmp=array->getPointer();
584 const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
585 std::copy(arr1,arr1+12,tmp);
586 f1->setTime(3.14,2,7);
587 f1->checkConsistencyLight();
589 const mcIdType renumber1[6]={2,1,5,0,3,4};
590 f1->renumberCells(renumber1,false);
591 WriteField(fileName,f1,true);
592 MEDCouplingFieldDouble *f2=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldCell(fileName,mesh->getName().c_str(),0,f1->getName().c_str(),2,7));
593 CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
601 * Shuffle de cells but no profile. Like pointe.med
603 void MEDLoaderTest::testMultiFieldShuffleRW1()
605 const char fileName[]="file17.med";
606 MEDCouplingUMesh *m=build3DMesh_2();
607 CPPUNIT_ASSERT_EQUAL(20,(int)m->getNumberOfCells());
608 CPPUNIT_ASSERT_EQUAL(ToIdType(45),m->getNumberOfNodes());
609 const mcIdType polys[3]={1,4,6};
610 std::vector<mcIdType> poly2(polys,polys+3);
611 m->convertToPolyTypes(&poly2[0],&poly2[0]+poly2.size());
612 const mcIdType renum[20]={1,3,2,8,9,12,13,16,19,0,4,7,5,15,14,17,10,18,6,11};
613 m->renumberCells(renum,false);
614 m->orientCorrectlyPolyhedrons();
616 WriteUMesh(fileName,m,true);
617 MEDCouplingFieldDouble *f1Tmp=m->getMeasureField(false);
618 MEDCouplingFieldDouble *f1=f1Tmp->buildNewTimeReprFromThis(ONE_TIME,false);
621 MEDCouplingFieldDouble *f_1=f1->cloneWithMesh(true);
622 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
623 f1->applyFunc("2*x");
624 f1->setTime(0.01,3,4);
625 MEDCouplingFieldDouble *f_2=f1->cloneWithMesh(true);
626 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
627 f1->applyFunc("2*x/3");
628 f1->setTime(0.02,5,6);
629 MEDCouplingFieldDouble *f_3=f1->cloneWithMesh(true);
630 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
633 std::vector<std::pair<int,int> > its;
634 its.push_back(std::pair<int,int>(1,2));
635 its.push_back(std::pair<int,int>(3,4));
636 its.push_back(std::pair<int,int>(5,6));
637 std::vector<MEDCouplingFieldDouble *> fs=ReadFieldsOnSameMesh(ON_CELLS,fileName,f_1->getMesh()->getName().c_str(),0,f_1->getName().c_str(),its);
638 CPPUNIT_ASSERT_EQUAL(3,(int)fs.size());
639 const MEDCouplingMesh *mm=fs[0]->getMesh();
640 CPPUNIT_ASSERT(fs[0]->isEqual(f_1,1e-12,1e-12));
641 CPPUNIT_ASSERT(fs[1]->isEqual(f_2,1e-12,1e-12));
642 CPPUNIT_ASSERT(fs[2]->isEqual(f_3,1e-12,1e-12));
643 CPPUNIT_ASSERT(mm==fs[1]->getMesh());// <- important for the test
644 CPPUNIT_ASSERT(mm==fs[2]->getMesh());// <- important for the test
645 for(std::vector<MEDCouplingFieldDouble *>::iterator iter=fs.begin();iter!=fs.end();iter++)
655 void MEDLoaderTest::testWriteUMeshesRW1()
657 const char fileName[]="file18.med";
658 MEDCouplingUMesh *m3d=build3DMesh_2();
659 const double pt[3]={0.,0.,-0.3};
660 const double vec[3]={0.,0.,1.};
661 std::vector<mcIdType> nodes;
662 m3d->findNodesOnPlane(pt,vec,1e-12,nodes);
663 MEDCouplingUMesh *m2d=(MEDCouplingUMesh *)m3d->buildFacePartOfMySelfNode(&nodes[0],&nodes[0]+nodes.size(),true);
664 const mcIdType renumber[5]={1,2,0,4,3};
665 m2d->renumberCells(renumber,false);
666 m2d->setName("ExampleOfMultiDimW");
667 std::vector<const MEDCouplingUMesh *> meshes;
668 meshes.push_back(m2d);
669 meshes.push_back(m3d);
670 WriteUMeshes(fileName,meshes,true);
671 MEDCouplingUMesh *m3d_bis=ReadUMeshFromFile(fileName,m2d->getName().c_str(),0);
672 CPPUNIT_ASSERT(!m3d_bis->isEqual(m3d,1e-12));
673 m3d_bis->setName(m3d->getName().c_str());
674 CPPUNIT_ASSERT(m3d_bis->isEqual(m3d,1e-12));
675 MEDCouplingUMesh *m2d_bis=ReadUMeshFromFile(fileName,m2d->getName().c_str(),-1);//-1 for faces
676 CPPUNIT_ASSERT(m2d_bis->isEqual(m2d,1e-12));
677 // Creation of a field on faces.
678 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
679 f1->setName("FieldOnFacesShuffle");
681 DataArrayDouble *array=DataArrayDouble::New();
682 array->alloc(m2d->getNumberOfCells(),2);
683 array->setInfoOnComponent(0,"plkj [mm]");
684 array->setInfoOnComponent(1,"pqqqss [mm]");
687 double *tmp=array->getPointer();
688 const double arr1[10]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.};
689 std::copy(arr1,arr1+10,tmp);
690 f1->setTime(3.14,2,7);
691 f1->checkConsistencyLight();
692 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
693 MEDCouplingFieldDouble *f2=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),-1,f1->getName().c_str(),2,7));
694 CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
704 void MEDLoaderTest::testMixCellAndNodesFieldRW1()
706 const char fileName[]="file21.med";
707 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
708 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
709 f1->setName("FieldMix");
711 DataArrayDouble *array=DataArrayDouble::New();
714 array->setInfoOnComponent(0,"plkj [mm]");
715 array->setInfoOnComponent(1,"pqqqss [mm]");
717 double *tmp=array->getPointer();
718 const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
719 std::copy(arr1,arr1+12,tmp);
720 f1->setTime(3.14,2,7);
721 f1->checkConsistencyLight();
723 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
724 f2->setName("FieldMix");
726 array=DataArrayDouble::New();
729 array->setInfoOnComponent(0,"plkj [mm]");
730 array->setInfoOnComponent(1,"pqqqss [mm]");
732 tmp=array->getPointer();
733 const double arr2[24]={
734 1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
735 1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
737 std::copy(arr2,arr2+24,tmp);
738 f2->setTime(3.14,2,7);
739 f2->checkConsistencyLight();
741 WriteField(fileName,f1,true);
742 std::vector<MEDCoupling::TypeOfField> ts=GetTypesOfField(fileName,f1->getMesh()->getName().c_str(),f1->getName().c_str());
743 CPPUNIT_ASSERT_EQUAL(1,(int)ts.size());
744 CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[0]);
745 std::vector<std::string> fs=GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName().c_str());
746 CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
747 CPPUNIT_ASSERT(fs[0]=="FieldMix");
748 WriteFieldUsingAlreadyWrittenMesh(fileName,f2);
749 fs=GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName().c_str());
750 CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
751 CPPUNIT_ASSERT(fs[0]=="FieldMix");
753 ts=GetTypesOfField(fileName,f1->getMesh()->getName().c_str(),f1->getName().c_str());
754 CPPUNIT_ASSERT_EQUAL(2,(int)ts.size());
755 CPPUNIT_ASSERT_EQUAL(ON_NODES,ts[0]);
756 CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[1]);
758 MEDCouplingFieldDouble *f3=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldNode(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,7));
759 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
761 f3=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),2,7));
762 CPPUNIT_ASSERT(f3->isEqual(f1,1e-12,1e-12));
770 void MEDLoaderTest::testGetAllFieldNamesRW1()
772 const char fileName[]="file22.med";
773 MEDCouplingUMesh *mesh=build2DMesh_2();
774 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
775 f1->setName("Field1");
776 f1->setTime(3.44,5,6);
778 f1->fillFromAnalytic(2,"x+y");
779 WriteField(fileName,f1,true);
780 f1->setTime(1002.3,7,8);
781 f1->fillFromAnalytic(2,"x+77.*y");
782 WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
783 f1->setName("Field2");
784 WriteField(fileName,f1,false);
785 f1->setName("Field3");
786 mesh->setName("2DMesh_2Bis");
787 WriteField(fileName,f1,false);
789 f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
790 f1->setName("Field8");
791 f1->setTime(8.99,7,9);
793 f1->fillFromAnalytic(3,"3*x+y");
794 WriteField(fileName,f1,false);
796 std::vector<std::string> fs=GetAllFieldNames(fileName);
797 CPPUNIT_ASSERT_EQUAL(4,(int)fs.size());
798 CPPUNIT_ASSERT(fs[0]=="Field1");
799 CPPUNIT_ASSERT(fs[1]=="Field2");
800 CPPUNIT_ASSERT(fs[2]=="Field3");
801 CPPUNIT_ASSERT(fs[3]=="Field8");
806 void MEDLoaderTest::testMEDLoaderRead1()
809 using namespace INTERP_KERNEL;
811 string fileName= INTERP_TEST::getResourceFile("pointe.med", 3);
812 vector<string> meshNames=GetMeshNames(fileName.c_str());
813 CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
814 MEDCouplingUMesh *mesh=ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
815 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
816 CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
817 CPPUNIT_ASSERT_EQUAL(16,(int)mesh->getNumberOfCells());
818 CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
819 CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllGeoTypes().size());
820 for(int i=0;i<12;i++)
821 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i));
822 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(12));
823 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(13));
824 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,mesh->getTypeOfCell(14));
825 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(15));
826 CPPUNIT_ASSERT_EQUAL(ToIdType(90),mesh->getNodalConnectivity()->getNbOfElems());
827 CPPUNIT_ASSERT_EQUAL(701,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+90,0));
828 CPPUNIT_ASSERT_EQUAL(705,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+17,0));
829 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
832 vector<string> families=GetMeshFamiliesNames(fileName.c_str(),meshNames[0].c_str());
833 CPPUNIT_ASSERT_EQUAL(8,(int)families.size());
834 CPPUNIT_ASSERT(families[2]=="FAMILLE_ELEMENT_3");
836 vector<string> families2;
837 families2.push_back(families[2]);
838 mesh=ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),0,families2);
839 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
840 CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
841 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getNumberOfCells());
842 CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
843 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
844 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(0));
845 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(1));
846 CPPUNIT_ASSERT_EQUAL(ToIdType(11),mesh->getNodalConnectivity()->getNbOfElems());
847 CPPUNIT_ASSERT_EQUAL(132,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+11,0));
848 CPPUNIT_ASSERT_EQUAL(16,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+3,0));
849 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
852 vector<string> groups=GetMeshGroupsNames(fileName.c_str(),meshNames[0].c_str());
853 CPPUNIT_ASSERT_EQUAL(5,(int)groups.size());
854 CPPUNIT_ASSERT(groups[0]=="groupe1");
855 CPPUNIT_ASSERT(groups[1]=="groupe2");
856 CPPUNIT_ASSERT(groups[2]=="groupe3");
857 CPPUNIT_ASSERT(groups[3]=="groupe4");
858 CPPUNIT_ASSERT(groups[4]=="groupe5");
859 vector<string> groups2;
860 groups2.push_back(groups[0]);
861 mesh=ReadUMeshFromGroups(fileName.c_str(),meshNames[0].c_str(),0,groups2);
862 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
863 CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
864 CPPUNIT_ASSERT_EQUAL(7,(int)mesh->getNumberOfCells());
865 CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
866 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
868 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(i));
869 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,mesh->getTypeOfCell(6));
870 CPPUNIT_ASSERT_EQUAL(ToIdType(36),mesh->getNodalConnectivity()->getNbOfElems());
871 CPPUNIT_ASSERT_EQUAL(254,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+36,0));
872 CPPUNIT_ASSERT_EQUAL(141,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+8,0));
873 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
876 std::vector<std::string> fieldsName=GetCellFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
877 CPPUNIT_ASSERT_EQUAL(2,(int)fieldsName.size());
878 CPPUNIT_ASSERT(fieldsName[0]=="fieldcelldoublescalar");
879 CPPUNIT_ASSERT(fieldsName[1]=="fieldcelldoublevector");
880 std::vector<std::pair<int,int> > its0=GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[0].c_str());
881 CPPUNIT_ASSERT_EQUAL(1,(int)its0.size());
882 CPPUNIT_ASSERT_EQUAL(-1,its0[0].first);
883 CPPUNIT_ASSERT_EQUAL(-1,its0[0].second);
884 std::vector<std::pair<int,int> > its1=GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[1].c_str());
885 CPPUNIT_ASSERT_EQUAL(1,(int)its1.size());
886 CPPUNIT_ASSERT_EQUAL(-1,its1[0].first);
887 CPPUNIT_ASSERT_EQUAL(-1,its1[0].second);
889 MEDCouplingFieldDouble *field0=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[0].c_str(),its0[0].first,its0[0].second));
890 field0->checkConsistencyLight();
891 CPPUNIT_ASSERT(field0->getName()==fieldsName[0]);
892 CPPUNIT_ASSERT_EQUAL(1,(int)field0->getNumberOfComponents());
893 CPPUNIT_ASSERT_EQUAL(16,(int)field0->getNumberOfTuples());
894 const double expectedValues[16]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,2.,3.,3.,2.};
895 double diffValue[16];
896 std::transform(field0->getArray()->getPointer(),field0->getArray()->getPointer()+16,expectedValues,diffValue,std::minus<double>());
897 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue,diffValue+16),1e-12);
898 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue,diffValue+16),1e-12);
899 const MEDCouplingUMesh *constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0->getMesh());
900 CPPUNIT_ASSERT(constMesh);
901 CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
902 CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
903 CPPUNIT_ASSERT_EQUAL(16,(int)constMesh->getNumberOfCells());
904 CPPUNIT_ASSERT_EQUAL(ToIdType(19),constMesh->getNumberOfNodes());
905 CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
906 for(int i=0;i<12;i++)
907 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
908 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
909 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
910 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
911 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
912 CPPUNIT_ASSERT_EQUAL(ToIdType(90),constMesh->getNodalConnectivity()->getNbOfElems());
913 CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
914 CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
915 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
918 MEDCouplingFieldDouble *field1=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[1].c_str(),its1[0].first,its1[0].second));
919 field1->checkConsistencyLight();
920 CPPUNIT_ASSERT(field1->getName()==fieldsName[1]);
921 CPPUNIT_ASSERT_EQUAL(3,(int)field1->getNumberOfComponents());
922 CPPUNIT_ASSERT_EQUAL(16,(int)field1->getNumberOfTuples());
923 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.};
924 double diffValue2[48];
925 std::transform(field1->getArray()->getPointer(),field1->getArray()->getPointer()+48,expectedValues2,diffValue2,std::minus<double>());
926 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue2,diffValue2+48),1e-12);
927 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue2,diffValue2+48),1e-12);
928 constMesh=dynamic_cast<const MEDCouplingUMesh *>(field1->getMesh());
929 CPPUNIT_ASSERT(constMesh);
930 CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
931 CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
932 CPPUNIT_ASSERT_EQUAL(16,(int)constMesh->getNumberOfCells());
933 CPPUNIT_ASSERT_EQUAL(ToIdType(19),constMesh->getNumberOfNodes());
934 CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
935 for(int i=0;i<12;i++)
936 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
937 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
938 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
939 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
940 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
941 CPPUNIT_ASSERT_EQUAL(ToIdType(90),constMesh->getNodalConnectivity()->getNbOfElems());
942 CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
943 CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
944 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
947 std::vector<std::string> fieldsNameNode=GetNodeFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
948 CPPUNIT_ASSERT_EQUAL(2,(int)fieldsNameNode.size());
949 CPPUNIT_ASSERT(fieldsNameNode[0]=="fieldnodedouble");
950 CPPUNIT_ASSERT(fieldsNameNode[1]=="fieldnodeint");
951 std::vector<std::pair<int,int> > its0Node=GetNodeFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsNameNode[0].c_str());
952 CPPUNIT_ASSERT_EQUAL(3,(int)its0Node.size());
953 CPPUNIT_ASSERT_EQUAL(-1,its0Node[0].first);
954 CPPUNIT_ASSERT_EQUAL(-1,its0Node[0].second);
955 CPPUNIT_ASSERT_EQUAL(1,its0Node[1].first);
956 CPPUNIT_ASSERT_EQUAL(-1,its0Node[1].second);
957 CPPUNIT_ASSERT_EQUAL(2,its0Node[2].first);
958 CPPUNIT_ASSERT_EQUAL(-1,its0Node[2].second);
959 MEDCouplingFieldDouble *field0Nodes=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[0].first,its0Node[0].second));
960 field0Nodes->checkConsistencyLight();
961 CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
962 CPPUNIT_ASSERT_EQUAL(1,(int)field0Nodes->getNumberOfComponents());
963 CPPUNIT_ASSERT_EQUAL(19,(int)field0Nodes->getNumberOfTuples());
964 const double expectedValues3[19]={1.,1.,1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.};
965 double diffValue3[19];
966 std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues3,diffValue3,std::minus<double>());
967 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
968 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
969 constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
970 CPPUNIT_ASSERT(constMesh);
971 field0Nodes->decrRef();
973 field0Nodes=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[2].first,its0Node[2].second));
974 field0Nodes->checkConsistencyLight();
975 CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
976 CPPUNIT_ASSERT_EQUAL(1,(int)field0Nodes->getNumberOfComponents());
977 CPPUNIT_ASSERT_EQUAL(19,(int)field0Nodes->getNumberOfTuples());
978 const double expectedValues4[19]={1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.,7.,7.};
979 std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues4,diffValue3,std::minus<double>());
980 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
981 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
982 constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
983 CPPUNIT_ASSERT(constMesh);
984 CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
985 CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
986 CPPUNIT_ASSERT_EQUAL(16,(int)constMesh->getNumberOfCells());
987 CPPUNIT_ASSERT_EQUAL(ToIdType(19),constMesh->getNumberOfNodes());
988 CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
989 for(int i=0;i<12;i++)
990 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
991 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
992 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
993 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
994 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
995 CPPUNIT_ASSERT_EQUAL(ToIdType(90),constMesh->getNodalConnectivity()->getNbOfElems());
996 CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
997 CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
998 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
999 field0Nodes->decrRef();
1001 field0Nodes=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldNode(fileName.c_str(),meshNames[0].c_str(),0,fieldsNameNode[0].c_str(),its0Node[0].first,its0Node[0].second));
1002 field0Nodes->checkConsistencyLight();
1003 CPPUNIT_ASSERT(field0Nodes->getName()==fieldsNameNode[0]);
1004 CPPUNIT_ASSERT_EQUAL(1,(int)field0Nodes->getNumberOfComponents());
1005 CPPUNIT_ASSERT_EQUAL(19,(int)field0Nodes->getNumberOfTuples());
1006 const double expectedValues5[19]={1.,1.,1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.};
1007 std::transform(field0Nodes->getArray()->getPointer(),field0Nodes->getArray()->getPointer()+19,expectedValues5,diffValue3,std::minus<double>());
1008 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue3,diffValue3+19),1e-12);
1009 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue3,diffValue3+19),1e-12);
1010 constMesh=dynamic_cast<const MEDCouplingUMesh *>(field0Nodes->getMesh());
1011 CPPUNIT_ASSERT(constMesh);
1012 CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
1013 CPPUNIT_ASSERT_EQUAL(3,constMesh->getMeshDimension());
1014 CPPUNIT_ASSERT_EQUAL(16,(int)constMesh->getNumberOfCells());
1015 CPPUNIT_ASSERT_EQUAL(ToIdType(19),constMesh->getNumberOfNodes());
1016 CPPUNIT_ASSERT_EQUAL(3,(int)constMesh->getAllGeoTypes().size());
1017 for(int i=0;i<12;i++)
1018 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,constMesh->getTypeOfCell(i));
1019 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(12));
1020 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(13));
1021 CPPUNIT_ASSERT_EQUAL(NORM_HEXA8,constMesh->getTypeOfCell(14));
1022 CPPUNIT_ASSERT_EQUAL(NORM_PYRA5,constMesh->getTypeOfCell(15));
1023 CPPUNIT_ASSERT_EQUAL(ToIdType(90),constMesh->getNodalConnectivity()->getNbOfElems());
1024 CPPUNIT_ASSERT_EQUAL(701,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+90,0));
1025 CPPUNIT_ASSERT_EQUAL(705,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+17,0));
1026 CPPUNIT_ASSERT_DOUBLES_EQUAL(46.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+57,0),1e-12);
1027 field0Nodes->decrRef();
1030 void MEDLoaderTest::testMEDLoaderPolygonRead()
1032 using namespace std;
1033 using namespace INTERP_KERNEL;
1035 string fileName=INTERP_TEST::getResourceFile("polygones.med", 3);
1036 vector<string> meshNames=GetMeshNames(fileName.c_str());
1037 CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
1038 CPPUNIT_ASSERT(meshNames[0]=="Bord");
1039 MEDCouplingUMesh *mesh=ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
1040 mesh->checkConsistencyLight();
1041 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1042 CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
1043 CPPUNIT_ASSERT_EQUAL(538,(int)mesh->getNumberOfCells());
1044 CPPUNIT_ASSERT_EQUAL(ToIdType(579),mesh->getNumberOfNodes());
1045 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
1046 for(int i=0;i<514;i++)
1047 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(i));
1048 for(int i=514;i<538;i++)
1049 CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(i));
1050 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+1737,0),1e-12);
1051 const double expectedVals1[12]={1.4851585216522212,-0.5,0.,1.4851585216522212,-0.4,0.,1.4851585216522212,-0.3,0., 1.5741585216522211, -0.5, 0. };
1052 double diffValue1[12];
1053 std::transform(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+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(ToIdType(2768),mesh->getNodalConnectivity()->getNbOfElems());
1057 CPPUNIT_ASSERT_EQUAL(651050,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+2768,0));
1058 CPPUNIT_ASSERT_EQUAL(725943,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+539,0));
1061 std::vector<std::string> fieldsName=GetCellFieldNamesOnMesh(fileName.c_str(),meshNames[0].c_str());
1062 CPPUNIT_ASSERT_EQUAL(3,(int)fieldsName.size());
1063 CPPUNIT_ASSERT(fieldsName[0]=="bord_:_distorsion");
1064 CPPUNIT_ASSERT(fieldsName[1]=="bord_:_familles");
1065 CPPUNIT_ASSERT(fieldsName[2]=="bord_:_non-ortho");
1066 std::vector<std::pair<int,int> > its0=GetCellFieldIterations(fileName.c_str(),meshNames[0].c_str(),fieldsName[0].c_str());
1067 CPPUNIT_ASSERT_EQUAL(1,(int)its0.size());
1068 MEDCouplingFieldDouble *field=dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ReadFieldCell(fileName.c_str(),meshNames[0].c_str(),0,fieldsName[0].c_str(),its0[0].first,its0[0].second));
1069 field->checkConsistencyLight();
1070 CPPUNIT_ASSERT(field->getName()==fieldsName[0]);
1071 CPPUNIT_ASSERT_EQUAL(1,(int)field->getNumberOfComponents());
1072 CPPUNIT_ASSERT_EQUAL(538,(int)field->getNumberOfTuples());
1073 const MEDCouplingUMesh *constMesh=dynamic_cast<const MEDCouplingUMesh *>(field->getMesh());
1074 CPPUNIT_ASSERT(constMesh);
1075 CPPUNIT_ASSERT_EQUAL(3,constMesh->getSpaceDimension());
1076 CPPUNIT_ASSERT_EQUAL(2,constMesh->getMeshDimension());
1077 CPPUNIT_ASSERT_EQUAL(538,(int)constMesh->getNumberOfCells());
1078 CPPUNIT_ASSERT_EQUAL(ToIdType(579),constMesh->getNumberOfNodes());
1079 CPPUNIT_ASSERT_EQUAL(2,(int)constMesh->getAllGeoTypes().size());
1080 for(int i=0;i<514;i++)
1081 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,constMesh->getTypeOfCell(i));
1082 for(int i=514;i<538;i++)
1083 CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,constMesh->getTypeOfCell(i));
1084 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,std::accumulate(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+1737,0),1e-12);
1085 std::transform(constMesh->getCoords()->getConstPointer(),constMesh->getCoords()->getConstPointer()+12,expectedVals1,diffValue1,std::minus<double>());
1086 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::max_element(diffValue1,diffValue1+12),1e-12);
1087 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,*std::min_element(diffValue1,diffValue1+12),1e-12);
1088 CPPUNIT_ASSERT_EQUAL(ToIdType(2768),constMesh->getNodalConnectivity()->getNbOfElems());
1089 CPPUNIT_ASSERT_EQUAL(651050,std::accumulate(constMesh->getNodalConnectivity()->getConstPointer(),constMesh->getNodalConnectivity()->getConstPointer()+2768,0));
1090 CPPUNIT_ASSERT_EQUAL(725943,std::accumulate(constMesh->getNodalConnectivityIndex()->getConstPointer(),constMesh->getNodalConnectivityIndex()->getConstPointer()+539,0));
1091 const double *values=field->getArray()->getPointer();
1092 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.87214203182918,std::accumulate(values,values+538,0.),1e-12);
1096 void MEDLoaderTest::testMEDLoaderPolyhedronRead()
1098 using namespace std;
1099 using namespace INTERP_KERNEL;
1101 string fileName=INTERP_TEST::getResourceFile("poly3D.med", 3);
1102 vector<string> meshNames=GetMeshNames(fileName.c_str());
1103 CPPUNIT_ASSERT_EQUAL(1,(int)meshNames.size());
1104 CPPUNIT_ASSERT(meshNames[0]=="poly3D");
1105 MEDCouplingUMesh *mesh=ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
1106 mesh->checkConsistencyLight();
1107 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1108 CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
1109 CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getNumberOfCells());
1110 CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
1111 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
1112 CPPUNIT_ASSERT_EQUAL(NORM_TETRA4,mesh->getTypeOfCell(0));
1113 CPPUNIT_ASSERT_EQUAL(NORM_POLYHED,mesh->getTypeOfCell(1));
1114 CPPUNIT_ASSERT_EQUAL(NORM_POLYHED,mesh->getTypeOfCell(2));
1115 CPPUNIT_ASSERT_EQUAL(ToIdType(98),mesh->getNodalConnectivity()->getNbOfElems());
1116 CPPUNIT_ASSERT_EQUAL(725,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+98,0));
1117 CPPUNIT_ASSERT_DOUBLES_EQUAL(110.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
1118 CPPUNIT_ASSERT_EQUAL(155,std::accumulate(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+4,0));
1121 mesh=ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),-1);
1122 mesh->checkConsistencyLight();
1123 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1124 CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
1125 CPPUNIT_ASSERT_EQUAL(17,(int)mesh->getNumberOfCells());
1126 CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
1127 CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getAllGeoTypes().size());
1128 CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(0));
1129 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(1));
1130 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(2));
1131 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(3));
1132 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(4));
1133 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(5));
1134 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(6));
1135 CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(7));
1136 CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(8));
1137 CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(9));
1138 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(10));
1139 CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(11));
1140 CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(12));
1141 CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(13));
1142 CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(14));
1143 CPPUNIT_ASSERT_EQUAL(NORM_QUAD4,mesh->getTypeOfCell(15));
1144 CPPUNIT_ASSERT_EQUAL(NORM_TRI3,mesh->getTypeOfCell(16));
1145 CPPUNIT_ASSERT_DOUBLES_EQUAL(110.,std::accumulate(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+57,0),1e-12);
1146 CPPUNIT_ASSERT_EQUAL(ToIdType(83),mesh->getNodalConnectivity()->getNbOfElems());
1147 CPPUNIT_ASSERT_EQUAL(619,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+83,0));
1150 vector<string> families=GetMeshFamiliesNames(fileName.c_str(),meshNames[0].c_str());
1151 CPPUNIT_ASSERT_EQUAL(4,(int)families.size());
1152 CPPUNIT_ASSERT(families[0]=="FAMILLE_FACE_POLYGONS3");
1153 CPPUNIT_ASSERT(families[1]=="FAMILLE_FACE_QUAD41");
1154 CPPUNIT_ASSERT(families[2]=="FAMILLE_FACE_TRIA32");
1155 CPPUNIT_ASSERT(families[3]=="FAMILLE_ZERO");
1156 vector<string> families2;
1157 families2.push_back(families[0]);
1158 mesh=ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),-1,families2);
1159 mesh->checkConsistencyLight();
1160 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1161 CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
1162 CPPUNIT_ASSERT_EQUAL(3,(int)mesh->getNumberOfCells());
1163 CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
1164 CPPUNIT_ASSERT_EQUAL(1,(int)mesh->getAllGeoTypes().size());
1165 for(int i=0;i<3;i++)
1166 CPPUNIT_ASSERT_EQUAL(NORM_POLYGON,mesh->getTypeOfCell(i));
1167 CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNodalConnectivity()->getNbOfElems());
1168 CPPUNIT_ASSERT_EQUAL(117,std::accumulate(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+19,0));
1171 mesh=ReadUMeshFromFamilies(fileName.c_str(),meshNames[0].c_str(),0,families2);
1172 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
1173 CPPUNIT_ASSERT_EQUAL(0,(int)mesh->getNumberOfCells());
1174 CPPUNIT_ASSERT_EQUAL(ToIdType(19),mesh->getNumberOfNodes());
1175 CPPUNIT_ASSERT_EQUAL(3,mesh->getMeshDimension());
1176 CPPUNIT_ASSERT_EQUAL(0,(int)mesh->getAllGeoTypes().size());
1180 MEDCouplingUMesh *MEDLoaderTest::build1DMesh_1()
1182 double coords[6]={ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 };
1183 mcIdType conn[9]={ 0,1, 1,2, 2,3 , 3,4,5};
1184 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
1185 mesh->setName("1DMesh_1");
1186 mesh->setMeshDimension(1);
1187 mesh->allocateCells(4);
1188 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
1189 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
1190 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
1191 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6);
1192 mesh->finishInsertingCells();
1193 DataArrayDouble *myCoords=DataArrayDouble::New();
1194 myCoords->alloc(6,1);
1195 myCoords->setInfoOnComponent(0,"tototototototot [m*m*m*m*m*m*m*m]");
1196 std::copy(coords,coords+6,myCoords->getPointer());
1197 mesh->setCoords(myCoords);
1198 myCoords->decrRef();
1202 MEDCouplingUMesh *MEDLoaderTest::build2DCurveMesh_1()
1204 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 };
1205 mcIdType conn[9]={ 0,1, 1,2, 2,3 , 3,4,5};
1206 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
1207 mesh->setName("2DCurveMesh_1");
1208 mesh->setMeshDimension(1);
1209 mesh->allocateCells(4);
1210 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
1211 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
1212 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
1213 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6);
1214 mesh->finishInsertingCells();
1215 DataArrayDouble *myCoords=DataArrayDouble::New();
1216 myCoords->alloc(6,2);
1217 std::copy(coords,coords+12,myCoords->getPointer());
1218 mesh->setCoords(myCoords);
1219 myCoords->decrRef();
1223 MEDCouplingUMesh *MEDLoaderTest::build2DMesh_1()
1225 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 };
1226 mcIdType 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};
1227 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
1228 targetMesh->setMeshDimension(2);
1229 targetMesh->allocateCells(6);
1230 targetMesh->setName("2DMesh_1");
1231 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
1232 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
1233 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
1234 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
1235 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
1236 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POLYGON,4,targetConn+20);
1237 targetMesh->finishInsertingCells();
1238 DataArrayDouble *myCoords=DataArrayDouble::New();
1239 myCoords->alloc(12,2);
1240 myCoords->setInfoOnComponent(0,"tototototototot [m]");
1241 myCoords->setInfoOnComponent(1,"energie [kW]");
1242 std::copy(targetCoords,targetCoords+24,myCoords->getPointer());
1243 targetMesh->setCoords(myCoords);
1244 myCoords->decrRef();
1248 MEDCouplingUMesh *MEDLoaderTest::build2DMesh_2()
1250 double targetCoords[24]={
1251 -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,
1252 -0.05,0.95, 0.2,1.2, 0.45,0.95
1254 mcIdType 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};
1255 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
1256 targetMesh->setMeshDimension(2);
1257 targetMesh->allocateCells(5);
1258 targetMesh->setName("2DMesh_2");
1259 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
1260 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
1261 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
1262 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
1263 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
1264 targetMesh->finishInsertingCells();
1265 DataArrayDouble *myCoords=DataArrayDouble::New();
1266 myCoords->alloc(12,2);
1267 myCoords->setInfoOnComponent(0,"toto [m]");
1268 myCoords->setInfoOnComponent(1,"energie [kW]");
1269 std::copy(targetCoords,targetCoords+24,myCoords->getPointer());
1270 targetMesh->setCoords(myCoords);
1271 myCoords->decrRef();
1275 MEDCouplingUMesh *MEDLoaderTest::build3DSurfMesh_1()
1277 double targetCoords[36]={
1278 -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
1279 ,-0.05,0.95,-0.3, 0.2,1.2,-0.3, 0.45,0.95,-0.3
1281 mcIdType 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};
1282 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
1283 targetMesh->setMeshDimension(2);
1284 targetMesh->allocateCells(6);
1285 targetMesh->setName("3DSurfMesh_1");
1286 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
1287 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
1288 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
1289 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
1290 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
1291 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POLYGON,4,targetConn+20);
1292 targetMesh->finishInsertingCells();
1293 DataArrayDouble *myCoords=DataArrayDouble::New();
1294 myCoords->alloc(12,3);
1295 myCoords->setInfoOnComponent(0,"toto [m]");
1296 myCoords->setInfoOnComponent(2,"ff [km]");//component 1 is not set for test
1297 std::copy(targetCoords,targetCoords+36,myCoords->getPointer());
1298 targetMesh->setCoords(myCoords);
1299 myCoords->decrRef();
1303 MEDCouplingUMesh *MEDLoaderTest::build3DMesh_1()
1305 double coords[180]={
1306 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.,
1307 3.,2.,0., 0.,1.,0., 1.,3.,0., 2.,2.,0., 2.,3.,0.,
1308 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.,
1309 3.,2.,1., 0.,1.,1., 1.,3.,1., 2.,2.,1., 2.,3.,1.,
1310 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.,
1311 3.,2.,2., 0.,1.,2., 1.,3.,2., 2.,2.,2., 2.,3.,2.,
1312 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.,
1313 3.,2.,3., 0.,1.,3., 1.,3.,3., 2.,2.,3., 2.,3.,3.};
1315 mcIdType conn[354]={
1317 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,
1318 1,6,5,3,16,21,20,18, 13,10,9,6,28,25,24,21,
1319 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,
1320 7,12,14,13,22,27,29,28,
1322 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,
1323 16,21,20,18,31,36,35,33, 28,25,24,21,43,40,39,36,
1324 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,
1325 22,27,29,28,37,42,44,43,
1327 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,
1328 31,36,35,33,46,51,50,48, 43,40,39,36,58,55,54,51,
1329 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,
1330 37,42,44,43,52,57,59,58
1333 MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
1334 ret->setName("3DMesh_1");
1335 ret->setMeshDimension(3);
1336 ret->allocateCells(18);
1338 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
1339 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+51);
1340 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+59);
1341 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+110);
1343 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+118);
1344 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+169);
1345 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+177);
1346 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+228);
1348 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+236);
1349 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+287);
1350 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+295);
1351 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+346);
1353 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+8);
1354 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+67);
1355 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+126);
1356 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+185);
1357 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+244);
1358 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+303);
1360 ret->finishInsertingCells();
1361 DataArrayDouble *myCoords=DataArrayDouble::New();
1362 myCoords->alloc(60,3);
1363 myCoords->setInfoOnComponent(0,"titi [m]");
1364 myCoords->setInfoOnComponent(1,"density power [MW/m^3]");
1365 myCoords->setInfoOnComponent(2,"t [kW]");
1366 std::copy(coords,coords+180,myCoords->getPointer());
1367 ret->setCoords(myCoords);
1368 myCoords->decrRef();
1372 MEDCouplingUMesh *MEDLoaderTest::build3DMesh_2()
1374 MEDCouplingUMesh *m3dsurfBase=build3DSurfMesh_1();
1375 mcIdType numbers[5]={0,1,2,3,5};
1376 MEDCouplingUMesh *m3dsurf=(MEDCouplingUMesh *)m3dsurfBase->buildPartOfMySelf(numbers,numbers+5,false);
1377 m3dsurfBase->decrRef();
1378 MEDCouplingUMesh *m1dBase=build1DMesh_1();
1379 mcIdType numbers2[4]={0,1,2,3};
1380 MEDCouplingUMesh *m1d=(MEDCouplingUMesh *)m1dBase->buildPartOfMySelf(numbers2,numbers2+4,false);
1382 m1d->changeSpaceDimension(3);
1383 const double vec[3]={0.,1.,0.};
1384 const double pt[3]={0.,0.,0.};
1385 m1d->rotate(pt,vec,-M_PI/2.);
1386 MEDCouplingUMesh *ret=m3dsurf->buildExtrudedMesh(m1d,0);
1392 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnCells_1()
1394 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1395 mcIdType nbOfCells=mesh->getNumberOfCells();
1396 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1397 f1->setName("VectorFieldOnCells");
1399 DataArrayDouble *array=DataArrayDouble::New();
1400 array->alloc(nbOfCells,3);
1401 array->setInfoOnComponent(0,"power [MW/m^3]");
1402 array->setInfoOnComponent(1,"density [g/cm^3]");
1403 array->setInfoOnComponent(2,"temperature [K]");
1404 f1->setArray(array);
1406 double *tmp=array->getPointer();
1407 const double arr1[18]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.};
1408 std::copy(arr1,arr1+18,tmp);
1409 f1->setTime(2.,0,1);
1410 f1->checkConsistencyLight();
1415 MEDCouplingFieldInt *MEDLoaderTest::buildIntVecFieldOnCells_1()
1417 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1418 mcIdType nbOfCells=mesh->getNumberOfCells();
1419 MEDCouplingFieldInt *f1=MEDCouplingFieldInt::New(ON_CELLS,ONE_TIME);
1420 f1->setName("IntVectorFieldOnCells");
1422 DataArrayInt32 *array=DataArrayInt32::New();
1423 array->alloc(nbOfCells,3);
1424 array->setInfoOnComponent(0,"val1 [MW/m^3]");
1425 array->setInfoOnComponent(1,"va2 [g/cm^3]");
1426 array->setInfoOnComponent(2,"val3 [K]");
1427 f1->setArray(array);
1429 int *tmp=array->getPointer();
1430 const int arr1[18]={0,10,20,1,11,21,2,12,22,3,13,23,4,14,24,5,15,25};
1431 std::copy(arr1,arr1+18,tmp);
1432 f1->setTime(2.,0,1);
1433 f1->checkConsistencyLight();
1438 MEDCouplingFieldInt64 *MEDLoaderTest::buildInt64VecFieldOnCells_1()
1440 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1441 mcIdType nbOfCells=mesh->getNumberOfCells();
1442 MEDCouplingFieldInt64 *f1=MEDCouplingFieldInt64::New(ON_CELLS,ONE_TIME);
1443 f1->setName("Int64VectorFieldOnCells");
1445 DataArrayInt64 *array=DataArrayInt64::New();
1446 array->alloc(nbOfCells,3);
1447 array->setInfoOnComponent(0,"val1 [MW/m^3]");
1448 array->setInfoOnComponent(1,"va2 [g/cm^3]");
1449 array->setInfoOnComponent(2,"val3 [K]");
1450 f1->setArray(array);
1452 int64_t *tmp=array->getPointer();
1453 const int64_t arr1[18]={0,10,20,1,11,21,2,12,22,3,13,23,4,14,24,5,15,25};
1454 std::copy(arr1,arr1+18,tmp);
1455 f1->setTime(2.,0,1);
1456 f1->checkConsistencyLight();
1461 MEDCouplingFieldFloat *MEDLoaderTest::buildFloatVecFieldOnCells_1()
1463 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1464 mcIdType nbOfCells=mesh->getNumberOfCells();
1465 MEDCouplingFieldFloat *f1=MEDCouplingFieldFloat::New(ON_CELLS,ONE_TIME);
1466 f1->setName("FloatVectorFieldOnCells");
1468 DataArrayFloat *array=DataArrayFloat::New();
1469 array->alloc(nbOfCells,3);
1470 array->setInfoOnComponent(0,"power [MW/m^3]");
1471 array->setInfoOnComponent(1,"density [g/cm^3]");
1472 array->setInfoOnComponent(2,"temperature [K]");
1473 f1->setArray(array);
1475 float *tmp=array->getPointer();
1476 const float arr1[18]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.};
1477 std::copy(arr1,arr1+18,tmp);
1478 f1->setTime(2.,0,1);
1479 f1->checkConsistencyLight();
1485 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnNodes_1()
1487 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1488 mcIdType nbOfNodes=mesh->getNumberOfNodes();
1489 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
1490 f1->setName("VectorFieldOnNodes");
1492 DataArrayDouble *array=DataArrayDouble::New();
1493 array->alloc(nbOfNodes,3);
1494 f1->setArray(array);
1495 array->setInfoOnComponent(0,"power [MW/m^3]");
1496 array->setInfoOnComponent(1,"density [g/cm^3]");
1497 array->setInfoOnComponent(2,"temperature [K]");
1499 double *tmp=array->getPointer();
1500 const double arr1[36]={
1501 70.,80.,90.,71.,81.,91.,72.,82.,92.,73.,83.,93.,74.,84.,94.,75.,85.,95.,
1502 1000.,10010.,10020.,1001.,10011.,10021.,1002.,10012.,10022.,1003.,10013.,10023.,1004.,10014.,10024.,1005.,10015.,10025.,
1504 std::copy(arr1,arr1+36,tmp);
1505 f1->setTime(2.12,2,3);
1506 f1->checkConsistencyLight();
1511 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGauss_1()
1513 const double _a=0.446948490915965;
1514 const double _b=0.091576213509771;
1515 const double _p1=0.11169079483905;
1516 const double _p2=0.0549758718227661;
1517 const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
1518 const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
1519 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
1520 const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
1521 std::vector<double> _refCoo1(refCoo1,refCoo1+6);
1522 std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
1523 std::vector<double> _wg1(wg1,wg1+6);
1524 MEDCouplingUMesh *m=build2DMesh_2();
1525 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,ONE_TIME);
1526 f->setTime(3.14,1,5);
1528 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
1529 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 };
1530 std::vector<double> _refCoo2(refCoo2,refCoo2+12);
1531 std::vector<double> _gsCoo2(_gsCoo1);
1532 std::vector<double> _wg2(_wg1);
1533 _gsCoo2.resize(6); _wg2.resize(3);
1534 const double refCoo3[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
1535 std::vector<double> _refCoo3(refCoo3,refCoo3+8);
1536 _gsCoo1.resize(4); _wg1.resize(2);
1537 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo3,_gsCoo1,_wg1);
1538 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI6,_refCoo2,_gsCoo2,_wg2);
1539 DataArrayDouble *array=DataArrayDouble::New();
1541 double *ptr=array->getPointer();
1542 for(int i=0;i<19*2;i++)
1543 ptr[i]=(double)(i+7);
1545 f->setName("MyFirstFieldOnGaussPoint");
1546 array->setInfoOnComponent(0,"power [MW/m^3]");
1547 array->setInfoOnComponent(1,"density");
1549 f->checkConsistencyLight();
1554 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGaussNE_1()
1556 MEDCouplingUMesh *m=build2DMesh_2();
1557 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,ONE_TIME);
1558 f->setTime(3.14,1,5);
1560 DataArrayDouble *array=DataArrayDouble::New();
1562 double *ptr=array->getPointer();
1563 for(int i=0;i<20*2;i++)
1564 ptr[i]=(double)(i+8);
1566 array->setInfoOnComponent(0,"power [W]");
1567 array->setInfoOnComponent(1,"temperature");
1568 f->setName("MyFieldOnGaussNE");
1570 f->checkConsistencyLight();