1 // Copyright (C) 2007-2021 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 __MEDFILEPARAMETER_HXX__
22 #define __MEDFILEPARAMETER_HXX__
24 #include "MEDLoaderDefines.hxx"
25 #include "MEDFileUtilities.txx"
26 #include "MEDCouplingMemArray.hxx"
31 class MEDFileParameter1TS : public RefCountObject
34 MEDLOADER_EXPORT virtual MEDFileParameter1TS *deepCopy() const = 0;
35 MEDLOADER_EXPORT virtual bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const;
36 MEDLOADER_EXPORT virtual void simpleRepr2(int bkOffset, std::ostream& oss) const = 0;
37 MEDLOADER_EXPORT virtual void readValue(med_idt fid, const std::string& name) = 0;
38 MEDLOADER_EXPORT virtual void writeAdvanced(med_idt fid, const std::string& name, const MEDFileWritable& mw) const = 0;
40 MEDLOADER_EXPORT void setIteration(int it) { _iteration=it; }
41 MEDLOADER_EXPORT int getIteration() const { return _iteration; }
42 MEDLOADER_EXPORT void setOrder(int order) { _order=order; }
43 MEDLOADER_EXPORT int getOrder() const { return _order; }
44 MEDLOADER_EXPORT void setTimeValue(double time) { _time=time; }
45 MEDLOADER_EXPORT void setTime(int dt, int it, double time) { _time=time; _iteration=dt; _order=it; }
46 MEDLOADER_EXPORT double getTime(int& dt, int& it) { dt=_iteration; it=_order; return _time; }
47 MEDLOADER_EXPORT double getTimeValue() const { return _time; }
49 MEDFileParameter1TS(int iteration, int order, double time);
50 MEDFileParameter1TS();
57 class MEDFileParameterDouble1TSWTI : public MEDFileParameter1TS
60 MEDLOADER_EXPORT static MEDFileParameterDouble1TSWTI *New(int iteration, int order, double time);
61 MEDLOADER_EXPORT std::string getClassName() const override { return std::string("MEDFileParameterDouble1TSWTI"); }
62 MEDLOADER_EXPORT MEDFileParameter1TS *deepCopy() const;
63 MEDLOADER_EXPORT void setValue(double val) { _arr=val; }
64 MEDLOADER_EXPORT double getValue() const { return _arr; }
65 MEDLOADER_EXPORT bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const;
66 MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
67 MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
68 MEDLOADER_EXPORT void readValue(med_idt fid, const std::string& name);
69 MEDLOADER_EXPORT std::string simpleRepr() const;
71 MEDFileParameterDouble1TSWTI();
72 MEDFileParameterDouble1TSWTI(int iteration, int order, double time);
73 void simpleRepr2(int bkOffset, std::ostream& oss) const;
74 void finishLoading(med_idt fid, const std::string& name, int dt, int it, int nbOfSteps);
75 void finishLoading(med_idt fid, const std::string& name, int timeStepId);
76 void writeAdvanced(med_idt fid, const std::string& name, const MEDFileWritable& mw) const;
81 class MEDFileParameterTinyInfo : public MEDFileWritable
84 MEDLOADER_EXPORT void setDescription(const std::string& name) { _desc_name=name; }
85 MEDLOADER_EXPORT std::string getDescription() const { return _desc_name; }
86 MEDLOADER_EXPORT void setTimeUnit(const std::string& unit) { _dt_unit=unit; }
87 MEDLOADER_EXPORT std::string getTimeUnit() const { return _dt_unit; }
88 MEDLOADER_EXPORT std::size_t getHeapMemSizeOfStrings() const;
89 MEDLOADER_EXPORT bool isEqualStrings(const MEDFileParameterTinyInfo& other, std::string& what) const;
91 void writeLLHeader(med_idt fid, med_parameter_type typ) const;
92 void mainRepr(int bkOffset, std::ostream& oss) const;
96 std::string _desc_name;
99 class MEDFileParameterDouble1TS : public MEDFileParameterDouble1TSWTI, public MEDFileParameterTinyInfo
102 MEDLOADER_EXPORT static MEDFileParameterDouble1TS *New();
103 MEDLOADER_EXPORT static MEDFileParameterDouble1TS *New(const std::string& fileName);
104 MEDLOADER_EXPORT static MEDFileParameterDouble1TS *New(const std::string& fileName, const std::string& paramName);
105 MEDLOADER_EXPORT static MEDFileParameterDouble1TS *New(const std::string& fileName, const std::string& paramName, int dt, int it);
106 MEDLOADER_EXPORT std::string getClassName() const override { return std::string("MEDFileParameterDouble1TS"); }
107 MEDLOADER_EXPORT virtual MEDFileParameter1TS *deepCopy() const;
108 MEDLOADER_EXPORT virtual bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const;
109 MEDLOADER_EXPORT virtual std::string simpleRepr() const;
110 MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
111 MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
112 MEDLOADER_EXPORT void setName(const std::string& name) { _name=name; }
113 MEDLOADER_EXPORT std::string getName() const { return _name; }
114 MEDLOADER_EXPORT void write(const std::string& fileName, int mode) const;
116 MEDFileParameterDouble1TS();
117 MEDFileParameterDouble1TS(const std::string& fileName);
118 MEDFileParameterDouble1TS(const std::string& fileName, const std::string& paramName);
119 MEDFileParameterDouble1TS(const std::string& fileName, const std::string& paramName, int dt, int it);
122 class MEDFileParameterMultiTS : public RefCountObject, public MEDFileParameterTinyInfo
125 MEDLOADER_EXPORT static MEDFileParameterMultiTS *New();
126 MEDLOADER_EXPORT static MEDFileParameterMultiTS *New(const std::string& fileName);
127 MEDLOADER_EXPORT static MEDFileParameterMultiTS *New(med_idt fid);
128 MEDLOADER_EXPORT static MEDFileParameterMultiTS *New(const std::string& fileName, const std::string& paramName);
129 MEDLOADER_EXPORT static MEDFileParameterMultiTS *New(med_idt fid, const std::string& paramName);
130 MEDLOADER_EXPORT std::string getClassName() const override { return std::string("MEDFileParameterMultiTS"); }
131 MEDLOADER_EXPORT std::string getName() const { return _name; }
132 MEDLOADER_EXPORT void setName(const std::string& name) { _name=name; }
133 MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
134 MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
135 MEDLOADER_EXPORT MEDFileParameterMultiTS *deepCopy() const;
136 MEDLOADER_EXPORT bool isEqual(const MEDFileParameterMultiTS *other, double eps, std::string& what) const;
137 MEDLOADER_EXPORT void write(const std::string& fileName, int mode) const;
138 MEDLOADER_EXPORT void writeAdvanced(med_idt fid, const MEDFileWritable& mw) const;
139 MEDLOADER_EXPORT std::string simpleRepr() const;
140 MEDLOADER_EXPORT void appendValue(int dt, int it, double time, double val);
141 MEDLOADER_EXPORT double getDoubleValue(int iteration, int order) const;
142 MEDLOADER_EXPORT int getPosOfTimeStep(int iteration, int order) const;
143 MEDLOADER_EXPORT int getPosGivenTime(double time, double eps=1e-8) const;
144 MEDLOADER_EXPORT MEDFileParameter1TS *getTimeStepAtPos(int posId) const;
145 MEDLOADER_EXPORT void eraseTimeStepIds(const int *startIds, const int *endIds);
146 MEDLOADER_EXPORT int getNumberOfTS() const;
147 MEDLOADER_EXPORT std::vector< std::pair<int,int> > getIterations() const;
148 MEDLOADER_EXPORT std::vector< std::pair<int,int> > getTimeSteps(std::vector<double>& ret1) const;
149 MEDLOADER_EXPORT void simpleRepr2(int bkOffset, std::ostream& oss) const;
151 MEDFileParameterMultiTS();
152 MEDFileParameterMultiTS(const MEDFileParameterMultiTS& other, bool deepCopy);
153 MEDFileParameterMultiTS(med_idt fid);
154 MEDFileParameterMultiTS(med_idt fid, const std::string& paramName);
155 void finishLoading(med_idt fid, med_parameter_type typ, int nbOfSteps);
157 std::vector< MCAuto<MEDFileParameter1TS> > _param_per_ts;
160 class MEDFileParameters : public RefCountObject, public MEDFileWritableStandAlone
163 MEDLOADER_EXPORT static MEDFileParameters *New();
164 MEDLOADER_EXPORT static MEDFileParameters *New(med_idt fid);
165 MEDLOADER_EXPORT static MEDFileParameters *New(DataArrayByte *db) { return BuildFromMemoryChunk<MEDFileParameters>(db); }
166 MEDLOADER_EXPORT static MEDFileParameters *New(const std::string& fileName);
167 MEDLOADER_EXPORT std::string getClassName() const override { return std::string("MEDFileParameters"); }
168 MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
169 MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
170 MEDLOADER_EXPORT MEDFileParameters *deepCopy() const;
171 MEDLOADER_EXPORT bool isEqual(const MEDFileParameters *other, double eps, std::string& what) const;
172 MEDLOADER_EXPORT void writeLL(med_idt fid) const;
173 MEDLOADER_EXPORT std::vector<std::string> getParamsNames() const;
174 MEDLOADER_EXPORT std::string simpleRepr() const;
175 MEDLOADER_EXPORT void simpleReprWithoutHeader(std::ostream& oss) const;
176 MEDLOADER_EXPORT void resize(int newSize);
177 MEDLOADER_EXPORT void pushParam(MEDFileParameterMultiTS *param);
178 MEDLOADER_EXPORT void setParamAtPos(int i, MEDFileParameterMultiTS *param);
179 MEDLOADER_EXPORT MEDFileParameterMultiTS *getParamAtPos(int i) const;
180 MEDLOADER_EXPORT MEDFileParameterMultiTS *getParamWithName(const std::string& paramName) const;
181 MEDLOADER_EXPORT void destroyParamAtPos(int i);
182 MEDLOADER_EXPORT int getPosFromParamName(const std::string& paramName) const;
183 MEDLOADER_EXPORT int getNumberOfParams() const;
185 void simpleRepr2(int bkOffset, std::ostream& oss) const;
186 MEDFileParameters(med_idt fid);
187 MEDFileParameters(const MEDFileParameters& other, bool deepCopy);
190 std::vector< MCAuto<MEDFileParameterMultiTS> > _params;