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());
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());
CPPUNIT_TEST( testUMeshSplitProfilePerType1 );
CPPUNIT_TEST( testDAIBuildExplicitArrByRanges1 );
CPPUNIT_TEST( testDAIComputeOffsets2 );
+ CPPUNIT_TEST( testMergeField3 );
//MEDCouplingBasicsTestInterp.cxx
CPPUNIT_TEST( test2DInterpP0P0_1 );
CPPUNIT_TEST( test2DInterpP0P0PL_1 );
void testUMeshSplitProfilePerType1();
void testDAIBuildExplicitArrByRanges1();
void testDAIComputeOffsets2();
+ void testMergeField3();
//MEDCouplingBasicsTestInterp.cxx
void test2DInterpP0P0_1();
void test2DInterpP0P0PL_1();
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();
+}
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