From 64b9e40804008acd0598813a80225d36cac18ac2 Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 7 Feb 2013 14:51:26 +0000 Subject: [PATCH] CurveLinearMesh 2 --- src/MEDLoader/MEDFileMesh.cxx | 57 ++++++++++++++++++++++++---- src/MEDLoader/Swig/MEDLoaderTest3.py | 33 ++++++++++++++++ 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 63f31a5d1..e2172ccf7 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -1363,6 +1363,21 @@ void MEDFileMesh::dealWithTinyInfo(const MEDCouplingMesh *m) throw(INTERP_KERNEL } } } + if(_desc_name.empty()) + _desc_name=m->getDescription(); + else + { + std::string name(m->getDescription()); + if(!name.empty()) + { + if(_desc_name!=name) + { + std::ostringstream oss; oss << "MEDFileMesh::dealWithTinyInfo : description of current MEDfile mesh is '" << _desc_name << "' whereas name of input mesh is : '"; + oss << name << "' ! Names must match !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } } void MEDFileMesh::getFamilyRepr(std::ostream& oss) const @@ -2930,24 +2945,46 @@ void MEDFileStructuredMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayI { if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setRenumFieldArr : Only available for levels 0 or 1 !"); - if(famArr) - famArr->incrRef(); + const MEDCouplingStructuredMesh *mesh=getStructuredMesh(); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setFamilyFieldArr : no structured mesh specified ! Impossible to set family array !"); if(meshDimRelToMaxExt==0) - _fam_cells=famArr; + { + int nbCells=mesh->getNumberOfCells(); + famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyArr : Problem in size of Family arr ! Mismatch with number of cells of mesh !"); + _fam_cells=famArr; + } else - _fam_nodes=famArr; + { + int nbNodes=mesh->getNumberOfNodes(); + famArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setFamilyArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !"); + _fam_nodes=famArr; + } + if(famArr) + famArr->incrRef(); } void MEDFileStructuredMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception) { if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setRenumFieldArr : Only available for levels 0 or 1 !"); - if(renumArr) - renumArr->incrRef(); + const MEDCouplingStructuredMesh *mesh=getStructuredMesh(); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setRenumFieldArr : no structured mesh specified ! Impossible to set number array !"); if(meshDimRelToMaxExt==0) - _num_cells=renumArr; + { + int nbCells=mesh->getNumberOfCells(); + renumArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setRenumFieldArr : Problem in size of Renum arr ! Mismatch with number of cells of mesh !"); + _num_cells=renumArr; + } else - _num_nodes=renumArr; + { + int nbNodes=mesh->getNumberOfNodes(); + renumArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setFamilyArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !"); + _num_nodes=renumArr; + } + if(renumArr) + renumArr->incrRef(); } const DataArrayInt *MEDFileStructuredMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) @@ -3161,6 +3198,10 @@ void MEDFileStructuredMesh::writeStructuredLL(med_idt fid, const char *maa) cons MEDmeshEntityFamilyNumberWr(fid,maa,_iteration,_order,MED_CELL,geoTypeReq,_fam_cells->getNumberOfTuples(),_fam_cells->getConstPointer()); if((const DataArrayInt *)_fam_nodes) MEDmeshEntityFamilyNumberWr(fid,maa,_iteration,_order,MED_NODE,MED_NONE,_fam_nodes->getNumberOfTuples(),_fam_nodes->getConstPointer()); + if((const DataArrayInt *)_num_cells) + MEDmeshEntityNumberWr(fid,maa,_iteration,_order,MED_CELL,geoTypeReq,_num_cells->getNumberOfTuples(),_num_cells->getConstPointer()); + if((const DataArrayInt *)_num_nodes) + MEDmeshEntityNumberWr(fid,maa,_iteration,_order,MED_NODE,MED_NONE,_num_nodes->getNumberOfTuples(),_num_nodes->getConstPointer()); // MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str); } diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index dbaf8df19..5d972d5bf 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -1967,6 +1967,39 @@ class MEDLoaderTest(unittest.TestCase): self.assertIn(fff.getProfile("pfl_NORM_QUAD4").getHeapMemorySize(),xrange(215-10,215+10)) self.assertIn(fff[1,-1].getHeapMemorySize(),xrange(700-10,700+10)) pass + + def testCurveLinearMesh1(self): + fname="Pyfile55.med" + mesh=MEDCouplingCurveLinearMesh(); + mesh.setTime(2.3,4,5); + mesh.setTimeUnit("us"); + mesh.setName("Example of Cuve linear mesh"); + mesh.setDescription("buildCLMesh"); + a1=DataArrayDouble(3*20,1); + a1.iota(7.) ; a1.rearrange(3); + mesh.setCoords(a1); + mesh.setNodeGridStructure([4,5]); + mesh.checkCoherency(); + # + m=MEDFileCurveLinearMesh() + m.setMesh(mesh) + d=DataArrayInt(20) ; d.iota(4) + m.setFamilyFieldArr(1,d) + d3=DataArrayInt(20) ; d3.iota(400) + m.setRenumFieldArr(1,d3) + d2=DataArrayInt(12) ; d2.iota(40) + m.setFamilyFieldArr(0,d2) + d4=DataArrayInt(21) ; d4.iota(4000) + self.assertRaises(InterpKernelException,m.setRenumFieldArr,1,d4) + d4.popBackSilent() + m.setRenumFieldArr(1,d4) + m.write(fname,2) + # + m1=MEDFileCurveLinearMesh(fname) + mm=m1.getMesh() + self.assertTrue(mm.isEqual(mesh,1e-12)) + pass + pass unittest.main() -- 2.39.2