From: ageay Date: Mon, 18 Jul 2011 16:31:37 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V6_main_FINAL~1002 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=74eb1044cf08104eef3dbdb8eb6a5011996964c7;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index f84fa61e0..8f0b96749 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -1383,10 +1383,16 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const MEDCouplingFie return ret; } +/*! + * This method returns a newly created field that is the union of all fields in input array 'a'. + * This method expects that 'a' is non empty. If not an exception will be thrown. + * If there is only one field in 'a' a deepCopy (except time information of mesh and field) of the unique field instance in 'a' will be returned. + * Generally speaking the first instance field in 'a' will be used to assign tiny attributes of returned field. + */ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vector& a) throw(INTERP_KERNEL::Exception) { - if(a.size()<=1) - throw INTERP_KERNEL::Exception("FieldDouble::MergeFields : size of array must be > 1 !"); + if(a.size()<1) + throw INTERP_KERNEL::Exception("FieldDouble::MergeFields : size of array must be >= 1 !"); std::vector< MEDCouplingAutoRefCountObjectPtr > ms(a.size()); std::vector< const MEDCouplingUMesh *> ms2(a.size()); std::vector< const MEDCouplingTimeDiscretization *> tds(a.size()); @@ -1404,6 +1410,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vector_time_discr; } MEDCouplingAutoRefCountObjectPtr m=MEDCouplingUMesh::MergeUMeshes(ms2); + m->setName(ms2[0]->getName()); m->setDescription(ms2[0]->getDescription()); MEDCouplingTimeDiscretization *td=tds[0]->aggregate(tds); td->copyTinyAttrFrom(*(a[0]->_time_discr)); MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(a[0]->getNature(),td,a[0]->_type->clone()); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index 23c43559e..30141dc2b 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -227,6 +227,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( testUMeshSplitProfilePerType1 ); CPPUNIT_TEST( testDAIBuildExplicitArrByRanges1 ); CPPUNIT_TEST( testDAIComputeOffsets2 ); + CPPUNIT_TEST( testMergeField3 ); //MEDCouplingBasicsTestInterp.cxx CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_1 ); @@ -480,6 +481,7 @@ namespace ParaMEDMEM void testUMeshSplitProfilePerType1(); void testDAIBuildExplicitArrByRanges1(); void testDAIComputeOffsets2(); + void testMergeField3(); //MEDCouplingBasicsTestInterp.cxx void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index 37aabd78a..3b4fff800 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -1469,3 +1469,31 @@ void MEDCouplingBasicsTest::testDAIComputeOffsets2() CPPUNIT_ASSERT_EQUAL(expected1[i],d->getIJ(0,i)); d->decrRef(); } + +void MEDCouplingBasicsTest::testMergeField3() +{ + MEDCouplingUMesh *m=build2DTargetMesh_1(); + m->getCoords()->setInfoOnComponent(0,"x [m]"); + m->getCoords()->setInfoOnComponent(1,"z [km]"); + m->setName("m"); + m->setDescription("desc"); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f1->setName("f1"); + f1->setMesh(m); + DataArrayDouble *arr=DataArrayDouble::New(); + arr->alloc(5,2); + arr->setInfoOnComponent(0,"X [m]"); + arr->setInfoOnComponent(1,"YY [mm]"); + arr->fillWithValue(2.); + f1->setArray(arr); + arr->decrRef(); + m->decrRef(); + // + std::vector tmp(1); + tmp[0]=f1; + MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::MergeFields(tmp); + CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12)); + // + f1->decrRef(); + f2->decrRef(); +} diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 61f3f1694..09ad1f4c2 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -7556,6 +7556,27 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(expected1[i],d.getIJ(0,i)); pass pass + + def testMergeField3(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + m.getCoords().setInfoOnComponent(0,"x [m]"); + m.getCoords().setInfoOnComponent(1,"z [km]"); + m.setName("m"); + m.setDescription("desc"); + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setName("f1"); + f1.setMesh(m); + arr=DataArrayDouble.New(); + arr.alloc(5,2); + arr.setInfoOnComponent(0,"X [m]"); + arr.setInfoOnComponent(1,"YY [mm]"); + arr.fillWithValue(2.); + f1.setArray(arr); + # + f2=MEDCouplingFieldDouble.MergeFields([f1]); + self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + # + pass def setUp(self): pass