From: Anida Khizar Date: Mon, 30 Jan 2023 15:34:18 +0000 (+0100) Subject: [Partial load] Adding test cases X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=59008e1e2144ac47dd75b9e99133c2673ae5fa76;p=tools%2Fmedcoupling.git [Partial load] Adding test cases --- 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 000000000..d4cfcd75c Binary files /dev/null and b/resources/SimpleTest2D.med differ 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); +} +