1 // Copyright (C) 2007-2024 CEA, EDF
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
20 #ifndef __INTERPOLATIONMATRIX_HXX__
21 #define __INTERPOLATIONMATRIX_HXX__
23 #include "MPIAccessDEC.hxx"
24 #include "MxN_Mapping.hxx"
25 #include "InterpolationOptions.hxx"
26 #include "DECOptions.hxx"
33 Internal class, not part of the public API.
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
40 class InterpolationMatrix : public INTERP_KERNEL::InterpolationOptions,
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);
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 MCAuto<DataArrayIdType> retrieveNonFetchedIdsTarget(mcIdType nbTuples) const;
58 void multiply(MEDCouplingFieldDouble& field) const;
59 MCAuto<DataArrayIdType> retrieveNonFetchedIdsSource() const;
60 void transposeMultiply(MEDCouplingFieldDouble& field)const;
62 mcIdType getNbRows() const { return ToIdType(_row_offsets.size()); }
63 MPIAccessDEC* getAccessDEC() { return _mapping.getAccessDEC(); }
64 void setDefaultValue(double val) { _presence_dft_value = true; _dft_value = val; }
66 void computeConservVolDenoW(ElementLocator& elementLocator);
67 void computeIntegralDenoW(ElementLocator& elementLocator);
68 void computeRevIntegralDenoW(ElementLocator& elementLocator);
69 void computeGlobConstraintDenoW(ElementLocator& elementLocator);
70 void computeConservVolDenoL(ElementLocator& elementLocator);
71 void computeIntegralDenoL(ElementLocator& elementLocator);
72 void computeRevIntegralDenoL(ElementLocator& elementLocator);
74 void computeLocalColSum(std::vector<double>& res) const;
75 void computeLocalRowSum(const std::vector<int>& distantProcs, std::vector<std::vector<mcIdType> >& resPerProcI,
76 std::vector<std::vector<double> >& resPerProcD) const;
77 void computeGlobalRowSum(ElementLocator& elementLocator, std::vector<std::vector<double> >& denoStrorage, std::vector<std::vector<double> >& denoStrorageInv);
78 void computeGlobalColSum(std::vector<std::vector<double> >& denoStrorage);
79 void resizeGlobalColSum(std::vector<std::vector<double> >& denoStrorage);
80 void fillDSFromVM(int iproc_distant, const mcIdType* distant_elems, const std::vector< std::map<mcIdType,double> >& values, MEDCouplingFieldDouble *surf);
81 void serializeMe(std::vector< std::vector< std::map<mcIdType,double> > >& data1, std::vector<int>& data2) const;
83 void findAdditionnalElements(ElementLocator& elementLocator, std::vector<std::vector<mcIdType> >& elementsToAdd,
84 const std::vector<std::vector<mcIdType> >& resPerProcI, const std::vector<std::vector<mcIdType> >& globalIdsPartial);
85 void addGhostElements(const std::vector<int>& distantProcs, const std::vector<std::vector<mcIdType> >& elementsToAdd);
86 int mergePolicies(const std::vector<int>& policyPartial);
87 void mergeRowSum(const std::vector< std::vector<double> >& rowsPartialSumD, const std::vector< std::vector<mcIdType> >& globalIdsPartial,
88 std::vector<mcIdType>& globalIdsLazySideInteraction, std::vector<double>& sumCorresponding);
89 void mergeRowSum2(const std::vector< std::vector<mcIdType> >& globalIdsPartial, std::vector< std::vector<double> >& rowsPartialSumD,
90 const std::vector<mcIdType>& globalIdsLazySideInteraction, const std::vector<double>& sumCorresponding);
91 void mergeRowSum3(const std::vector< std::vector<mcIdType> >& globalIdsPartial, std::vector< std::vector<double> >& rowsPartialSumD);
92 void mergeCoeffs(const std::vector<int>& procsInInteraction, const std::vector< std::vector<mcIdType> >& rowsPartialSumI,
93 const std::vector<std::vector<mcIdType> >& globalIdsPartial, std::vector<std::vector<double> >& denoStrorageInv);
94 void divideByGlobalRowSum(const std::vector<int>& distantProcs, const std::vector<std::vector<mcIdType> >& resPerProcI,
95 const std::vector<std::vector<double> >& resPerProcD, std::vector<std::vector<double> >& deno);
97 bool isSurfaceComputationNeeded(const std::string& method) const;
99 bool _presence_dft_value = false;
100 double _dft_value = 0.0;
101 const MEDCoupling::ParaFIELD *_source_field;
102 std::vector<mcIdType> _row_offsets;
103 std::map<std::pair<int,mcIdType>, mcIdType > _col_offsets;
104 MEDCouplingPointSet *_source_support;
105 MxN_Mapping _mapping;
107 const ProcessorGroup& _source_group;
108 const ProcessorGroup& _target_group;
109 std::vector< std::vector<double> > _target_volume;
110 std::vector<std::vector<std::pair<int,double> > > _coeffs;
111 std::vector<std::vector<double> > _deno_multiply;
112 std::vector<std::vector<double> > _deno_reverse_multiply;