]> SALOME platform Git repositories - modules/med.git/blob - src/ParaMEDMEM/OverlapInterpolationMatrix.hxx
Salome HOME
Merge branch 'master' of ssh://git.salome-platform.org/modules/med
[modules/med.git] / src / ParaMEDMEM / OverlapInterpolationMatrix.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 // Author : Anthony Geay (CEA/DEN)
20
21 #ifndef __OVERLAPINTERPOLATIONMATRIX_HXX__
22 #define __OVERLAPINTERPOLATIONMATRIX_HXX__
23
24 #include "MPIAccessDEC.hxx"
25 #include "OverlapMapping.hxx"
26 #include "InterpolationOptions.hxx"
27 #include "DECOptions.hxx"
28
29 namespace ParaMEDMEM
30 {
31   class ParaFIELD;
32   class MEDCouplingPointSet;
33
34   /*!
35    * Internal class, not part of the public API.
36    *
37    * Similar to InterpolationMatrix, but for the OverlapDEC instead of the InterpKernelDEC.
38    */
39   class OverlapInterpolationMatrix : public INTERP_KERNEL::InterpolationOptions,
40                                      public DECOptions
41   {
42   public:
43     
44     OverlapInterpolationMatrix(ParaFIELD *source_field,
45                                ParaFIELD *target_field,
46                                const ProcessorGroup& group,
47                                const DECOptions& dec_opt,
48                                const InterpolationOptions& i_opt);
49
50     void keepTracksOfSourceIds(int procId, DataArrayInt *ids);
51
52     void keepTracksOfTargetIds(int procId, DataArrayInt *ids);
53
54     void addContribution(const MEDCouplingPointSet *src, const DataArrayInt *srcIds, const std::string& srcMeth, int srcProcId,
55                          const MEDCouplingPointSet *trg, const DataArrayInt *trgIds, const std::string& trgMeth, int trgProcId);
56
57     void prepare(const std::vector< std::vector<int> >& procsInInteraction);
58     
59     void computeDeno();
60
61     void multiply();
62
63     void transposeMultiply();
64     
65     virtual ~OverlapInterpolationMatrix();
66 #if 0
67     void addContribution(MEDCouplingPointSet& distant_support, int iproc_distant,
68                          const int* distant_elems, const std::string& srcMeth, const std::string& targetMeth);
69     void finishContributionW(ElementLocator& elementLocator);
70     void finishContributionL(ElementLocator& elementLocator);
71     void multiply(MEDCouplingFieldDouble& field) const;
72     void transposeMultiply(MEDCouplingFieldDouble& field)const;
73     void prepare();
74     int getNbRows() const { return _row_offsets.size(); }
75     MPIAccessDEC* getAccessDEC() { return _mapping.getAccessDEC(); }
76   private:
77     void computeConservVolDenoW(ElementLocator& elementLocator);
78     void computeIntegralDenoW(ElementLocator& elementLocator);
79     void computeRevIntegralDenoW(ElementLocator& elementLocator);
80     void computeGlobConstraintDenoW(ElementLocator& elementLocator);
81     void computeConservVolDenoL(ElementLocator& elementLocator);
82     void computeIntegralDenoL(ElementLocator& elementLocator);
83     void computeRevIntegralDenoL(ElementLocator& elementLocator);
84     
85     void computeLocalColSum(std::vector<double>& res) const;
86     void computeLocalRowSum(const std::vector<int>& distantProcs, std::vector<std::vector<int> >& resPerProcI,
87                             std::vector<std::vector<double> >& resPerProcD) const;
88     void computeGlobalRowSum(ElementLocator& elementLocator, std::vector<std::vector<double> >& denoStrorage, std::vector<std::vector<double> >& denoStrorageInv);
89     void computeGlobalColSum(std::vector<std::vector<double> >& denoStrorage);
90     void resizeGlobalColSum(std::vector<std::vector<double> >& denoStrorage);
91     void fillDSFromVM(int iproc_distant, const int* distant_elems, const std::vector< std::map<int,double> >& values, MEDCouplingFieldDouble *surf);
92     void serializeMe(std::vector< std::vector< std::map<int,double> > >& data1, std::vector<int>& data2) const;
93     void initialize();
94     void findAdditionnalElements(ElementLocator& elementLocator, std::vector<std::vector<int> >& elementsToAdd,
95                                  const std::vector<std::vector<int> >& resPerProcI, const std::vector<std::vector<int> >& globalIdsPartial);
96     void addGhostElements(const std::vector<int>& distantProcs, const std::vector<std::vector<int> >& elementsToAdd);
97     int mergePolicies(const std::vector<int>& policyPartial);
98     void mergeRowSum(const std::vector< std::vector<double> >& rowsPartialSumD, const std::vector< std::vector<int> >& globalIdsPartial,
99                      std::vector<int>& globalIdsLazySideInteraction, std::vector<double>& sumCorresponding);
100     void mergeRowSum2(const std::vector< std::vector<int> >& globalIdsPartial, std::vector< std::vector<double> >& rowsPartialSumD,
101                       const std::vector<int>& globalIdsLazySideInteraction, const std::vector<double>& sumCorresponding);
102     void mergeRowSum3(const std::vector< std::vector<int> >& globalIdsPartial, std::vector< std::vector<double> >& rowsPartialSumD);
103     void mergeCoeffs(const std::vector<int>& procsInInteraction, const std::vector< std::vector<int> >& rowsPartialSumI,
104                      const std::vector<std::vector<int> >& globalIdsPartial, std::vector<std::vector<double> >& denoStrorageInv);
105     void divideByGlobalRowSum(const std::vector<int>& distantProcs, const std::vector<std::vector<int> >& resPerProcI,
106                               const std::vector<std::vector<double> >& resPerProcD, std::vector<std::vector<double> >& deno);
107 #endif
108   private:
109     bool isSurfaceComputationNeeded(const std::string& method) const;
110     void fillDistributedMatrix(const std::vector< std::map<int,double> >& res,
111                                const DataArrayInt *srcIds, int srcProc,
112                                const DataArrayInt *trgIds, int trgProc);
113     static void TransposeMatrix(const std::vector<std::map<int,double> >& matIn, int nbColsMatIn, std::vector<std::map<int,double> >& matOut);
114   private:
115     ParaMEDMEM::ParaFIELD *_source_field;
116     ParaMEDMEM::ParaFIELD *_target_field;
117     std::vector<int> _row_offsets;
118     std::map<std::pair<int,int>, int > _col_offsets;
119     MEDCouplingPointSet *_source_support;
120     MEDCouplingPointSet *_target_support;
121     OverlapMapping _mapping;
122  
123     const ProcessorGroup& _group;
124     std::vector< std::vector<double> > _target_volume;
125     std::vector<std::vector<std::pair<int,double> > > _coeffs;
126     std::vector<std::vector<double> > _deno_multiply;
127     std::vector<std::vector<double> > _deno_reverse_multiply;
128   };
129 }
130
131 #endif