1 // Copyright (C) 2007-2013 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.
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 __PARAMEDMEM_MEDCOUPLINGREMAPPER_HXX__
22 #define __PARAMEDMEM_MEDCOUPLINGREMAPPER_HXX__
24 #include "MEDCoupling.hxx"
25 #include "MEDCouplingTimeLabel.hxx"
26 #include "InterpolationOptions.hxx"
27 #include "MEDCouplingNatureOfField.hxx"
28 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
30 #include "InterpKernelException.hxx"
37 class MEDCouplingMesh;
38 class MEDCouplingFieldDouble;
39 class MEDCouplingFieldTemplate;
47 NOT_IK_ONLY_PREFERED = 1,
50 } InterpolationMatrixPolicy;
52 class MEDCouplingRemapper : public TimeLabel, public INTERP_KERNEL::InterpolationOptions
55 MEDCOUPLINGREMAPPER_EXPORT MEDCouplingRemapper();
56 MEDCOUPLINGREMAPPER_EXPORT ~MEDCouplingRemapper();
57 MEDCOUPLINGREMAPPER_EXPORT int prepare(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const char *method) throw(INTERP_KERNEL::Exception);
58 MEDCOUPLINGREMAPPER_EXPORT int prepareEx(const MEDCouplingFieldTemplate *src, const MEDCouplingFieldTemplate *target) throw(INTERP_KERNEL::Exception);
59 MEDCOUPLINGREMAPPER_EXPORT void transfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception);
60 MEDCOUPLINGREMAPPER_EXPORT void partialTransfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField) throw(INTERP_KERNEL::Exception);
61 MEDCOUPLINGREMAPPER_EXPORT void reverseTransfer(MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception);
62 MEDCOUPLINGREMAPPER_EXPORT MEDCouplingFieldDouble *transferField(const MEDCouplingFieldDouble *srcField, double dftValue) throw(INTERP_KERNEL::Exception);
63 MEDCOUPLINGREMAPPER_EXPORT MEDCouplingFieldDouble *reverseTransferField(const MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception);
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) throw(INTERP_KERNEL::Exception);
70 MEDCOUPLINGREMAPPER_EXPORT int nullifiedTinyCoeffInCrudeMatrixAbs(double maxValAbs) throw(INTERP_KERNEL::Exception);
71 MEDCOUPLINGREMAPPER_EXPORT int nullifiedTinyCoeffInCrudeMatrix(double scaleFactor) throw(INTERP_KERNEL::Exception);
72 MEDCOUPLINGREMAPPER_EXPORT double getMaxValueInCrudeMatrix() const throw(INTERP_KERNEL::Exception);
74 MEDCOUPLINGREMAPPER_EXPORT const std::vector<std::map<int,double> >& getCrudeMatrix() const;
75 MEDCOUPLINGREMAPPER_EXPORT static void PrintMatrix(const std::vector<std::map<int,double> >& m);
77 int prepareInterpKernelOnly() throw(INTERP_KERNEL::Exception);
78 int prepareInterpKernelOnlyUU() throw(INTERP_KERNEL::Exception);
79 int prepareInterpKernelOnlyEE() throw(INTERP_KERNEL::Exception);
80 int prepareInterpKernelOnlyUC() throw(INTERP_KERNEL::Exception);
81 int prepareInterpKernelOnlyCU() throw(INTERP_KERNEL::Exception);
82 int prepareInterpKernelOnlyCC() throw(INTERP_KERNEL::Exception);
84 int prepareNotInterpKernelOnly() throw(INTERP_KERNEL::Exception);
85 int prepareNotInterpKernelOnlyGaussGauss() throw(INTERP_KERNEL::Exception);
87 static int CheckInterpolationMethodManageableByNotOnlyInterpKernel(const std::string& method) throw(INTERP_KERNEL::Exception);
89 bool isInterpKernelOnlyOrNotOnly() const throw(INTERP_KERNEL::Exception);
90 void updateTime() const;
91 void checkPrepare() const throw(INTERP_KERNEL::Exception);
92 std::string checkAndGiveInterpolationMethodStr(std::string& srcMeth, std::string& trgMeth) const throw(INTERP_KERNEL::Exception);
93 void releaseData(bool matrixSuppression);
94 void transferUnderground(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, bool isDftVal, double dftValue) throw(INTERP_KERNEL::Exception);
95 void computeDeno(NatureOfField nat, const MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *trgField);
96 void computeDenoFromScratch(NatureOfField nat, const MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *trgField) throw(INTERP_KERNEL::Exception);
97 void computeProduct(const double *inputPointer, int inputNbOfCompo, bool isDftVal, double dftValue, double *resPointer);
98 void computeReverseProduct(const double *inputPointer, int inputNbOfCompo, double dftValue, double *resPointer);
99 void buildFinalInterpolationMatrixByConvolution(const std::vector< std::map<int,double> >& m1D,
100 const std::vector< std::map<int,double> >& m2D,
101 const int *corrCellIdSrc, int nbOf2DCellsSrc, int nbOf1DCellsSrc,
102 const int *corrCellIdTrg);
103 static void ReverseMatrix(const std::vector<std::map<int,double> >& matIn, int nbColsMatIn,
104 std::vector<std::map<int,double> >& matOut);
105 static void ComputeRowSumAndColSum(const std::vector<std::map<int,double> >& matrixDeno,
106 std::vector<std::map<int,double> >& deno, std::vector<std::map<int,double> >& denoReverse);
107 static void ComputeColSumAndRowSum(const std::vector<std::map<int,double> >& matrixDeno,
108 std::vector<std::map<int,double> >& deno, std::vector<std::map<int,double> >& denoReverse);
110 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldTemplate> _src_ft;
111 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldTemplate> _target_ft;
112 InterpolationMatrixPolicy _interp_matrix_pol;
113 NatureOfField _nature_of_deno;
114 unsigned int _time_deno_update;
115 std::vector<std::map<int,double> > _matrix;
116 std::vector<std::map<int,double> > _deno_multiply;
117 std::vector<std::map<int,double> > _deno_reverse_multiply;