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