Salome HOME
MEDCoupling1SGTUMesh::sortHexa8EachOther
[tools/medcoupling.git] / src / ParaMEDMEM / InterpolationMatrix.hxx
1 // Copyright (C) 2007-2013  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.
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 : public INTERP_KERNEL::InterpolationOptions,
33                               public DECOptions
34   {
35   public:
36     
37     InterpolationMatrix(const ParaMEDMEM::ParaFIELD *source_field, 
38                         const ProcessorGroup& source_group,
39                         const ProcessorGroup& target_group,
40                         const DECOptions& dec_opt,
41                         const InterpolationOptions& i_opt);
42
43     
44     virtual ~InterpolationMatrix();
45     void addContribution(MEDCouplingPointSet& distant_support, int iproc_distant,
46                          const int* distant_elems, const std::string& srcMeth, const std::string& targetMeth);
47     void finishContributionW(ElementLocator& elementLocator);
48     void finishContributionL(ElementLocator& elementLocator);
49     void multiply(MEDCouplingFieldDouble& field) const;
50     void transposeMultiply(MEDCouplingFieldDouble& field)const;
51     void prepare();
52     int getNbRows() const { return _row_offsets.size(); }
53     MPIAccessDEC* getAccessDEC() { return _mapping.getAccessDEC(); }
54   private:
55     void computeConservVolDenoW(ElementLocator& elementLocator);
56     void computeIntegralDenoW(ElementLocator& elementLocator);
57     void computeRevIntegralDenoW(ElementLocator& elementLocator);
58     void computeGlobConstraintDenoW(ElementLocator& elementLocator);
59     void computeConservVolDenoL(ElementLocator& elementLocator);
60     void computeIntegralDenoL(ElementLocator& elementLocator);
61     void computeRevIntegralDenoL(ElementLocator& elementLocator);
62     
63     void computeLocalColSum(std::vector<double>& res) const;
64     void computeLocalRowSum(const std::vector<int>& distantProcs, std::vector<std::vector<int> >& resPerProcI,
65                             std::vector<std::vector<double> >& resPerProcD) const;
66     void computeGlobalRowSum(ElementLocator& elementLocator, std::vector<std::vector<double> >& denoStrorage, std::vector<std::vector<double> >& denoStrorageInv);
67     void computeGlobalColSum(std::vector<std::vector<double> >& denoStrorage);
68     void resizeGlobalColSum(std::vector<std::vector<double> >& denoStrorage);
69     void fillDSFromVM(int iproc_distant, const int* distant_elems, const std::vector< std::map<int,double> >& values, MEDCouplingFieldDouble *surf);
70     void serializeMe(std::vector< std::vector< std::map<int,double> > >& data1, std::vector<int>& data2) const;
71     void initialize();
72     void findAdditionnalElements(ElementLocator& elementLocator, std::vector<std::vector<int> >& elementsToAdd,
73                                  const std::vector<std::vector<int> >& resPerProcI, const std::vector<std::vector<int> >& globalIdsPartial);
74     void addGhostElements(const std::vector<int>& distantProcs, const std::vector<std::vector<int> >& elementsToAdd);
75     int mergePolicies(const std::vector<int>& policyPartial);
76     void mergeRowSum(const std::vector< std::vector<double> >& rowsPartialSumD, const std::vector< std::vector<int> >& globalIdsPartial,
77                      std::vector<int>& globalIdsLazySideInteraction, std::vector<double>& sumCorresponding);
78     void mergeRowSum2(const std::vector< std::vector<int> >& globalIdsPartial, std::vector< std::vector<double> >& rowsPartialSumD,
79                       const std::vector<int>& globalIdsLazySideInteraction, const std::vector<double>& sumCorresponding);
80     void mergeRowSum3(const std::vector< std::vector<int> >& globalIdsPartial, std::vector< std::vector<double> >& rowsPartialSumD);
81     void mergeCoeffs(const std::vector<int>& procsInInteraction, const std::vector< std::vector<int> >& rowsPartialSumI,
82                      const std::vector<std::vector<int> >& globalIdsPartial, std::vector<std::vector<double> >& denoStrorageInv);
83     void divideByGlobalRowSum(const std::vector<int>& distantProcs, const std::vector<std::vector<int> >& resPerProcI,
84                               const std::vector<std::vector<double> >& resPerProcD, std::vector<std::vector<double> >& deno);
85   private:
86     bool isSurfaceComputationNeeded(const std::string& method) const;
87   private:
88     const ParaMEDMEM::ParaFIELD *_source_field;
89     std::vector<int> _row_offsets;
90     std::map<std::pair<int,int>, int > _col_offsets;
91     MEDCouplingPointSet *_source_support;
92     MxN_Mapping _mapping;
93  
94     const ProcessorGroup& _source_group;
95     const ProcessorGroup& _target_group;
96     std::vector< std::vector<double> > _target_volume;
97     std::vector<std::vector<std::pair<int,double> > > _coeffs;
98     std::vector<std::vector<double> > _deno_multiply;
99     std::vector<std::vector<double> > _deno_reverse_multiply;
100   };
101 }
102
103 #endif