From 59008e1e2144ac47dd75b9e99133c2673ae5fa76 Mon Sep 17 00:00:00 2001 From: Anida Khizar Date: Mon, 30 Jan 2023 16:34:18 +0100 Subject: [PATCH] [Partial load] Adding test cases --- resources/CMakeLists.txt | 1 + resources/SimpleTest2D.med | Bin 0 -> 14999 bytes src/ParaMEDLoader/ParaMEDFileMesh.cxx | 1 + src/ParaMEDMEMTest/CMakeLists.txt | 2 + src/ParaMEDMEMTest/ParaMEDMEMTest.hxx | 7 ++ .../ParaMEDMEMTest_MEDLoader.cxx | 110 +++++++++++++++++- 6 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 resources/SimpleTest2D.med diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 85482604e..12135b962 100644 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -39,6 +39,7 @@ SET(MED_other_FILES Test2Dpoly.med Test3D.med Test3Dpoly.med + SimpleTest2D.med UnitTetraDegenT.med DegenEdgeXY.med DegenFaceXYZ.med diff --git a/resources/SimpleTest2D.med b/resources/SimpleTest2D.med new file mode 100644 index 0000000000000000000000000000000000000000..d4cfcd75c87e7025954eef419e8368460dadbb4e GIT binary patch literal 14999 zcmeGjZH!da^}d^jvomjY2WH;v&g@cDl3f%QEKom) ziYBELC4mBI`O&PJR+FkJA*->qP3n&gv{ft7Dx|GaQ+2h*f+3B~Hl(x|dd|J)y!m)< z-j2(r26!jgIq%(j?z!ild+$5vo^y9kS3EH_cx}*EQzID86AZPgk}y^LZQ;WMnXY)& zryuqI>Gs0EZN4j!h8r>t`h+G#;93D_deTf}a{Zl#X=I}*BlkOE8i1CXm|~c@{&Y0D z7w8cJ)3DT^h~}oxDJqF|Mdw_vO7J%&zWb!JNYA*5bk&uj$}Vo`%R=~}B7~Lc=n63d zbfVPKE_~1%6iX;3Oqw=A8ign#%o?e(gt_0=1)ay?uG;CSrm8LLw{EOO0TB#^F8KG% ziP2?Jr24{{#^(pL@pb#WUkPB4&H_tN()o+RHdyRbHWDED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ytf8S6hopH{ct9262#Xe5n8M%wG^AxZmuC!AaoJk|ZpVs)XO5_2m8l15slE zG8~Ay**(NTFR|~blWnCpyN5{AL8}*E;*};9*Z**z6|gL4T|{CDJ6^Tg{&0rxSnVCka4m7)L73O05MHP5!vY$*q}Cf%|J~NpdSs$;m9HEFshj zDIJn>G9d;BX?eKBJEPbe{^L$w;BsFWYecDN`EzBSsLUrQPY^551!VHT)4=Dh0k!`r fmxa;{9zL*6v&>b+|3~&8zM22IkH{0?vuNOd=8pvk literal 0 HcmV?d00001 diff --git a/src/ParaMEDLoader/ParaMEDFileMesh.cxx b/src/ParaMEDLoader/ParaMEDFileMesh.cxx index 364141bd0..013079d05 100644 --- a/src/ParaMEDLoader/ParaMEDFileMesh.cxx +++ b/src/ParaMEDLoader/ParaMEDFileMesh.cxx @@ -150,6 +150,7 @@ MEDFileUMesh *ParaMEDFileUMesh::NewPrivate(med_idt fid, const MPI_Comm& com, con med_geometry_type geoMedType(typmai3[geoType]); med_bool changement,transformation; med_int totalNumberOfElements(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_CELL,geoMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation)); + mcIdType nbEltsInDistribLoc = distrib.size(); mcIdType nbEltsInDistribTot = -1; #ifdef HAVE_MPI diff --git a/src/ParaMEDMEMTest/CMakeLists.txt b/src/ParaMEDMEMTest/CMakeLists.txt index b6813e2a5..83c1b7648 100644 --- a/src/ParaMEDMEMTest/CMakeLists.txt +++ b/src/ParaMEDMEMTest/CMakeLists.txt @@ -23,6 +23,7 @@ ADD_DEFINITIONS(${MPI_DEFINITIONS} ${CPPUNIT_DEFINITIONS}) INCLUDE_DIRECTORIES( ${MPI_INCLUDE_DIRS} + ${MEDFILE_INCLUDE_DIRS} ${CPPUNIT_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/../ParaMEDLoader ${CMAKE_CURRENT_SOURCE_DIR}/../ParaMEDMEM @@ -46,6 +47,7 @@ SET(ParaMEDMEMTest_SOURCES ParaMEDMEMTest_FabienAPI.cxx ParaMEDMEMTest_NonCoincidentDEC.cxx ParaMEDMEMTest_OverlapDEC.cxx + ParaMEDMEMTest_MEDLoader.cxx ) ADD_LIBRARY(ParaMEDMEMTest ${ParaMEDMEMTest_SOURCES}) diff --git a/src/ParaMEDMEMTest/ParaMEDMEMTest.hxx b/src/ParaMEDMEMTest/ParaMEDMEMTest.hxx index 240f94830..b26be7356 100644 --- a/src/ParaMEDMEMTest/ParaMEDMEMTest.hxx +++ b/src/ParaMEDMEMTest/ParaMEDMEMTest.hxx @@ -85,6 +85,8 @@ class ParaMEDMEMTest : public CppUnit::TestFixture CPPUNIT_TEST(testFabienAPI1); // 3 procs CPPUNIT_TEST(testFabienAPI2); // 3 procs + CPPUNIT_TEST(testParallelLoad1); // 2 procs + CPPUNIT_TEST(testParallelLoad2); // 2 procs CPPUNIT_TEST_SUITE_END(); public: @@ -148,6 +150,9 @@ public: void testFabienAPI1(); void testFabienAPI2(); + void testParallelLoad1(); + void testParallelLoad2(); + std::string getTmpDirectory(); std::string makeTmpFile( const std::string&, const std::string& = "" ); @@ -166,6 +171,8 @@ private: void testInterpKernelDEC2_2D_(const char *srcMeth, const char *targetMeth); void testInterpKernelDEC_3D_(const char *srcMeth, const char *targetMeth); void testGauthier3_GEN(bool, int); + + }; // to automatically remove temporary files from disk diff --git a/src/ParaMEDMEMTest/ParaMEDMEMTest_MEDLoader.cxx b/src/ParaMEDMEMTest/ParaMEDMEMTest_MEDLoader.cxx index 485186b09..379846bd0 100644 --- a/src/ParaMEDMEMTest/ParaMEDMEMTest_MEDLoader.cxx +++ b/src/ParaMEDMEMTest/ParaMEDMEMTest_MEDLoader.cxx @@ -19,7 +19,11 @@ #include "ParaMEDMEMTest.hxx" #include "MEDLoader.hxx" -#include "MEDCouplingUMesh.hxx" + +#include "ParaMEDFileMesh.hxx" +#include "MEDFileMesh.hxx" +#include "MEDFileField1TS.hxx" +#include "TestInterpKernelUtils.hxx" #include "MEDCouplingFieldDouble.hxx" #include @@ -29,7 +33,107 @@ #include #include -using namespace std; -using namespace INTERP_KERNEL; using namespace MEDCoupling; +MEDCouplingUMesh* genLocMesh(int rk) +{ + int nxTot=4,nyTot=2; + int nx=2,ny=2; + MCAuto msh = MEDCouplingCMesh::New("mesh"); + MCAuto dax = DataArrayDouble::New(); dax->alloc(nx+1,1); + MCAuto day = DataArrayDouble::New(); day->alloc(ny+1,1); + dax->iota(); day->iota(); + if (rk == 0) + { + std::transform(dax->begin(), dax->end(), + dax->rwBegin(), + [nxTot](const int& c){return c/(float)nxTot;}); + std::transform(day->begin(), day->end(), + day->rwBegin(), + [nyTot](const int& c){return c/(float)nyTot;}); + } + else + { + std::transform(dax->begin(), dax->end(), + dax->rwBegin(), + [nxTot](const int& c){return c/(float)nxTot+0.5; }); + std::transform(day->begin(), day->end(), + day->rwBegin(), + [nyTot](const int& c){return c/(float)nyTot;}); + } + msh->setCoords(dax, day); + MCAuto ret = msh->buildUnstructured(); + return ret.retn(); +} + +MEDCouplingFieldDouble *genLocField(int rank) +{ + MCAuto mesh = genLocMesh(rank); + MCAuto f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f1->setName("field"); + f1->setMesh(mesh); + + MCAuto array(DataArrayDouble::New()); + double* values = new double[4]; + if(rank == 0) + values[0]= 0.,values[1]=10.,values[2]=40.,values[3]=50.; + 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"); + f1->setArray(array); + return f1.retn(); +} + + +void ParaMEDMEMTest::testParallelLoad1() +{ + 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,4,5}; //c++ type of indexing: index starts from zero! + else + distrib = {2,3,6,7}; + + 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); + 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!=2) + return ; + + std::vector distrib; + if (rank == 0) + distrib = {0,1,4,5}; //c++ type of indexing: index starts from zero! + else + distrib = {2,3,6,7}; + + std::string filename=INTERP_TEST::getResourceFile("SimpleTest2D.med"); + MCAuto mu = ParaMEDFileUMesh::ParaNew(distrib, MPI_COMM_WORLD, MPI_INFO_NULL, filename, "mesh"); + MCAuto f1TS = ParaMEDFileField1TS::ParaNew(mu, filename, "mesh", "field"); + MCAuto partField = f1TS->field(mu); + MCAuto fieldRef = genLocField(rank); + CPPUNIT_ASSERT_EQUAL(4,(int)partField->getNumberOfTuples()); + CPPUNIT_ASSERT(partField->getArray()->isEqual(*fieldRef->getArray(),1e-12)); + MPI_Barrier(MPI_COMM_WORLD); +} + -- 2.39.2