1 // Copyright (C) 2019 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, anthony.geay@edf.fr, EDF R&D
23 #include "PyObjectRAII.hxx"
48 NonLinearLeastSquares,
58 std::string getParamForSet(const GenericKeyVal& entry) const;
61 class PythonLeafVisitor;
62 class RecursiveVisitor;
67 virtual bool isNeeded() const = 0;
68 virtual Type getType() const = 0;
69 virtual std::string pyStr() const = 0;
70 virtual void visitPython(MainModel *godFather, PythonLeafVisitor *visitor) { }
71 virtual void visitAll(MainModel *godFather, RecursiveVisitor *visitor);
72 virtual ~GenericKeyVal() { }
73 std::string pyStrKeyVal() const;
74 std::string getKey() const { return _key; }
76 GenericKeyVal(const std::string& key):_key(key) { }
81 class NeededGenericKeyVal : public GenericKeyVal
84 NeededGenericKeyVal(const std::string& key):GenericKeyVal(key) { }
86 bool isNeeded() const override { return true; }
89 class NotNeededGenericKeyVal : public GenericKeyVal
92 bool isNeeded() const override { return false; }
95 class DoubleKeyVal : public NeededGenericKeyVal
98 DoubleKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
99 Type getType() const override { return Type::Double; }
100 void setVal(double val) { _val=val; }
101 double getVal() const { return _val; }
102 std::string pyStr() const override;
107 class BoolKeyVal : public NeededGenericKeyVal
110 BoolKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
111 Type getType() const override { return Type::Bool; }
112 virtual void setVal(bool val) { _val=val; }
113 bool getVal() const { return _val; }
114 std::string pyStr() const override;
119 class CostDecrementTolerance : public DoubleKeyVal
122 CostDecrementTolerance():DoubleKeyVal(KEY) { setVal(1e-7); }
124 static const char KEY[];
127 class StringKeyVal : public NeededGenericKeyVal
130 StringKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
131 Type getType() const override { return Type::String; }
132 std::string pyStr() const override;
133 void setVal(const std::string& val) { _val = val; }
134 std::string getVal() const { return _val; }
139 class NoneKeyVal : public NeededGenericKeyVal
142 NoneKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
143 Type getType() const override { return Type::None; }
144 std::string pyStr() const override;
147 class StringObserver : public NoneKeyVal
150 StringObserver():NoneKeyVal(KEY) { }
152 static const char KEY[];
155 class InfoObserver : public NoneKeyVal
158 InfoObserver():NoneKeyVal(KEY) { }
160 static const char KEY[];
163 class ListStringsKeyVal : public NeededGenericKeyVal
166 ListStringsKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
168 Type getType() const override { return Type::ListStrings; }
169 std::string pyStr() const override;
171 std::vector< std::string > _val;
174 class StoreSupplKeyVal : public ListStringsKeyVal
179 static const char *DFTL[];
180 static const char KEY[];
185 class EnumAlgoKeyVal : public NeededGenericKeyVal
188 EnumAlgoKeyVal():NeededGenericKeyVal(KEY),_enum(EnumAlgo::ThreeDVar) { }
189 Type getType() const override { return Type::EnumAlgo; }
190 std::shared_ptr<DictKeyVal> generateDftParameters() const;
191 std::string getRepresentation() const;
192 std::string pyStr() const override;
193 void setVal(EnumAlgo newAlgo) { _enum = newAlgo; }
194 EnumAlgo getVal() const { return _enum; }
196 std::shared_ptr<DictKeyVal> templateForBlue() const;
197 std::shared_ptr<DictKeyVal> templateForOthers() const;
199 static const char KEY[];
203 class DictKeyVal : public NeededGenericKeyVal
206 DictKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
207 void pushBack(std::shared_ptr<GenericKeyVal> elt) { _pairs.push_back(elt); }
208 Type getType() const override { return Type::Child; }
209 std::string pyStr() const override;
210 void visitPython(MainModel *godFather, PythonLeafVisitor *visitor) override;
211 void visitAll(MainModel *godFather, RecursiveVisitor *visitor) override;
213 std::vector< std::shared_ptr<GenericKeyVal> > _pairs;
216 class ParametersOfAlgorithmParameters : public DictKeyVal
219 ParametersOfAlgorithmParameters():DictKeyVal(KEY) { }
221 static const char KEY[];
224 class PyObjKeyVal : public NeededGenericKeyVal
227 PyObjKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
228 Type getType() const override { return Type::PyObj; }
229 void setVal(PyObject *obj) { _val = PyObjectRAII::FromBorrowed(obj); }
231 PyObject *getVal() const { return _val; }
232 std::string pyStr() const;
233 void setVarName(const std::string& vn) { _var_name = vn; }
234 void visitPython(MainModel *godFather, PythonLeafVisitor *visitor) override;
237 std::string _var_name;
240 class Bounds : public PyObjKeyVal
243 Bounds():PyObjKeyVal(KEY) { }
245 static const char KEY[];
248 class UnsignedIntKeyVal : public NeededGenericKeyVal
251 UnsignedIntKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
252 void setVal(unsigned int val) { _val=val; }
253 unsigned int getVal() const { return _val; }
254 Type getType() const override { return Type::UnsignedInt; }
255 std::string pyStr() const;
257 unsigned int _val = -1;
260 class MaximumNumberOfSteps : public UnsignedIntKeyVal
263 MaximumNumberOfSteps():UnsignedIntKeyVal(KEY) { setVal(100); }
265 static const char KEY[];
268 class VectorBackground : public PyObjKeyVal
271 VectorBackground():PyObjKeyVal(KEY) { }
273 static const char KEY[];
276 class StoreBackground : public BoolKeyVal
279 StoreBackground():BoolKeyVal(KEY) { }
281 static const char KEY[];
284 class MatrixBackgroundError : public PyObjKeyVal
287 MatrixBackgroundError():PyObjKeyVal(KEY) { }
289 static const char KEY[];
292 class ScalarSparseMatrixError : public DoubleKeyVal
295 ScalarSparseMatrixError(double val):DoubleKeyVal(KEY) { setVal(val); }
297 static const char KEY[];
300 class DiagonalSparseMatrixError : public PyObjKeyVal
303 DiagonalSparseMatrixError():PyObjKeyVal(KEY) { }
305 static const char KEY[];
308 class OneFunction : public PyObjKeyVal
311 OneFunction():PyObjKeyVal(KEY) { }
313 static const char KEY[];
316 class DifferentialIncrement : public DoubleKeyVal
319 DifferentialIncrement():DoubleKeyVal(KEY) { setVal(0.0001); }
321 static const char KEY[];
324 class ObservationOperatorParameters : public DictKeyVal
327 ObservationOperatorParameters();
329 static const char KEY[];
332 class CenteredFiniteDifference : public BoolKeyVal
335 CenteredFiniteDifference():BoolKeyVal(KEY) { setVal(false); }
337 static const char KEY[];
340 class InputFunctionAsMulti : public BoolKeyVal
343 InputFunctionAsMulti():BoolKeyVal(KEY) { BoolKeyVal::setVal(true); }
344 void setVal(bool val) override;
346 static const char KEY[];
349 class VariableKV : public StringKeyVal
352 VariableKV():StringKeyVal(KEY) { setVal("CurrentState"); }
354 static const char KEY[];
357 class TemplateKV : public StringKeyVal
360 TemplateKV():StringKeyVal(KEY) { setVal("CurrentState"); }
362 static const char KEY[];
367 class AlgorithmParameters : public DictKeyVal, public TopEntry
370 AlgorithmParameters();
372 static const char KEY[];
375 class Background : public DictKeyVal, public TopEntry
380 static const char KEY[];
383 class GenericError : public DictKeyVal, public TopEntry
386 GenericError(const std::string& key, double dftValForScalarSparseMatrix);
389 class BackgroundError : public GenericError
392 BackgroundError():GenericError(KEY,BACKGROUND_SCALAR_SPARSE_DFT) { }
394 static const char KEY[];
395 static const double BACKGROUND_SCALAR_SPARSE_DFT;
398 class ObservationError : public GenericError
401 ObservationError():GenericError(KEY,BACKGROUND_SCALAR_SPARSE_DFT) { }
403 static const char KEY[];
404 static const double BACKGROUND_SCALAR_SPARSE_DFT;
407 class ObservationOperator : public DictKeyVal, public TopEntry
410 ObservationOperator();
412 static const char KEY[];
415 class Observation : public DictKeyVal, public TopEntry
420 static const char KEY[];
423 class ObserverEntry : public DictKeyVal, public TopEntry
428 static const char KEY[];
433 class PythonLeafVisitor
436 virtual void visit(MainModel *godFather, PyObjKeyVal *obj) = 0;
437 virtual ~PythonLeafVisitor() { }
440 class RecursiveVisitor
443 virtual ~RecursiveVisitor() { }
444 virtual void visit(GenericKeyVal *obj) = 0;
445 virtual void enterSubDir(DictKeyVal *subdir) = 0;
446 virtual void exitSubDir(DictKeyVal *subdir) = 0;
453 std::string findPathOf(GenericKeyVal *elt);
454 std::string pyStr() const;
455 std::vector< std::shared_ptr<GenericKeyVal> > toVect() const;
456 void visitPythonLeaves(PythonLeafVisitor *visitor);
457 void visitAll(RecursiveVisitor *visitor);
459 std::shared_ptr<AlgorithmParameters> _algo;
460 std::shared_ptr<Background> _bg;
461 std::shared_ptr<BackgroundError> _bg_err;
462 std::shared_ptr<Observation> _obs;
463 std::shared_ptr<ObservationError> _obs_err;
464 std::shared_ptr<ObservationOperator> _observ_op;
465 std::shared_ptr<ObserverEntry> _observ_entry;