]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Mon, 18 Jul 2011 16:31:37 +0000 (16:31 +0000)
committerageay <ageay>
Mon, 18 Jul 2011 16:31:37 +0000 (16:31 +0000)
src/MEDCoupling/MEDCouplingFieldDouble.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index f84fa61e0957d00a73aa5b3e2834c5e6ecc26733..8f0b96749b176eb920ac48ef051ebb18c63f9942 100644 (file)
@@ -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<const MEDCouplingFieldDouble *>& 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<MEDCouplingUMesh> > 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<co
       tds[i]=a[i]->_time_discr;
     }
   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> 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());
index 23c43559ed18a324ecf5e2d1635098d9d4b15f03..30141dc2b27bb615306f96e84141a70bbebd9c5f 100644 (file)
@@ -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();
index 37aabd78a2fbd734fabe074402dc598156034cff..3b4fff800ec8a721db7fdb54a7af80030408db40 100644 (file)
@@ -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<const MEDCouplingFieldDouble *> tmp(1);
+  tmp[0]=f1;
+  MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::MergeFields(tmp);
+  CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
+  //
+  f1->decrRef();
+  f2->decrRef();
+}
index 61f3f16948566d337e780904c216980480574c67..09ad1f4c21d20625bc5ecd7fb91a651191536c94 100644 (file)
@@ -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