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