Salome HOME
Move medtool folder to MED base repository
[modules/med.git] / medtool / src / ParaMEDMEM / InterpolationMatrix.hxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __INTERPOLATIONMATRIX_HXX__
21 #define __INTERPOLATIONMATRIX_HXX__
22
23 #include "MPIAccessDEC.hxx"
24 #include "MxN_Mapping.hxx"
25 #include "InterpolationOptions.hxx"
26 #include "DECOptions.hxx"
27
28 namespace ParaMEDMEM
29 {
30   class ElementLocator;
31
32   /**! class InterpolationMatrix
33    This class enables the storage of an interpolation matrix Wij mapping
34    source field Sj to target field Ti via Ti=Vi^(-1).Wij.Sj.
35    The matrix is built and stored on the processors belonging to the source
36    group.
37    */
38   class InterpolationMatrix : public INTERP_KERNEL::InterpolationOptions,
39                               public DECOptions
40   {
41   public:
42     
43     InterpolationMatrix(const ParaMEDMEM::ParaFIELD *source_field, 
44                         const ProcessorGroup& source_group,
45                         const ProcessorGroup& target_group,
46                         const DECOptions& dec_opt,
47                         const InterpolationOptions& i_opt);
48
49     
50     virtual ~InterpolationMatrix();
51     void addContribution(MEDCouplingPointSet& distant_support, int iproc_distant,
52                          const int* distant_elems, const std::string& srcMeth, const std::string& targetMeth);
53     void finishContributionW(ElementLocator& elementLocator);
54     void finishContributionL(ElementLocator& elementLocator);
55     void multiply(MEDCouplingFieldDouble& field) const;
56     void transposeMultiply(MEDCouplingFieldDouble& field)const;
57     void prepare();
58     int getNbRows() const { return _row_offsets.size(); }
59     MPIAccessDEC* getAccessDEC() { return _mapping.getAccessDEC(); }
60   private:
61     void computeConservVolDenoW(ElementLocator& elementLocator);
62     void computeIntegralDenoW(ElementLocator& elementLocator);
63     void computeRevIntegralDenoW(ElementLocator& elementLocator);
64     void computeGlobConstraintDenoW(ElementLocator& elementLocator);
65     void computeConservVolDenoL(ElementLocator& elementLocator);
66     void computeIntegralDenoL(ElementLocator& elementLocator);
67     void computeRevIntegralDenoL(ElementLocator& elementLocator);
68     
69     void computeLocalColSum(std::vector<double>& res) const;
70     void computeLocalRowSum(const std::vector<int>& distantProcs, std::vector<std::vector<int> >& resPerProcI,
71                             std::vector<std::vector<double> >& resPerProcD) const;
72     void computeGlobalRowSum(ElementLocator& elementLocator, std::vector<std::vector<double> >& denoStrorage, std::vector<std::vector<double> >& denoStrorageInv);
73     void computeGlobalColSum(std::vector<std::vector<double> >& denoStrorage);
74     void resizeGlobalColSum(std::vector<std::vector<double> >& denoStrorage);
75     void fillDSFromVM(int iproc_distant, const int* distant_elems, const std::vector< std::map<int,double> >& values, MEDCouplingFieldDouble *surf);
76     void serializeMe(std::vector< std::vector< std::map<int,double> > >& data1, std::vector<int>& data2) const;
77     void initialize();
78     void findAdditionnalElements(ElementLocator& elementLocator, std::vector<std::vector<int> >& elementsToAdd,
79                                  const std::vector<std::vector<int> >& resPerProcI, const std::vector<std::vector<int> >& globalIdsPartial);
80     void addGhostElements(const std::vector<int>& distantProcs, const std::vector<std::vector<int> >& elementsToAdd);
81     int mergePolicies(const std::vector<int>& policyPartial);
82     void mergeRowSum(const std::vector< std::vector<double> >& rowsPartialSumD, const std::vector< std::vector<int> >& globalIdsPartial,
83                      std::vector<int>& globalIdsLazySideInteraction, std::vector<double>& sumCorresponding);
84     void mergeRowSum2(const std::vector< std::vector<int> >& globalIdsPartial, std::vector< std::vector<double> >& rowsPartialSumD,
85                       const std::vector<int>& globalIdsLazySideInteraction, const std::vector<double>& sumCorresponding);
86     void mergeRowSum3(const std::vector< std::vector<int> >& globalIdsPartial, std::vector< std::vector<double> >& rowsPartialSumD);
87     void mergeCoeffs(const std::vector<int>& procsInInteraction, const std::vector< std::vector<int> >& rowsPartialSumI,
88                      const std::vector<std::vector<int> >& globalIdsPartial, std::vector<std::vector<double> >& denoStrorageInv);
89     void divideByGlobalRowSum(const std::vector<int>& distantProcs, const std::vector<std::vector<int> >& resPerProcI,
90                               const std::vector<std::vector<double> >& resPerProcD, std::vector<std::vector<double> >& deno);
91   private:
92     bool isSurfaceComputationNeeded(const std::string& method) const;
93   private:
94     const ParaMEDMEM::ParaFIELD *_source_field;
95     std::vector<int> _row_offsets;
96     std::map<std::pair<int,int>, int > _col_offsets;
97     MEDCouplingPointSet *_source_support;
98     MxN_Mapping _mapping;
99  
100     const ProcessorGroup& _source_group;
101     const ProcessorGroup& _target_group;
102     std::vector< std::vector<double> > _target_volume;
103     std::vector<std::vector<std::pair<int,double> > > _coeffs;
104     std::vector<std::vector<double> > _deno_multiply;
105     std::vector<std::vector<double> > _deno_reverse_multiply;
106   };
107 }
108
109 #endif