]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Introduction of 3D/2D interpolation into MEDCouplingRemapper.
authorageay <ageay>
Fri, 30 Sep 2011 09:28:09 +0000 (09:28 +0000)
committerageay <ageay>
Fri, 30 Sep 2011 09:28:09 +0000 (09:28 +0000)
src/MEDCoupling/MEDCouplingRemapper.cxx
src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx

index 8c9f3ee4050ab78acf359a69dc7fe8dc41ac7b69..9e675e370d8f8135e13a2f62f187b1c3d331228d 100644 (file)
@@ -31,6 +31,7 @@
 #include "Interpolation3D.txx"
 #include "Interpolation3DSurf.hxx"
 #include "Interpolation2D1D.txx"
+#include "Interpolation3D2D.txx"
 
 using namespace ParaMEDMEM;
 
@@ -251,6 +252,17 @@ int MEDCouplingRemapper::prepareUU(const char *method) throw(INTERP_KERNEL::Exce
           nbCols=interpolation.interpolateMeshes(target_mesh_wrapper,source_mesh_wrapper,matrixTmp,method);
           reverseMatrix(matrixTmp,nbCols,_matrix);
           nbCols=matrixTmp.size();
+          INTERP_KERNEL::Interpolation2D1D::DuplicateFacesType duplicateFaces=interpolation.retrieveDuplicateFaces();
+          if(!duplicateFaces.empty())
+            {
+              std::ostringstream oss; oss << "An unexpected situation happend ! For the following 1D Cells are part of edges shared by 2D cells :\n";
+              for(std::map<int,std::set<int> >::const_iterator it=duplicateFaces.begin();it!=duplicateFaces.end();it++)
+                {
+                  oss << "1D Cell #" << (*it).first << " is part of common edge of following 2D cells ids : ";
+                  std::copy((*it).second.begin(),(*it).second.end(),std::ostream_iterator<int>(oss," "));
+                  oss << std::endl;
+                }
+            }
         }
     }
   else if(srcMeshDim==1 && trgMeshDim==2 && srcSpaceDim==2)
@@ -271,6 +283,56 @@ int MEDCouplingRemapper::prepareUU(const char *method) throw(INTERP_KERNEL::Exce
           MEDCouplingNormalizedUnstructuredMesh<2,2> target_mesh_wrapper(target_mesh);
           INTERP_KERNEL::Interpolation2D1D interpolation(*this);
           nbCols=interpolation.interpolateMeshes(source_mesh_wrapper,target_mesh_wrapper,_matrix,method);
+          INTERP_KERNEL::Interpolation2D1D::DuplicateFacesType duplicateFaces=interpolation.retrieveDuplicateFaces();
+          if(!duplicateFaces.empty())
+            {
+              std::ostringstream oss; oss << "An unexpected situation happend ! For the following 1D Cells are part of edges shared by 2D cells :\n";
+              for(std::map<int,std::set<int> >::const_iterator it=duplicateFaces.begin();it!=duplicateFaces.end();it++)
+                {
+                  oss << "1D Cell #" << (*it).first << " is part of common edge of following 2D cells ids : ";
+                  std::copy((*it).second.begin(),(*it).second.end(),std::ostream_iterator<int>(oss," "));
+                  oss << std::endl;
+                }
+            }
+        }
+    }
+  else if(srcMeshDim==2 && trgMeshDim==3 && srcSpaceDim==3)
+    {
+      MEDCouplingNormalizedUnstructuredMesh<3,3> source_mesh_wrapper(src_mesh);
+      MEDCouplingNormalizedUnstructuredMesh<3,3> target_mesh_wrapper(target_mesh);
+      INTERP_KERNEL::Interpolation3D2D interpolation(*this);
+      nbCols=interpolation.interpolateMeshes(source_mesh_wrapper,target_mesh_wrapper,_matrix,method);
+      INTERP_KERNEL::Interpolation3D2D::DuplicateFacesType duplicateFaces=interpolation.retrieveDuplicateFaces();
+      if(!duplicateFaces.empty())
+        {
+          std::ostringstream oss; oss << "An unexpected situation happend ! For the following 2D Cells are part of edges shared by 3D cells :\n";
+          for(std::map<int,std::set<int> >::const_iterator it=duplicateFaces.begin();it!=duplicateFaces.end();it++)
+            {
+              oss << "2D Cell #" << (*it).first << " is part of common face of following 3D cells ids : ";
+              std::copy((*it).second.begin(),(*it).second.end(),std::ostream_iterator<int>(oss," "));
+              oss << std::endl;
+            }
+        }
+    }
+  else if(srcMeshDim==3 && trgMeshDim==2 && srcSpaceDim==3)
+    {
+      MEDCouplingNormalizedUnstructuredMesh<3,3> source_mesh_wrapper(src_mesh);
+      MEDCouplingNormalizedUnstructuredMesh<3,3> target_mesh_wrapper(target_mesh);
+      INTERP_KERNEL::Interpolation3D2D interpolation(*this);
+      std::vector<std::map<int,double> > matrixTmp;
+      nbCols=interpolation.interpolateMeshes(target_mesh_wrapper,source_mesh_wrapper,matrixTmp,method);
+      reverseMatrix(matrixTmp,nbCols,_matrix);
+      nbCols=matrixTmp.size();
+      INTERP_KERNEL::Interpolation3D2D::DuplicateFacesType duplicateFaces=interpolation.retrieveDuplicateFaces();
+      if(!duplicateFaces.empty())
+        {
+          std::ostringstream oss; oss << "An unexpected situation happend ! For the following 2D Cells are part of edges shared by 3D cells :\n";
+          for(std::map<int,std::set<int> >::const_iterator it=duplicateFaces.begin();it!=duplicateFaces.end();it++)
+            {
+              oss << "2D Cell #" << (*it).first << " is part of common face of following 3D cells ids : ";
+              std::copy((*it).second.begin(),(*it).second.end(),std::ostream_iterator<int>(oss," "));
+              oss << std::endl;
+            }
         }
     }
   else if(trgMeshDim==-1)
index 58d2de4f669ebfda5b22cb870627e5e3836c7771..3bbb7e2e46c54dd22553aaba8a2036d1bbce6dd9 100644 (file)
@@ -687,6 +687,43 @@ void MEDCouplingRemapperTest::testMultiDimCombi()
   trgField->decrRef();
   sourceMesh->decrRef();
   targetMesh->decrRef();
+  //------------- 2D -> 3D
+  sourceMesh=MEDCouplingBasicsTest::build3D2DSourceMesh();
+  targetMesh=MEDCouplingBasicsTest::build3D2DTargetMesh();
+  remapper.setIntersectionType(INTERP_KERNEL::Triangulation);
+  CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
+  srcField=MEDCouplingFieldDouble::New(ON_CELLS);
+  srcField->setNature(ConservativeVolumic);
+  srcField->setMesh(sourceMesh);
+  array=DataArrayDouble::New();
+  array->alloc(7,1); array->iota(2.);
+  srcField->setArray(array); array->decrRef();
+  trgField=remapper.transferField(srcField,4.57);
+  const double valuesExpected12[3]={5.70909090909091, 6.08362715128042, 6.92857142857143};
+  CPPUNIT_ASSERT_EQUAL(3,trgField->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(1,trgField->getNumberOfComponents());
+  for(int i=0;i<3;i++)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected12[i],trgField->getIJ(i,0),1e-13);
+  srcField->decrRef();
+  trgField->decrRef();
+  //------------- 3D -> 2D
+  CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(targetMesh,sourceMesh,"P0P0"));
+  srcField=MEDCouplingFieldDouble::New(ON_CELLS);
+  srcField->setNature(ConservativeVolumic);
+  srcField->setMesh(targetMesh);
+  array=DataArrayDouble::New();
+  array->alloc(3,1); array->iota(2.);
+  srcField->setArray(array); array->decrRef();
+  trgField=remapper.transferField(srcField,4.57);
+  const double valuesExpected13[7]={3., 4., 2.5, 2.909090909090909, 2., 3.5, 3.3571428571428572};
+  CPPUNIT_ASSERT_EQUAL(7,trgField->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(1,trgField->getNumberOfComponents());
+  for(int i=0;i<7;i++)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected13[i],trgField->getIJ(i,0),1e-13);
+  srcField->decrRef();
+  trgField->decrRef();
+  sourceMesh->decrRef();
+  targetMesh->decrRef();
 }
 
 void MEDCouplingRemapperTest::testNatureOfField()