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"
57 std::string getParamForSet(const GenericKeyVal& entry) const;
60 class PythonLeafVisitor;
61 class RecursiveVisitor;
66 virtual bool isNeeded() const = 0;
67 virtual Type getType() const = 0;
68 virtual std::string pyStr() const = 0;
69 virtual void visitPython(MainModel *godFather, PythonLeafVisitor *visitor) { }
70 virtual void visitAll(MainModel *godFather, RecursiveVisitor *visitor);
71 virtual ~GenericKeyVal() { }
72 std::string pyStrKeyVal() const;
73 std::string getKey() const { return _key; }
75 GenericKeyVal(const std::string& key):_key(key) { }
80 class NeededGenericKeyVal : public GenericKeyVal
83 NeededGenericKeyVal(const std::string& key):GenericKeyVal(key) { }
85 bool isNeeded() const override { return true; }
88 class NotNeededGenericKeyVal : public GenericKeyVal
91 bool isNeeded() const override { return false; }
94 class DoubleKeyVal : public NeededGenericKeyVal
97 DoubleKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
98 Type getType() const override { return Type::Double; }
99 void setVal(double val) { _val=val; }
100 double getVal() const { return _val; }
101 std::string pyStr() const override;
106 class BoolKeyVal : public NeededGenericKeyVal
109 BoolKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
110 Type getType() const override { return Type::Bool; }
111 virtual void setVal(bool val) { _val=val; }
112 bool getVal() const { return _val; }
113 std::string pyStr() const override;
118 class CostDecrementTolerance : public DoubleKeyVal
121 CostDecrementTolerance():DoubleKeyVal(KEY) { setVal(1e-7); }
123 static const char KEY[];
126 class StringKeyVal : public NeededGenericKeyVal
129 StringKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
130 Type getType() const override { return Type::String; }
131 std::string pyStr() const override;
132 void setVal(const std::string& val) { _val = val; }
133 std::string getVal() const { return _val; }
138 class NoneKeyVal : public NeededGenericKeyVal
141 NoneKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
142 Type getType() const override { return Type::None; }
143 std::string pyStr() const override;
146 class StringObserver : public NoneKeyVal
149 StringObserver():NoneKeyVal(KEY) { }
151 static const char KEY[];
154 class InfoObserver : public NoneKeyVal
157 InfoObserver():NoneKeyVal(KEY) { }
159 static const char KEY[];
162 class ListStringsKeyVal : public NeededGenericKeyVal
165 ListStringsKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
167 Type getType() const override { return Type::ListStrings; }
168 std::string pyStr() const override;
170 std::vector< std::string > _val;
173 class StoreSupplKeyVal : public ListStringsKeyVal
178 static const char *DFTL[];
179 static const char KEY[];
184 class EnumAlgoKeyVal : public NeededGenericKeyVal
187 EnumAlgoKeyVal():NeededGenericKeyVal(KEY),_enum(EnumAlgo::ThreeDVar) { }
188 Type getType() const override { return Type::EnumAlgo; }
189 std::shared_ptr<DictKeyVal> generateDftParameters() const;
190 std::string getRepresentation() const;
191 std::string pyStr() const override;
192 void setVal(EnumAlgo newAlgo) { _enum = newAlgo; }
193 EnumAlgo getVal() const { return _enum; }
195 std::shared_ptr<DictKeyVal> templateForBlue() const;
196 std::shared_ptr<DictKeyVal> templateForOthers() const;
198 static const char KEY[];
202 class DictKeyVal : public NeededGenericKeyVal
205 DictKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
206 void pushBack(std::shared_ptr<GenericKeyVal> elt) { _pairs.push_back(elt); }
207 Type getType() const override { return Type::Child; }
208 std::string pyStr() const override;
209 void visitPython(MainModel *godFather, PythonLeafVisitor *visitor) override;
210 void visitAll(MainModel *godFather, RecursiveVisitor *visitor) override;
212 std::vector< std::shared_ptr<GenericKeyVal> > _pairs;
215 class ParametersOfAlgorithmParameters : public DictKeyVal
218 ParametersOfAlgorithmParameters():DictKeyVal(KEY) { }
220 static const char KEY[];
223 class PyObjKeyVal : public NeededGenericKeyVal
226 PyObjKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
227 Type getType() const override { return Type::PyObj; }
228 void setVal(PyObject *obj) { _val = PyObjectRAII::FromBorrowed(obj); }
230 PyObject *getVal() const { return _val; }
231 std::string pyStr() const;
232 void setVarName(const std::string& vn) { _var_name = vn; }
233 void visitPython(MainModel *godFather, PythonLeafVisitor *visitor) override;
236 std::string _var_name;
239 class Bounds : public PyObjKeyVal
242 Bounds():PyObjKeyVal(KEY) { }
244 static const char KEY[];
247 class UnsignedIntKeyVal : public NeededGenericKeyVal
250 UnsignedIntKeyVal(const std::string& key):NeededGenericKeyVal(key) { }
251 void setVal(unsigned int val) { _val=val; }
252 unsigned int getVal() const { return _val; }
253 Type getType() const override { return Type::UnsignedInt; }
254 std::string pyStr() const;
256 unsigned int _val = -1;
259 class MaximumNumberOfSteps : public UnsignedIntKeyVal
262 MaximumNumberOfSteps():UnsignedIntKeyVal(KEY) { setVal(100); }
264 static const char KEY[];
267 class VectorBackground : public PyObjKeyVal
270 VectorBackground():PyObjKeyVal(KEY) { }
272 static const char KEY[];
275 class StoreBackground : public BoolKeyVal
278 StoreBackground():BoolKeyVal(KEY) { }
280 static const char KEY[];
283 class MatrixBackgroundError : public PyObjKeyVal
286 MatrixBackgroundError():PyObjKeyVal(KEY) { }
288 static const char KEY[];
291 class ScalarSparseMatrixError : public DoubleKeyVal
294 ScalarSparseMatrixError(double val):DoubleKeyVal(KEY) { setVal(val); }
296 static const char KEY[];
299 class DiagonalSparseMatrixError : public PyObjKeyVal
302 DiagonalSparseMatrixError():PyObjKeyVal(KEY) { }
304 static const char KEY[];
307 class OneFunction : public PyObjKeyVal
310 OneFunction():PyObjKeyVal(KEY) { }
312 static const char KEY[];
315 class DifferentialIncrement : public DoubleKeyVal
318 DifferentialIncrement():DoubleKeyVal(KEY) { setVal(0.0001); }
320 static const char KEY[];
323 class ObservationOperatorParameters : public DictKeyVal
326 ObservationOperatorParameters();
328 static const char KEY[];
331 class CenteredFiniteDifference : public BoolKeyVal
334 CenteredFiniteDifference():BoolKeyVal(KEY) { setVal(false); }
336 static const char KEY[];
339 class InputFunctionAsMulti : public BoolKeyVal
342 InputFunctionAsMulti():BoolKeyVal(KEY) { BoolKeyVal::setVal(true); }
343 void setVal(bool val) override;
345 static const char KEY[];
348 class VariableKV : public StringKeyVal
351 VariableKV():StringKeyVal(KEY) { setVal("CurrentState"); }
353 static const char KEY[];
356 class TemplateKV : public StringKeyVal
359 TemplateKV():StringKeyVal(KEY) { setVal("CurrentState"); }
361 static const char KEY[];
366 class AlgorithmParameters : public DictKeyVal, public TopEntry
369 AlgorithmParameters();
371 static const char KEY[];
374 class Background : public DictKeyVal, public TopEntry
379 static const char KEY[];
382 class GenericError : public DictKeyVal, public TopEntry
385 GenericError(const std::string& key, double dftValForScalarSparseMatrix);
388 class BackgroundError : public GenericError
391 BackgroundError():GenericError(KEY,BACKGROUND_SCALAR_SPARSE_DFT) { }
393 static const char KEY[];
394 static const double BACKGROUND_SCALAR_SPARSE_DFT;
397 class ObservationError : public GenericError
400 ObservationError():GenericError(KEY,BACKGROUND_SCALAR_SPARSE_DFT) { }
402 static const char KEY[];
403 static const double BACKGROUND_SCALAR_SPARSE_DFT;
406 class ObservationOperator : public DictKeyVal, public TopEntry
409 ObservationOperator();
411 static const char KEY[];
414 class Observation : public DictKeyVal, public TopEntry
419 static const char KEY[];
422 class ObserverEntry : public DictKeyVal, public TopEntry
427 static const char KEY[];
432 class PythonLeafVisitor
435 virtual void visit(MainModel *godFather, PyObjKeyVal *obj) = 0;
436 virtual ~PythonLeafVisitor() { }
439 class RecursiveVisitor
442 virtual ~RecursiveVisitor() { }
443 virtual void visit(GenericKeyVal *obj) = 0;
444 virtual void enterSubDir(DictKeyVal *subdir) = 0;
445 virtual void exitSubDir(DictKeyVal *subdir) = 0;
452 std::string findPathOf(GenericKeyVal *elt);
453 std::string pyStr() const;
454 std::vector< std::shared_ptr<GenericKeyVal> > toVect() const;
455 void visitPythonLeaves(PythonLeafVisitor *visitor);
456 void visitAll(RecursiveVisitor *visitor);
458 std::shared_ptr<AlgorithmParameters> _algo;
459 std::shared_ptr<Background> _bg;
460 std::shared_ptr<BackgroundError> _bg_err;
461 std::shared_ptr<Observation> _obs;
462 std::shared_ptr<ObservationError> _obs_err;
463 std::shared_ptr<ObservationOperator> _observ_op;
464 std::shared_ptr<ObserverEntry> _observ_entry;