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