//
#include "MEDCouplingMesh.hxx"
+#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingMemArray.hxx"
#include "MEDCouplingFieldDouble.hxx"
#include "MEDCouplingFieldDiscretization.hxx"
/*!
* 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<const MEDCouplingMesh *>& meshes) throw(INTERP_KERNEL::Exception)
+{
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > ms1(meshes.size());
+ std::vector< const MEDCouplingUMesh * > ms2(meshes.size());
+ for(std::size_t i=0;i<meshes.size();i++)
+ {
+ if(meshes[i])
+ {
+ MEDCouplingUMesh *cur=meshes[i]->buildUnstructured();
+ ms1[i]=cur; ms2[i]=cur;
+ }
+ else
+ {
+ std::ostringstream oss; oss << "MEDCouplingMesh::MergeMeshes(std::vector<const MEDCouplingMesh *>& 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<int>& elts) const
{
int ret=getCellContainingPoint(pos,eps);
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<const MEDCouplingMesh *>& meshes) throw(INTERP_KERNEL::Exception);
//serialisation-unserialization
virtual void getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const = 0;
virtual void resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const = 0;
PyList_SetItem(res,i,PyInt_FromLong(*iL));
return res;
}
+
+ static MEDCouplingMesh *MergeMeshes(PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<const ParaMEDMEM::MEDCouplingMesh *> tmp;
+ convertPyObjToVecMeshesCst(li,tmp);
+ return MEDCouplingMesh::MergeMeshes(tmp);
+ }
}
};
}
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);
int status=SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,0|0);
if(!SWIG_IsOK(status))
{
- const char msg[]="list must contain only MEDCouplingUMesh";
+ const char msg[]="list must contain only instance of MEDCouplingUMesh";
PyErr_SetString(PyExc_TypeError,msg);
throw INTERP_KERNEL::Exception(msg);
}
}
}
+void convertPyObjToVecMeshesCst(PyObject *ms, std::vector<const ParaMEDMEM::MEDCouplingMesh *>& v) throw(INTERP_KERNEL::Exception)
+{
+ if(PyList_Check(ms))
+ {
+ int size=PyList_Size(ms);
+ v.resize(size);
+ for(int i=0;i<size;i++)
+ {
+ PyObject *obj=PyList_GetItem(ms,i);
+ void *argp;
+ int status=SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMesh,0|0);
+ if(!SWIG_IsOK(status))
+ {
+ const char msg[]="list must contain only instance of MEDCouplingMesh";
+ PyErr_SetString(PyExc_TypeError,msg);
+ throw INTERP_KERNEL::Exception(msg);
+ }
+ const ParaMEDMEM::MEDCouplingMesh *arg=reinterpret_cast< const ParaMEDMEM::MEDCouplingMesh * >(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<const ParaMEDMEM::DataArrayDouble *>& v) throw(INTERP_KERNEL::Exception)
{
if(PyList_Check(ms))
int status=SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0);
if(!SWIG_IsOK(status))
{
- const char msg[]="list must contain only MEDCouplingFieldDouble";
+ const char msg[]="list must contain only instance of MEDCouplingFieldDouble";
PyErr_SetString(PyExc_TypeError,msg);
throw INTERP_KERNEL::Exception(msg);
}
int status=SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
if(!SWIG_IsOK(status))
{
- const char msg[]="list must contain only DataArrayInt";
+ const char msg[]="list must contain only instance of DataArrayInt";
PyErr_SetString(PyExc_TypeError,msg);
throw INTERP_KERNEL::Exception(msg);
}