1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDPARTITIONERTest.hxx"
22 #include "MEDPARTITIONER_MeshCollection.hxx"
23 #include "MEDPARTITIONER_ParallelTopology.hxx"
24 #include "MEDPARTITIONER_ParaDomainSelector.hxx"
25 #include "MEDPARTITIONER_Utils.hxx"
27 #include "CellModel.hxx"
28 #include "MEDFileMesh.hxx"
29 #include "MEDLoader.hxx"
30 #include "MEDLoaderBase.hxx"
31 #include "MEDCouplingUMesh.hxx"
32 #include "MEDCouplingMappedExtrudedMesh.hxx"
33 #include "MEDCouplingFieldDouble.hxx"
34 #include "MEDCouplingMemArray.hxx"
35 #include "MEDCouplingMultiFields.hxx"
37 #include <cppunit/TestAssert.h>
48 #define getcwd _getcwd
58 using namespace MEDCoupling;
59 using namespace MEDPARTITIONER;
61 void MEDPARTITIONERTest::setSize(int ni, int nj, int nk)
63 this->_ni=ni; //nb of hexa9
66 this->_ntot=_ni*_nj*_nk;
67 string ijk=IntToStr(ni)+"x"+IntToStr(nj)+"x"+IntToStr(nk);
68 this->_file_name="tmp_testMesh_"+ijk+".med";
69 this->_file_name_with_faces="tmp_testMeshWithFaces_"+ijk+".med";
70 string ij=IntToStr(ni)+"x"+IntToStr(nj);
71 this->_file_name2="tmp_testMesh_"+ij+".med";
72 this->_mesh_name="testMesh";
75 void MEDPARTITIONERTest::setSmallSize()
77 setSize(2,3,5); //nb of hexa9
80 void MEDPARTITIONERTest::setMedianSize()
82 setSize(20,30,50); //nb of hexa9
85 void MEDPARTITIONERTest::setbigSize()
87 setSize(200,300,500); //nb of hexa9
90 std::string MEDPARTITIONERTest::getPartitionerExe() const
93 if ( getenv("MEDCOUPLING_ROOT_DIR") )
95 execName=getenv("MEDCOUPLING_ROOT_DIR"); //.../INSTALL/MED
96 execName+="/bin/medpartitioner";
97 std::ifstream my_file(execName.c_str());
101 execName = getcwd(NULL, 0);
102 execName += "/../../MEDPartitioner/medpartitioner";
103 if (! std::ifstream(execName.c_str()))
104 CPPUNIT_FAIL("Can't find medpartitioner, please set MEDCOUPLING_ROOT_DIR");
108 // ============================================================================
110 * Set up the environment called at every CPPUNIT_TEST ()
112 // ============================================================================
113 void MEDPARTITIONERTest::setUp()
116 #if defined(HAVE_MPI)
117 if (MyGlobals::_Rank==-1) //do once only
120 MPI_Comm_size(MPI_COMM_WORLD, &MyGlobals::_World_Size);
121 MPI_Comm_rank(MPI_COMM_WORLD, &MyGlobals::_Rank);
124 //sequential : no MPI
125 MyGlobals::_World_Size=1;
131 #if defined(HAVE_MPI)
132 cout<<"\ndefined(HAVE_MPI)"<<endl;
134 cout<<"\nNOT defined(HAVE_MPI)"<<endl;
136 #if defined(MED_ENABLE_PARMETIS)
137 cout<<"defined(MED_ENABLE_PARMETIS)"<<endl;
139 cout<<"NOT defined(MED_ENABLE_PARMETIS)"<<endl;
141 #if defined(MED_ENABLE_METIS)
142 cout<<"defined(MED_ENABLE_METIS)"<<endl;
144 cout<<"NOT defined(MED_ENABLE_METIS)"<<endl;
146 #if defined(MED_ENABLE_SCOTCH)
147 cout<<"defined(MED_ENABLE_SCOTCH)"<<endl;
149 cout<<"NOT defined(MED_ENABLE_SCOTCH)"<<endl;
154 // ============================================================================
158 // ============================================================================
159 void MEDPARTITIONERTest::tearDown()
163 MEDCoupling::MEDCouplingUMesh * MEDPARTITIONERTest::buildCUBE3DMesh()
168 for (int k=0; k<=_nk; k++)
169 for (int j=0; j<=_nj; j++)
170 for (int i=0; i<=_ni; i++)
172 coor.push_back(i+.1);
173 coor.push_back(j+.2);
174 coor.push_back(k+.3);
177 for (int k=0; k<_nk; k++)
178 for (int j=0; j<_nj; j++)
179 for (int i=0; i<_ni; i++)
181 ii=i + j*(_ni+1) + k*(_ni+1)*(_nj+1);
183 conn.push_back(ii+1);
186 conn.push_back(ii-1);
188 ii=i + j*(_ni+1) + (k+1)*(_ni+1)*(_nj+1);
190 conn.push_back(ii+1);
193 conn.push_back(ii-1);
197 if (_verbose) //only for debug
199 cout<< "\nnb coor " << (_ni+1)*(_nj+1)*(_nk+1)*3 << " " << coor.size() << endl;
200 for (int i=0; i<(int)coor.size(); i++)
201 cout << coor[i] << " ";
203 cout << "\nnb conn " << (_ni)*(_nj)*(_nk)*8 << " " << conn.size() << endl;
204 for (int i=0; i<(int)conn.size(); i=i+8)
206 for (int j=0; j<8; j++)
207 cout << conn[i+j] << " ";
214 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
215 mesh->setMeshDimension(3);
216 int nbc=conn.size()/8; //nb of cells
217 int nbv=coor.size()/3; //nb of vertices
218 mesh->allocateCells(nbc);
219 for(int i=0; i<nbc; i++)
222 std::copy(conn.begin()+i*8,conn.begin()+(i+1)*8,onehexa);
223 if (false) //(_verbose)
225 for (int j=0; j<8; j++) cout<<onehexa[j]<<" ";
228 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,onehexa);
230 mesh->finishInsertingCells();
231 DataArrayDouble *myCoords=DataArrayDouble::New();
232 myCoords->alloc(nbv,3);
233 std::copy(coor.begin(),coor.end(),myCoords->getPointer());
234 mesh->setCoords(myCoords);
235 mesh->setName(_mesh_name.c_str());
237 mesh->checkConsistencyLight();
241 MEDCoupling::MEDCouplingUMesh * MEDPARTITIONERTest::buildCARRE3DMesh()
242 //only quad4 in oblique (k=j)
246 for (int j=0; j<=_nj; j++)
247 for (int i=0; i<=_ni; i++)
250 coor.push_back(i+.1);
251 coor.push_back(j+.2);
252 coor.push_back(k+.3);
256 for (int j=0; j<_nj; j++)
257 for (int i=0; i<_ni; i++)
259 ii=i + j*(_ni+1) + k*(_ni+1)*(_nj+1);
261 conn.push_back(ii+1);
264 conn.push_back(ii-1);
267 if (false) //(_verbose)
269 cout<<"\nnb coor "<<(_ni+1)*(_nj+1)*3<<" "<<coor.size()<<endl;
270 for (int i=0; i<(int)coor.size(); i++)
271 cout << coor[i] << " ";
273 cout<<"\nnb conn "<<(_ni)*(_nj)*4<<" "<<conn.size()<<endl;
274 for (int i=0; i<(int)conn.size(); i=i+4)
276 for (int j=0; j<4; j++) cout<<conn[i+j]<<" ";
282 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
283 mesh->setMeshDimension(2);
284 int nbc=conn.size()/4; //nb of cells
285 int nbv=coor.size()/3; //nb of vertices
286 mesh->allocateCells(nbc);
287 for(int i=0; i<nbc; i++)
290 std::copy(conn.begin()+i*4,conn.begin()+(i+1)*4,onequa);
291 if (false) //(_verbose)
293 for (int j=0; j<4; j++) cout<<onequa[j]<<" ";
296 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,onequa);
298 mesh->finishInsertingCells();
299 DataArrayDouble *myCoords=DataArrayDouble::New();
300 myCoords->alloc(nbv,3);
301 std::copy(coor.begin(),coor.end(),myCoords->getPointer());
302 mesh->setCoords(myCoords);
303 mesh->setName(_mesh_name.c_str());
305 mesh->checkConsistencyLight();
309 MEDCoupling::MEDCouplingUMesh * MEDPARTITIONERTest::buildFACE3DMesh()
310 //only quad4 on a global face of the CUBE3D (k=0)
314 for (int j=0; j<=_nj; j++)
315 for (int i=0; i<=_ni; i++)
318 coor.push_back(i+.1);
319 coor.push_back(j+.2);
320 coor.push_back(k+.3);
324 for (int j=0; j<_nj; j++)
325 for (int i=0; i<_ni; i++)
327 ii=i + j*(_ni+1) + k*(_ni+1)*(_nj+1);
329 conn.push_back(ii+1);
332 conn.push_back(ii-1);
335 if (false) //(_verbose)
337 cout<<"\nnb coor "<<(_ni+1)*(_nj+1)*3<<" "<<coor.size()<<endl;
338 for (int i=0; i<(int)coor.size(); i++)
339 cout << coor[i] << " ";
341 cout<<"\nnb conn "<<(_ni)*(_nj)*4<<" "<<conn.size()<<endl;
342 for (int i=0; i<(int)conn.size(); i=i+4)
344 for (int j=0; j<4; j++)
345 cout << conn[i+j] << " ";
351 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
352 mesh->setMeshDimension(2);
353 int nbc=conn.size()/4; //nb of cells
354 int nbv=coor.size()/3; //nb of vertices
355 mesh->allocateCells(nbc);
356 for(int i=0; i<nbc; i++)
359 std::copy(conn.begin()+i*4,conn.begin()+(i+1)*4,onequa);
360 if (false) //(_verbose)
362 for (int j=0; j<4; j++) cout<<onequa[j]<<" ";
365 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,onequa);
367 mesh->finishInsertingCells();
368 DataArrayDouble *myCoords=DataArrayDouble::New();
369 myCoords->alloc(nbv,3);
370 std::copy(coor.begin(),coor.end(),myCoords->getPointer());
371 mesh->setCoords(myCoords);
372 mesh->setName(_mesh_name.c_str());
374 mesh->checkConsistencyLight();
378 MEDCouplingFieldDouble * MEDPARTITIONERTest::buildVecFieldOnCells(string myfileName)
380 //int ni=2,nj=3,nk=5; //nb of hexa9
381 vector<double> field;
382 for (int k=0; k<_nk; k++)
383 for (int j=0; j<_nj; j++)
384 for (int i=0; i<_ni; i++)
386 field.push_back(i+.1);
387 field.push_back(j+.2);
388 field.push_back(k+.3);
391 MEDCouplingUMesh *mesh=ReadUMeshFromFile(myfileName.c_str(),_mesh_name.c_str(),0);
392 int nbOfCells=mesh->getNumberOfCells();
393 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
394 f1->setName("VectorFieldOnCells");
395 f1->setDescription("DescriptionOfFieldOnCells"); //not saved in file?
397 DataArrayDouble *myField=DataArrayDouble::New();
398 myField->alloc(nbOfCells,3);
399 std::copy(field.begin(),field.end(),myField->getPointer());
400 f1->setArray(myField);
401 myField->setInfoOnComponent(0,"vx");
402 myField->setInfoOnComponent(1,"vy");
403 myField->setInfoOnComponent(2,"vz");
406 f1->checkConsistencyLight();
411 MEDCouplingFieldDouble * MEDPARTITIONERTest::buildVecFieldOnNodes()
413 //int ni=2,nj=3,nk=5; //nb of hexa9
414 vector<double> field;
415 for (int k=0; k<=_nk; k++)
416 for (int j=0; j<=_nj; j++)
417 for (int i=0; i<=_ni; i++)
419 field.push_back(i+.1);
420 field.push_back(j+.2);
421 field.push_back(k+.3);
424 MEDCouplingUMesh *mesh=ReadUMeshFromFile(_file_name.c_str(),_mesh_name.c_str(),0);
425 int nbOfNodes=mesh->getNumberOfNodes();
426 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
427 f1->setName("VectorFieldOnNodes");
428 f1->setDescription("DescriptionOfFieldOnNodes"); //not saved in file?
430 DataArrayDouble *myField=DataArrayDouble::New();
431 myField->alloc(nbOfNodes,3);
432 std::copy(field.begin(),field.end(),myField->getPointer());
433 f1->setArray(myField);
434 myField->setInfoOnComponent(0,"vx");
435 myField->setInfoOnComponent(1,"vy");
436 myField->setInfoOnComponent(2,"vz");
439 f1->checkConsistencyLight();
445 void MEDPARTITIONERTest::createTestMeshWithoutField()
448 MEDCouplingUMesh * mesh = buildCUBE3DMesh();
449 WriteUMesh(_file_name.c_str(),mesh,true);
450 if (_verbose) cout<<endl<<_file_name<<" created"<<endl;
451 if (_ntot<1000000) //too long
453 MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile(_file_name.c_str(),mesh->getName().c_str(),0);
454 if (_verbose) cout<<_file_name<<" reread"<<endl;
455 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
462 vector<const MEDCoupling::MEDCouplingUMesh*> meshes;
463 MEDCouplingUMesh * mesh1 = buildCUBE3DMesh();
464 MEDCouplingUMesh * mesh2 = buildFACE3DMesh();
465 mesh1->setName("testMesh");
466 mesh2->setName("theFaces");
467 mesh2->tryToShareSameCoordsPermute(*mesh1, 1e-9);
468 mesh2->checkConsistencyLight();
469 mesh1->checkConsistencyLight();
470 meshes.push_back(mesh1);
471 meshes.push_back(mesh2);
472 WriteUMeshes(_file_name_with_faces.c_str(), meshes, true);
474 MEDCoupling::MEDFileUMesh* mfm=MEDCoupling::MEDFileUMesh::New(_file_name_with_faces.c_str(), mesh1->getName().c_str());
475 DataArrayInt* FacesFam=DataArrayInt::New();
476 FacesFam->alloc(mfm->getSizeAtLevel(-1),1);
477 FacesFam->fillWithValue(-1);
478 DataArrayInt* CellsFam=DataArrayInt::New();
479 CellsFam->alloc(mfm->getSizeAtLevel(0),1);
480 CellsFam->fillWithValue(1);
481 mfm->setFamilyFieldArr(-1,FacesFam);
482 mfm->setFamilyFieldArr(0,CellsFam);
483 map<string,int> theFamilies;
484 theFamilies["FAMILLE_ZERO"]=0;
485 theFamilies["FamilyFaces"]=-1;
486 theFamilies["FamilyCells"]=1;
487 map<string, vector<string> > theGroups;
488 theGroups["GroupFaces"].push_back("FamilyFaces");
489 theGroups["GroupCells"].push_back("FamilyCells");
490 mfm->setFamilyInfo(theFamilies);
491 mfm->setGroupInfo(theGroups);
492 mfm->write(_file_name_with_faces.c_str(),0);
496 /*ce truc marche pas!
497 MEDCoupling::MEDFileUMesh* mfm=MEDCoupling::MEDFileUMesh::New(_file_name_with_faces.c_str(), mesh1->getName());
498 vector<const MEDCoupling::MEDCouplingUMesh*> ms;
500 mfm->setGroupsFromScratch(-1, ms);
501 mfm->write(_file_name_with_faces.c_str(),0);
504 if (_verbose) cout<<endl<<_file_name_with_faces<<" created"<<endl;
505 if (_ntot<1000000) //too long
507 MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile(_file_name_with_faces.c_str(),mesh1->getName().c_str(),0);
508 if (_verbose) cout<<_file_name_with_faces<<" reread"<<endl;
509 CPPUNIT_ASSERT(mesh1->isEqual(mesh_rw,1e-12));
518 MEDCouplingUMesh * mesh = buildCARRE3DMesh();
519 WriteUMesh(_file_name2.c_str(),mesh,true);
520 if (_verbose) cout<<endl<<_file_name2<<" created"<<endl;
521 MEDCouplingUMesh *mesh_rw=ReadUMeshFromFile(_file_name2.c_str(),mesh->getName().c_str(),0);
522 if (_verbose) cout<<_file_name2<<" reread"<<endl;
523 CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
530 create a set of nbx*nby*nbz files mesh of ni*ny*nz cells
532 void MEDPARTITIONERTest::createHugeTestMesh(int ni, int nj, int nk, int nbx, int nby, int nbz, int nbTarget)
535 _nb_target_huge=nbTarget;
536 MEDCouplingUMesh * mesh = buildCUBE3DMesh();
537 //int nbx=1, nby=1, nbz=2;
538 std::vector< double > cooDep,cooFin;
539 mesh->getCoordinatesOfNode(0, cooDep);
540 mesh->getCoordinatesOfNode(mesh->getNumberOfNodes()-1, cooFin);
541 //cout<<endl<<cooDep[0]<<" "<<cooDep[1]<<" "<<cooDep[2]<<endl;
542 //cout<<cooFin[0]<<" "<<cooFin[1]<<" "<<cooFin[2]<<endl;
545 <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n \
547 <version maj=\"2\" min=\"3\" ver=\"1\"/>\n \
548 <description what=\"\" when=\"YYMMDDHHmm\"/>\n \
550 <mesh name=\"testMesh\"/>\n \
553 <subdomain number=\"$subdomainNumber\"/>\n \
554 <global_numbering present=\"no\"/>\n \
556 <files>\n$tagSubfile \
558 <mapping>\n$tagMesh \
562 string tagSubfiles, tagSubfile="\
563 <subfile id=\"$xyz\">\n \
564 <name>$fileName</name>\n \
565 <machine>localhost</machine>\n \
567 string tagMeshes, tagMesh="\
568 <mesh name=\"testMesh\">\n \
569 <chunk subdomain=\"$xyz\">\n \
570 <name>testMesh</name>\n \
576 DataArrayDouble* coordsInit=mesh->getCoords()->deepCopy();
577 double* ptrInit=coordsInit->getPointer();
578 double deltax=cooFin[0]-cooDep[0];
579 double deltay=cooFin[1]-cooDep[1];
580 double deltaz=cooFin[2]-cooDep[2];
583 for (int z=0; z<nbz; z++)
586 for (int y=0; y<nby; y++)
589 for (int x=0; x<nbx; x++)
593 fileName="tmp_testMeshHuge_"+IntToStr(_ni)+"x"+IntToStr(_nj)+"x"+IntToStr(_nk)+"_"+sxyz+".med";
595 DataArrayDouble* coords=mesh->getCoords();
596 //int nbOfComp=coords->getNumberOfComponents(); //be 3D
597 int nbOfTuple=coords->getNumberOfTuples();
598 double* ptr=coords->getPointer();
599 double* ptrini=ptrInit;
600 for (int i=0; i<nbOfTuple; i++)
602 *ptr=(*ptrini)+dx; ptr++; ptrini++; //be 3D
603 *ptr=(*ptrini)+dy; ptr++; ptrini++;
604 *ptr=(*ptrini)+dz; ptr++; ptrini++;
607 WriteUMesh(fileName.c_str(),mesh,true);
609 tagSubfiles+=tagSubfile;
610 tagSubfiles.replace(tagSubfiles.find("$xyz"),4,sxyz);
611 tagSubfiles.replace(tagSubfiles.find("$fileName"),9,fileName);
614 tagMeshes.replace(tagMeshes.find("$xyz"),4,sxyz);
622 coordsInit->decrRef();
624 tagXml.replace(tagXml.find("$subdomainNumber"),16,sxyz);
625 tagXml.replace(tagXml.find("$tagSubfile"),11,tagSubfiles);
626 tagXml.replace(tagXml.find("$tagMesh"),8,tagMeshes);
629 _file_name_huge_xml="tmp_testMeshHuge_"+IntToStr(_ni)+"x"+IntToStr(_nj)+"x"+IntToStr(_nk)+"_"+sxyz+".xml";
630 std::ofstream f(_file_name_huge_xml.c_str());
633 //cout<<"\n"<<tagXml<<endl;
635 cout<<endl<<nameFileXml<<" created"<<endl;
639 void MEDPARTITIONERTest::createTestMeshWithVecFieldOnCells()
642 string name=_file_name;
643 MEDCouplingFieldDouble *f1=buildVecFieldOnCells(name);
644 name.replace(name.find(".med"),4,"_WithVecFieldOnCells.med");
645 WriteField(name.c_str(),f1,true);
646 f1->setTime(3.,1,1); //time,it,order
647 f1->applyFunc("x/2.");
648 WriteField(name.c_str(),f1,false);
649 if (_verbose) cout<<endl<<name<<" created"<<endl;
650 if (_ntot<1000000) //too long
652 MCAuto<MEDCouplingFieldDouble> f2=ReadFieldCell(name.c_str(),f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),0,1);
653 //DataArrayDouble *res=f2->getArray();
654 if (_verbose) cout<<name<<" reread"<<endl;
655 //CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
660 string name=_file_name;
661 MEDCouplingFieldDouble *f1=buildVecFieldOnCells(name);
662 name.replace(name.find(".med"),4,"_WithVecFieldOnGaussNe.med");
663 MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::New(ON_GAUSS_NE,ONE_TIME);
664 f3->setMesh(f1->getMesh());
665 //cout<<"\nNumberOfMeshPlacesExpected "<<f3->getNumberOfMeshPlacesExpected()<<" "
666 // /*<<getNumberOfTuples(f1->getMesh())<<" "*/
667 // <<f3->getMesh()->getNumberOfNodes()<<" "
668 // <<f3->getMesh()->getNumberOfCells()<<endl;
669 f3->setName("MyFieldOnGaussNE");
670 f3->setDescription("MyDescriptionNE");
671 DataArrayDouble *array=DataArrayDouble::New();
672 //int nb=f1->getMesh()->getNumberOfNodes();
674 /*8 pt de gauss by cell
675 int nb=f3->getMesh()->getNumberOfCells()*8;
677 double *ptr=array->getPointer();
678 for (int i=0; i<nb*2; i=i+2) {ptr[i]=(double)(i/8) ; ptr[i]=2.*(double)(i/8);}
681 //more nbptgauss=8 by default needs set MEDCouplingFieldDiscretizationPerCell
682 //theory: (may be) http://www.code-aster.org/V2/doc/v9/fr/man_r/r3/r3.06.03.pdf
683 int nbptgauss=8; //nb pt de gauss by cell
684 int nbcell=f3->getMesh()->getNumberOfCells();
685 int nb=nbcell*nbptgauss;
687 array->alloc(nb,nbcomp);
688 double *ptr=array->getPointer();
690 for (int i=0; i<nbcell; i++)
691 for (int j=0; j<nbptgauss; j++)
692 for (int k=0; k<nbcomp; k++)
694 //123.4 for 12th cell,3rd component, 4th gausspoint
695 ptr[ii]=(double)((i+1)*10+(k+1))+((double)(j+1))/10.;
698 array->setInfoOnComponent(0,"vGx");
699 array->setInfoOnComponent(1,"vGy");
703 WriteField(name.c_str(),f3,true);
704 if (_verbose) cout<<endl<<name<<" created"<<endl;
705 f3->checkConsistencyLight();
707 if (_ntot<1000000) //too long
709 MCAuto<MEDCouplingFieldDouble> f4=ReadField(ON_GAUSS_NE, name.c_str(), f3->getMesh()->getName().c_str(), 0, "MyFieldOnGaussNE", 5, 6);
710 if (_verbose) cout<<"MyFieldOnGaussNE reread"<<endl;
715 string name=_file_name_with_faces;
716 MEDCouplingFieldDouble *f1=buildVecFieldOnCells(name);
717 name.replace(name.find(".med"),4,"_WithVecFieldOnCells.med");
718 WriteField(name.c_str(),f1,true);
719 if (_verbose) cout<<endl<<name<<" created"<<endl;
720 if (_ntot<1000000) //too long
722 MCAuto<MEDCouplingFieldDouble> f2=ReadFieldCell(name.c_str(),f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),0,1);
723 if (_verbose) cout<<name<<" reread"<<endl;
724 //CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12)); assertion failed!!
730 void MEDPARTITIONERTest::createTestMeshWithVecFieldOnNodes()
732 MEDCouplingFieldDouble *f1=buildVecFieldOnNodes();
733 string name=_file_name;
734 name.replace(name.find(".med"),4,"_WithVecFieldOnNodes.med");
735 WriteField(name.c_str(),f1,true);
736 if (_verbose) cout<<endl<<name<<" created"<<endl;
737 if (_ntot<1000000) //too long
739 MCAuto<MEDCouplingFieldDouble> f2=ReadFieldNode(name.c_str(),f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),0,1);
740 if (_verbose) cout<<name<<" reread"<<endl;
741 //CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12)); assertion failed!!
746 void MEDPARTITIONERTest::verifyTestMeshWithVecFieldOnNodes()
748 string name=_file_name;
749 name.replace(name.find(".med"),4,"_WithVecFieldOnNodes.med");
750 MEDCouplingUMesh * m=ReadUMeshFromFile(name.c_str(),_mesh_name.c_str(),0);
751 std::set<INTERP_KERNEL::NormalizedCellType> types(m->getAllGeoTypes());
754 cout<<"\n types in "<<name<<" : ";
755 //for (std::set<INTERP_KERNEL::NormalizedCellType>::iterator t=types.begin(); t!=types.end(); ++t) cout<<" "<<*t;
756 for (std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator t=types.begin(); t!=types.end(); ++t)
758 //INTERP_KERNEL::CellModel essai=INTERP_KERNEL::CellModel::GetCellModel(*t);
759 cout<<" "<<(INTERP_KERNEL::CellModel::GetCellModel(*t)).getRepr();
765 MEDFileUMesh * mf = MEDFileUMesh::New(_file_name.c_str(),_mesh_name.c_str(),-1,-1);
767 lev=mf->getNonEmptyLevels();
770 cout<<" levels in "<<name<<" : ";
771 for (vector<int>::iterator l=lev.begin(); l!=lev.end(); ++l) cout<<" "<<*l;
777 void MEDPARTITIONERTest::createTestMeshes()
779 createTestMeshWithoutField();
780 createTestMeshWithVecFieldOnCells();
781 createTestMeshWithVecFieldOnNodes();
784 void MEDPARTITIONERTest::deleteTestMeshes()
786 string cmd="rm *tmp_testMesh*";
787 if (_verbose) cout<<endl<<cmd<<endl;
788 system(cmd.c_str()); //may be not if debug
791 void MEDPARTITIONERTest::testMeshCollectionSingle()
795 MyGlobals::_World_Size=1;
797 string fileName=_file_name_with_faces;
798 MEDPARTITIONER::ParaDomainSelector parallelizer(false);
799 MEDPARTITIONER::MeshCollection collection(fileName,parallelizer);
800 CPPUNIT_ASSERT(collection.isParallelMode());
801 CPPUNIT_ASSERT_EQUAL(3, collection.getMeshDimension());
802 CPPUNIT_ASSERT(collection.getName()=="testMesh");
803 CPPUNIT_ASSERT_EQUAL(1,collection.getNbOfLocalMeshes());
804 CPPUNIT_ASSERT_EQUAL(1,collection.getNbOfGlobalMeshes());
805 CPPUNIT_ASSERT_EQUAL(_ni*_nj*_nk,collection.getNbOfLocalCells());
806 CPPUNIT_ASSERT_EQUAL(_ni*_nj,collection.getNbOfLocalFaces());
809 void MEDPARTITIONERTest::testMeshCollectionXml()
812 createHugeTestMesh(_ni, _nj, _nk, 2, 2, 2, 32); //xml but not so huge
813 string fileName=_file_name_huge_xml;
814 MEDPARTITIONER::ParaDomainSelector parallelizer(false);
815 MEDPARTITIONER::MeshCollection collection(fileName,parallelizer);
816 CPPUNIT_ASSERT(collection.isParallelMode());
817 CPPUNIT_ASSERT_EQUAL(3, collection.getMeshDimension());
818 CPPUNIT_ASSERT(collection.getName()=="testMesh");
819 CPPUNIT_ASSERT_EQUAL(8,collection.getNbOfLocalMeshes());
820 CPPUNIT_ASSERT_EQUAL(8,collection.getNbOfGlobalMeshes());
821 CPPUNIT_ASSERT_EQUAL(_ni*_nj*_nk*8,collection.getNbOfLocalCells());
822 CPPUNIT_ASSERT_EQUAL(0,collection.getNbOfLocalFaces());
826 //#################for metis
830 #if defined(MED_ENABLE_METIS)
831 void MEDPARTITIONERTest::testMeshCollectionSinglePartitionMetis()
835 //MyGlobals::_Verbose=500;
836 string fileName=_file_name_with_faces;
838 bool split_family=false;
839 bool empty_groups=false;
840 MEDPARTITIONER::ParaDomainSelector parallelizer(false);
841 MEDPARTITIONER::MeshCollection collection(fileName,parallelizer);
843 MEDPARTITIONER::ParallelTopology* aPT = (MEDPARTITIONER::ParallelTopology*) collection.getTopology();
844 aPT->setGlobalNumerotationDefault(collection.getParaDomainSelector());
845 //Creating the graph and partitioning it
846 auto_ptr< MEDPARTITIONER::Topology > new_topo;
847 new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::METIS) );
848 //Creating a new mesh collection from the partitioning
849 MEDPARTITIONER::MeshCollection new_collection(collection,new_topo.get(),split_family,empty_groups);
851 //example to create files
852 //MyGlobals::_General_Informations.clear();
853 //MyGlobals::_General_Informations.push_back(SerializeFromString("finalMeshName=Merge"));
854 //if (MyGlobals::_Verbose>100) cout << "generalInformations : \n"<<ReprVectorOfString(MyGlobals::_General_Informations);
855 //new_collection.write("ttmp")
857 CPPUNIT_ASSERT(new_collection.isParallelMode());
858 CPPUNIT_ASSERT_EQUAL(3, new_collection.getMeshDimension());
859 CPPUNIT_ASSERT(new_collection.getName()==collection.getName());
860 CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfLocalMeshes());
861 CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfGlobalMeshes());
862 CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalCells(),new_collection.getNbOfLocalCells());
863 CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalFaces(),new_collection.getNbOfLocalFaces());
866 void MEDPARTITIONERTest::testMeshCollectionComplexPartitionMetis()
869 createHugeTestMesh(_ni, _nj, _nk, 2, 2, 2, 32); //xml on 2*2*2 meshes but not so huge
870 string fileName=_file_name_huge_xml;
871 bool split_family=false;
872 bool empty_groups=false;
873 MEDPARTITIONER::ParaDomainSelector parallelizer(false);
874 MEDPARTITIONER::MeshCollection collection(fileName,parallelizer);
876 MEDPARTITIONER::ParallelTopology* aPT = (MEDPARTITIONER::ParallelTopology*) collection.getTopology();
877 aPT->setGlobalNumerotationDefault(collection.getParaDomainSelector());
879 for (int ndomains=2 ; ndomains<=16 ; ndomains++)
881 //Creating the graph and partitioning it
882 auto_ptr< MEDPARTITIONER::Topology > new_topo;
883 new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::METIS) );
884 //Creating a new mesh collection from the partitioning
885 MEDPARTITIONER::MeshCollection new_collection(collection,new_topo.get(),split_family,empty_groups);
887 CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfLocalMeshes());
888 CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfGlobalMeshes());
889 CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalCells(),new_collection.getNbOfLocalCells());
890 CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalFaces(),new_collection.getNbOfLocalFaces());
894 void MEDPARTITIONERTest::testMetisSmallSize()
896 //#if !defined(HAVE_MPI)
899 std::string MetisOrScotch("metis");
900 launchMetisOrScotchMedpartitionerOnTestMeshes(MetisOrScotch);
901 verifyMetisOrScotchMedpartitionerOnSmallSizeForMesh(MetisOrScotch);
902 verifyMetisOrScotchMedpartitionerOnSmallSizeForFieldOnCells(MetisOrScotch);
903 verifyMetisOrScotchMedpartitionerOnSmallSizeForFieldOnGaussNe(MetisOrScotch);
909 //#################for scotch
912 #if defined(MED_ENABLE_SCOTCH)
913 void MEDPARTITIONERTest::testMeshCollectionSinglePartitionScotch()
917 //MyGlobals::_Verbose=500;
918 string fileName=_file_name_with_faces;
920 bool split_family=false;
921 bool empty_groups=false;
922 MEDPARTITIONER::ParaDomainSelector parallelizer(false);
923 MEDPARTITIONER::MeshCollection collection(fileName,parallelizer);
925 MEDPARTITIONER::ParallelTopology* aPT = (MEDPARTITIONER::ParallelTopology*) collection.getTopology();
926 aPT->setGlobalNumerotationDefault(collection.getParaDomainSelector());
927 //Creating the graph and partitioning it
928 auto_ptr< MEDPARTITIONER::Topology > new_topo;
929 new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH) );
930 //Creating a new mesh collection from the partitioning
931 MEDPARTITIONER::MeshCollection new_collection(collection,new_topo.get(),split_family,empty_groups);
933 //example to create files
934 //MyGlobals::_General_Informations.clear();
935 //MyGlobals::_General_Informations.push_back(SerializeFromString("finalMeshName=Merge"));
936 //if (MyGlobals::_Verbose>100) cout << "generalInformations : \n"<<ReprVectorOfString(MyGlobals::_General_Informations);
937 //new_collection.write("ttmp")
939 CPPUNIT_ASSERT(new_collection.isParallelMode());
940 CPPUNIT_ASSERT_EQUAL(3, new_collection.getMeshDimension());
941 CPPUNIT_ASSERT(new_collection.getName()==collection.getName());
942 CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfLocalMeshes());
943 CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfGlobalMeshes());
944 CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalCells(),new_collection.getNbOfLocalCells());
945 CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalFaces(),new_collection.getNbOfLocalFaces());
948 void MEDPARTITIONERTest::testMeshCollectionComplexPartitionScotch()
951 createHugeTestMesh(_ni, _nj, _nk, 2, 2, 2, 32); //xml on 2*2*2 meshes but not so huge
952 string fileName=_file_name_huge_xml;
953 bool split_family=false;
954 bool empty_groups=false;
955 MEDPARTITIONER::ParaDomainSelector parallelizer(false);
956 MEDPARTITIONER::MeshCollection collection(fileName,parallelizer);
958 MEDPARTITIONER::ParallelTopology* aPT = (MEDPARTITIONER::ParallelTopology*) collection.getTopology();
959 aPT->setGlobalNumerotationDefault(collection.getParaDomainSelector());
961 for (int ndomains=2 ; ndomains<=16 ; ndomains++)
963 //Creating the graph and partitioning it
964 auto_ptr< MEDPARTITIONER::Topology > new_topo;
965 new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH) );
966 //Creating a new mesh collection from the partitioning
967 MEDPARTITIONER::MeshCollection new_collection(collection,new_topo.get(),split_family,empty_groups);
969 CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfLocalMeshes());
970 CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfGlobalMeshes());
971 CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalCells(),new_collection.getNbOfLocalCells());
972 CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalFaces(),new_collection.getNbOfLocalFaces());
976 void MEDPARTITIONERTest::testScotchSmallSize()
978 //#if !defined(HAVE_MPI)
981 std::string MetisOrScotch("scotch");
982 launchMetisOrScotchMedpartitionerOnTestMeshes(MetisOrScotch);
983 verifyMetisOrScotchMedpartitionerOnSmallSizeForMesh(MetisOrScotch);
984 verifyMetisOrScotchMedpartitionerOnSmallSizeForFieldOnCells(MetisOrScotch);
985 verifyMetisOrScotchMedpartitionerOnSmallSizeForFieldOnGaussNe(MetisOrScotch);
990 void MEDPARTITIONERTest::launchMetisOrScotchMedpartitionerOnTestMeshes(std::string MetisOrScotch)
993 string cmd,execName,sourceName,targetName;
995 execName=getPartitionerExe();
997 cmd="which "+execName+" 2>/dev/null 1>/dev/null"; //no trace
998 res=system(cmd.c_str());
999 CPPUNIT_ASSERT_EQUAL_MESSAGE(execName + " - INVALID PATH TO medpartitioner", 0, res);
1001 cmd=execName+" --ndomains=2 --split-method="+MetisOrScotch; //on same proc
1002 sourceName=_file_name;
1003 targetName=_file_name;
1004 targetName.replace(targetName.find(".med"),4,"_partitionedTo2_");
1005 cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
1006 if (_verbose) cout<<endl<<cmd<<endl;
1007 res=system(cmd.c_str());
1008 CPPUNIT_ASSERT_EQUAL(0, res);
1010 cmd=execName+" --ndomains=5 --split-method="+MetisOrScotch; //on less proc
1011 sourceName=_file_name;
1012 targetName=_file_name;
1013 targetName.replace(targetName.find(".med"),4,"_partitionedTo5_");
1014 cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
1015 if (_verbose) cout<<endl<<cmd<<endl;
1016 res=system(cmd.c_str());
1017 CPPUNIT_ASSERT_EQUAL(0, res);
1019 cmd=execName+" --ndomains=1 --split-method="+MetisOrScotch; //on 1 proc
1020 sourceName=targetName+".xml";
1021 targetName=_file_name;
1022 targetName.replace(targetName.find(".med"),4,"_remergedFrom5_");
1023 cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
1024 if (_verbose) cout<<endl<<cmd<<endl;
1025 res=system(cmd.c_str());
1026 CPPUNIT_ASSERT_EQUAL(0, res);
1028 cmd=execName+" --ndomains=1 --split-method="+MetisOrScotch; //on more proc
1029 //sourceName=targetName+".xml";
1030 targetName=_file_name;
1031 targetName.replace(targetName.find(".med"),4,"_remergedFrom5_");
1032 cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
1033 if (_verbose) cout<<endl<<cmd<<endl;
1034 res=system(cmd.c_str());
1035 CPPUNIT_ASSERT_EQUAL(0, res);
1038 void MEDPARTITIONERTest::verifyMetisOrScotchMedpartitionerOnSmallSizeForMesh(std::string MetisOrScotch)
1041 string fileName,cmd,execName,sourceName,targetName,input;
1042 execName=getPartitionerExe();
1043 fileName=_file_name_with_faces;
1045 MEDCoupling::MEDFileUMesh* initialMesh=MEDCoupling::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str());
1046 MEDCoupling::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false);
1047 MEDCoupling::MEDCouplingUMesh* faceMesh=initialMesh->getLevelM1Mesh(false);
1049 cmd=execName+" --ndomains=5 --split-method="+MetisOrScotch; //on same proc
1050 sourceName=fileName;
1051 targetName=fileName;
1052 targetName.replace(targetName.find(".med"),4,"_partitionedTo5_");
1053 cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
1054 if (_verbose) cout<<endl<<cmd<<endl;
1055 res=system(cmd.c_str());
1056 CPPUNIT_ASSERT_EQUAL(0, res);
1057 input=targetName+".xml";
1059 MEDPARTITIONER::ParaDomainSelector parallelizer(false);
1060 MEDPARTITIONER::MeshCollection collection(input,parallelizer);
1061 CPPUNIT_ASSERT_EQUAL(3, collection.getMeshDimension());
1062 std::vector<MEDCoupling::MEDCouplingUMesh*>cellMeshes=collection.getMesh();
1063 CPPUNIT_ASSERT_EQUAL(5, (int) cellMeshes.size());
1065 for (std::size_t i = 0; i < cellMeshes.size(); i++)
1066 nbcells+=cellMeshes[i]->getNumberOfCells();
1067 CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), nbcells);
1069 std::vector<MEDCoupling::MEDCouplingUMesh*>faceMeshes=collection.getFaceMesh();
1070 CPPUNIT_ASSERT_EQUAL(5, (int) faceMeshes.size());
1072 for (std::size_t i=0; i < faceMeshes.size(); i++)
1073 nbfaces+=faceMeshes[i]->getNumberOfCells();
1074 CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), nbfaces);
1076 //merge split meshes and test equality
1077 cmd=execName+" --ndomains=1 --split-method="+MetisOrScotch; //on same proc
1078 sourceName=targetName+".xml";
1079 targetName=fileName;
1080 targetName.replace(targetName.find(".med"),4,"_remergedFrom5_");
1081 cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
1082 if (_verbose) cout<<endl<<cmd<<endl;
1083 res=system(cmd.c_str());
1084 CPPUNIT_ASSERT_EQUAL(0, res);
1086 string refusedName=targetName+"1.med";
1087 MEDCoupling::MEDFileUMesh* refusedMesh=MEDCoupling::MEDFileUMesh::New(refusedName.c_str(),_mesh_name.c_str());
1088 MEDCoupling::MEDCouplingUMesh* refusedCellMesh=refusedMesh->getLevel0Mesh(false);
1089 MEDCoupling::MEDCouplingUMesh* refusedFaceMesh=refusedMesh->getLevelM1Mesh(false);
1091 CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells());
1092 CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), refusedFaceMesh->getNumberOfCells());
1095 MEDCoupling::MEDCouplingMesh* mergeCell=cellMesh->mergeMyselfWith(refusedCellMesh);
1096 CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), mergeCell->getNumberOfCells());
1098 MEDCoupling::MEDCouplingMesh* mergeFace=faceMesh->mergeMyselfWith(refusedFaceMesh);
1099 CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), mergeFace->getNumberOfCells());
1101 CPPUNIT_ASSERT(faceMesh->isEqual(refusedFaceMesh,1e-12));
1104 std::vector<const MEDCouplingUMesh *> meshes;
1105 std::vector<DataArrayInt *> corr;
1106 meshes.push_back(cellMesh);
1107 refusedCellMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-9);
1108 meshes.push_back(refusedCellMesh);
1109 MEDCouplingUMesh* fusedCell=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
1110 CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), fusedCell->getNumberOfCells());
1113 for (std::size_t i = 0; i < corr.size(); i++)
1116 meshes.push_back(faceMesh);
1117 refusedFaceMesh->tryToShareSameCoordsPermute(*faceMesh, 1e-9);
1118 meshes.push_back(refusedFaceMesh);
1119 MEDCouplingUMesh* fusedFace=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
1120 CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), fusedFace->getNumberOfCells());
1122 for (std::size_t i = 0; i < corr.size(); i++)
1124 fusedFace->decrRef();
1125 refusedFaceMesh->decrRef();
1126 faceMesh->decrRef();
1127 fusedCell->decrRef();
1128 refusedCellMesh->decrRef();
1129 refusedMesh->decrRef();
1130 cellMesh->decrRef();
1131 initialMesh->decrRef();
1132 //done in ~collection
1133 //for (int i = 0; i < faceMeshes.size(); i++) faceMeshes[i]->decrRef();
1134 //for (int i = 0; i < cellMeshes.size(); i++) cellMeshes[i]->decrRef();
1137 void MEDPARTITIONERTest::verifyMetisOrScotchMedpartitionerOnSmallSizeForFieldOnCells(std::string MetisOrScotch)
1140 string fileName,cmd,execName,sourceName,targetName,input;
1141 execName=getPartitionerExe();
1142 fileName=_file_name;
1143 fileName.replace(fileName.find(".med"),4,"_WithVecFieldOnCells.med");
1145 MEDCoupling::MEDFileUMesh* initialMesh=MEDCoupling::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str());
1146 MEDCoupling::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false);
1148 cmd=execName+" --ndomains=5 --split-method="+MetisOrScotch; //on same proc
1149 sourceName=fileName;
1150 targetName=fileName;
1151 targetName.replace(targetName.find(".med"),4,"_partitionedTo5_");
1152 cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
1153 if (_verbose) cout<<endl<<cmd<<endl;
1154 res=system(cmd.c_str());
1155 CPPUNIT_ASSERT_EQUAL(0, res);
1156 input=targetName+".xml";
1158 //merge split meshes and test equality
1159 cmd=execName+" --ndomains=1 --split-method="+MetisOrScotch; //on same proc
1160 sourceName=targetName+".xml";
1161 targetName=fileName;
1162 targetName.replace(targetName.find(".med"),4,"_remergedFrom5_");
1163 cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
1164 if (_verbose) cout<<endl<<cmd<<endl;
1165 res=system(cmd.c_str());
1166 CPPUNIT_ASSERT_EQUAL(0, res);
1168 string refusedName=targetName+"1.med";
1169 MEDCoupling::MEDFileUMesh* refusedMesh=MEDCoupling::MEDFileUMesh::New(refusedName.c_str(),_mesh_name.c_str());
1170 MEDCoupling::MEDCouplingUMesh* refusedCellMesh=refusedMesh->getLevel0Mesh(false);
1172 CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells());
1174 std::vector<const MEDCouplingUMesh *> meshes;
1175 std::vector<DataArrayInt *> corr;
1176 meshes.push_back(cellMesh);
1177 refusedCellMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-9);
1178 meshes.push_back(refusedCellMesh);
1179 MEDCouplingUMesh* fusedCell=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
1180 CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), fusedCell->getNumberOfCells());
1182 MCAuto<MEDCouplingFieldDouble> field1=ReadFieldCell(fileName.c_str(),initialMesh->getName().c_str(),0,"VectorFieldOnCells",0,1);
1183 MCAuto<MEDCouplingFieldDouble> field2=ReadFieldCell(refusedName.c_str(),refusedCellMesh->getName().c_str(),0,"VectorFieldOnCells",0,1);
1185 int nbcells=corr[1]->getNumberOfTuples();
1186 CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), nbcells);
1187 //use corr to test equality of field
1188 DataArrayDouble* f1=field1->getArray();
1189 DataArrayDouble* f2=field2->getArray();
1192 cout<<"\nf1 : "<<f1->reprZip();
1193 cout<<"\nf2 : "<<f2->reprZip(); //field2->advancedRepradvancedRepr();
1194 for (std::size_t i = 0; i < corr.size(); i++)
1195 cout << "\ncorr " << i << " : " << corr[i]->reprZip();
1199 int nbcomp=field1->getNumberOfComponents();
1200 double* p1=f1->getPointer();
1201 double* p2=f2->getPointer();
1202 int* pc=corr[1]->getPointer();
1203 for (int i = 0; i < nbcells; i++)
1205 int i1=pc[i]*nbcomp;
1207 for (int j = 0; j < nbcomp; j++)
1209 if (p1[i1+j]==p2[i2+j]) nbequal++;
1210 //cout<<" "<<p1[i1+j]<<"="<<p2[i2+j];
1213 CPPUNIT_ASSERT_EQUAL(nbcells*nbcomp, nbequal);
1215 for (std::size_t i = 0; i < corr.size(); i++)
1217 fusedCell->decrRef();
1218 refusedMesh->decrRef();
1219 refusedCellMesh->decrRef();
1220 cellMesh->decrRef();
1221 initialMesh->decrRef();
1224 void MEDPARTITIONERTest::verifyMetisOrScotchMedpartitionerOnSmallSizeForFieldOnGaussNe(std::string MetisOrScotch)
1227 string fileName,cmd,execName,sourceName,targetName,input;
1228 execName=getPartitionerExe();
1229 fileName=_file_name;
1230 fileName.replace(fileName.find(".med"),4,"_WithVecFieldOnGaussNe.med");
1232 MEDCoupling::MEDFileUMesh* initialMesh=MEDCoupling::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str());
1233 MEDCoupling::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false);
1235 cmd=execName+" --ndomains=5 --split-method="+MetisOrScotch; //on same proc
1236 sourceName=fileName;
1237 targetName=fileName;
1238 targetName.replace(targetName.find(".med"),4,"_partitionedTo5_");
1239 cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
1240 if (_verbose) cout<<endl<<cmd<<endl;
1241 res=system(cmd.c_str());
1242 CPPUNIT_ASSERT_EQUAL(0, res);
1243 input=targetName+".xml";
1245 //merge split meshes and test equality
1246 cmd=execName+" --ndomains=1 --split-method="+MetisOrScotch; //on same proc
1247 sourceName=targetName+".xml";
1248 targetName=fileName;
1249 targetName.replace(targetName.find(".med"),4,"_remergedFrom5_");
1250 cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
1251 if (_verbose) cout<<endl<<cmd<<endl;
1252 res=system(cmd.c_str());
1253 CPPUNIT_ASSERT_EQUAL(0, res);
1255 string refusedName=targetName+"1.med";
1256 MEDCoupling::MEDFileUMesh* refusedMesh=MEDCoupling::MEDFileUMesh::New(refusedName.c_str(),_mesh_name.c_str());
1257 MEDCoupling::MEDCouplingUMesh* refusedCellMesh=refusedMesh->getLevel0Mesh(false);
1259 CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells());
1261 std::vector<const MEDCouplingUMesh *> meshes;
1262 std::vector<DataArrayInt *> corr;
1263 meshes.push_back(cellMesh);
1264 refusedCellMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-9);
1265 meshes.push_back(refusedCellMesh);
1266 MEDCouplingUMesh* fusedCell=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
1267 CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), fusedCell->getNumberOfCells());
1269 MCAuto<MEDCouplingFieldDouble> field1=ReadField(ON_GAUSS_NE,fileName.c_str(),initialMesh->getName().c_str(),0,"MyFieldOnGaussNE",5,6);
1270 MCAuto<MEDCouplingFieldDouble> field2=ReadField(ON_GAUSS_NE,refusedName.c_str(),refusedCellMesh->getName().c_str(),0,"MyFieldOnGaussNE",5,6);
1272 int nbcells=corr[1]->getNumberOfTuples();
1273 CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), nbcells);
1274 //use corr to test equality of field
1275 DataArrayDouble* f1=field1->getArray();
1276 DataArrayDouble* f2=field2->getArray();
1279 cout << "\nf1 : " << f1->reprZip(); //123.4 for 12th cell,3rd component, 4th gausspoint
1280 cout << "\nf2 : " << f2->reprZip(); //field2->advancedRepradvancedRepr();
1281 for (std::size_t i = 0; i < corr.size(); i++)
1282 cout << "\ncorr " << i << " : " << corr[i]->reprZip();
1287 int nbcomp=field1->getNumberOfComponents();
1288 double* p1=f1->getPointer();
1289 double* p2=f2->getPointer();
1290 int* pc=corr[1]->getPointer();
1291 for (int i = 0; i < nbcells; i++)
1293 int i1=pc[i]*nbcomp*nbptgauss;
1294 int i2=i*nbcomp*nbptgauss;
1295 for (int j = 0; j < nbcomp*nbptgauss; j++)
1297 if (p1[i1+j]==p2[i2+j]) nbequal++;
1298 //cout<<" "<<p1[i1+j]<<"="<<p2[i2+j];
1301 CPPUNIT_ASSERT_EQUAL(nbcells*nbcomp*nbptgauss, nbequal);
1303 for (std::size_t i = 0; i < corr.size(); i++)
1305 fusedCell->decrRef();
1306 refusedMesh->decrRef();
1307 refusedCellMesh->decrRef();
1308 cellMesh->decrRef();
1309 initialMesh->decrRef();
1312 //================================================================================
1314 * \brief Test for 0021756: [CEA 602] MEDPartitioner improvements
1316 //================================================================================
1318 void MEDPARTITIONERTest::testCreateBoundaryFaces2D()
1320 // Fixed complains are:
1321 // - 2D is not available
1322 // - groups and family handling is bugged (probably due to bug in the handling
1323 // of arrayTo in castIntField())
1324 // - creates boundary faces option is not handled
1326 // Create a 2D mesh in a file
1328 const char fileName[] = "tmp_testCreateBoundaryFaces2D.med";
1330 const int idFam1 = 3, idFam2 = 2;
1331 int nbFam1, nbFam2, nbc;
1333 const int nbX = 20, nbY = 15;
1335 vector<double> coor;
1336 for (int j=0; j<=nbY; j++)
1337 for (int i=0; i<=nbX; i++)
1339 coor.push_back(i+.1);
1340 coor.push_back(j+.2);
1343 for (int j=0; j<nbY; j++)
1344 for (int i=0; i<nbX; i++)
1348 conn.push_back(ii+1);
1351 conn.push_back(ii-1);
1353 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
1354 mesh->setMeshDimension(2);
1356 nbc=conn.size()/4; //nb of cells
1357 mesh->allocateCells(nbc);
1358 int* pConn = &conn[0];
1359 for(int i=0; i<nbc; i++, pConn+=4)
1360 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,pConn);
1361 mesh->finishInsertingCells();
1363 int nbv=coor.size()/2; //nb of vertices
1364 DataArrayDouble *myCoords=DataArrayDouble::New();
1365 myCoords->useArray( &coor[0], /*ownership=*/false, CPP_DEALLOC, nbv, 2 );
1366 mesh->setCoords(myCoords);
1367 mesh->setName("FacesIn2D");
1368 myCoords->decrRef();
1369 mesh->checkConsistencyLight();
1372 DataArrayInt* cellsFam=DataArrayInt::New();
1373 cellsFam->alloc(nbc,1);
1374 nbFam1 = nbc/3, nbFam2 = nbc/2;
1376 for ( int i = 0; i < nbFam1; ++i ) cellsFam->getPointer()[ iE++ ] = idFam1;
1377 for ( int i = 0; i < nbFam2; ++i ) cellsFam->getPointer()[ iE++ ] = idFam2;
1378 for ( ; iE < nbc; ) cellsFam->getPointer()[ iE++ ] = 0;
1379 map<string,int> theFamilies;
1380 theFamilies["FAMILLE_ZERO"]=0;
1381 theFamilies["Family1" ]=idFam1;
1382 theFamilies["Family2" ]=idFam2;
1383 map<string, vector<string> > theGroups;
1384 theGroups["Group1"].push_back("Family1");
1385 theGroups["Group2"].push_back("Family2");
1388 MEDFileUMesh * fileMesh = MEDFileUMesh::New();
1389 fileMesh->setMeshAtLevel(0, mesh);
1390 fileMesh->setFamilyInfo(theFamilies);
1391 fileMesh->setGroupInfo(theGroups);
1392 fileMesh->setFamilyFieldArr(0, cellsFam);
1393 fileMesh->write(fileName,2);
1395 cellsFam->decrRef();
1397 fileMesh->decrRef();
1401 // Partition the mesh into 4 parts
1403 const int ndomains = 4;
1404 ParaDomainSelector parallelizer(false);
1405 MeshCollection collection(fileName,parallelizer);
1406 ParallelTopology* aPT = (ParallelTopology*) collection.getTopology();
1407 aPT->setGlobalNumerotationDefault(collection.getParaDomainSelector());
1409 std::auto_ptr< Topology > new_topo;
1410 #if defined(MED_ENABLE_METIS) || defined(MED_ENABLE_PARMETIS)
1411 new_topo.reset( collection.createPartition(ndomains,Graph::METIS) );
1413 #if defined(MED_ENABLE_SCOTCH)
1414 if ( !new_topo.get() )
1415 new_topo.reset( collection.createPartition(ndomains,Graph::SCOTCH) );
1417 if ( !new_topo.get() )
1420 // Check that "2D is available"
1422 const char xmlName[] = "tmp_testCreateBoundaryFaces2D";
1424 MyGlobals::_Creates_Boundary_Faces = true;
1425 MeshCollection new_collection(collection,new_topo.get());
1427 CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfLocalMeshes());
1428 CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfGlobalMeshes());
1429 CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalCells(),new_collection.getNbOfLocalCells());
1430 CPPUNIT_ASSERT_EQUAL(0,collection.getNbOfLocalFaces());
1431 CPPUNIT_ASSERT (new_collection.getNbOfLocalFaces() > 0 );
1433 MyGlobals::_General_Informations.clear();
1434 MyGlobals::_General_Informations.push_back(SerializeFromString("finalMeshName=2D"));
1435 new_collection.write( xmlName );
1438 // Check that "groups and family handling is NOT bugged"
1440 MeshCollection new_collection(std::string(xmlName)+".xml");
1441 std::map< int, int > famId2nb; // count total nb of cells in divided families
1442 std::map< int, int >::iterator id2nn;
1444 const std::vector<MEDCoupling::DataArrayInt*>& famIdsVec = new_collection.getCellFamilyIds();
1445 for ( size_t i = 0; i < famIdsVec.size(); ++i )
1447 MEDCoupling::DataArrayInt* famIdsArr = famIdsVec[i];
1448 for ( int j = famIdsArr->getNbOfElems()-1; j >= 0; --j )
1450 id2nn = famId2nb.insert( make_pair( famIdsArr->getPointer()[j], 0 )).first;
1455 CPPUNIT_ASSERT_EQUAL( 3, (int) famId2nb.size() ); // 3 fams/groups in all
1456 CPPUNIT_ASSERT_EQUAL( 1, (int) famId2nb.count( 0 ));
1457 CPPUNIT_ASSERT_EQUAL( 1, (int) famId2nb.count( idFam1 ));
1458 CPPUNIT_ASSERT_EQUAL( 1, (int) famId2nb.count( idFam2 ));
1459 CPPUNIT_ASSERT_EQUAL( nbFam1, famId2nb[ idFam1 ]);
1460 CPPUNIT_ASSERT_EQUAL( nbFam2, famId2nb[ idFam2 ]);
1461 CPPUNIT_ASSERT_EQUAL( nbc - nbFam1 - nbFam2, famId2nb[ 0 ]);
1463 // Check that "creates boundary faces option is handled"
1466 const std::vector<MEDCoupling::DataArrayInt*>& famIdsVec = new_collection.getFaceFamilyIds();
1467 for ( size_t i = 0; i < famIdsVec.size(); ++i )
1469 MEDCoupling::DataArrayInt* famIdsArr = famIdsVec[i];
1470 for ( int j = famIdsArr->getNbOfElems()-1; j >= 0; --j )
1472 id2nn = famId2nb.insert( make_pair( famIdsArr->getPointer()[j], 0 )).first;
1477 CPPUNIT_ASSERT( !famId2nb.empty() );
1479 // for each "JOINT_n_p_..." group there must be "JOINT_p_n_..." group
1481 std::map<std::string,int>& famName2id = new_collection.getFamilyInfo();
1482 std::map<std::string,int>::iterator na2id = famName2id.begin(), na2id2;
1483 std::set< int > okFamIds;
1485 for ( ; na2id != famName2id.end(); ++na2id )
1487 if ( okFamIds.count( na2id->second ) || na2id->first[0] != 'J')
1490 bool groupOK = false;
1491 while ( !groupOK && ++na2id2 != famName2id.end() )
1492 groupOK = ( na2id2->first.find_first_not_of( na2id->first ) == std::string::npos );
1494 CPPUNIT_ASSERT( groupOK );
1495 CPPUNIT_ASSERT( na2id->second != na2id2->second);
1496 CPPUNIT_ASSERT_EQUAL( 1, (int) famId2nb.count( na2id2->second ));
1497 CPPUNIT_ASSERT_EQUAL( 1, (int) famId2nb.count( na2id->second ));
1498 CPPUNIT_ASSERT_EQUAL( (int) famId2nb[ na2id2->second ],
1499 (int) famId2nb[ na2id->second ]);
1500 okFamIds.insert( na2id2->second );