From aa3348706b539108b3deae1cbca45c6ae2859bcd Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 17 Oct 2011 09:37:14 +0000 Subject: [PATCH] Imp for not fully set umesh. --- src/MEDCoupling/MEDCouplingUMesh.cxx | 93 +++++++++++++++++++ src/MEDCoupling/MEDCouplingUMesh.hxx | 2 + .../Test/MEDCouplingBasicsTest4.cxx | 30 ++++++ .../Test/MEDCouplingBasicsTest4.hxx | 4 + src/MEDCoupling_Swig/MEDCoupling.i | 2 + src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 19 ++++ 6 files changed, 150 insertions(+) diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 5681a69a6..a1229a17a 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1776,6 +1776,7 @@ std::string MEDCouplingUMesh::advancedRepr() const reprConnectivityOfThisLL(ret); return ret.str(); } + std::string MEDCouplingUMesh::reprConnectivityOfThis() const { std::ostringstream ret; @@ -1783,6 +1784,58 @@ std::string MEDCouplingUMesh::reprConnectivityOfThis() const 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 ret=MEDCouplingUMesh::New(getName(),mdim); + MEDCouplingAutoRefCountObjectPtr 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 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) @@ -4279,7 +4332,45 @@ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshes(const MEDCouplingUMesh *mesh1, 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& a) throw(INTERP_KERNEL::Exception) +{ + std::size_t sz=a.size(); + if(sz==0) + return MergeUMeshesLL(a); + std::vector< MEDCouplingAutoRefCountObjectPtr > bb(sz); + std::vector< const MEDCouplingUMesh * > aa(sz); + int spaceDim=-3; + for(std::size_t i=0;igetCoords(); + 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;ibuildSetInstanceFromThis(spaceDim); + aa[i]=bb[i]; + } + return MergeUMeshesLL(aa); +} + +/// @cond INTERNAL + +MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesLL(std::vector& a) throw(INTERP_KERNEL::Exception) { if(a.empty()) throw INTERP_KERNEL::Exception("MEDCouplingUMesh::MergeUMeshes : input array must be NON EMPTY !"); @@ -4338,6 +4429,8 @@ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshes(std::vector& elts, std::vector& eltsIndex) const; /// @cond INTERNAL + static MEDCouplingUMesh *MergeUMeshesLL(std::vector& 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); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index 6be7b0ac8..7cbb56c7e 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -1671,3 +1671,33 @@ void MEDCouplingBasicsTest4::testDaDSetPartOfValuesAdv1() 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(); +} diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.hxx index cc7391759..bd7cdbaec 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.hxx @@ -79,6 +79,8 @@ namespace ParaMEDMEM CPPUNIT_TEST( testConvertExtrudedPolyhedra1 ); CPPUNIT_TEST( testNonRegressionCopyTinyStrings ); CPPUNIT_TEST( testDaDSetPartOfValuesAdv1 ); + CPPUNIT_TEST( testUMeshBuildSetInstanceFromThis1 ); + CPPUNIT_TEST( testUMeshMergeMeshesCVW1 ); CPPUNIT_TEST_SUITE_END(); public: void testDescriptionInMeshTimeUnit1(); @@ -126,6 +128,8 @@ namespace ParaMEDMEM void testConvertExtrudedPolyhedra1(); void testNonRegressionCopyTinyStrings(); void testDaDSetPartOfValuesAdv1(); + void testUMeshBuildSetInstanceFromThis1(); + void testUMeshMergeMeshesCVW1(); }; } diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 8e3ea8ff1..381eec04b 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -261,6 +261,7 @@ using namespace INTERP_KERNEL; %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; @@ -1001,6 +1002,7 @@ namespace ParaMEDMEM 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 getQuadraticStatus() const throw(INTERP_KERNEL::Exception); DataArrayInt *findCellsIdsOnBoundary() const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index a648bbcff..1e9465aeb 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -7867,6 +7867,25 @@ class MEDCouplingBasicsTest(unittest.TestCase): 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 -- 2.39.2