From: ageay Date: Thu, 31 Mar 2011 10:00:44 +0000 (+0000) Subject: Adding prepare with FieldTemplate as input. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=93ebb90e6f24ae0e9643fbad947306015c77ad0a;p=tools%2Fmedcoupling.git Adding prepare with FieldTemplate as input. --- diff --git a/src/MEDCoupling/MEDCouplingRemapper.cxx b/src/MEDCoupling/MEDCouplingRemapper.cxx index 0fc9fc3fb..648c58e48 100644 --- a/src/MEDCoupling/MEDCouplingRemapper.cxx +++ b/src/MEDCoupling/MEDCouplingRemapper.cxx @@ -20,6 +20,7 @@ #include "MEDCouplingRemapper.hxx" #include "MEDCouplingMemArray.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingFieldTemplate.hxx" #include "MEDCouplingFieldDiscretization.hxx" #include "MEDCouplingExtrudedMesh.hxx" #include "MEDCouplingNormalizedUnstructuredMesh.txx" @@ -44,7 +45,7 @@ MEDCouplingRemapper::~MEDCouplingRemapper() int MEDCouplingRemapper::prepare(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const char *method) throw(INTERP_KERNEL::Exception) { releaseData(true); - _src_mesh=(MEDCouplingMesh *)srcMesh; _target_mesh=(MEDCouplingMesh *)targetMesh; + _src_mesh=const_cast(srcMesh); _target_mesh=const_cast(targetMesh); _src_mesh->incrRef(); _target_mesh->incrRef(); int meshInterpType=((int)_src_mesh->getType()*16)+(int)_target_mesh->getType(); switch(meshInterpType) @@ -58,6 +59,13 @@ int MEDCouplingRemapper::prepare(const MEDCouplingMesh *srcMesh, const MEDCoupli } } +int MEDCouplingRemapper::prepareEx(const MEDCouplingFieldTemplate *src, const MEDCouplingFieldTemplate *target) throw(INTERP_KERNEL::Exception) +{ + std::string meth(src->getDiscretization()->getStringRepr()); + meth+=target->getDiscretization()->getStringRepr(); + return prepare(src->getMesh(),target->getMesh(),meth.c_str()); +} + void MEDCouplingRemapper::transfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception) { if(_src_method!=srcField->getDiscretization()->getStringRepr()) diff --git a/src/MEDCoupling/MEDCouplingRemapper.hxx b/src/MEDCoupling/MEDCouplingRemapper.hxx index 07d2be0a0..7946a7a7c 100644 --- a/src/MEDCoupling/MEDCouplingRemapper.hxx +++ b/src/MEDCoupling/MEDCouplingRemapper.hxx @@ -34,6 +34,7 @@ namespace ParaMEDMEM class MEDCouplingMesh; class MEDCouplingUMesh; class MEDCouplingFieldDouble; + class MEDCouplingFieldTemplate; } namespace ParaMEDMEM @@ -44,6 +45,7 @@ namespace ParaMEDMEM MEDCOUPLINGREMAPPER_EXPORT MEDCouplingRemapper(); MEDCOUPLINGREMAPPER_EXPORT ~MEDCouplingRemapper(); MEDCOUPLINGREMAPPER_EXPORT int prepare(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const char *method) throw(INTERP_KERNEL::Exception); + MEDCOUPLINGREMAPPER_EXPORT int prepareEx(const MEDCouplingFieldTemplate *src, const MEDCouplingFieldTemplate *target) throw(INTERP_KERNEL::Exception); MEDCOUPLINGREMAPPER_EXPORT void transfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception); MEDCOUPLINGREMAPPER_EXPORT void reverseTransfer(MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception); MEDCOUPLINGREMAPPER_EXPORT MEDCouplingFieldDouble *transferField(const MEDCouplingFieldDouble *srcField, double dftValue) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx b/src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx index 1050f75ce..d1b1daed8 100644 --- a/src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx +++ b/src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx @@ -21,6 +21,7 @@ #include "MEDCouplingUMesh.hxx" #include "MEDCouplingExtrudedMesh.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingFieldTemplate.hxx" #include "MEDCouplingMemArray.hxx" #include "MEDCouplingRemapper.hxx" @@ -982,6 +983,44 @@ void MEDCouplingRemapperTest::testExtruded2() meshTF->decrRef(); } +void MEDCouplingRemapperTest::testPrepareEx1() +{ + MEDCouplingUMesh *sourceMesh=MEDCouplingBasicsTest::build2DSourceMesh_1(); + MEDCouplingUMesh *targetMesh=build2DTargetMesh_3(); + // + MEDCouplingRemapper remapper; + remapper.setPrecision(1e-12); + remapper.setIntersectionType(INTERP_KERNEL::Triangulation); + MEDCouplingFieldTemplate *srcFt=MEDCouplingFieldTemplate::New(ON_CELLS); + MEDCouplingFieldTemplate *trgFt=MEDCouplingFieldTemplate::New(ON_CELLS); + srcFt->setMesh(sourceMesh); + trgFt->setMesh(targetMesh); + CPPUNIT_ASSERT_EQUAL(1,remapper.prepareEx(srcFt,trgFt)); + srcFt->decrRef(); + trgFt->decrRef(); + MEDCouplingFieldDouble *srcField=MEDCouplingFieldDouble::New(ON_CELLS); + srcField->setNature(ConservativeVolumic); + srcField->setMesh(sourceMesh); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(sourceMesh->getNumberOfCells(),1); + srcField->setArray(array); + double *ptr=array->getPointer(); + for(int i=0;igetNumberOfCells();i++) + ptr[i]=(double)(i+7); + array->decrRef(); + MEDCouplingFieldDouble *trgfield=remapper.transferField(srcField,4.220173); + const double *values=trgfield->getArray()->getConstPointer(); + const double valuesExpected[4]={7.75, 7.0625, 4.220173,8.0}; + CPPUNIT_ASSERT_EQUAL(4,trgfield->getArray()->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,trgfield->getArray()->getNumberOfComponents()); + for(int i0=0;i0<4;i0++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected[i0],values[i0],1e-12); + trgfield->decrRef(); + srcField->decrRef(); + sourceMesh->decrRef(); + targetMesh->decrRef(); +} + MEDCouplingUMesh *MEDCouplingRemapperTest::build1DTargetMesh_2() { double targetCoords[20]={ diff --git a/src/MEDCoupling/Test/MEDCouplingRemapperTest.hxx b/src/MEDCoupling/Test/MEDCouplingRemapperTest.hxx index 2b45b4b06..51fad76ca 100644 --- a/src/MEDCoupling/Test/MEDCouplingRemapperTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingRemapperTest.hxx @@ -40,6 +40,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( testNatureOfField ); CPPUNIT_TEST( testExtruded ); CPPUNIT_TEST( testExtruded2 ); + CPPUNIT_TEST( testPrepareEx1 ); CPPUNIT_TEST_SUITE_END(); public: void test2DInterpP0P0_1(); @@ -50,6 +51,7 @@ namespace ParaMEDMEM void testNatureOfField(); void testExtruded(); void testExtruded2(); + void testPrepareEx1(); private: static MEDCouplingUMesh *build1DTargetMesh_2(); static MEDCouplingUMesh *build2DTargetMesh_3();