]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Adding prepare with FieldTemplate as input.
authorageay <ageay>
Thu, 31 Mar 2011 10:00:44 +0000 (10:00 +0000)
committerageay <ageay>
Thu, 31 Mar 2011 10:00:44 +0000 (10:00 +0000)
src/MEDCoupling/MEDCouplingRemapper.cxx
src/MEDCoupling/MEDCouplingRemapper.hxx
src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx
src/MEDCoupling/Test/MEDCouplingRemapperTest.hxx

index 0fc9fc3fb0eefaa167d3fc560b6e95678d2d85ba..648c58e489a5da388f716827c580d40f4a2ecc5a 100644 (file)
@@ -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<MEDCouplingMesh *>(srcMesh); _target_mesh=const_cast<MEDCouplingMesh *>(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())
index 07d2be0a0573c8a2b98be894fa23b23d187ef07d..7946a7a7c45ee3f3c572eba6bdd916e11f95f763 100644 (file)
@@ -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);
index 1050f75ce5735cad96707d1edcc9e57d73cf34fe..d1b1daed85c83d8c9994943fb714ffedaaaf480a 100644 (file)
@@ -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;i<sourceMesh->getNumberOfCells();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]={
index 2b45b4b0665d2b31e60c78cfc333ccec0796fb8d..51fad76ca5a5a5e99f4f97955a3fd3519e787998 100644 (file)
@@ -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();