From d32b694191ad3293d489d1b99883a61e0ff72eaa Mon Sep 17 00:00:00 2001 From: imn Date: Thu, 28 May 2015 20:22:31 +0300 Subject: [PATCH] 0022875: fixed method "isEqual" and added some methods in MEDFileJoint --- src/MEDLoader/MEDFileJoint.cxx | 121 ++++++++++-------- src/MEDLoader/MEDFileJoint.hxx | 11 +- src/MEDLoader/Swig/MEDLoaderCommon.i | 46 +------ src/MEDLoader/Swig/MEDLoaderTest3.py | 4 +- src/MEDPartitioner_Swig/MEDPartitionerTest.py | 33 ++++- 5 files changed, 114 insertions(+), 101 deletions(-) diff --git a/src/MEDLoader/MEDFileJoint.cxx b/src/MEDLoader/MEDFileJoint.cxx index afd525b78..f81cfab48 100644 --- a/src/MEDLoader/MEDFileJoint.cxx +++ b/src/MEDLoader/MEDFileJoint.cxx @@ -27,6 +27,7 @@ #include +extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO]; extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO]; extern med_geometry_type typmai3[34]; @@ -160,31 +161,18 @@ void MEDFileJointCorrespondence::setCorrespondence(DataArrayInt *corr) /*! * Checks if \a this and another mesh are equal. * \param [in] other - the mesh to compare with. - * \param [in,out] what - the string returning description of unequal data. * \return bool - \c true if the meshes are equal, \c false, else. */ -bool MEDFileJointCorrespondence::isEqual(const MEDFileJointCorrespondence *other, std::string& what) const +bool MEDFileJointCorrespondence::isEqual(const MEDFileJointCorrespondence *other) const { if(_is_nodal!=other->_is_nodal) - { - what="Entity type differ !"; - return false; - } + return false; if(_loc_geo_type!=other->_loc_geo_type) - { - what="Local geometry type differ !"; - return false; - } + return false; if(_rem_geo_type!=other->_rem_geo_type) - { - what="Remote geometry type differ !"; - return false; - } - if(_correspondence!=other->_correspondence) - { - what="Correspondence differ !"; - return false; - } + return false; + if(!_correspondence->isEqual(*other->_correspondence)) + return false; return true; } @@ -295,8 +283,8 @@ MEDFileJointOneStep::MEDFileJointOneStep(med_idt fid, const std::string& mName, loc_geo_type, rem_ent_type, rem_geo_type, correspondence->getPointer()); MEDFileJointCorrespondence *cor=MEDFileJointCorrespondence::New(); cor->setIsNodal( loc_ent_type == MED_NODE ); - cor->setLocalGeometryType ( typmai2[ loc_geo_type ]); - cor->setRemoteGeometryType( typmai2[ rem_geo_type ]); + cor->setLocalGeometryType ( convertGeometryType( loc_geo_type )); + cor->setRemoteGeometryType( convertGeometryType( rem_geo_type )); cor->setCorrespondence( correspondence ); _correspondences.push_back(cor); } @@ -340,23 +328,38 @@ void MEDFileJointOneStep::pushCorrespondence(MEDFileJointCorrespondence* corresp correspondence->incrRef(); } +int MEDFileJointOneStep::getNumberOfCorrespondences() const +{ + return _correspondences.size(); +} + +/** Return a borrowed reference (caller is not responsible) */ +MEDFileJointCorrespondence *MEDFileJointOneStep::getCorrespondenceAtPos(int i) const +{ + if(i<0 || i>=(int)_correspondences.size()) + { + std::ostringstream oss; oss << "MEDFileJointOneStep::getCorrespondenceAtPos : invalid correspondence id given in parameter ! Should be in [0;" << _correspondences.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const MEDFileJointCorrespondence* ret = _correspondences[i]; + return const_cast( ret ); +} + /*! * Checks if \a this and another Joint are equal. * \param [in] other - the Joint to compare with. - * \param [in,out] what - the string returning description of unequal data. * \return bool - \c true if the Joints are equal, \c false, else. */ -bool MEDFileJointOneStep::isEqual(const MEDFileJointOneStep *other, std::string& what) const +bool MEDFileJointOneStep::isEqual(const MEDFileJointOneStep *other) const { if(_order!=other->_order) - { - what="Orders differ !"; - return false; - } + return false; if(_iteration!=other->_iteration) + return false; + for(int i=0; iisEqual(other->getCorrespondenceAtPos(i))) + return false; } return true; } @@ -395,7 +398,19 @@ std::string MEDFileJointOneStep::simpleRepr() const } return oss.str(); } - +INTERP_KERNEL::NormalizedCellType MEDFileJointOneStep::convertGeometryType(med_geometry_type geotype) +{ + INTERP_KERNEL::NormalizedCellType result=INTERP_KERNEL::NORM_ERROR; + for(int i=0; i); @@ -504,38 +519,44 @@ void MEDFileJoint::pushStep(MEDFileJointOneStep* step) step->incrRef(); } +int MEDFileJoint::getNumberOfSteps() const +{ + return _joint.size(); +} + +/** Return a borrowed reference (caller is not responsible) */ +MEDFileJointOneStep *MEDFileJoint::getStepAtPos(int i) const +{ + if(i<0 || i>=(int)_joint.size()) + { + std::ostringstream oss; oss << "MEDFileJoint::getStepAtPos : invalid step id given in parameter ! Should be in [0;" << _joint.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const MEDFileJointOneStep* ret = _joint[i]; + return const_cast( ret ); +} + /*! * Checks if \a this and another Joint are equal. * \param [in] other - the Joint to compare with. - * \param [in,out] what - the string returning description of unequal data. * \return bool - \c true if the Joints are equal, \c false, else. */ -bool MEDFileJoint::isEqual(const MEDFileJoint *other, std::string& what) const +bool MEDFileJoint::isEqual(const MEDFileJoint *other) const { if(_loc_mesh_name!=other->_loc_mesh_name) - { - what="Local mesh names differ !"; - return false; - } + return false; if(_joint_name!=other->_joint_name) - { - what="Joint names differ !"; - return false; - } + return false; if(_desc_name!=other->_desc_name) - { - what="Description names differ !"; return false; - } if(_rem_mesh_name!=other->_rem_mesh_name) - { - what="Remote mesh names differ !"; - return false; - } + return false; if(_domain_number!=other->_domain_number) + return false; + for(int i=0; iisEqual(other->getStepAtPos(i))) + return false; } return true; } @@ -645,7 +666,7 @@ MEDFileJoint *MEDFileJoints::getJointAtPos(int i) const { if(i<0 || i>=(int)_joints.size()) { - std::ostringstream oss; oss << "MEDFileJoints::getMeshAtPos : invalid mesh id given in parameter ! Should be in [0;" << _joints.size() << ") !"; + std::ostringstream oss; oss << "MEDFileJoints::getJointAtPos : invalid joint id given in parameter ! Should be in [0;" << _joints.size() << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } const MEDFileJoint* ret = _joints[i]; diff --git a/src/MEDLoader/MEDFileJoint.hxx b/src/MEDLoader/MEDFileJoint.hxx index 8df6995f4..1d32312f8 100644 --- a/src/MEDLoader/MEDFileJoint.hxx +++ b/src/MEDLoader/MEDFileJoint.hxx @@ -45,7 +45,7 @@ public: MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; MEDLOADER_EXPORT MEDFileJointCorrespondence *deepCpy() const; MEDLOADER_EXPORT MEDFileJointCorrespondence *shallowCpy() const; - MEDLOADER_EXPORT bool isEqual(const MEDFileJointCorrespondence *other, std::string& what) const; + MEDLOADER_EXPORT bool isEqual(const MEDFileJointCorrespondence *other) const; MEDLOADER_EXPORT void setIsNodal(bool isNodal) { _is_nodal = isNodal; } MEDLOADER_EXPORT bool getIsNodal() const { return _is_nodal; } MEDLOADER_EXPORT void setLocalGeometryType(INTERP_KERNEL::NormalizedCellType type) { _loc_geo_type=type; } @@ -84,12 +84,14 @@ public: MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; MEDLOADER_EXPORT MEDFileJointOneStep *deepCpy() const; MEDLOADER_EXPORT MEDFileJointOneStep *shallowCpy() const; - MEDLOADER_EXPORT bool isEqual(const MEDFileJointOneStep *other, std::string& what) const; + MEDLOADER_EXPORT bool isEqual(const MEDFileJointOneStep *other) const; MEDLOADER_EXPORT void setOrder(int order) { _order=order; } MEDLOADER_EXPORT int getOrder() const { return _order; } MEDLOADER_EXPORT void setIteration(int it) { _iteration=it; } MEDLOADER_EXPORT int getIteration() const { return _iteration; } MEDLOADER_EXPORT void pushCorrespondence(MEDFileJointCorrespondence* correspondence); + MEDLOADER_EXPORT int getNumberOfCorrespondences() const; + MEDLOADER_EXPORT MEDFileJointCorrespondence *getCorrespondenceAtPos(int i) const; MEDLOADER_EXPORT void write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName) const; @@ -98,6 +100,7 @@ public: private: MEDFileJointOneStep(); MEDFileJointOneStep(med_idt fid, const std::string& mName, const std::string& jointName, int number); + MEDLOADER_EXPORT INTERP_KERNEL::NormalizedCellType convertGeometryType(med_geometry_type geotype); protected: int _order; int _iteration; @@ -120,7 +123,7 @@ public: MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; MEDLOADER_EXPORT MEDFileJoint *deepCpy() const; MEDLOADER_EXPORT MEDFileJoint *shallowCpy() const; - MEDLOADER_EXPORT bool isEqual(const MEDFileJoint *other, std::string& what) const; + MEDLOADER_EXPORT bool isEqual(const MEDFileJoint *other) const; MEDLOADER_EXPORT void setLocalMeshName(const std::string& name) { _loc_mesh_name=name; } MEDLOADER_EXPORT std::string getLocalMeshName() const { return _loc_mesh_name; } MEDLOADER_EXPORT void setRemoteMeshName(const std::string& name) { _rem_mesh_name=name; } @@ -133,6 +136,8 @@ public: MEDLOADER_EXPORT void setDomainNumber(const int& number) { _domain_number=number; } MEDLOADER_EXPORT int getDomainNumber() const { return _domain_number; } MEDLOADER_EXPORT void pushStep(MEDFileJointOneStep* step); + MEDLOADER_EXPORT int getNumberOfSteps() const; + MEDLOADER_EXPORT MEDFileJointOneStep *getStepAtPos(int i) const; MEDLOADER_EXPORT void write(const std::string& fileName, int mode) const; MEDLOADER_EXPORT void write(med_idt fid) const; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 7a4a1d37b..a1e73eb3c 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -510,6 +510,7 @@ namespace ParaMEDMEM MEDFileJointCorrespondence *shallowCpy() const; void setIsNodal(bool isNodal); bool getIsNodal() const; + bool isEqual(const MEDFileJointCorrespondence *other) const; void setLocalGeometryType(INTERP_KERNEL::NormalizedCellType type); INTERP_KERNEL::NormalizedCellType getLocalGeometryType() const; void setRemoteGeometryType(INTERP_KERNEL::NormalizedCellType type); @@ -539,19 +540,6 @@ namespace ParaMEDMEM { return self->simpleRepr(); } - - PyObject *isEqual(const MEDFileJointCorrespondence *other) const throw(INTERP_KERNEL::Exception) - { - std::string what; - bool ret0=self->isEqual(other,what); - PyObject *res=PyList_New(2); - PyObject *ret0Py=ret0?Py_True:Py_False; - Py_XINCREF(ret0Py); - PyList_SetItem(res,0,ret0Py); - PyList_SetItem(res,1,PyString_FromString(what.c_str())); - return res; - } - } }; @@ -562,12 +550,14 @@ namespace ParaMEDMEM static MEDFileJointOneStep *New(const std::string& fileName, const std::string& mName, const std::string& jointName, int number=1) throw(INTERP_KERNEL::Exception); MEDFileJointOneStep *deepCpy() const; MEDFileJointOneStep *shallowCpy() const; - bool isEqual(const MEDFileJointOneStep *other, std::string& what) const; + bool isEqual(const MEDFileJointOneStep *other) const; void setOrder(int order); int getOrder() const; void setIteration(int it); int getIteration() const; void pushCorrespondence(MEDFileJointCorrespondence* correspondence); + int getNumberOfCorrespondences() const; + MEDFileJointCorrespondence *getCorrespondenceAtPos(int i) const; void write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName) const throw(INTERP_KERNEL::Exception); std::string simpleRepr() const throw(INTERP_KERNEL::Exception); %extend @@ -586,18 +576,6 @@ namespace ParaMEDMEM { return self->simpleRepr(); } - - PyObject *isEqual(const MEDFileJointOneStep *other) const throw(INTERP_KERNEL::Exception) - { - std::string what; - bool ret0=self->isEqual(other,what); - PyObject *res=PyList_New(2); - PyObject *ret0Py=ret0?Py_True:Py_False; - Py_XINCREF(ret0Py); - PyList_SetItem(res,0,ret0Py); - PyList_SetItem(res,1,PyString_FromString(what.c_str())); - return res; - } } }; class MEDFileJoint : public RefCountObject, public MEDFileWritable @@ -608,7 +586,7 @@ namespace ParaMEDMEM static MEDFileJoint *New(const std::string& jointName, const std::string& locMeshName, const std::string& remoteMeshName, int remoteMeshNum ) throw(INTERP_KERNEL::Exception); MEDFileJoint *deepCpy() const; MEDFileJoint *shallowCpy() const; - bool isEqual(const MEDFileJoint *other, std::string& what) const; + bool isEqual(const MEDFileJoint *other) const; void setLocalMeshName(const std::string& name); std::string getLocalMeshName() const; void setRemoteMeshName(const std::string& name); @@ -621,6 +599,8 @@ namespace ParaMEDMEM void setDomainNumber(const int& number); int getDomainNumber() const; void pushStep(MEDFileJointOneStep* step); + int getNumberOfSteps() const; + MEDFileJointOneStep *getStepAtPos(int i) const; void write(const std::string& fileName, int mode) const throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; %extend @@ -639,18 +619,6 @@ namespace ParaMEDMEM { return self->simpleRepr(); } - - PyObject *isEqual(const MEDFileJoint *other) const throw(INTERP_KERNEL::Exception) - { - std::string what; - bool ret0=self->isEqual(other,what); - PyObject *res=PyList_New(2); - PyObject *ret0Py=ret0?Py_True:Py_False; - Py_XINCREF(ret0Py); - PyList_SetItem(res,0,ret0Py); - PyList_SetItem(res,1,PyString_FromString(what.c_str())); - return res; - } } }; diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index dfa62dc91..2c0d40bf0 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -4192,8 +4192,8 @@ class MEDLoaderTest(unittest.TestCase): node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8])) cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3) one_step_joint=MEDFileJointOneStep() - one_step_joint.pushCorrespondence(node_correspond) one_step_joint.pushCorrespondence(cell_correspond) + one_step_joint.pushCorrespondence(node_correspond) one_joint=MEDFileJoint() one_joint.pushStep(one_step_joint) one_joint.setLocalMeshName("maa1") @@ -4235,8 +4235,8 @@ class MEDLoaderTest(unittest.TestCase): two_joint=MEDFileJoint() one_step_joint.pushCorrespondence(node_correspond) one_joint.pushStep(one_step_joint) - two_step_joint.pushCorrespondence(node_correspond) two_step_joint.pushCorrespondence(cell_correspond) + two_step_joint.pushCorrespondence(node_correspond) two_joint.pushStep(two_step_joint) one_joint.setLocalMeshName("maa1") one_joint.setRemoteMeshName("maa1") diff --git a/src/MEDPartitioner_Swig/MEDPartitionerTest.py b/src/MEDPartitioner_Swig/MEDPartitionerTest.py index 845c41ef1..2b2ed5a6d 100644 --- a/src/MEDPartitioner_Swig/MEDPartitionerTest.py +++ b/src/MEDPartitioner_Swig/MEDPartitionerTest.py @@ -40,8 +40,7 @@ class MEDPartitionerTest(unittest.TestCase): m2d=data2.getMeshes().getMeshAtPos(0) self.assertTrue(m1d.isEqual(m2d,1e-12)) pass - def testPartition2(self): - fname="PyPartitionTest2.med" + def testPartitionWithJoints(self): # cartesian mesh 4x4 arr=DataArrayDouble(5) ; arr.iota() c=MEDCouplingCMesh() ; c.setCoords(arr,arr) @@ -52,18 +51,38 @@ class MEDPartitionerTest(unittest.TestCase): ms=MEDFileMeshes() ; ms.pushMesh(mm) data=MEDFileData() data.setMeshes(ms) - data.write(fname,2) part_file=MEDPartitioner(data,4,"metis",True,True,True) - part_file.write("splitted_PyPartitionTest2") + data_file=part_file.getMEDFileData() + meshes=data_file.getMeshes() + self.assertEqual( meshes.getNumberOfMeshes(), 4) + self.assertEqual( meshes.getMeshAtPos(0).getJoints().getNumberOfJoints(), 3) + self.assertEqual( meshes.getMeshAtPos(1).getJoints().getNumberOfJoints(), 3) + self.assertEqual( meshes.getMeshAtPos(2).getJoints().getNumberOfJoints(), 3) + self.assertEqual( meshes.getMeshAtPos(3).getJoints().getNumberOfJoints(), 3) + joints=meshes.getMeshAtPos(0).getJoints() + self.assertEqual( joints.getJointAtPos(0).getJointName(), "joint_1") + self.assertEqual( joints.getJointAtPos(1).getJointName(), "joint_2") + self.assertEqual( joints.getJointAtPos(2).getJointName(), "joint_3") + self.assertEqual( joints.getJointAtPos(0).getDescription(), "connect_zone_0") + self.assertEqual( joints.getJointAtPos(1).getDescription(), "connect_zone_1") + self.assertEqual( joints.getJointAtPos(2).getDescription(), "connect_zone_8") + self.assertEqual( joints.getJointAtPos(0).getDomainNumber(), 1) + self.assertEqual( joints.getJointAtPos(1).getDomainNumber(), 2) + self.assertEqual( joints.getJointAtPos(2).getDomainNumber(), 3) + self.assertEqual( joints.getJointAtPos(0).getStepAtPos(0).getNumberOfCorrespondences(), 2) + self.assertEqual( joints.getJointAtPos(1).getStepAtPos(0).getNumberOfCorrespondences(), 2) + self.assertEqual( joints.getJointAtPos(2).getStepAtPos(0).getNumberOfCorrespondences(), 1) + self.assertTrue(joints.getJointAtPos(0).getStepAtPos(0).getCorrespondenceAtPos(0).getCorrespondence().isEqual(DataArrayInt([6,0,7,1,8,2]))) + self.assertTrue(joints.getJointAtPos(0).getStepAtPos(0).getCorrespondenceAtPos(1).getCorrespondence().isEqual(DataArrayInt([1,3,2,4]))) pass - def testPartition3(self): - from MEDCoupling import MEDCouplingCMesh + def testPartitionPartGraph(self): + from MEDCoupling import MEDCouplingSkyLineArray arr=DataArrayDouble(5) ; arr.iota() c=MEDCouplingCMesh() ; c.setCoords(arr,arr) m=c.buildUnstructured() part=MEDPartitioner.Graph(m.generateGraph()) part.partGraph(2) a=part.getGraph() -# #assert(isinstance(a,SkyLineArray)) + self.assertTrue(isinstance(a,MEDCouplingSkyLineArray)) pass unittest.main() -- 2.39.2