From 3c28eaa9181d95e001b082ccc023109897774f42 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 28 Nov 2022 17:34:34 +0100 Subject: [PATCH] [EDF26362] : Check at write time of MEDFileUMesh instance consitency between DataArrayDouble instances indirectly aggregated accross data structure --- src/MEDLoader/MEDFileMesh.cxx | 5 ++++- src/MEDLoader/MEDFileMeshLL.cxx | 11 +++++++++++ src/MEDLoader/MEDFileMeshLL.hxx | 1 + src/MEDLoader/Swig/MEDLoaderTest4.py | 13 +++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 9a2e20afe..425c183d0 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -3091,8 +3091,11 @@ void MEDFileUMesh::writeMeshLL(med_idt fid) const std::string meshName(MEDLoaderBase::buildStringFromFortran(maa,MED_NAME_SIZE)); MEDFileUMeshL2::WriteCoords(fid,meshName,_iteration,_order,_time,_coords,_fam_coords,_num_coords,_name_coords,_global_num_coords); for(std::vector< MCAuto >::const_iterator it=_ms.begin();it!=_ms.end();it++) - if((const MEDFileUMeshSplitL1 *)(*it)!=0) + if(it->isNotNull()) + { + (*it)->checkCoordsConsistency(coo); (*it)->write(fid,meshName,mdim); + } MEDFileUMeshL2::WriteFamiliesAndGrps(fid,meshName,_families,_groups,_too_long_str); } diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 8419e4099..656955a1c 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -1417,6 +1417,17 @@ void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector ms(_m_by_types.getParts()); + for(auto mesh : ms) + { + if(mesh) + if(mesh->getCoords() != coords) + mesh->getCoords()->checkNbOfTuplesAndComp(*coords,"MEDFileUMeshSplitL1::checkCoordsConsistency : mismatch between coordinates instance in MEDFileUMesh and instance in subparts"); + } +} + void MEDFileUMeshSplitL1::write(med_idt fid, const std::string& mName, int mdim) const { std::vector ms(_m_by_types.getParts()); diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 7fa00c5e7..c79c371c8 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -303,6 +303,7 @@ MCAuto& _coords, MCAuto& _fam_coords, MCAuto& ms, std::map& familyIds, std::map >& groups); + void checkCoordsConsistency(const DataArrayDouble *coords) const; void write(med_idt fid, const std::string& mName, int mdim) const; // void setFamilyArr(DataArrayIdType *famArr); diff --git a/src/MEDLoader/Swig/MEDLoaderTest4.py b/src/MEDLoader/Swig/MEDLoaderTest4.py index c33c092d6..aed4f3b51 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest4.py +++ b/src/MEDLoader/Swig/MEDLoaderTest4.py @@ -5703,6 +5703,19 @@ class MEDLoaderTest4(unittest.TestCase): self.assertTrue( cas1.getGroupArr(0,"GCELL2").isEqual(gcell2) ) self.assertTrue( cas1.getGroupArr(0,"GCELL3").isEqual(gcell3) ) + @WriteInTmpDir + def test46(self): + """ + EDF26362 : unconsistency between DataArrayDouble instance in MEDFileUMesh and those of MEDCouplingUMesh or MEDCoupling1GTUMesh used at write time + """ + fname = "test46.med" + arr=DataArrayDouble([0,1,1,2,3]) + m = MEDCouplingUMesh.Build1DMeshFromCoords(arr) + mm = MEDFileUMesh() + mm[0] = m + m.mergeNodes(1e-5) # coords into m has been modified so coords of mm and m mismatches + self.assertRaises(InterpKernelException,mm.write,fname,2) # write fails due to mismatch of number of tuples of coords of mm and those of m + pass if __name__ == "__main__": -- 2.39.2