1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #ifndef __OVERLAPINTERPOLATIONMATRIX_HXX__
22 #define __OVERLAPINTERPOLATIONMATRIX_HXX__
24 #include "MPIAccessDEC.hxx"
25 #include "OverlapMapping.hxx"
26 #include "InterpolationOptions.hxx"
27 #include "DECOptions.hxx"
32 class MEDCouplingPointSet;
35 * Internal class, not part of the public API.
37 * Similar to InterpolationMatrix, but for the OverlapDEC instead of the InterpKernelDEC.
39 class OverlapInterpolationMatrix : public INTERP_KERNEL::InterpolationOptions,
44 OverlapInterpolationMatrix(ParaFIELD *source_field,
45 ParaFIELD *target_field,
46 const ProcessorGroup& group,
47 const DECOptions& dec_opt,
48 const InterpolationOptions& i_opt);
50 void keepTracksOfSourceIds(int procId, DataArrayInt *ids);
52 void keepTracksOfTargetIds(int procId, DataArrayInt *ids);
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);
57 void prepare(const std::vector< std::vector<int> >& procsInInteraction);
63 void transposeMultiply();
65 virtual ~OverlapInterpolationMatrix();
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;
74 int getNbRows() const { return _row_offsets.size(); }
75 MPIAccessDEC* getAccessDEC() { return _mapping.getAccessDEC(); }
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);
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;
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);
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);
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;
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;