Salome HOME
3543875d42b10f0a63dec3a7e65ad7f33e8a9261
[tools/medcoupling.git] / src / ParaMEDMEM / InterpolationMatrix.hxx
1 // Copyright (C) 2007-2019  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 MEDCoupling
29 {
30   class ElementLocator;
31
32   /*!
33    Internal class, not part of the public API.
34
35    This class enables the storage of an interpolation matrix Wij mapping
36    a source field Sj to a target field Ti via Ti=Vi^(-1).Wij.Sj.
37    The matrix is built and stored on the processors belonging to the source
38    group.
39    */
40   class InterpolationMatrix : public INTERP_KERNEL::InterpolationOptions,
41                               public DECOptions
42   {
43   public:
44     
45     InterpolationMatrix(const MEDCoupling::ParaFIELD *source_field, 
46                         const ProcessorGroup& source_group,
47                         const ProcessorGroup& target_group,
48                         const DECOptions& dec_opt,
49                         const InterpolationOptions& i_opt);
50
51     
52     virtual ~InterpolationMatrix();
53     void addContribution(MEDCouplingPointSet& distant_support, int iproc_distant,
54                          const mcIdType* distant_elems, const std::string& srcMeth, const std::string& targetMeth);
55     void finishContributionW(ElementLocator& elementLocator);
56     void finishContributionL(ElementLocator& elementLocator);
57     void multiply(MEDCouplingFieldDouble& field) const;
58     void transposeMultiply(MEDCouplingFieldDouble& field)const;
59     void prepare();
60     mcIdType getNbRows() const { return ToIdType(_row_offsets.size()); }
61     MPIAccessDEC* getAccessDEC() { return _mapping.getAccessDEC(); }
62   private:
63     void computeConservVolDenoW(ElementLocator& elementLocator);
64     void computeIntegralDenoW(ElementLocator& elementLocator);
65     void computeRevIntegralDenoW(ElementLocator& elementLocator);
66     void computeGlobConstraintDenoW(ElementLocator& elementLocator);
67     void computeConservVolDenoL(ElementLocator& elementLocator);
68     void computeIntegralDenoL(ElementLocator& elementLocator);
69     void computeRevIntegralDenoL(ElementLocator& elementLocator);
70     
71     void computeLocalColSum(std::vector<double>& res) const;
72     void computeLocalRowSum(const std::vector<int>& distantProcs, std::vector<std::vector<mcIdType> >& resPerProcI,
73                             std::vector<std::vector<double> >& resPerProcD) const;
74     void computeGlobalRowSum(ElementLocator& elementLocator, std::vector<std::vector<double> >& denoStrorage, std::vector<std::vector<double> >& denoStrorageInv);
75     void computeGlobalColSum(std::vector<std::vector<double> >& denoStrorage);
76     void resizeGlobalColSum(std::vector<std::vector<double> >& denoStrorage);
77     void fillDSFromVM(int iproc_distant, const mcIdType* distant_elems, const std::vector< std::map<mcIdType,double> >& values, MEDCouplingFieldDouble *surf);
78     void serializeMe(std::vector< std::vector< std::map<mcIdType,double> > >& data1, std::vector<int>& data2) const;
79     void initialize();
80     void findAdditionnalElements(ElementLocator& elementLocator, std::vector<std::vector<mcIdType> >& elementsToAdd,
81                                  const std::vector<std::vector<mcIdType> >& resPerProcI, const std::vector<std::vector<mcIdType> >& globalIdsPartial);
82     void addGhostElements(const std::vector<int>& distantProcs, const std::vector<std::vector<mcIdType> >& elementsToAdd);
83     int mergePolicies(const std::vector<int>& policyPartial);
84     void mergeRowSum(const std::vector< std::vector<double> >& rowsPartialSumD, const std::vector< std::vector<mcIdType> >& globalIdsPartial,
85                      std::vector<mcIdType>& globalIdsLazySideInteraction, std::vector<double>& sumCorresponding);
86     void mergeRowSum2(const std::vector< std::vector<mcIdType> >& globalIdsPartial, std::vector< std::vector<double> >& rowsPartialSumD,
87                       const std::vector<mcIdType>& globalIdsLazySideInteraction, const std::vector<double>& sumCorresponding);
88     void mergeRowSum3(const std::vector< std::vector<mcIdType> >& globalIdsPartial, std::vector< std::vector<double> >& rowsPartialSumD);
89     void mergeCoeffs(const std::vector<int>& procsInInteraction, const std::vector< std::vector<mcIdType> >& rowsPartialSumI,
90                      const std::vector<std::vector<mcIdType> >& globalIdsPartial, std::vector<std::vector<double> >& denoStrorageInv);
91     void divideByGlobalRowSum(const std::vector<int>& distantProcs, const std::vector<std::vector<mcIdType> >& resPerProcI,
92                               const std::vector<std::vector<double> >& resPerProcD, std::vector<std::vector<double> >& deno);
93   private:
94     bool isSurfaceComputationNeeded(const std::string& method) const;
95   private:
96     const MEDCoupling::ParaFIELD *_source_field;
97     std::vector<mcIdType> _row_offsets;
98     std::map<std::pair<int,mcIdType>, mcIdType > _col_offsets;
99     MEDCouplingPointSet *_source_support;
100     MxN_Mapping _mapping;
101  
102     const ProcessorGroup& _source_group;
103     const ProcessorGroup& _target_group;
104     std::vector< std::vector<double> > _target_volume;
105     std::vector<std::vector<std::pair<int,double> > > _coeffs;
106     std::vector<std::vector<double> > _deno_multiply;
107     std::vector<std::vector<double> > _deno_reverse_multiply;
108   };
109 }
110
111 #endif