1 // Copyright (C) 2007-2014 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 __PARAMEDMEM_MEDCOUPLINGFIELDDOUBLE_HXX__
22 #define __PARAMEDMEM_MEDCOUPLINGFIELDDOUBLE_HXX__
24 #include "MEDCoupling.hxx"
25 #include "MEDCouplingField.hxx"
26 #include "MEDCouplingTimeDiscretization.hxx"
27 #include "MEDCouplingMemArray.hxx"
31 class MEDCouplingFieldTemplate;
33 class MEDCouplingFieldDouble : public MEDCouplingField
36 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME);
37 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME);
38 MEDCOUPLING_EXPORT void setTimeUnit(const std::string& unit);
39 MEDCOUPLING_EXPORT std::string getTimeUnit() const;
40 MEDCOUPLING_EXPORT void synchronizeTimeWithSupport();
41 MEDCOUPLING_EXPORT void copyTinyStringsFrom(const MEDCouplingField *other);
42 MEDCOUPLING_EXPORT void copyTinyAttrFrom(const MEDCouplingFieldDouble *other);
43 MEDCOUPLING_EXPORT void copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other);
44 MEDCOUPLING_EXPORT std::string simpleRepr() const;
45 MEDCOUPLING_EXPORT std::string advancedRepr() const;
46 MEDCOUPLING_EXPORT std::string writeVTK(const std::string& fileName, bool isBinary=true) const;
47 MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const;
48 MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const;
49 MEDCOUPLING_EXPORT bool areCompatibleForMerge(const MEDCouplingField *other) const;
50 MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingField *other) const;
51 MEDCOUPLING_EXPORT bool areCompatibleForMul(const MEDCouplingField *other) const;
52 MEDCOUPLING_EXPORT bool areCompatibleForDiv(const MEDCouplingField *other) const;
53 MEDCOUPLING_EXPORT bool areCompatibleForMeld(const MEDCouplingFieldDouble *other) const;
54 MEDCOUPLING_EXPORT void renumberCells(const int *old2NewBg, bool check=true);
55 MEDCOUPLING_EXPORT void renumberCellsWithoutMesh(const int *old2NewBg, bool check=true);
56 MEDCOUPLING_EXPORT void renumberNodes(const int *old2NewBg, double eps=1e-15);
57 MEDCOUPLING_EXPORT void renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps=1e-15);
58 MEDCOUPLING_EXPORT DataArrayInt *getIdsInRange(double vmin, double vmax) const;
59 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildSubPart(const DataArrayInt *part) const;
60 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildSubPart(const int *partBg, const int *partEnd) const;
61 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildSubPartRange(int begin, int end, int step) const;
62 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *deepCpy() const;
63 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *clone(bool recDeepCpy) const;
64 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const;
65 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const;
66 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *nodeToCellDiscretization() const;
67 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *cellToNodeDiscretization() const;
68 MEDCOUPLING_EXPORT TypeOfTimeDiscretization getTimeDiscretization() const;
69 MEDCOUPLING_EXPORT void checkCoherency() const;
70 MEDCOUPLING_EXPORT void setNature(NatureOfField nat);
71 MEDCOUPLING_EXPORT void setTimeTolerance(double val) { _time_discr->setTimeTolerance(val); }
72 MEDCOUPLING_EXPORT double getTimeTolerance() const { return _time_discr->getTimeTolerance(); }
73 MEDCOUPLING_EXPORT void setIteration(int it) { _time_discr->setIteration(it); }
74 MEDCOUPLING_EXPORT void setEndIteration(int it) { _time_discr->setEndIteration(it); }
75 MEDCOUPLING_EXPORT void setOrder(int order) { _time_discr->setOrder(order); }
76 MEDCOUPLING_EXPORT void setEndOrder(int order) { _time_discr->setEndOrder(order); }
77 MEDCOUPLING_EXPORT void setTimeValue(double val) { _time_discr->setTimeValue(val); }
78 MEDCOUPLING_EXPORT void setEndTimeValue(double val) { _time_discr->setEndTimeValue(val); }
79 MEDCOUPLING_EXPORT void setTime(double val, int iteration, int order) { _time_discr->setTime(val,iteration,order); }
80 MEDCOUPLING_EXPORT void synchronizeTimeWithMesh();
81 MEDCOUPLING_EXPORT void setStartTime(double val, int iteration, int order) { _time_discr->setStartTime(val,iteration,order); }
82 MEDCOUPLING_EXPORT void setEndTime(double val, int iteration, int order) { _time_discr->setEndTime(val,iteration,order); }
83 MEDCOUPLING_EXPORT double getTime(int& iteration, int& order) const { return _time_discr->getTime(iteration,order); }
84 MEDCOUPLING_EXPORT double getStartTime(int& iteration, int& order) const { return _time_discr->getStartTime(iteration,order); }
85 MEDCOUPLING_EXPORT double getEndTime(int& iteration, int& order) const { return _time_discr->getEndTime(iteration,order); }
86 MEDCOUPLING_EXPORT double getIJ(int tupleId, int compoId) const { return getArray()->getIJ(tupleId,compoId); }
87 MEDCOUPLING_EXPORT double getIJK(int cellId, int nodeIdInCell, int compoId) const;
88 MEDCOUPLING_EXPORT void setArray(DataArrayDouble *array);
89 MEDCOUPLING_EXPORT void setEndArray(DataArrayDouble *array);
90 MEDCOUPLING_EXPORT void setArrays(const std::vector<DataArrayDouble *>& arrs);
91 MEDCOUPLING_EXPORT const DataArrayDouble *getArray() const { return _time_discr->getArray(); }
92 MEDCOUPLING_EXPORT DataArrayDouble *getArray() { return _time_discr->getArray(); }
93 MEDCOUPLING_EXPORT const DataArrayDouble *getEndArray() const { return _time_discr->getEndArray(); }
94 MEDCOUPLING_EXPORT DataArrayDouble *getEndArray() { return _time_discr->getEndArray(); }
95 MEDCOUPLING_EXPORT std::vector<DataArrayDouble *> getArrays() const { std::vector<DataArrayDouble *> ret; _time_discr->getArrays(ret); return ret; }
96 MEDCOUPLING_EXPORT double accumulate(int compId) const;
97 MEDCOUPLING_EXPORT void accumulate(double *res) const;
98 MEDCOUPLING_EXPORT double getMaxValue() const;
99 MEDCOUPLING_EXPORT double getMaxValue2(DataArrayInt*& tupleIds) const;
100 MEDCOUPLING_EXPORT double getMinValue() const;
101 MEDCOUPLING_EXPORT double getMinValue2(DataArrayInt*& tupleIds) const;
102 MEDCOUPLING_EXPORT double getAverageValue() const;
103 MEDCOUPLING_EXPORT double norm2() const;
104 MEDCOUPLING_EXPORT double normMax() const;
105 MEDCOUPLING_EXPORT void getWeightedAverageValue(double *res, bool isWAbs=true) const;
106 MEDCOUPLING_EXPORT double getWeightedAverageValue(int compId, bool isWAbs=true) const;
107 MEDCOUPLING_EXPORT double normL1(int compId) const;
108 MEDCOUPLING_EXPORT void normL1(double *res) const;
109 MEDCOUPLING_EXPORT double normL2(int compId) const;
110 MEDCOUPLING_EXPORT void normL2(double *res) const;
111 MEDCOUPLING_EXPORT double integral(int compId, bool isWAbs) const;
112 MEDCOUPLING_EXPORT void integral(bool isWAbs, double *res) const;
113 MEDCOUPLING_EXPORT void getValueOnPos(int i, int j, int k, double *res) const;
114 MEDCOUPLING_EXPORT void getValueOn(const double *spaceLoc, double *res) const;
115 MEDCOUPLING_EXPORT void getValueOn(const double *spaceLoc, double time, double *res) const;
116 MEDCOUPLING_EXPORT DataArrayDouble *getValueOnMulti(const double *spaceLoc, int nbOfPoints) const;
117 MEDCOUPLING_EXPORT void applyLin(double a, double b, int compoId);
118 MEDCOUPLING_EXPORT void applyLin(double a, double b);
119 MEDCOUPLING_EXPORT MEDCouplingFieldDouble &operator=(double value);
120 MEDCOUPLING_EXPORT void fillFromAnalytic(int nbOfComp, FunctionToEvaluate func);
121 MEDCOUPLING_EXPORT void fillFromAnalytic(int nbOfComp, const std::string& func);
122 MEDCOUPLING_EXPORT void fillFromAnalytic2(int nbOfComp, const std::string& func);
123 MEDCOUPLING_EXPORT void fillFromAnalytic3(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func);
124 MEDCOUPLING_EXPORT void applyFunc(int nbOfComp, FunctionToEvaluate func);
125 MEDCOUPLING_EXPORT void applyFunc(int nbOfComp, double val);
126 MEDCOUPLING_EXPORT void applyFunc(int nbOfComp, const std::string& func);
127 MEDCOUPLING_EXPORT void applyFunc2(int nbOfComp, const std::string& func);
128 MEDCOUPLING_EXPORT void applyFunc3(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func);
129 MEDCOUPLING_EXPORT void applyFunc(const std::string& func);
130 MEDCOUPLING_EXPORT void applyFuncFast32(const std::string& func);
131 MEDCOUPLING_EXPORT void applyFuncFast64(const std::string& func);
132 MEDCOUPLING_EXPORT int getNumberOfComponents() const;
133 MEDCOUPLING_EXPORT int getNumberOfTuples() const;
134 MEDCOUPLING_EXPORT int getNumberOfValues() const;
135 MEDCOUPLING_EXPORT void updateTime() const;
136 MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
137 MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
139 MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
140 MEDCOUPLING_EXPORT void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
141 MEDCOUPLING_EXPORT void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
142 MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays);
143 MEDCOUPLING_EXPORT void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
144 MEDCOUPLING_EXPORT void serialize(DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays) const;
146 MEDCOUPLING_EXPORT void changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double precOnMesh, double eps=1e-15);
147 MEDCOUPLING_EXPORT void substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double precOnMesh, double eps=1e-15);
148 MEDCOUPLING_EXPORT bool mergeNodes(double eps, double epsOnVals=1e-15);
149 MEDCOUPLING_EXPORT bool mergeNodes2(double eps, double epsOnVals=1e-15);
150 MEDCOUPLING_EXPORT bool zipCoords(double epsOnVals=1e-15);
151 MEDCOUPLING_EXPORT bool zipConnectivity(int compType, double epsOnVals=1e-15);
152 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *extractSlice3D(const double *origin, const double *vec, double eps) const;
153 MEDCOUPLING_EXPORT bool simplexize(int policy);
154 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *doublyContractedProduct() const;
155 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *determinant() const;
156 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *eigenValues() const;
157 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *eigenVectors() const;
158 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *inverse() const;
159 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *trace() const;
160 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *deviator() const;
161 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *magnitude() const;
162 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *maxPerTuple() const;
163 MEDCOUPLING_EXPORT void changeNbOfComponents(int newNbOfComp, double dftValue=0.);
164 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *keepSelectedComponents(const std::vector<int>& compoIds) const;
165 MEDCOUPLING_EXPORT void setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector<int>& compoIds);
166 MEDCOUPLING_EXPORT void sortPerTuple(bool asc);
167 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *MergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
168 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *MergeFields(const std::vector<const MEDCouplingFieldDouble *>& a);
169 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *MeldFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
170 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *DotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
171 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *dot(const MEDCouplingFieldDouble& other) const { return DotFields(this,&other); }
172 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *CrossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
173 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *crossProduct(const MEDCouplingFieldDouble& other) const { return CrossProductFields(this,&other); }
174 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *MaxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
175 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *max(const MEDCouplingFieldDouble& other) const { return MaxFields(this,&other); }
176 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *MinFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
177 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *min(const MEDCouplingFieldDouble& other) const { return MinFields(this,&other); }
178 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *negate() const;
179 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return AddFields(this,&other); }
180 MEDCOUPLING_EXPORT const MEDCouplingFieldDouble &operator+=(const MEDCouplingFieldDouble& other);
181 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *AddFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
182 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *operator-(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return SubstractFields(this,&other); }
183 MEDCOUPLING_EXPORT const MEDCouplingFieldDouble &operator-=(const MEDCouplingFieldDouble& other);
184 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *SubstractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
185 MEDCouplingFieldDouble *operator*(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return MultiplyFields(this,&other); }
186 MEDCOUPLING_EXPORT const MEDCouplingFieldDouble &operator*=(const MEDCouplingFieldDouble& other);
187 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *MultiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
188 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return DivideFields(this,&other); }
189 MEDCOUPLING_EXPORT const MEDCouplingFieldDouble &operator/=(const MEDCouplingFieldDouble& other);
190 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
191 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *operator^(const MEDCouplingFieldDouble& other) const;
192 MEDCOUPLING_EXPORT const MEDCouplingFieldDouble &operator^=(const MEDCouplingFieldDouble& other);
193 MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *PowFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2);
194 MEDCOUPLING_EXPORT static std::string WriteVTK(const std::string& fileName, const std::vector<const MEDCouplingFieldDouble *>& fs, bool isBinary=true);
196 MEDCOUPLING_EXPORT const MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() const { return _time_discr; }
197 MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() { return _time_discr; }
198 MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
200 MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td);
201 MEDCouplingFieldDouble(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td);
202 MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCopy);
203 MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type);
204 ~MEDCouplingFieldDouble();
206 MEDCouplingTimeDiscretization *_time_discr;