From: Anida Khizar Date: Fri, 24 Mar 2023 15:31:37 +0000 (+0100) Subject: [Partial load] Adding more tests X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d7d1a008216cf3705ecef1fba9393e4443c39f5d;p=tools%2Fmedcoupling.git [Partial load] Adding more tests --- diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 12135b962..6a3a63e72 100644 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -40,6 +40,8 @@ SET(MED_other_FILES Test3D.med Test3Dpoly.med SimpleTest2D.med + SimpleTest3D.med + Test2DMultiGeoType.med UnitTetraDegenT.med DegenEdgeXY.med DegenFaceXYZ.med diff --git a/resources/SimpleTest2D.med b/resources/SimpleTest2D.med index d4cfcd75c..3c890eba6 100644 Binary files a/resources/SimpleTest2D.med and b/resources/SimpleTest2D.med differ diff --git a/resources/SimpleTest3D.med b/resources/SimpleTest3D.med new file mode 100644 index 000000000..62bbc2e5b Binary files /dev/null and b/resources/SimpleTest3D.med differ diff --git a/resources/Test2DMultiGeoType.med b/resources/Test2DMultiGeoType.med new file mode 100644 index 000000000..dc6cf5533 Binary files /dev/null and b/resources/Test2DMultiGeoType.med differ diff --git a/src/ParaMEDMEMTest/ParaMEDMEMTest.hxx b/src/ParaMEDMEMTest/ParaMEDMEMTest.hxx index b26be7356..3223aaf48 100644 --- a/src/ParaMEDMEMTest/ParaMEDMEMTest.hxx +++ b/src/ParaMEDMEMTest/ParaMEDMEMTest.hxx @@ -86,7 +86,10 @@ class ParaMEDMEMTest : public CppUnit::TestFixture CPPUNIT_TEST(testFabienAPI2); // 3 procs CPPUNIT_TEST(testParallelLoad1); // 2 procs - CPPUNIT_TEST(testParallelLoad2); // 2 procs + CPPUNIT_TEST(testParallelLoad2); // 3 procs + CPPUNIT_TEST(testParallelLoad3); // 2 procs + CPPUNIT_TEST(testParallelLoad4); // 2 procs + CPPUNIT_TEST(testParallelLoad5); // 2 procs CPPUNIT_TEST_SUITE_END(); public: @@ -152,6 +155,9 @@ public: void testParallelLoad1(); void testParallelLoad2(); + void testParallelLoad3(); + void testParallelLoad4(); + void testParallelLoad5(); std::string getTmpDirectory(); std::string makeTmpFile( const std::string&, const std::string& = "" ); diff --git a/src/ParaMEDMEMTest/ParaMEDMEMTest_MEDLoader.cxx b/src/ParaMEDMEMTest/ParaMEDMEMTest_MEDLoader.cxx index 2420a4fa0..1de4cd0b9 100644 --- a/src/ParaMEDMEMTest/ParaMEDMEMTest_MEDLoader.cxx +++ b/src/ParaMEDMEMTest/ParaMEDMEMTest_MEDLoader.cxx @@ -35,7 +35,7 @@ using namespace MEDCoupling; -MEDCouplingUMesh* genLocMesh(int rk) +MEDCouplingUMesh* genLocMesh2D(int rk) { int nxTot=4,nyTot=2; int nx=2,ny=2; @@ -66,21 +66,95 @@ MEDCouplingUMesh* genLocMesh(int rk) return ret.retn(); } -MEDCouplingFieldDouble *genLocField(int rank) +MEDCouplingUMesh* genLocMeshMultipleTypes1() { - MCAuto mesh = genLocMesh(rank); + MCAuto ret= MEDCouplingUMesh::New("mesh",2); + double coords[10] = {0.,1., 0.,2., 1.,2., 0.,3., 1.,3.}; + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(5,2); + std::copy(coords,coords+10,myCoords->getPointer()); + ret->setCoords(myCoords); + myCoords->decrRef(); + mcIdType conn[7]={0,2,1, 1,2,4,3}; + ret->allocateCells(2); + ret->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn); + ret->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+3); + ret->finishInsertingCells(); + return ret.retn(); +} + +MEDCouplingUMesh* genLocMeshMultipleTypes2() +{ + MCAuto ret= MEDCouplingUMesh::New("mesh",2); + double coords[10] = {0.,0., 1.,0., 0.,1., 1.,1., 1.,2.}; + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(5,2); + std::copy(coords,coords+10,myCoords->getPointer()); + ret->setCoords(myCoords); + myCoords->decrRef(); + mcIdType conn[7]={2,3,4, 0,1,3,2}; + ret->allocateCells(2); + ret->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn); + ret->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+3); + ret->finishInsertingCells(); + return ret.retn(); +} + +MEDCouplingUMesh* genLocMeshMultipleTypes3() +{ + MCAuto ret= MEDCouplingUMesh::New("mesh",2); + double coords[16] = {1.,0., 2.,0., 1.,1., 2.,1., 1.,2., 2.,2., 1.,3., 2.,3.}; + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(8,2); + std::copy(coords,coords+16,myCoords->getPointer()); + ret->setCoords(myCoords); + myCoords->decrRef(); + mcIdType conn[14]={0,1,3, 0,3,2, 2,3,5,4, 4,5,7,6}; + ret->allocateCells(4); + ret->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn); + ret->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+3); + ret->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+6); + ret->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); + ret->finishInsertingCells(); + return ret.retn(); +} + +MEDCouplingFieldDouble *genLocFieldCells(int rank) +{ + MCAuto mesh = genLocMesh2D(rank); MCAuto f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); f1->setName("field"); f1->setMesh(mesh); MCAuto array(DataArrayDouble::New()); - double* values = new double[4]; + array->alloc(4,2); + std::vector values; if(rank == 0) - values[0]= 0.,values[1]=10.,values[2]=40.,values[3]=50.; + values = { 0., 10., 20., 30., 80., 90., 100., 110.}; else - values[0]=20.,values[1]=30.,values[2]=60.,values[3]=70.; - array->useArray(values,true, DeallocType::CPP_DEALLOC,4,1); - array->setInfoOnComponent(0,"s"); + values = { 40., 50., 60., 70., 120., 130., 140., 150.}; + std::copy(values.data(),values.data()+8,array->getPointer()); + array->setInfoOnComponent(0,""); + f1->setArray(array); + return f1.retn(); +} + +MEDCouplingFieldDouble *genLocFieldNodes(int rank) +{ + MCAuto mesh = genLocMesh2D(rank); + MCAuto f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME); + f1->setName("field"); + f1->setMesh(mesh); + + MCAuto array(DataArrayDouble::New()); + array->alloc(9,2); + std::vector values; + if(rank == 0) + values= { 0., 10., 20., 30., 40., 50., 100., 110., 120., 130., 140., 150., 200., 210., 220., 230., 240., 250. }; + else + values= { 40., 50., 60., 70., 80., 90., 140., 150., 160., 170., 180., 190., 240., 250., 260., 270., 280., 290. }; + std::copy(values.data(),values.data()+18,array->getPointer()); + array->setInfoOnComponent(0,""); f1->setArray(array); return f1.retn(); } @@ -104,13 +178,120 @@ void ParaMEDMEMTest::testParallelLoad1() std::string filename=INTERP_TEST::getResourceFile("SimpleTest2D.med"); MCAuto mu = ParaMEDFileUMesh::ParaNew(distrib, MPI_COMM_WORLD, MPI_INFO_NULL, filename, "mesh"); - MCAuto meshRef = genLocMesh(rank); + MCAuto meshRef = genLocMesh2D(rank); CPPUNIT_ASSERT(mu->getMeshAtLevel(0)->isEqual(meshRef,1e-12)); MPI_Barrier(MPI_COMM_WORLD); } - void ParaMEDMEMTest::testParallelLoad2() +{ + int size; + int rank; + MPI_Comm_size(MPI_COMM_WORLD,&size); + MPI_Comm_rank(MPI_COMM_WORLD,&rank); + // + if(size!=3) + return ; + + std::map> distrib; + // independant numerotation for each geometric type! + if (rank == 0) + distrib = { {INTERP_KERNEL::NORM_TRI3,{3}} , {INTERP_KERNEL::NORM_QUAD4,{2}} }; + else if(rank == 1) + distrib = { {INTERP_KERNEL::NORM_TRI3,{2}} , {INTERP_KERNEL::NORM_QUAD4,{0}} }; + else + distrib= { {INTERP_KERNEL::NORM_TRI3,{0,1}} , {INTERP_KERNEL::NORM_QUAD4,{1,3}} }; + + std::string filename=INTERP_TEST::getResourceFile("Test2DMultiGeoType.med"); + MCAuto mu = ParaMEDFileUMesh::ParaNew(distrib, MPI_COMM_WORLD, MPI_INFO_NULL, filename, "mesh"); + MEDCouplingUMesh *meshRef; + if(rank==0) + meshRef=genLocMeshMultipleTypes1(); + else if(rank==1) + meshRef=genLocMeshMultipleTypes2(); + else + meshRef=genLocMeshMultipleTypes3(); + int equal = (int)mu->getMeshAtLevel(0)->isEqual(meshRef,1e-12); + int allEqual = -1; + MPI_Allreduce(&equal, &allEqual, 1, MPI_INT,MPI_SUM,MPI_COMM_WORLD); + CPPUNIT_ASSERT(allEqual==3); + meshRef->decrRef(); + MPI_Barrier(MPI_COMM_WORLD); +} + +void ParaMEDMEMTest::testParallelLoad3() +{ + int size; + int rank; + MPI_Comm_size(MPI_COMM_WORLD,&size); + MPI_Comm_rank(MPI_COMM_WORLD,&rank); + // + if(size!=2) + return ; + + std::map> distrib; + if (rank == 0) + { + std::vector distribCells = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,48,49,50,51,52,53,54,55,56,57, + 58,59,60,61,62,63,64,65,66,67,68,69,70,71,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118, + 119,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167}; + distrib = { {INTERP_KERNEL::NORM_TETRA4,distribCells} }; + } + else + { + std::vector distribCells = {24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,72,73,74,75,76,77,78,79,80, + 81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142, + 143,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191}; + distrib = { {INTERP_KERNEL::NORM_TETRA4,distribCells} }; + } + + std::string filename=INTERP_TEST::getResourceFile("SimpleTest3D.med"); + MCAuto mu = ParaMEDFileUMesh::ParaNew(distrib, MPI_COMM_WORLD, MPI_INFO_NULL, filename, "mesh"); + MCAuto mesh = mu->getMeshAtLevel(0); + + double nodalConnec[480] = {14, 1, 7, 18, 24, 14, 7, 6, 18, 24, 14, 6, 0, 18, 24, 14, 0, 1, 18, 24, 14, 1, 0, 19, 24, 14, 0, 2, 19, 24, 14, 2, 3, 19, 24, + 14, 3, 1, 19, 24, 14, 1, 3, 20, 24, 14, 3, 9, 20, 24, 14, 9, 7, 20, 24, 14, 7, 1, 20, 24, 14, 0, 6, 21, 24, 14, 6, 8, 21, 24, 14, 8, 2, 21, 24, + 14, 2, 0, 21, 24, 14, 7, 9, 22, 24, 14, 9, 8, 22, 24, 14, 8, 6, 22, 24, 14, 6, 7, 22, 24, 14, 2, 8, 23, 24, 14, 8, 9, 23, 24, 14, 9, 3, 23, 24, + 14, 3, 2, 23, 24, 14, 3, 9, 25, 31, 14, 9, 8, 25, 31, 14, 8, 2, 25, 31, 14, 2, 3, 25, 31, 14, 3, 2, 26, 31, 14, 2, 4, 26, 31, 14, 4, 5, 26, 31, + 14, 5, 3, 26, 31, 14, 3, 5, 27, 31, 14, 5, 11, 27, 31, 14, 11, 9, 27, 31, 14, 9, 3, 27, 31, 14, 2, 8, 28, 31, 14, 8, 10, 28, 31, 14, 10, 4, 28, 31, + 14, 4, 2, 28, 31, 14, 9, 11, 29, 31, 14, 11, 10, 29, 31, 14, 10, 8, 29, 31, 14, 8, 9, 29, 31, 14, 4, 10, 30, 31, 14, 10, 11, 30, 31, 14, 11, 5, 30, 31, + 14, 5, 4, 30, 31, 14, 7, 13, 32, 38, 14, 13, 12, 32, 38, 14, 12, 6, 32, 38, 14, 6, 7, 32, 38, 14, 7, 6, 33, 38, 14, 6, 8, 33, 38, 14, 8, 9, 33, 38, + 14, 9, 7, 33, 38, 14, 7, 9, 34, 38, 14, 9, 15, 34, 38, 14, 15, 13, 34, 38, 14, 13, 7, 34, 38, 14, 6, 12, 35, 38, 14, 12, 14, 35, 38, 14, 14, 8, 35, 38, + 14, 8, 6, 35, 38, 14, 13, 15, 36, 38, 14, 15, 14, 36, 38, 14, 14, 12, 36, 38, 14, 12, 13, 36, 38, 14, 8, 14, 37, 38, 14, 14, 15, 37, 38, 14, 15, 9, 37, 38, + 14, 9, 8, 37, 38, 14, 9, 15, 39, 45, 14, 15, 14, 39, 45, 14, 14, 8, 39, 45, 14, 8, 9, 39, 45, 14, 9, 8, 40, 45, 14, 8, 10, 40, 45, 14, 10, 11, 40, 45, + 14, 11, 9, 40, 45, 14, 9, 11, 41, 45, 14, 11, 17, 41, 45, 14, 17, 15, 41, 45, 14, 15, 9, 41, 45, 14, 8, 14, 42, 45, 14, 14, 16, 42, 45, 14, 16, 10, 42, 45, + 14, 10, 8, 42, 45, 14, 15, 17, 43, 45, 14, 17, 16, 43, 45, 14, 16, 14, 43, 45, 14, 14, 15, 43, 45, 14, 10, 16, 44, 45, 14, 16, 17, 44, 45, 14, 17, 11, 44, 45, + 14, 11, 10, 44, 45}; + DataArrayIdType *nodalConnecRef=DataArrayIdType::New(); + nodalConnecRef->alloc(480,1); + std::copy(nodalConnec,nodalConnec+480,nodalConnecRef->getPointer()); + CPPUNIT_ASSERT(mesh->getNodalConnectivity()->isEqual(*nodalConnecRef)); + nodalConnecRef->decrRef(); + + std::vector coords(138); + if(rank == 0) + coords = {0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 2.0, 0.0, 2.0, 2.0, 0.0, 0.0, 4.0, 0.0, 2.0, 4.0, 0.0, 0.0, 0.0, 2.0, 2.0, 0.0, 2.0, 0.0, 2.0, + 2.0, 2.0, 2.0, 2.0, 0.0, 4.0, 2.0, 2.0, 4.0, 2.0, 0.0, 0.0, 4.0, 2.0, 0.0, 4.0, 0.0, 2.0, 4.0, 2.0, 2.0, 4.0, 0.0, 4.0, 4.0, 2.0, 4.0, 4.0, 1.0, 0.0, + 1.0, 1.0, 1.0, 0.0, 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 3.0, 0.0, 2.0, 3.0, 1.0, 0.0, 3.0, + 1.0, 1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sRef->getPointer()); + CPPUNIT_ASSERT(mesh->getCoords()->isEqual(*coordsRef,1e-12)); + coordsRef->decrRef(); + + MPI_Barrier(MPI_COMM_WORLD); +} + +void ParaMEDMEMTest::testParallelLoad4() { int size; int rank; @@ -127,9 +308,34 @@ void ParaMEDMEMTest::testParallelLoad2() distrib = {2,3,6,7}; std::string filename=INTERP_TEST::getResourceFile("SimpleTest2D.med"); - MCAuto f1TS = ParaMEDFileField1TS::ParaNew(MPI_COMM_WORLD, MPI_INFO_NULL,filename,"field","mesh",distrib,ON_CELLS); - MCAuto fieldRef = genLocField(rank); + MCAuto f1TS = ParaMEDFileField1TS::ParaNew(MPI_COMM_WORLD, MPI_INFO_NULL,filename,"fieldOnCells","mesh",distrib,ON_CELLS); + MCAuto fieldRef = genLocFieldCells(rank); CPPUNIT_ASSERT(f1TS->getUndergroundDataArray()->isEqual(*fieldRef->getArray(),1e-12)); MPI_Barrier(MPI_COMM_WORLD); } +void ParaMEDMEMTest::testParallelLoad5() +{ + int size; + int rank; + MPI_Comm_size(MPI_COMM_WORLD,&size); + MPI_Comm_rank(MPI_COMM_WORLD,&rank); + // + if(size!=2) + return ; + + std::vector distrib; + if (rank == 0) + distrib = {0,1,2,5,6,7,10,11,12}; //c++ type of indexing: index starts from zero! + else + distrib = {2,3,4,7,8,9,12,13,14}; + + std::string filename=INTERP_TEST::getResourceFile("SimpleTest2D.med"); + MCAuto f1TS = ParaMEDFileField1TS::ParaNew(MPI_COMM_WORLD, MPI_INFO_NULL,filename,"fieldOnNodes","mesh",distrib,ON_NODES); + MCAuto fieldRef = genLocFieldNodes(rank); + CPPUNIT_ASSERT(f1TS->getUndergroundDataArray()->isEqual(*fieldRef->getArray(),1e-12)); + MPI_Barrier(MPI_COMM_WORLD); +} + + +