#include <set>
+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];
/*!
* 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;
}
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);
}
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<MEDFileJointCorrespondence *>( 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; i<getNumberOfCorrespondences(); i++)
{
- what="Iterations differ !";
- return false;
+ if(!getCorrespondenceAtPos(i)->isEqual(other->getCorrespondenceAtPos(i)))
+ return false;
}
return true;
}
}
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<MED_N_CELL_FIXED_GEO; i++)
+ {
+ if (typmai[i]==geotype)
+ {
+ result=typmai2[i];
+ break;
+ }
+ }
+ return result;
+}
std::size_t MEDFileJoint::getHeapMemorySizeWithoutChildren() const
{
return _joint.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileJointOneStep>);
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<MEDFileJointOneStep *>( 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; i<getNumberOfSteps(); i++)
{
- what="Domain numbers differ !";
- return false;
+ if(!getStepAtPos(i)->isEqual(other->getStepAtPos(i)))
+ return false;
}
return true;
}
{
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];
MEDLOADER_EXPORT std::vector<const BigMemoryObject *> 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; }
MEDLOADER_EXPORT std::vector<const BigMemoryObject *> 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;
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;
MEDLOADER_EXPORT std::vector<const BigMemoryObject *> 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; }
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;
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);
{
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;
- }
-
}
};
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
{
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
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);
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
{
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;
- }
}
};
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")
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")
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)
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()