Salome HOME
Make it compile with intel compiler into int64 mode
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingRemapper.hxx
1 // Copyright (C) 2007-2020  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 __PARAMEDMEM_MEDCOUPLINGREMAPPER_HXX__
22 #define __PARAMEDMEM_MEDCOUPLINGREMAPPER_HXX__
23
24 #include "MEDCoupling.hxx"
25 #include "MEDCouplingTimeLabel.hxx"
26 #include "InterpolationOptions.hxx"
27 #include "MEDCouplingNatureOfField.hxx"
28 #include "MCType.hxx"
29 #include "MCAuto.hxx"
30
31 #include "InterpKernelException.hxx"
32
33 #include <map>
34 #include <vector>
35
36 namespace MEDCoupling
37 {
38   class MEDCouplingMesh;
39   class MEDCouplingFieldDouble;
40   class MEDCouplingFieldTemplate;
41 }
42
43 namespace MEDCoupling
44 {
45   typedef enum
46   {
47     IK_ONLY_PREFERED = 0,
48     NOT_IK_ONLY_PREFERED = 1,
49     IK_ONLY_FORCED = 2,
50     NOT_IK_ONLY_FORCED =3
51   } InterpolationMatrixPolicy;
52
53   class MEDCouplingRemapper : public TimeLabel, public INTERP_KERNEL::InterpolationOptions
54   {
55   public:
56     MEDCOUPLINGREMAPPER_EXPORT MEDCouplingRemapper();
57     MEDCOUPLINGREMAPPER_EXPORT ~MEDCouplingRemapper();
58     MEDCOUPLINGREMAPPER_EXPORT int prepare(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const std::string& method);
59     MEDCOUPLINGREMAPPER_EXPORT int prepareEx(const MEDCouplingFieldTemplate *src, const MEDCouplingFieldTemplate *target);
60     MEDCOUPLINGREMAPPER_EXPORT void setCrudeMatrix(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const std::string& method, const std::vector<std::map<mcIdType,double> >& m);
61     MEDCOUPLINGREMAPPER_EXPORT void setCrudeMatrixEx(const MEDCouplingFieldTemplate *src, const MEDCouplingFieldTemplate *target, const std::vector<std::map<mcIdType,double> >& m);
62     MEDCOUPLINGREMAPPER_EXPORT void transfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, double dftValue);
63     MEDCOUPLINGREMAPPER_EXPORT void partialTransfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField);
64     MEDCOUPLINGREMAPPER_EXPORT void reverseTransfer(MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *targetField, double dftValue);
65     MEDCOUPLINGREMAPPER_EXPORT MEDCouplingFieldDouble *transferField(const MEDCouplingFieldDouble *srcField, double dftValue);
66     MEDCOUPLINGREMAPPER_EXPORT MEDCouplingFieldDouble *reverseTransferField(const MEDCouplingFieldDouble *targetField, double dftValue);
67     MEDCOUPLINGREMAPPER_EXPORT bool setOptionInt(const std::string& key, int value);
68     MEDCOUPLINGREMAPPER_EXPORT bool setOptionDouble(const std::string& key, double value);
69     MEDCOUPLINGREMAPPER_EXPORT bool setOptionString(const std::string& key, const std::string& value);
70     MEDCOUPLINGREMAPPER_EXPORT int getInterpolationMatrixPolicy() const;
71     MEDCOUPLINGREMAPPER_EXPORT void setInterpolationMatrixPolicy(int newInterpMatPol);
72     //
73     MEDCOUPLINGREMAPPER_EXPORT int nullifiedTinyCoeffInCrudeMatrixAbs(double maxValAbs);
74     MEDCOUPLINGREMAPPER_EXPORT int nullifiedTinyCoeffInCrudeMatrix(double scaleFactor);
75     MEDCOUPLINGREMAPPER_EXPORT double getMaxValueInCrudeMatrix() const;
76   public:
77     MEDCOUPLINGREMAPPER_EXPORT const std::vector<std::map<mcIdType,double> >& getCrudeMatrix() const;
78     MEDCOUPLINGREMAPPER_EXPORT mcIdType getNumberOfColsOfMatrix() const;
79     MEDCOUPLINGREMAPPER_EXPORT static void PrintMatrix(const std::vector<std::map<mcIdType,double> >& m);
80     MEDCOUPLINGREMAPPER_EXPORT static std::string BuildMethodFrom(const std::string& meth1, const std::string& meth2);
81     MEDCOUPLINGREMAPPER_EXPORT void BuildFieldTemplatesFrom(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const std::string& method, MCAuto<MEDCouplingFieldTemplate>& src, MCAuto<MEDCouplingFieldTemplate>& target);
82   private:
83     int prepareInterpKernelOnly();
84     int prepareInterpKernelOnlyUU();
85     int prepareInterpKernelOnlyEE();
86     int prepareInterpKernelOnlyUC();
87     int prepareInterpKernelOnlyCU();
88     int prepareInterpKernelOnlyCC();
89     //
90     int prepareNotInterpKernelOnly();
91     int prepareNotInterpKernelOnlyGaussGauss();
92     //
93     static int CheckInterpolationMethodManageableByNotOnlyInterpKernel(const std::string& method);
94     //
95     bool isInterpKernelOnlyOrNotOnly() const;
96     void updateTime() const;
97     void checkPrepare() const;
98     std::string checkAndGiveInterpolationMethodStr(std::string& srcMeth, std::string& trgMeth) const;
99     void releaseData(bool matrixSuppression);
100     void restartUsing(const MEDCouplingFieldTemplate *src, const MEDCouplingFieldTemplate *target);
101     void transferUnderground(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, bool isDftVal, double dftValue);
102     void computeDeno(NatureOfField nat, const MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *trgField);
103     void computeDenoFromScratch(NatureOfField nat, const MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *trgField);
104     void computeProduct(const double *inputPointer, int inputNbOfCompo, bool isDftVal, double dftValue, double *resPointer);
105     void computeReverseProduct(const double *inputPointer, int inputNbOfCompo, double dftValue, double *resPointer);
106     void buildFinalInterpolationMatrixByConvolution(const std::vector< std::map<mcIdType,double> >& m1D,
107                                                     const std::vector< std::map<mcIdType,double> >& m2D,
108                                                     const mcIdType *corrCellIdSrc, mcIdType nbOf2DCellsSrc, mcIdType nbOf1DCellsSrc,
109                                                     const mcIdType *corrCellIdTrg);
110     static void ReverseMatrix(const std::vector<std::map<mcIdType,double> >& matIn, mcIdType nbColsMatIn,
111                               std::vector<std::map<mcIdType,double> >& matOut);
112     static void ComputeRowSumAndColSum(const std::vector<std::map<mcIdType,double> >& matrixDeno,
113                                        std::vector<std::map<mcIdType,double> >& deno, std::vector<std::map<mcIdType,double> >& denoReverse);
114     static void ComputeColSumAndRowSum(const std::vector<std::map<mcIdType,double> >& matrixDeno,
115                                        std::vector<std::map<mcIdType,double> >& deno, std::vector<std::map<mcIdType,double> >& denoReverse);
116   private:
117     MCAuto<MEDCouplingFieldTemplate> _src_ft;
118     MCAuto<MEDCouplingFieldTemplate> _target_ft;
119     InterpolationMatrixPolicy _interp_matrix_pol;
120     NatureOfField _nature_of_deno;
121     unsigned int _time_deno_update;
122     std::vector<std::map<mcIdType,double> > _matrix;
123     std::vector<std::map<mcIdType,double> > _deno_multiply;
124     std::vector<std::map<mcIdType,double> > _deno_reverse_multiply;
125   };
126 }
127
128 #endif