reprConnectivityOfThisLL(ret);
return ret.str();
}
+
std::string MEDCouplingUMesh::reprConnectivityOfThis() const
{
std::ostringstream ret;
return ret.str();
}
+/*!
+ * This method builds a newly allocated instance (with the same name than 'this') that the caller has the responsability to deal with.
+ * This method returns an instance with all arrays allocated (connectivity, connectivity index, coordinates)
+ * but with length of these arrays set to 0. It allows to define an "empty" mesh (with nor cells nor nodes but compliant with
+ * some algos).
+ *
+ * This method expects that 'this' has a mesh dimension set and higher or equal to 0. If not an exception will be thrown.
+ * This method analyzes the 3 arrays of 'this'. For each the following behaviour is done : if the array is null a newly one is created
+ * with number of tuples set to 0, if not the array is taken as this in the returned instance.
+ */
+MEDCouplingUMesh *MEDCouplingUMesh::buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception)
+{
+ int mdim=getMeshDimension();
+ if(mdim<0)
+ throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildSetInstanceFromThis : invalid mesh dimension ! Should be >= 0 !");
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New(getName(),mdim);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1,tmp2;
+ bool needToCpyCT=true;
+ if(!_nodal_connec)
+ {
+ tmp1=DataArrayInt::New(); tmp1->alloc(0,1);
+ needToCpyCT=false;
+ }
+ else
+ {
+ tmp1=_nodal_connec;
+ tmp1->incrRef();
+ }
+ if(!_nodal_connec_index)
+ {
+ tmp2=DataArrayInt::New(); tmp2->alloc(1,1); tmp2->setIJ(0,0,0);
+ needToCpyCT=false;
+ }
+ else
+ {
+ tmp2=_nodal_connec_index;
+ tmp2->incrRef();
+ }
+ ret->setConnectivity(tmp1,tmp2,false);
+ if(needToCpyCT)
+ ret->_types=_types;
+ if(!_coords)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords=DataArrayDouble::New(); coords->alloc(0,spaceDim);
+ ret->setCoords(coords);
+ }
+ else
+ ret->setCoords(_coords);
+ ret->incrRef();
+ return ret;
+}
+
void MEDCouplingUMesh::reprConnectivityOfThisLL(std::ostringstream& stream) const
{
if(_nodal_connec!=0 && _nodal_connec_index!=0)
return MergeUMeshes(tmp);
}
+/*!
+ * This method returns in case of success a mesh constitued from union of all meshes in 'a'.
+ * There should be \b no presence of null pointer into 'a'.
+ * The returned mesh will contain aggregation of nodes in 'a' (in the same order) and aggregation of
+ * cells in meshes in 'a' (in the same order too).
+ */
MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshes(std::vector<const MEDCouplingUMesh *>& a) throw(INTERP_KERNEL::Exception)
+{
+ std::size_t sz=a.size();
+ if(sz==0)
+ return MergeUMeshesLL(a);
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > bb(sz);
+ std::vector< const MEDCouplingUMesh * > aa(sz);
+ int spaceDim=-3;
+ for(std::size_t i=0;i<sz && spaceDim==-3;i++)
+ {
+ const MEDCouplingUMesh *cur=a[i];
+ if(!cur)
+ {
+ std::ostringstream oss; oss << "MEDCouplingUMesh::MergeUMeshes : item #" << i << " in input array is empty !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ const DataArrayDouble *coo=cur->getCoords();
+ if(coo)
+ spaceDim=coo->getNumberOfComponents();
+ }
+ if(spaceDim==-3)
+ throw INTERP_KERNEL::Exception("MEDCouplingUMesh::MergeUMeshes : no spaceDim specified ! unable to perform merge !");
+ for(std::size_t i=0;i<sz;i++)
+ {
+ bb[i]=a[i]->buildSetInstanceFromThis(spaceDim);
+ aa[i]=bb[i];
+ }
+ return MergeUMeshesLL(aa);
+}
+
+/// @cond INTERNAL
+
+MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesLL(std::vector<const MEDCouplingUMesh *>& a) throw(INTERP_KERNEL::Exception)
{
if(a.empty())
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::MergeUMeshes : input array must be NON EMPTY !");
return ret;
}
+/// @endcond
+
/*!
* Idem MergeUMeshes except that 'meshes' are expected to lyie on the same coords and 'meshes' have the same meshdim.
* 'meshes' must be a non empty vector.
MEDCOUPLING_EXPORT std::string simpleRepr() const;
MEDCOUPLING_EXPORT std::string advancedRepr() const;
MEDCOUPLING_EXPORT std::string reprConnectivityOfThis() const;
+ MEDCOUPLING_EXPORT MEDCouplingUMesh *buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT int getNumberOfNodesInCell(int cellId) const;
MEDCOUPLING_EXPORT int getNumberOfCells() const;
MEDCOUPLING_EXPORT int getMeshDimension() const;
void getCellsContainingPointsAlg(const double *coords, const double *pos, int nbOfPoints,
double eps, std::vector<int>& elts, std::vector<int>& eltsIndex) const;
/// @cond INTERNAL
+ static MEDCouplingUMesh *MergeUMeshesLL(std::vector<const MEDCouplingUMesh *>& a) throw(INTERP_KERNEL::Exception);
typedef int (*DimM1DescNbrer)(int id, unsigned nb, const INTERP_KERNEL::CellModel& cm, bool compute, const int *conn1, const int *conn2);
MEDCouplingUMesh *buildDescendingConnectivityGen(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx, DimM1DescNbrer nbrer) const throw(INTERP_KERNEL::Exception);
static void FillInCompact3DMode(int spaceDim, int nbOfNodesInCell, const int *conn, const double *coo, double *zipFrmt) throw(INTERP_KERNEL::Exception);
b->decrRef();
c->decrRef();
}
+
+void MEDCouplingBasicsTest4::testUMeshBuildSetInstanceFromThis1()
+{
+ MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
+ MEDCouplingUMesh *m2=m->buildSetInstanceFromThis(3);
+ CPPUNIT_ASSERT_EQUAL(m->getNodalConnectivity(),m2->getNodalConnectivity());
+ CPPUNIT_ASSERT_EQUAL(m->getNodalConnectivityIndex(),m2->getNodalConnectivityIndex());
+ CPPUNIT_ASSERT_EQUAL(m->getCoords(),m2->getCoords());
+ m2->decrRef();
+ m->decrRef();
+ //
+ m=MEDCouplingUMesh::New("toto",2);
+ m2=m->buildSetInstanceFromThis(3);
+ CPPUNIT_ASSERT_EQUAL(0,m2->getNumberOfNodes());
+ CPPUNIT_ASSERT_EQUAL(0,m2->getNumberOfCells());
+ m->decrRef();
+ m2->decrRef();
+}
+
+void MEDCouplingBasicsTest4::testUMeshMergeMeshesCVW1()
+{
+ MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
+ MEDCouplingUMesh *m2=MEDCouplingUMesh::New("toto",2);
+ MEDCouplingUMesh *m3=MEDCouplingUMesh::MergeUMeshes(m,m2);
+ m3->setName(m->getName());
+ CPPUNIT_ASSERT(m->isEqual(m3,1e-12));
+ m3->decrRef();
+ m->decrRef();
+ m2->decrRef();
+}
CPPUNIT_TEST( testConvertExtrudedPolyhedra1 );
CPPUNIT_TEST( testNonRegressionCopyTinyStrings );
CPPUNIT_TEST( testDaDSetPartOfValuesAdv1 );
+ CPPUNIT_TEST( testUMeshBuildSetInstanceFromThis1 );
+ CPPUNIT_TEST( testUMeshMergeMeshesCVW1 );
CPPUNIT_TEST_SUITE_END();
public:
void testDescriptionInMeshTimeUnit1();
void testConvertExtrudedPolyhedra1();
void testNonRegressionCopyTinyStrings();
void testDaDSetPartOfValuesAdv1();
+ void testUMeshBuildSetInstanceFromThis1();
+ void testUMeshMergeMeshesCVW1();
};
}
%newobject ParaMEDMEM::MEDCouplingUMesh::Build0DMeshFromCoords;
%newobject ParaMEDMEM::MEDCouplingUMesh::findCellsIdsOnBoundary;
%newobject ParaMEDMEM::MEDCouplingUMesh::getCellIdsLyingOnNodes;
+%newobject ParaMEDMEM::MEDCouplingUMesh::buildSetInstanceFromThis;
%newobject ParaMEDMEM::MEDCouplingUMeshCellByTypeEntry::__iter__;
%newobject ParaMEDMEM::MEDCouplingUMeshCellEntry::__iter__;
%newobject ParaMEDMEM::MEDCouplingExtrudedMesh::New;
int getMeshLength() const throw(INTERP_KERNEL::Exception);
void computeTypes() throw(INTERP_KERNEL::Exception);
std::string reprConnectivityOfThis() const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception);
//tools
std::vector<bool> getQuadraticStatus() const throw(INTERP_KERNEL::Exception);
DataArrayInt *findCellsIdsOnBoundary() const throw(INTERP_KERNEL::Exception);
expected1=[3.,4.,5., 13.,14.,15., 26.,27.,28., 6.,7.,8., 16.,17.,18., 53.,54.,55.]
self.assertEqual(expected1,a.getValues());
pass
+
+ def testUMeshBuildSetInstanceFromThis1(self):
+ m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
+ m2=m.buildSetInstanceFromThis(3);
+ self.assertTrue(m.isEqual(m2,1e-12));
+ #
+ m=MEDCouplingUMesh.New("toto",2);
+ m2=m.buildSetInstanceFromThis(3);
+ self.assertEqual(0,m2.getNumberOfNodes());
+ self.assertEqual(0,m2.getNumberOfCells());
+ pass
+
+ def testUMeshMergeMeshesCVW1(self):
+ m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
+ m2=MEDCouplingUMesh.New("toto",2);
+ m3=MEDCouplingUMesh.MergeUMeshes([m,m2]);
+ m3.setName(m.getName());
+ self.assertTrue(m.isEqual(m3,1e-12));
+ pass
def setUp(self):
pass