Salome HOME
Remove useless dependency to py2cpp.
[tools/adao_interface.git] / ThreeDVarCase.py
1 # coding: utf-8
2 #
3 # Copyright (C) 2019 EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21 # Author: Anthony Geay, anthony.geay@edf.fr, EDF R&D
22
23 # ***** <class 'numpy.matrixlib.defmatrix.matrix'>
24 # ***** <class 'numpy.ndarray'>
25 # ***** <class 'numpy.ndarray'>
26 # ***** <class 'numpy.ndarray'>
27
28 def BuildCase(cppFunc):
29     def evaluator( xserie ):
30         import numpy as np
31         yserie = [np.array(elt) for elt in cppFunc(xserie)]
32         return yserie
33     
34     from adao import adaoBuilder
35     #
36     Xb = (5.0, 7, 9.0)
37     observations = [2, 6, 12, 20]
38     alphamin, alphamax = 0., 10.
39     betamin,  betamax  = 3, 13
40     gammamin, gammamax = 1.5, 15.5
41     Bounds = (
42         (alphamin, alphamax),
43         (betamin,  betamax ),
44         (gammamin, gammamax))
45     #
46     # TUI ADAO
47     # --------
48     case = adaoBuilder.New()
49     case.set( 'AlgorithmParameters',
50         Algorithm = '3DVAR',                  # Mots-clé réservé
51         Parameters = {                        # Dictionnaire
52             "Bounds":Bounds,                  # Liste de paires de Real ou de None
53             "MaximumNumberOfSteps":100,       # Int >= 0
54             "CostDecrementTolerance":1.e-7,   # Real > 0
55             "StoreSupplementaryCalculations":[# Liste de mots-clés réservés
56                 "CostFunctionJAtCurrentOptimum",
57                 "CostFunctionJoAtCurrentOptimum",
58                 "CurrentOptimum",
59                 "SimulatedObservationAtCurrentOptimum",
60                 "SimulatedObservationAtOptimum",
61                 ],
62             }
63         )
64     case.set( 'Background',
65         Vector = Xb,                          # array, list, tuple, matrix
66         Stored = True,                        # Bool
67         )
68     case.set( 'Observation',
69         Vector = observations,                # array, list, tuple, matrix
70         Stored = False,                       # Bool
71         )
72     case.set( 'BackgroundError',
73         Matrix = None,                        # None ou matrice carrée
74         ScalarSparseMatrix = 1.0e10,          # None ou Real > 0
75         DiagonalSparseMatrix = None,          # None ou vecteur
76         )
77     case.set( 'ObservationError',
78         Matrix = None,                        # None ou matrice carrée
79         ScalarSparseMatrix = 1.0,             # None ou Real > 0
80         DiagonalSparseMatrix = None,          # None ou vecteur
81         )
82     case.set( 'ObservationOperator',
83         OneFunction = evaluator,              # MultiFonction [Y] = F([X]) multisimulation
84         Parameters  = {                       # Dictionnaire
85             "DifferentialIncrement":0.0001,   # Real > 0
86             "CenteredFiniteDifference":False, # Bool
87             },
88         InputFunctionAsMulti = True,          # Bool
89         )
90     case.set( 'Observer',
91         Variable = "CurrentState",            # Mot-clé
92         Template = "ValuePrinter",            # Mot-clé
93         String   = None,                      # None ou code Python
94         Info     = None,                      # None ou string
95         )
96     return case