1 // Copyright (C) 2007-2012 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.
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
20 #include "MEDLoaderTest.hxx"
21 #include "MEDLoader.hxx"
22 #include "MEDLoaderBase.hxx"
23 #include "MEDCouplingUMesh.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
25 #include "MEDCouplingMemArray.hxx"
29 using namespace ParaMEDMEM;
31 void MEDLoaderTest::testMesh1DRW()
33 MEDCouplingUMesh *mesh=build1DMesh_1();
34 mesh->checkCoherency();
35 MEDLoader::WriteUMesh("file1.med",mesh,true);
36 MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file1.med",mesh->getName(),0);
37 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
42 void MEDLoaderTest::testMesh2DCurveRW()
44 MEDCouplingUMesh *mesh=build2DCurveMesh_1();
45 mesh->checkCoherency();
46 MEDLoader::WriteUMesh("file2.med",mesh,true);
47 MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file2.med",mesh->getName(),0);
48 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
53 void MEDLoaderTest::testMesh2DRW()
55 MEDCouplingUMesh *mesh=build2DMesh_1();
56 mesh->checkCoherency();
57 MEDLoader::WriteUMesh("file3.med",mesh,true);
58 MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file3.med",mesh->getName(),0);
59 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
64 void MEDLoaderTest::testMesh3DSurfRW()
66 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
67 mesh->checkCoherency();
68 MEDLoader::WriteUMesh("file4.med",mesh,true);
69 MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file4.med",mesh->getName(),0);
70 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
75 void MEDLoaderTest::testMesh3DRW()
77 MEDCouplingUMesh *mesh=build3DMesh_1();
78 mesh->checkCoherency();
79 MEDLoader::WriteUMesh("file5.med",mesh,true);
80 MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file5.med",mesh->getName(),0);
81 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
87 * Most basic test : one and only one MEDCoupling field in a new file.
89 void MEDLoaderTest::testFieldRW1()
91 MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
92 MEDLoader::WriteField("file6.med",f1,true);
93 MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell("file6.med",f1->getMesh()->getName(),0,f1->getName(),0,1);
94 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
98 f1=buildVecFieldOnNodes_1();
99 MEDLoader::WriteField("file7.med",f1,true);
100 f2=MEDLoader::ReadFieldNode("file7.med",f1->getMesh()->getName(),0,f1->getName(),2,3);
101 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
102 // testing kind message on error of field type.
103 CPPUNIT_ASSERT_THROW(MEDLoader::ReadFieldCell("file7.med",f1->getMesh()->getName(),0,f1->getName(),2,3),INTERP_KERNEL::Exception);
110 * Multi field writing in a same file.
112 void MEDLoaderTest::testFieldRW2()
114 const char fileName[]="file8.med";
115 static const double VAL1=12345.67890314;
116 static const double VAL2=-1111111111111.;
117 MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
118 MEDLoader::WriteField(fileName,f1,true);
119 f1->setTime(10.,8,9);
120 double *tmp=f1->getArray()->getPointer();
122 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
123 f1->setTime(10.14,18,19);
125 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
126 //retrieving time steps...
127 MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),8,9);
128 f1->setTime(10.,8,9);
130 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
132 f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),0,1);
133 MEDCouplingFieldDouble *f3=buildVecFieldOnCells_1();
134 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
137 f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),18,19);
138 f1->setTime(10.14,18,19);
140 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
141 //test of throw on invalid (dt,it)
142 CPPUNIT_ASSERT_THROW(MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),28,19),INTERP_KERNEL::Exception);
146 f1=buildVecFieldOnNodes_1();
147 const char fileName2[]="file9.med";
148 MEDLoader::WriteField(fileName2,f1,true);
149 f1->setTime(110.,108,109);
150 tmp=f1->getArray()->getPointer();
152 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
153 f1->setTime(210.,208,209);
155 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
156 f2=MEDLoader::ReadFieldNode(fileName2,f1->getMesh()->getName(),0,f1->getName(),108,109);
157 f1->setTime(110.,108,109);
159 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
161 f2=MEDLoader::ReadFieldNode(fileName2,f1->getMesh()->getName(),0,f1->getName(),2,3);
162 f3=buildVecFieldOnNodes_1();
163 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
166 f2=MEDLoader::ReadFieldNode(fileName2,f1->getMesh()->getName(),0,f1->getName(),208,209);
167 f1->setTime(210.,208,209);
169 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
175 * Multi field in a same file, but this field has several
177 void MEDLoaderTest::testFieldRW3()
179 const char fileName[]="file11.med";
180 static const double VAL1=12345.67890314;
181 static const double VAL2=-1111111111111.;
182 const char name1[]="AField";
183 const char name3[]="AMesh1";
184 MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
185 (const_cast<MEDCouplingMesh *>(f1->getMesh()))->setName(name3);
187 f1->setTime(10.,8,9);
188 double *tmp=f1->getArray()->getPointer();
190 MEDLoader::WriteField(fileName,f1,true);
191 f1->setTime(10.14,18,19);
193 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
194 f1->setTime(10.55,28,29);
196 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
197 f1->setTime(10.66,38,39);
199 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
200 f1->setTime(10.77,48,49);
202 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
205 f1=buildVecFieldOnNodes_1();
207 (const_cast<MEDCouplingMesh *>(f1->getMesh()))->setName(name3);
208 f1->setTime(110.,8,9);
209 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
210 f1->setTime(110.,108,109);
211 tmp=f1->getArray()->getPointer();
213 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
214 f1->setTime(210.,208,209);
216 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
218 std::vector< std::pair<int,int> > it1=MEDLoader::GetCellFieldIterations(fileName,name3,name1);
219 CPPUNIT_ASSERT_EQUAL(5,(int)it1.size());
220 CPPUNIT_ASSERT_EQUAL(8,it1[0].first); CPPUNIT_ASSERT_EQUAL(9,it1[0].second);
221 CPPUNIT_ASSERT_EQUAL(18,it1[1].first); CPPUNIT_ASSERT_EQUAL(19,it1[1].second);
222 CPPUNIT_ASSERT_EQUAL(28,it1[2].first); CPPUNIT_ASSERT_EQUAL(29,it1[2].second);
223 CPPUNIT_ASSERT_EQUAL(38,it1[3].first); CPPUNIT_ASSERT_EQUAL(39,it1[3].second);
224 CPPUNIT_ASSERT_EQUAL(48,it1[4].first); CPPUNIT_ASSERT_EQUAL(49,it1[4].second);
225 std::vector< std::pair<int,int> > it3=MEDLoader::GetNodeFieldIterations(fileName,name3,name1);
226 CPPUNIT_ASSERT_EQUAL(3,(int)it3.size());
227 CPPUNIT_ASSERT_EQUAL(8,it3[0].first); CPPUNIT_ASSERT_EQUAL(9,it3[0].second);
228 CPPUNIT_ASSERT_EQUAL(108,it3[1].first); CPPUNIT_ASSERT_EQUAL(109,it3[1].second);
229 CPPUNIT_ASSERT_EQUAL(208,it3[2].first); CPPUNIT_ASSERT_EQUAL(209,it3[2].second);
233 f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,8,9);
234 CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[0],1e-13);
236 f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,18,19);
237 CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[0],1e-13);
239 f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,28,29);
240 CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL1,f1->getArray()->getConstPointer()[0],1e-13);
242 f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,38,39);
243 CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
245 f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,48,49);
246 CPPUNIT_ASSERT_DOUBLES_EQUAL(4*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
249 f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,8,9);
250 CPPUNIT_ASSERT_DOUBLES_EQUAL(71.,f1->getArray()->getConstPointer()[3],1e-13);
252 f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,108,109);
253 CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[3],1e-13);
255 f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,208,209);
256 CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[3],1e-13);
260 void MEDLoaderTest::testMultiMeshRW1()
262 const char fileName[]="file10.med";
263 MEDCouplingUMesh *mesh1=build3DMesh_1();
264 const int part1[5]={1,2,4,13,15};
265 MEDCouplingUMesh *mesh2=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part1,part1+5,true);
266 mesh2->setName("mesh2");
267 const int part2[4]={3,4,13,14};
268 MEDCouplingUMesh *mesh3=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part2,part2+4,true);
269 mesh3->setName("mesh3");
270 MEDCouplingUMesh *mesh4=MEDCouplingUMesh::New();
271 mesh4->setName("mesh4");
272 mesh4->setMeshDimension(3);
273 mesh4->allocateCells(1);
274 int conn[4]={0,11,1,3};
275 mesh4->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,conn);
276 mesh4->finishInsertingCells();
277 mesh4->setCoords(mesh1->getCoords());
278 std::vector<const MEDCouplingUMesh *> meshes;
279 meshes.push_back(mesh1);
280 meshes.push_back(mesh2);
281 meshes.push_back(mesh3);
282 meshes.push_back(mesh4);
283 const char mnane[]="3DToto";
284 MEDLoader::WriteUMeshesPartition(fileName,mnane,meshes,true);
286 MEDCouplingUMesh *mesh5=MEDLoader::ReadUMeshFromFile(fileName,mnane);
287 mesh1->setName(mnane);
288 const int part3[18]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
289 MEDCouplingUMesh *mesh6=(MEDCouplingUMesh *)mesh5->buildPartOfMySelf(part3,part3+18,true);
290 mesh6->setName(mnane);
292 CPPUNIT_ASSERT(mesh6->isEqual(mesh1,1e-12));
294 std::vector<std::string> grps=MEDLoader::GetMeshGroupsNames(fileName,mnane);
295 CPPUNIT_ASSERT_EQUAL(4,(int)grps.size());
296 CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh2"))!=grps.end());
297 CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh3"))!=grps.end());
298 CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("mesh4"))!=grps.end());
299 CPPUNIT_ASSERT(std::find(grps.begin(),grps.end(),std::string("3DMesh_1"))!=grps.end());
301 std::vector<std::string> vec;
302 vec.push_back(std::string("mesh2"));
303 MEDCouplingUMesh *mesh2_2=MEDLoader::ReadUMeshFromGroups(fileName,mnane,0,vec);
304 CPPUNIT_ASSERT(mesh2_2->isEqual(mesh2,1e-12));
306 vec.clear(); vec.push_back(std::string("mesh3"));
307 MEDCouplingUMesh *mesh3_2=MEDLoader::ReadUMeshFromGroups(fileName,mnane,0,vec);
308 CPPUNIT_ASSERT(mesh3_2->isEqual(mesh3,1e-12));
310 vec.clear(); vec.push_back(std::string("mesh4"));
311 MEDCouplingUMesh *mesh4_2=MEDLoader::ReadUMeshFromGroups(fileName,mnane,0,vec);
312 CPPUNIT_ASSERT(mesh4_2->isEqual(mesh4,1e-12));
314 vec.clear(); vec.push_back(std::string("3DMesh_1"));
315 MEDCouplingUMesh *mesh1_2=MEDLoader::ReadUMeshFromGroups(fileName,mnane,0,vec);
316 mesh1->setName("3DMesh_1");
317 CPPUNIT_ASSERT(mesh1_2->isEqual(mesh1,1e-12));
320 vec.clear(); vec.push_back(std::string("Family_4")); vec.push_back(std::string("Family_2"));
321 mesh2_2=MEDLoader::ReadUMeshFromFamilies(fileName,mnane,0,vec);
322 mesh2_2->setName("mesh2");
323 CPPUNIT_ASSERT(mesh2_2->isEqual(mesh2,1e-12));
326 std::vector<std::string> ret=MEDLoader::GetMeshFamiliesNamesOnGroup(fileName,"3DToto","3DMesh_1");
327 CPPUNIT_ASSERT_EQUAL(4,(int)ret.size());
328 CPPUNIT_ASSERT(ret[0]=="Family_1");
329 CPPUNIT_ASSERT(ret[1]=="Family_2");
330 CPPUNIT_ASSERT(ret[2]=="Family_3");
331 CPPUNIT_ASSERT(ret[3]=="Family_4");
333 std::vector<std::string> ret1=MEDLoader::GetMeshGroupsNamesOnFamily(fileName,"3DToto","Family_2");
334 CPPUNIT_ASSERT_EQUAL(2,(int)ret1.size());
335 CPPUNIT_ASSERT(ret1[0]=="3DMesh_1");
336 CPPUNIT_ASSERT(ret1[1]=="mesh2");
344 void MEDLoaderTest::testFieldProfilRW1()
346 const char fileName[]="file12.med";
347 MEDCouplingUMesh *mesh1=build3DMesh_1();
350 DataArrayInt *da=mesh1->mergeNodes(1e-12,b,newNbOfNodes);
352 MEDLoader::WriteUMesh(fileName,mesh1,true);
353 const int part1[5]={1,2,4,13,15};
354 MEDCouplingUMesh *mesh2=(MEDCouplingUMesh *)mesh1->buildPartOfMySelf(part1,part1+5,true);
355 mesh2->setName(mesh1->getName());//<- important for the test
357 int nbOfCells=mesh2->getNumberOfCells();
358 CPPUNIT_ASSERT_EQUAL(5,nbOfCells);
359 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
360 f1->setName("VectorFieldOnCells");
362 DataArrayDouble *array=DataArrayDouble::New();
363 array->alloc(nbOfCells,2);
366 double *tmp=array->getPointer();
367 const double arr1[10]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.};
368 std::copy(arr1,arr1+10,tmp);
369 f1->setTime(3.14,2,7);
370 f1->checkCoherency();
372 MEDLoader::WriteField(fileName,f1,false);//<- false important for the test
374 MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
375 std::vector<ParaMEDMEM::TypeOfField> types=MEDLoader::GetTypesOfField(fileName,f1->getMesh()->getName(),f1->getName());
376 CPPUNIT_ASSERT_EQUAL(1,(int)types.size());
377 CPPUNIT_ASSERT(types[0]==ON_CELLS);
378 f2->checkCoherency();
379 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
388 * Test MED file profiles.
390 void MEDLoaderTest::testFieldNodeProfilRW1()
392 const char fileName[]="file19.med";
393 const char fileName2[]="file20.med";
394 MEDCouplingUMesh *m=build2DMesh_1();
395 int nbOfNodes=m->getNumberOfNodes();
396 MEDLoader::WriteUMesh(fileName,m,true);
397 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
398 f1->setName("VFieldOnNodes");
400 DataArrayDouble *array=DataArrayDouble::New();
401 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.};
402 array->alloc(nbOfNodes,2);
403 std::copy(arr1,arr1+24,array->getPointer());
405 array->setInfoOnComponent(0,"tyty [mm]");
406 array->setInfoOnComponent(1,"uiop [MW]");
408 f1->setTime(3.14,2,7);
409 f1->checkCoherency();
410 const int arr2[2]={1,4};//node ids are 2,4,5,3,6,7
411 MEDCouplingFieldDouble *f2=f1->buildSubPart(arr2,arr2+2);
412 (const_cast<MEDCouplingMesh *>(f2->getMesh()))->setName(f1->getMesh()->getName());
413 MEDLoader::WriteField(fileName,f2,false);//<- false important for the test
415 MEDCouplingFieldDouble *f3=MEDLoader::ReadFieldNode(fileName,f2->getMesh()->getName(),0,f2->getName(),2,7);
416 f3->checkCoherency();
417 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
420 const int arr3[6]={1,3,0,5,2,4};
421 f2->renumberNodes(arr3);
422 MEDLoader::WriteUMesh(fileName2,m,true);
423 MEDLoader::WriteField(fileName2,f2,false);//<- false important for the test
424 f3=MEDLoader::ReadFieldNode(fileName2,f2->getMesh()->getName(),0,f2->getName(),2,7);
425 f3->checkCoherency();
426 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
434 void MEDLoaderTest::testFieldNodeProfilRW2()
436 const char fileName[]="file23.med";
437 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
438 MEDLoader::WriteUMesh(fileName,mesh,true);
440 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
441 f1->setName("FieldMix");
443 const double arr2[24]={
444 1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
445 1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
447 DataArrayDouble *array=DataArrayDouble::New();
450 array->setInfoOnComponent(0,"plkj [mm]");
451 array->setInfoOnComponent(1,"pqqqss [mm]");
453 double *tmp=array->getPointer();
454 std::copy(arr2,arr2+24,tmp);
455 f1->setTime(3.17,2,7);
457 const int renumArr[12]={3,7,2,1,5,11,10,0,9,6,8,4};
458 f1->renumberNodes(renumArr);
459 f1->checkCoherency();
460 MEDLoader::WriteField(fileName,f1,false);//<- false important for the test
461 MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldNode(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
462 CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
469 void MEDLoaderTest::testFieldGaussRW1()
471 const char fileName[]="file13.med";
472 MEDCouplingFieldDouble *f1=buildVecFieldOnGauss_1();
473 MEDLoader::WriteField(fileName,f1,true);
474 MEDCouplingFieldDouble *f2=MEDLoader::ReadField(ON_GAUSS_PT,fileName,f1->getMesh()->getName(),0,f1->getName(),1,5);
475 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
480 void MEDLoaderTest::testFieldGaussNERW1()
482 const char fileName[]="file14.med";
483 MEDCouplingFieldDouble *f1=buildVecFieldOnGaussNE_1();
484 MEDLoader::WriteField(fileName,f1,true);
485 MEDCouplingFieldDouble *f2=MEDLoader::ReadField(ON_GAUSS_NE,fileName,f1->getMesh()->getName(),0,f1->getName(),1,5);
486 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
491 void MEDLoaderTest::testLittleStrings1()
493 std::string s("azeeeerrrtty");
494 MEDLoaderBase::zipEqualConsChar(s,3);
495 CPPUNIT_ASSERT(s=="azertty");
498 void MEDLoaderTest::testSplitIntoNameAndUnit1()
500 std::string s(" []");
502 MEDLoaderBase::splitIntoNameAndUnit(s,c,u);
503 CPPUNIT_ASSERT(c.empty());
504 CPPUNIT_ASSERT(u.empty());
506 MEDLoaderBase::strip(s);
507 CPPUNIT_ASSERT(s=="lmmm kki jjj");
509 MEDLoaderBase::strip(s);
510 CPPUNIT_ASSERT(s.empty());
512 MEDLoaderBase::strip(s);
513 CPPUNIT_ASSERT(s.empty());
515 MEDLoaderBase::strip(s);
516 CPPUNIT_ASSERT(s.empty());
518 MEDLoaderBase::strip(s);
519 CPPUNIT_ASSERT(s=="pp");
522 void MEDLoaderTest::testMesh3DSurfShuffleRW()
524 const char fileName[]="file15.med";
525 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
526 const int renumber1[6]={2,5,1,0,3,4};
527 mesh->renumberCells(renumber1,false);
528 mesh->checkCoherency();
529 MEDLoader::WriteUMesh(fileName,mesh,true);
530 MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile(fileName,mesh->getName(),0);
531 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
536 void MEDLoaderTest::testFieldShuffleRW1()
538 const char fileName[]="file16.med";
539 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
540 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
541 f1->setName("FieldOnCellsShuffle");
543 DataArrayDouble *array=DataArrayDouble::New();
547 double *tmp=array->getPointer();
548 const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
549 std::copy(arr1,arr1+12,tmp);
550 f1->setTime(3.14,2,7);
551 f1->checkCoherency();
553 const int renumber1[6]={2,1,5,0,3,4};
554 f1->renumberCells(renumber1,false);
555 MEDLoader::WriteField(fileName,f1,true);
556 MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,mesh->getName(),0,f1->getName(),2,7);
557 CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
565 * Shuffle de cells but no profile. Like pointe.med
567 void MEDLoaderTest::testMultiFieldShuffleRW1()
569 const char fileName[]="file17.med";
570 MEDCouplingUMesh *m=build3DMesh_2();
571 CPPUNIT_ASSERT_EQUAL(20,m->getNumberOfCells());
572 CPPUNIT_ASSERT_EQUAL(45,m->getNumberOfNodes());
573 const int polys[3]={1,4,6};
574 std::vector<int> poly2(polys,polys+3);
575 m->convertToPolyTypes(&poly2[0],&poly2[0]+poly2.size());
576 const int renum[20]={1,3,2,8,9,12,13,16,19,0,4,7,5,15,14,17,10,18,6,11};
577 m->renumberCells(renum,false);
578 m->orientCorrectlyPolyhedrons();
580 MEDLoader::WriteUMesh(fileName,m,true);
581 MEDCouplingFieldDouble *f1Tmp=m->getMeasureField(false);
582 MEDCouplingFieldDouble *f1=f1Tmp->buildNewTimeReprFromThis(ONE_TIME,false);
585 MEDCouplingFieldDouble *f_1=f1->cloneWithMesh(true);
586 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
587 f1->applyFunc("2*x");
588 f1->setTime(0.01,3,4);
589 MEDCouplingFieldDouble *f_2=f1->cloneWithMesh(true);
590 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
591 f1->applyFunc("2*x/3");
592 f1->setTime(0.02,5,6);
593 MEDCouplingFieldDouble *f_3=f1->cloneWithMesh(true);
594 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
597 std::vector<std::pair<int,int> > its;
598 its.push_back(std::pair<int,int>(1,2));
599 its.push_back(std::pair<int,int>(3,4));
600 its.push_back(std::pair<int,int>(5,6));
601 std::vector<MEDCouplingFieldDouble *> fs=MEDLoader::ReadFieldsOnSameMesh(ON_CELLS,fileName,f_1->getMesh()->getName(),0,f_1->getName(),its);
602 CPPUNIT_ASSERT_EQUAL(3,(int)fs.size());
603 const MEDCouplingMesh *mm=fs[0]->getMesh();
604 CPPUNIT_ASSERT(fs[0]->isEqual(f_1,1e-12,1e-12));
605 CPPUNIT_ASSERT(fs[1]->isEqual(f_2,1e-12,1e-12));
606 CPPUNIT_ASSERT(fs[2]->isEqual(f_3,1e-12,1e-12));
607 CPPUNIT_ASSERT(mm==fs[1]->getMesh());// <- important for the test
608 CPPUNIT_ASSERT(mm==fs[2]->getMesh());// <- important for the test
609 for(std::vector<MEDCouplingFieldDouble *>::iterator iter=fs.begin();iter!=fs.end();iter++)
619 void MEDLoaderTest::testWriteUMeshesRW1()
621 const char fileName[]="file18.med";
622 MEDCouplingUMesh *m3d=build3DMesh_2();
623 const double pt[3]={0.,0.,-0.3};
624 const double vec[3]={0.,0.,1.};
625 std::vector<int> nodes;
626 m3d->findNodesOnPlane(pt,vec,1e-12,nodes);
627 MEDCouplingUMesh *m2d=(MEDCouplingUMesh *)m3d->buildFacePartOfMySelfNode(&nodes[0],&nodes[0]+nodes.size(),true);
628 const int renumber[5]={1,2,0,4,3};
629 m2d->renumberCells(renumber,false);
630 m2d->setName("ExampleOfMultiDimW");
631 std::vector<const MEDCouplingUMesh *> meshes;
632 meshes.push_back(m2d);
633 meshes.push_back(m3d);
634 MEDLoader::WriteUMeshes(fileName,meshes,true);
635 MEDCouplingUMesh *m3d_bis=MEDLoader::ReadUMeshFromFile(fileName,m2d->getName(),0);
636 CPPUNIT_ASSERT(!m3d_bis->isEqual(m3d,1e-12));
637 m3d_bis->setName(m3d->getName());
638 CPPUNIT_ASSERT(m3d_bis->isEqual(m3d,1e-12));
639 MEDCouplingUMesh *m2d_bis=MEDLoader::ReadUMeshFromFile(fileName,m2d->getName(),-1);//-1 for faces
640 CPPUNIT_ASSERT(m2d_bis->isEqual(m2d,1e-12));
641 // Creation of a field on faces.
642 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
643 f1->setName("FieldOnFacesShuffle");
645 DataArrayDouble *array=DataArrayDouble::New();
646 array->alloc(m2d->getNumberOfCells(),2);
647 array->setInfoOnComponent(0,"plkj [mm]");
648 array->setInfoOnComponent(1,"pqqqss [mm]");
651 double *tmp=array->getPointer();
652 const double arr1[10]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.};
653 std::copy(arr1,arr1+10,tmp);
654 f1->setTime(3.14,2,7);
655 f1->checkCoherency();
656 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
657 MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),-1,f1->getName(),2,7);
658 CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
668 void MEDLoaderTest::testMixCellAndNodesFieldRW1()
670 const char fileName[]="file21.med";
671 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
672 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
673 f1->setName("FieldMix");
675 DataArrayDouble *array=DataArrayDouble::New();
678 array->setInfoOnComponent(0,"plkj [mm]");
679 array->setInfoOnComponent(1,"pqqqss [mm]");
681 double *tmp=array->getPointer();
682 const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
683 std::copy(arr1,arr1+12,tmp);
684 f1->setTime(3.14,2,7);
685 f1->checkCoherency();
687 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
688 f2->setName("FieldMix");
690 array=DataArrayDouble::New();
693 array->setInfoOnComponent(0,"plkj [mm]");
694 array->setInfoOnComponent(1,"pqqqss [mm]");
696 tmp=array->getPointer();
697 const double arr2[24]={
698 1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
699 1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
701 std::copy(arr2,arr2+24,tmp);
702 f2->setTime(3.14,2,7);
703 f2->checkCoherency();
705 MEDLoader::WriteField(fileName,f1,true);
706 std::vector<ParaMEDMEM::TypeOfField> ts=MEDLoader::GetTypesOfField(fileName,f1->getMesh()->getName(),f1->getName());
707 CPPUNIT_ASSERT_EQUAL(1,(int)ts.size());
708 CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[0]);
709 std::vector<std::string> fs=MEDLoader::GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName());
710 CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
711 CPPUNIT_ASSERT(fs[0]=="FieldMix");
712 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f2);
713 fs=MEDLoader::GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName());
714 CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
715 CPPUNIT_ASSERT(fs[0]=="FieldMix");
717 ts=MEDLoader::GetTypesOfField(fileName,f1->getMesh()->getName(),f1->getName());
718 CPPUNIT_ASSERT_EQUAL(2,(int)ts.size());
719 CPPUNIT_ASSERT_EQUAL(ON_NODES,ts[0]);
720 CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[1]);
722 MEDCouplingFieldDouble *f3=MEDLoader::ReadFieldNode(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
723 CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
725 f3=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
726 CPPUNIT_ASSERT(f3->isEqual(f1,1e-12,1e-12));
734 void MEDLoaderTest::testGetAllFieldNamesRW1()
736 const char fileName[]="file22.med";
737 MEDCouplingUMesh *mesh=build2DMesh_2();
738 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
739 f1->setName("Field1");
740 f1->setTime(3.44,5,6);
742 f1->fillFromAnalytic(2,"x+y");
743 MEDLoader::WriteField(fileName,f1,true);
744 f1->setTime(1002.3,7,8);
745 f1->fillFromAnalytic(2,"x+77.*y");
746 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
747 f1->setName("Field2");
748 MEDLoader::WriteField(fileName,f1,false);
749 f1->setName("Field3");
750 mesh->setName("2DMesh_2Bis");
751 MEDLoader::WriteField(fileName,f1,false);
753 f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
754 f1->setName("Field8");
755 f1->setTime(8.99,7,9);
757 f1->fillFromAnalytic(3,"3*x+y");
758 MEDLoader::WriteField(fileName,f1,false);
760 std::vector<std::string> fs=MEDLoader::GetAllFieldNames(fileName);
761 CPPUNIT_ASSERT_EQUAL(4,(int)fs.size());
762 CPPUNIT_ASSERT(fs[0]=="Field1");
763 CPPUNIT_ASSERT(fs[1]=="Field2");
764 CPPUNIT_ASSERT(fs[2]=="Field3");
765 CPPUNIT_ASSERT(fs[3]=="Field8");
769 MEDCouplingUMesh *MEDLoaderTest::build1DMesh_1()
771 double coords[6]={ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 };
772 int conn[9]={ 0,1, 1,2, 2,3 , 3,4,5};
773 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
774 mesh->setName("1DMesh_1");
775 mesh->setMeshDimension(1);
776 mesh->allocateCells(4);
777 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
778 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
779 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
780 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6);
781 mesh->finishInsertingCells();
782 DataArrayDouble *myCoords=DataArrayDouble::New();
783 myCoords->alloc(6,1);
784 myCoords->setInfoOnComponent(0,"tototototototot [m*m*m*m*m*m*m*m]");
785 std::copy(coords,coords+6,myCoords->getPointer());
786 mesh->setCoords(myCoords);
791 MEDCouplingUMesh *MEDLoaderTest::build2DCurveMesh_1()
793 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 };
794 int conn[9]={ 0,1, 1,2, 2,3 , 3,4,5};
795 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
796 mesh->setName("2DCurveMesh_1");
797 mesh->setMeshDimension(1);
798 mesh->allocateCells(4);
799 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
800 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
801 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
802 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6);
803 mesh->finishInsertingCells();
804 DataArrayDouble *myCoords=DataArrayDouble::New();
805 myCoords->alloc(6,2);
806 std::copy(coords,coords+12,myCoords->getPointer());
807 mesh->setCoords(myCoords);
812 MEDCouplingUMesh *MEDLoaderTest::build2DMesh_1()
814 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 };
815 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};
816 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
817 targetMesh->setMeshDimension(2);
818 targetMesh->allocateCells(6);
819 targetMesh->setName("2DMesh_1");
820 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
821 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
822 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
823 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
824 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
825 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POLYGON,4,targetConn+20);
826 targetMesh->finishInsertingCells();
827 DataArrayDouble *myCoords=DataArrayDouble::New();
828 myCoords->alloc(12,2);
829 myCoords->setInfoOnComponent(0,"tototototototot [m]");
830 myCoords->setInfoOnComponent(1,"energie [kW]");
831 std::copy(targetCoords,targetCoords+24,myCoords->getPointer());
832 targetMesh->setCoords(myCoords);
837 MEDCouplingUMesh *MEDLoaderTest::build2DMesh_2()
839 double targetCoords[24]={
840 -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,
841 -0.05,0.95, 0.2,1.2, 0.45,0.95
843 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};
844 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
845 targetMesh->setMeshDimension(2);
846 targetMesh->allocateCells(5);
847 targetMesh->setName("2DMesh_2");
848 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
849 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
850 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
851 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
852 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
853 targetMesh->finishInsertingCells();
854 DataArrayDouble *myCoords=DataArrayDouble::New();
855 myCoords->alloc(12,2);
856 myCoords->setInfoOnComponent(0,"toto [m]");
857 myCoords->setInfoOnComponent(1,"energie [kW]");
858 std::copy(targetCoords,targetCoords+24,myCoords->getPointer());
859 targetMesh->setCoords(myCoords);
864 MEDCouplingUMesh *MEDLoaderTest::build3DSurfMesh_1()
866 double targetCoords[36]={
867 -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
868 ,-0.05,0.95,-0.3, 0.2,1.2,-0.3, 0.45,0.95,-0.3
870 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};
871 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
872 targetMesh->setMeshDimension(2);
873 targetMesh->allocateCells(6);
874 targetMesh->setName("3DSurfMesh_1");
875 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn);
876 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3);
877 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12);
878 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16);
879 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6);
880 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POLYGON,4,targetConn+20);
881 targetMesh->finishInsertingCells();
882 DataArrayDouble *myCoords=DataArrayDouble::New();
883 myCoords->alloc(12,3);
884 myCoords->setInfoOnComponent(0,"toto [m]");
885 myCoords->setInfoOnComponent(2,"ff [km]");//component 1 is not set for test
886 std::copy(targetCoords,targetCoords+36,myCoords->getPointer());
887 targetMesh->setCoords(myCoords);
892 MEDCouplingUMesh *MEDLoaderTest::build3DMesh_1()
895 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.,
896 3.,2.,0., 0.,1.,0., 1.,3.,0., 2.,2.,0., 2.,3.,0.,
897 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.,
898 3.,2.,1., 0.,1.,1., 1.,3.,1., 2.,2.,1., 2.,3.,1.,
899 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.,
900 3.,2.,2., 0.,1.,2., 1.,3.,2., 2.,2.,2., 2.,3.,2.,
901 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.,
902 3.,2.,3., 0.,1.,3., 1.,3.,3., 2.,2.,3., 2.,3.,3.};
906 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,
907 1,6,5,3,16,21,20,18, 13,10,9,6,28,25,24,21,
908 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,
909 7,12,14,13,22,27,29,28,
911 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,
912 16,21,20,18,31,36,35,33, 28,25,24,21,43,40,39,36,
913 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,
914 22,27,29,28,37,42,44,43,
916 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,
917 31,36,35,33,46,51,50,48, 43,40,39,36,58,55,54,51,
918 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,
919 37,42,44,43,52,57,59,58
922 MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
923 ret->setName("3DMesh_1");
924 ret->setMeshDimension(3);
925 ret->allocateCells(18);
927 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
928 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+51);
929 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+59);
930 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+110);
932 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+118);
933 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+169);
934 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+177);
935 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+228);
937 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+236);
938 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+287);
939 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+295);
940 ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+346);
942 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+8);
943 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+67);
944 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+126);
945 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+185);
946 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+244);
947 ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+303);
949 ret->finishInsertingCells();
950 DataArrayDouble *myCoords=DataArrayDouble::New();
951 myCoords->alloc(60,3);
952 myCoords->setInfoOnComponent(0,"titi [m]");
953 myCoords->setInfoOnComponent(1,"density power [MW/m^3]");
954 myCoords->setInfoOnComponent(2,"t [kW]");
955 std::copy(coords,coords+180,myCoords->getPointer());
956 ret->setCoords(myCoords);
961 MEDCouplingUMesh *MEDLoaderTest::build3DMesh_2()
963 MEDCouplingUMesh *m3dsurfBase=build3DSurfMesh_1();
964 int numbers[5]={0,1,2,3,5};
965 MEDCouplingUMesh *m3dsurf=(MEDCouplingUMesh *)m3dsurfBase->buildPartOfMySelf(numbers,numbers+5,false);
966 m3dsurfBase->decrRef();
967 MEDCouplingUMesh *m1dBase=build1DMesh_1();
968 int numbers2[4]={0,1,2,3};
969 MEDCouplingUMesh *m1d=(MEDCouplingUMesh *)m1dBase->buildPartOfMySelf(numbers2,numbers2+4,false);
971 m1d->changeSpaceDimension(3);
972 const double vec[3]={0.,1.,0.};
973 const double pt[3]={0.,0.,0.};
974 m1d->rotate(pt,vec,-M_PI/2.);
975 MEDCouplingUMesh *ret=m3dsurf->buildExtrudedMesh(m1d,0);
981 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnCells_1()
983 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
984 int nbOfCells=mesh->getNumberOfCells();
985 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
986 f1->setName("VectorFieldOnCells");
988 DataArrayDouble *array=DataArrayDouble::New();
989 array->alloc(nbOfCells,3);
990 array->setInfoOnComponent(0,"power [MW/m^3]");
991 array->setInfoOnComponent(1,"density [g/cm^3]");
992 array->setInfoOnComponent(2,"temperature [K]");
995 double *tmp=array->getPointer();
996 const double arr1[18]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.};
997 std::copy(arr1,arr1+18,tmp);
999 f1->checkCoherency();
1004 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnNodes_1()
1006 MEDCouplingUMesh *mesh=build3DSurfMesh_1();
1007 int nbOfNodes=mesh->getNumberOfNodes();
1008 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
1009 f1->setName("VectorFieldOnNodes");
1011 DataArrayDouble *array=DataArrayDouble::New();
1012 array->alloc(nbOfNodes,3);
1013 f1->setArray(array);
1014 array->setInfoOnComponent(0,"power [MW/m^3]");
1015 array->setInfoOnComponent(1,"density [g/cm^3]");
1016 array->setInfoOnComponent(2,"temperature [K]");
1018 double *tmp=array->getPointer();
1019 const double arr1[36]={
1020 70.,80.,90.,71.,81.,91.,72.,82.,92.,73.,83.,93.,74.,84.,94.,75.,85.,95.,
1021 1000.,10010.,10020.,1001.,10011.,10021.,1002.,10012.,10022.,1003.,10013.,10023.,1004.,10014.,10024.,1005.,10015.,10025.,
1023 std::copy(arr1,arr1+36,tmp);
1024 f1->setTime(2.12,2,3);
1025 f1->checkCoherency();
1030 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGauss_1()
1032 const double _a=0.446948490915965;
1033 const double _b=0.091576213509771;
1034 const double _p1=0.11169079483905;
1035 const double _p2=0.0549758718227661;
1036 const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
1037 const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
1038 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
1039 const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
1040 std::vector<double> _refCoo1(refCoo1,refCoo1+6);
1041 std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
1042 std::vector<double> _wg1(wg1,wg1+6);
1043 MEDCouplingUMesh *m=build2DMesh_2();
1044 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,ONE_TIME);
1045 f->setTime(3.14,1,5);
1047 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
1048 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 };
1049 std::vector<double> _refCoo2(refCoo2,refCoo2+12);
1050 std::vector<double> _gsCoo2(_gsCoo1);
1051 std::vector<double> _wg2(_wg1);
1052 _gsCoo2.resize(6); _wg2.resize(3);
1053 const double refCoo3[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
1054 std::vector<double> _refCoo3(refCoo3,refCoo3+8);
1055 _gsCoo1.resize(4); _wg1.resize(2);
1056 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo3,_gsCoo1,_wg1);
1057 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI6,_refCoo2,_gsCoo2,_wg2);
1058 DataArrayDouble *array=DataArrayDouble::New();
1060 double *ptr=array->getPointer();
1061 for(int i=0;i<19*2;i++)
1062 ptr[i]=(double)(i+7);
1064 f->setName("MyFirstFieldOnGaussPoint");
1065 array->setInfoOnComponent(0,"power [MW/m^3]");
1066 array->setInfoOnComponent(1,"density");
1068 f->checkCoherency();
1073 MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGaussNE_1()
1075 MEDCouplingUMesh *m=build2DMesh_2();
1076 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,ONE_TIME);
1077 f->setTime(3.14,1,5);
1079 DataArrayDouble *array=DataArrayDouble::New();
1081 double *ptr=array->getPointer();
1082 for(int i=0;i<20*2;i++)
1083 ptr[i]=(double)(i+8);
1085 array->setInfoOnComponent(0,"power [W]");
1086 array->setInfoOnComponent(1,"temperature");
1087 f->setName("MyFieldOnGaussNE");
1089 f->checkCoherency();