Salome HOME
MERGE stage 1: keep doc/dev and src/MEDCalc/doc
[tools/medcoupling.git] / src / ParaMEDMEM / InterpolationMatrix.cxx
index fc6f4161070f8e7dcb0c09a09d34c6b80a67bd9a..8b8c50f610a4ff9398cf3aad59a8c1e887e86db7 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include <algorithm>
 
-// class InterpolationMatrix
-// This class enables the storage of an interpolation matrix Wij mapping 
-// source field Sj to target field Ti via Ti=Vi^(-1).Wij.Sj.
-// The matrix is built and stored on the processors belonging to the source
-// group. 
-
 using namespace std;
 
 namespace ParaMEDMEM
 {
 
-  //   ====================================================================
-  //   Creates an empty matrix structure linking two distributed supports.
-  //   The method must be called by all processors belonging to source
-  //   and target groups.
-  //   param source_support local support
-  //   param source_group processor group containing the local processors
-  //   param target_group processor group containing the distant processors
-  //   param method interpolation method
-  //   ====================================================================
-
+  /**!
+     Creates an empty matrix structure linking two distributed supports.
+     The method must be called by all processors belonging to source
+     and target groups.
+     \param source_support local support
+     \param source_group processor group containing the local processors
+     \param target_group processor group containing the distant processors
+     \param method interpolation method
+  */
   InterpolationMatrix::InterpolationMatrix(const ParaMEDMEM::ParaFIELD *source_field, 
                                            const ProcessorGroup& source_group,
                                            const ProcessorGroup& target_group,
@@ -84,22 +77,21 @@ namespace ParaMEDMEM
   }
 
 
-  //   ======================================================================
-  //   \brief Adds the contribution of a distant subdomain to the*
-  //   interpolation matrix.
-  //   The method adds contribution to the interpolation matrix.
-  //   For each row of the matrix, elements are addded as
-  //   a (column, coeff) pair in the _coeffs array. This column number refers
-  //   to an element on the target side via the _col_offsets array.
-  //   It is made of a series of (iproc, ielem) pairs. 
-  //   The number of elements per row is stored in the row_offsets array.
-
-  //   param distant_support local representation of the distant subdomain
-  //   param iproc_distant id of the distant subdomain (in the distant group)
-  //   param distant_elems mapping between the local representation of
-  //   the subdomain and the actual elem ids on the distant subdomain
-  //   ======================================================================
-
+  /*!
+     \brief Adds the contribution of a distant subdomain to the*
+     interpolation matrix.
+     The method adds contribution to the interpolation matrix.
+     For each row of the matrix, elements are addded as
+     a (column, coeff) pair in the _coeffs array. This column number refers
+     to an element on the target side via the _col_offsets array.
+     It is made of a series of (iproc, ielem) pairs.
+     The number of elements per row is stored in the row_offsets array.
+
+     param distant_support local representation of the distant subdomain
+     param iproc_distant id of the distant subdomain (in the distant group)
+     param distant_elems mapping between the local representation of
+     the subdomain and the actual elem ids on the distant subdomain
+   */
   void InterpolationMatrix::addContribution ( MEDCouplingPointSet& distant_support,
                                               int iproc_distant,
                                               const int* distant_elems,
@@ -110,7 +102,6 @@ namespace ParaMEDMEM
     interpMethod+=srcMeth;
     //creating the interpolator structure
     vector<map<int,double> > surfaces;
-    int colSize=0;
     //computation of the intersection volumes between source and target elements
     MEDCouplingUMesh *distant_supportC=dynamic_cast<MEDCouplingUMesh *>(&distant_support);
     MEDCouplingUMesh *source_supportC=dynamic_cast<MEDCouplingUMesh *>(_source_support);
@@ -120,19 +111,19 @@ namespace ParaMEDMEM
           {
             MEDCouplingNormalizedUnstructuredMesh<2,2> source_mesh_wrapper(source_supportC);
             INTERP_KERNEL::Interpolation2D interpolation(*this);
-            colSize=interpolation.fromIntegralUniform(source_mesh_wrapper,surfaces,srcMeth.c_str());
+            interpolation.fromIntegralUniform(source_mesh_wrapper,surfaces,srcMeth);
           }
         else if(source_supportC->getMeshDimension()==3 && source_supportC->getSpaceDimension()==3)
           {
             MEDCouplingNormalizedUnstructuredMesh<3,3> source_mesh_wrapper(source_supportC);
             INTERP_KERNEL::Interpolation3D interpolation(*this);
-            colSize=interpolation.fromIntegralUniform(source_mesh_wrapper,surfaces,srcMeth.c_str());
+            interpolation.fromIntegralUniform(source_mesh_wrapper,surfaces,srcMeth);
           }
         else if(source_supportC->getMeshDimension()==2 && source_supportC->getSpaceDimension()==3)
           {
             MEDCouplingNormalizedUnstructuredMesh<3,2> source_mesh_wrapper(source_supportC);
             INTERP_KERNEL::Interpolation3DSurf interpolation(*this);
-            colSize=interpolation.fromIntegralUniform(source_mesh_wrapper,surfaces,srcMeth.c_str());
+            interpolation.fromIntegralUniform(source_mesh_wrapper,surfaces,srcMeth);
           }
         else
           throw INTERP_KERNEL::Exception("No para interpolation available for the given mesh and space dimension of source mesh to -1D targetMesh");
@@ -143,19 +134,19 @@ namespace ParaMEDMEM
           {
             MEDCouplingNormalizedUnstructuredMesh<2,2> distant_mesh_wrapper(distant_supportC);
             INTERP_KERNEL::Interpolation2D interpolation(*this);
-            colSize=interpolation.toIntegralUniform(distant_mesh_wrapper,surfaces,srcMeth.c_str());
+            interpolation.toIntegralUniform(distant_mesh_wrapper,surfaces,srcMeth);
           }
         else if(distant_supportC->getMeshDimension()==3 && distant_supportC->getSpaceDimension()==3)
           {
             MEDCouplingNormalizedUnstructuredMesh<3,3> distant_mesh_wrapper(distant_supportC);
             INTERP_KERNEL::Interpolation3D interpolation(*this);
-            colSize=interpolation.toIntegralUniform(distant_mesh_wrapper,surfaces,srcMeth.c_str());
+            interpolation.toIntegralUniform(distant_mesh_wrapper,surfaces,srcMeth);
           }
         else if(distant_supportC->getMeshDimension()==2 && distant_supportC->getSpaceDimension()==3)
           {
             MEDCouplingNormalizedUnstructuredMesh<3,2> distant_mesh_wrapper(distant_supportC);
             INTERP_KERNEL::Interpolation3DSurf interpolation(*this);
-            colSize=interpolation.toIntegralUniform(distant_mesh_wrapper,surfaces,srcMeth.c_str());
+            interpolation.toIntegralUniform(distant_mesh_wrapper,surfaces,srcMeth);
           }
         else
           throw INTERP_KERNEL::Exception("No para interpolation available for the given mesh and space dimension of distant mesh to -1D sourceMesh");
@@ -167,7 +158,7 @@ namespace ParaMEDMEM
         MEDCouplingNormalizedUnstructuredMesh<3,3> target_wrapper(distant_supportC);
         MEDCouplingNormalizedUnstructuredMesh<3,3> source_wrapper(source_supportC);
         INTERP_KERNEL::Interpolation3D2D interpolator (*this);
-        colSize=interpolator.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod.c_str());
+        interpolator.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod);
         target_wrapper.releaseTempArrays();
         source_wrapper.releaseTempArrays();
       }
@@ -178,7 +169,18 @@ namespace ParaMEDMEM
         MEDCouplingNormalizedUnstructuredMesh<2,2> target_wrapper(distant_supportC);
         MEDCouplingNormalizedUnstructuredMesh<2,2> source_wrapper(source_supportC);
         INTERP_KERNEL::Interpolation2D1D interpolator (*this);
-        colSize=interpolator.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod.c_str());
+        interpolator.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod);
+        target_wrapper.releaseTempArrays();
+        source_wrapper.releaseTempArrays();
+      }
+    else if ( distant_support.getMeshDimension() == 3
+              && _source_support->getMeshDimension() == 1
+              && distant_support.getSpaceDimension() == 3 && _source_support->getSpaceDimension() == 3)
+      {
+        MEDCouplingNormalizedUnstructuredMesh<3,3> target_wrapper(distant_supportC);
+        MEDCouplingNormalizedUnstructuredMesh<3,3> source_wrapper(source_supportC);
+        INTERP_KERNEL::Interpolation3D interpolator (*this);
+        interpolator.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod);
         target_wrapper.releaseTempArrays();
         source_wrapper.releaseTempArrays();
       }
@@ -193,7 +195,7 @@ namespace ParaMEDMEM
         MEDCouplingNormalizedUnstructuredMesh<1,1> source_wrapper(source_supportC);
 
         INTERP_KERNEL::Interpolation1D interpolation(*this);
-        colSize=interpolation.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod.c_str());
+        interpolation.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod);
         target_wrapper.releaseTempArrays();
         source_wrapper.releaseTempArrays();
       }
@@ -204,7 +206,7 @@ namespace ParaMEDMEM
         MEDCouplingNormalizedUnstructuredMesh<2,1> source_wrapper(source_supportC);
 
         INTERP_KERNEL::Interpolation2DCurve interpolation(*this);
-        colSize=interpolation.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod.c_str());
+        interpolation.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod);
         target_wrapper.releaseTempArrays();
         source_wrapper.releaseTempArrays();
       }
@@ -215,7 +217,7 @@ namespace ParaMEDMEM
         MEDCouplingNormalizedUnstructuredMesh<3,2> source_wrapper(source_supportC);
 
         INTERP_KERNEL::Interpolation3DSurf interpolator (*this);
-        colSize=interpolator.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod.c_str());
+        interpolator.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod);
         target_wrapper.releaseTempArrays();
         source_wrapper.releaseTempArrays();
       }
@@ -226,7 +228,7 @@ namespace ParaMEDMEM
         MEDCouplingNormalizedUnstructuredMesh<2,2> source_wrapper(source_supportC);
 
         INTERP_KERNEL::Interpolation2D interpolator (*this);
-        colSize=interpolator.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod.c_str());
+        interpolator.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod);
         target_wrapper.releaseTempArrays();
         source_wrapper.releaseTempArrays();
       }
@@ -237,7 +239,7 @@ namespace ParaMEDMEM
         MEDCouplingNormalizedUnstructuredMesh<3,3> source_wrapper(source_supportC);
 
         INTERP_KERNEL::Interpolation3D interpolator (*this);
-        colSize=interpolator.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod.c_str());
+        interpolator.interpolateMeshes(target_wrapper,source_wrapper,surfaces,interpMethod);
         target_wrapper.releaseTempArrays();
         source_wrapper.releaseTempArrays();
       }
@@ -830,14 +832,13 @@ namespace ParaMEDMEM
       }
   }
 
-  // ==================================================================
-  // The call to this method updates the arrays on the target side
-  //   so that they know which amount of data from which processor they 
-  //   should expect. 
-  //   That call makes actual interpolations via multiply method 
-  //   available.
-  // ==================================================================
 
+ /**!  The call to this method updates the arrays on the target side
+     so that they know which amount of data from which processor they
+     should expect.
+     That call makes actual interpolations via multiply method
+     available.
+     */
   void InterpolationMatrix::prepare()
   {
     int nbelems = _source_field->getField()->getNumberOfTuples();
@@ -849,18 +850,18 @@ namespace ParaMEDMEM
   }
 
 
-  //   =======================================================================
-  //   brief performs t=Ws, where t is the target field, s is the source field
 
-  //   The call to this method must be called both on the working side 
-  //   and on the idle side. On the working side, the vector  T=VT^(-1).(W.S)
-  //   is computed and sent. On the idle side, no computation is done, but the 
-  //   result from the working side is received and the field is updated.
+  /*!
+     \brief performs t=Ws, where t is the target field, s is the source field
 
-  //   param field source field on processors involved on the source side,
-  //   target field on processors on the target side
-  //   =======================================================================
+     The call to this method must be called both on the working side
+     and on the idle side. On the working side, the vector  T=VT^(-1).(W.S)
+     is computed and sent. On the idle side, no computation is done, but the
+     result from the working side is received and the field is updated.
 
+     \param field source field on processors involved on the source side,
+     target field on processors on the target side
+   */
   void InterpolationMatrix::multiply(MEDCouplingFieldDouble& field) const
   {
     int nbcomp = field.getArray()->getNumberOfComponents();
@@ -907,20 +908,19 @@ namespace ParaMEDMEM
   }
   
 
-  // =========================================================================
-  // brief performs s=WTt, where t is the target field, s is the source field,
-  // WT is the transpose matrix from W
-
-  //   The call to this method must be called both on the working side 
-  //   and on the idle side. On the working side, the target vector T is
-  //   received and the vector  S=VS^(-1).(WT.T) is computed to update
-  //   the field. 
-  //   On the idle side, no computation is done, but the field is sent.
+  /**!
+   \brief performs s=WTt, where t is the target field, s is the source field,
+   WT is the transpose matrix from W
 
-  //   param field source field on processors involved on the source side,
-  //   target field on processors on the target side
-  // =========================================================================
+     The call to this method must be called both on the working side
+     and on the idle side. On the working side, the target vector T is
+     received and the vector  S=VS^(-1).(WT.T) is computed to update
+     the field.
+     On the idle side, no computation is done, but the field is sent.
 
+     param field source field on processors involved on the source side,
+     target field on processors on the target side
+     */
   void InterpolationMatrix::transposeMultiply(MEDCouplingFieldDouble& field) const
   {
     int nbcomp = field.getArray()->getNumberOfComponents();