From: ageay Date: Tue, 24 Apr 2012 10:46:44 +0000 (+0000) Subject: MEDCouplingMesh::MergeMeshes X-Git-Tag: TRIPOLI_323~32 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8bba699561d2606149be61b6c61172a91fe0cf4a;p=tools%2Fmedcoupling.git MEDCouplingMesh::MergeMeshes --- diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx index 9bfca39fd..e6996122e 100644 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -18,6 +18,7 @@ // #include "MEDCouplingMesh.hxx" +#include "MEDCouplingUMesh.hxx" #include "MEDCouplingMemArray.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldDiscretization.hxx" @@ -295,13 +296,45 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic3(TypeOfField t, int nb /*! * retruns a newly created mesh with counter=1 - * that is the union of mesh1 and mesh2 if possible. The cells of mesh2 will appear after cells of 'mesh1'. Idem for nodes. + * that is the union of \b mesh1 and \b mesh2 if possible. The cells of \b mesh2 will appear after cells of \b mesh1. Idem for nodes. + * The only contraint is that \b mesh1 an \b mesh2 have the same mesh types. If it is not the case please use the other API of MEDCouplingMesh::MergeMeshes, + * with input vector of meshes. */ -MEDCouplingMesh *MEDCouplingMesh::MergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2) +MEDCouplingMesh *MEDCouplingMesh::MergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2) throw(INTERP_KERNEL::Exception) { + if(!mesh1) + throw INTERP_KERNEL::Exception("MEDCouplingMesh::MergeMeshes : first parameter is an empty mesh !"); + if(!mesh2) + throw INTERP_KERNEL::Exception("MEDCouplingMesh::MergeMeshes : second parameter is an empty mesh !"); return mesh1->mergeMyselfWith(mesh2); } +/*! + * retruns a newly created mesh with counter=1 + * that is the union of meshes if possible. The cells of \b meshes[1] will appear after cells of \b meshes[0]. Idem for nodes. + * This method performs a systematic conversion to unstructured meshes before performing aggregation contrary to the other ParaMEDMEM::MEDCouplingMesh::MergeMeshes with + * two parameters that work only on the same type of meshes. So here it is possible to mix different type of meshes. + */ +MEDCouplingMesh *MEDCouplingMesh::MergeMeshes(std::vector& meshes) throw(INTERP_KERNEL::Exception) +{ + std::vector< MEDCouplingAutoRefCountObjectPtr > ms1(meshes.size()); + std::vector< const MEDCouplingUMesh * > ms2(meshes.size()); + for(std::size_t i=0;ibuildUnstructured(); + ms1[i]=cur; ms2[i]=cur; + } + else + { + std::ostringstream oss; oss << "MEDCouplingMesh::MergeMeshes(std::vector& meshes) : mesh at pos #" << i << " of input vector of size " << meshes.size() << " is empty !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + return MEDCouplingUMesh::MergeUMeshes(ms2); +} + void MEDCouplingMesh::getCellsContainingPoint(const double *pos, double eps, std::vector& elts) const { int ret=getCellContainingPoint(pos,eps); diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index 0311d5967..9724ca3e6 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -113,7 +113,8 @@ namespace ParaMEDMEM virtual MEDCouplingUMesh *buildUnstructured() const throw(INTERP_KERNEL::Exception) = 0; virtual DataArrayInt *simplexize(int policy) throw(INTERP_KERNEL::Exception) = 0; virtual bool areCompatibleForMerge(const MEDCouplingMesh *other) const; - static MEDCouplingMesh *MergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2); + static MEDCouplingMesh *MergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2) throw(INTERP_KERNEL::Exception); + static MEDCouplingMesh *MergeMeshes(std::vector& meshes) throw(INTERP_KERNEL::Exception); //serialisation-unserialization virtual void getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const = 0; virtual void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const = 0; diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 21b52859e..106f3bb91 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -667,6 +667,13 @@ namespace ParaMEDMEM PyList_SetItem(res,i,PyInt_FromLong(*iL)); return res; } + + static MEDCouplingMesh *MergeMeshes(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyObjToVecMeshesCst(li,tmp); + return MEDCouplingMesh::MergeMeshes(tmp); + } } }; } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 1df73b78f..5682979c7 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -6948,6 +6948,9 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(10,m4.getNumberOfCells()); self.assertEqual(20,m4.getNumberOfNodes()); self.assertEqual(45,m4.getMeshLength()); + m4bis=MEDCouplingMesh.MergeMeshes(ms); + self.assertTrue(m4.isEqual(m4bis,1e-12)) + del m4bis # vec3=[0,1,2,3,4] m4_1=m4.buildPartOfMySelf(vec3,False); diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index ccd64ca86..f9e28d3e4 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -551,7 +551,7 @@ void convertPyObjToVecUMeshesCst(PyObject *ms, std::vector& v) throw(INTERP_KERNEL::Exception) +{ + if(PyList_Check(ms)) + { + int size=PyList_Size(ms); + v.resize(size); + for(int i=0;i(argp); + v[i]=arg; + } + } + else + { + const char msg[]="convertPyObjToVecUMeshesCst : not a list"; + PyErr_SetString(PyExc_TypeError,msg); + throw INTERP_KERNEL::Exception(msg); + } +} + void convertPyObjToVecDataArrayDblCst(PyObject *ms, std::vector& v) throw(INTERP_KERNEL::Exception) { if(PyList_Check(ms)) @@ -609,7 +638,7 @@ void convertPyObjToVecFieldDblCst(PyObject *ms, std::vector