]> SALOME platform Git repositories - modules/adao.git/blob - src/daComposant/daAlgorithms/3DVAR.py
Salome HOME
Minor improvements and fixes for internal variables
[modules/adao.git] / src / daComposant / daAlgorithms / 3DVAR.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2021 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: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
22
23 import logging, numpy
24 from daCore import BasicObjects, NumericObjects
25
26 # ==============================================================================
27 class ElementaryAlgorithm(BasicObjects.Algorithm):
28     def __init__(self):
29         BasicObjects.Algorithm.__init__(self, "3DVAR")
30         self.defineRequiredParameter(
31             name     = "Minimizer",
32             default  = "LBFGSB",
33             typecast = str,
34             message  = "Minimiseur utilisé",
35             listval  = [
36                 "LBFGSB",
37                 "TNC",
38                 "CG",
39                 "NCG",
40                 "BFGS",
41                 ],
42             )
43         self.defineRequiredParameter(
44             name     = "Variant",
45             default  = "3DVAR",
46             typecast = str,
47             message  = "Variant ou formulation de la méthode",
48             listval  = [
49                 "3DVAR",
50                 "3DVAR-VAN",
51                 "3DVAR-Incr",
52                 "3DVAR-PSAS",
53                 ],
54             listadv  = [
55                 "3DVAR-Std",
56                 "OneCycle3DVAR-Std",
57                 ],
58             )
59         self.defineRequiredParameter(
60             name     = "EstimationOf",
61             default  = "Parameters",
62             typecast = str,
63             message  = "Estimation d'état ou de paramètres",
64             listval  = ["State", "Parameters"],
65             )
66         self.defineRequiredParameter(
67             name     = "MaximumNumberOfSteps",
68             default  = 15000,
69             typecast = int,
70             message  = "Nombre maximal de pas d'optimisation",
71             minval   = -1,
72             )
73         self.defineRequiredParameter(
74             name     = "CostDecrementTolerance",
75             default  = 1.e-7,
76             typecast = float,
77             message  = "Diminution relative minimale du coût lors de l'arrêt",
78             minval   = 0.,
79             )
80         self.defineRequiredParameter(
81             name     = "ProjectedGradientTolerance",
82             default  = -1,
83             typecast = float,
84             message  = "Maximum des composantes du gradient projeté lors de l'arrêt",
85             minval   = -1,
86             )
87         self.defineRequiredParameter(
88             name     = "GradientNormTolerance",
89             default  = 1.e-05,
90             typecast = float,
91             message  = "Maximum des composantes du gradient lors de l'arrêt",
92             minval   = 0.,
93             )
94         self.defineRequiredParameter(
95             name     = "StoreInternalVariables",
96             default  = False,
97             typecast = bool,
98             message  = "Stockage des variables internes ou intermédiaires du calcul",
99             )
100         self.defineRequiredParameter(
101             name     = "StoreSupplementaryCalculations",
102             default  = [],
103             typecast = tuple,
104             message  = "Liste de calculs supplémentaires à stocker et/ou effectuer",
105             listval  = [
106                 "Analysis",
107                 "APosterioriCorrelations",
108                 "APosterioriCovariance",
109                 "APosterioriStandardDeviations",
110                 "APosterioriVariances",
111                 "BMA",
112                 "CostFunctionJ",
113                 "CostFunctionJAtCurrentOptimum",
114                 "CostFunctionJb",
115                 "CostFunctionJbAtCurrentOptimum",
116                 "CostFunctionJo",
117                 "CostFunctionJoAtCurrentOptimum",
118                 "CurrentIterationNumber",
119                 "CurrentOptimum",
120                 "CurrentState",
121                 "ForecastState",
122                 "IndexOfOptimum",
123                 "Innovation",
124                 "InnovationAtCurrentState",
125                 "JacobianMatrixAtBackground",
126                 "JacobianMatrixAtOptimum",
127                 "KalmanGainAtOptimum",
128                 "MahalanobisConsistency",
129                 "OMA",
130                 "OMB",
131                 "SigmaObs2",
132                 "SimulatedObservationAtBackground",
133                 "SimulatedObservationAtCurrentOptimum",
134                 "SimulatedObservationAtCurrentState",
135                 "SimulatedObservationAtOptimum",
136                 "SimulationQuantiles",
137                 ]
138             )
139         self.defineRequiredParameter(
140             name     = "Quantiles",
141             default  = [],
142             typecast = tuple,
143             message  = "Liste des valeurs de quantiles",
144             minval   = 0.,
145             maxval   = 1.,
146             )
147         self.defineRequiredParameter(
148             name     = "SetSeed",
149             typecast = numpy.random.seed,
150             message  = "Graine fixée pour le générateur aléatoire",
151             )
152         self.defineRequiredParameter(
153             name     = "NumberOfSamplesForQuantiles",
154             default  = 100,
155             typecast = int,
156             message  = "Nombre d'échantillons simulés pour le calcul des quantiles",
157             minval   = 1,
158             )
159         self.defineRequiredParameter(
160             name     = "SimulationForQuantiles",
161             default  = "Linear",
162             typecast = str,
163             message  = "Type de simulation pour l'estimation des quantiles",
164             listval  = ["Linear", "NonLinear"]
165             )
166         self.defineRequiredParameter( # Pas de type
167             name     = "Bounds",
168             message  = "Liste des valeurs de bornes",
169             )
170         self.defineRequiredParameter(
171             name     = "InitializationPoint",
172             typecast = numpy.ravel,
173             message  = "État initial imposé (par défaut, c'est l'ébauche si None)",
174             )
175         self.requireInputArguments(
176             mandatory= ("Xb", "Y", "HO", "R", "B" ),
177             )
178         self.setAttributes(tags=(
179             "DataAssimilation",
180             "NonLinear",
181             "Variational",
182             ))
183
184     def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
185         self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q)
186         #
187         #--------------------------
188         # Default 3DVAR
189         if   self._parameters["Variant"] in ["3DVAR", "3DVAR-Std"]:
190             NumericObjects.multi3dvar(self, Xb, Y, U, HO, EM, CM, R, B, Q, NumericObjects.std3dvar)
191         #
192         elif self._parameters["Variant"] == "3DVAR-VAN":
193             NumericObjects.multi3dvar(self, Xb, Y, U, HO, EM, CM, R, B, Q, NumericObjects.van3dvar)
194         #
195         elif self._parameters["Variant"] in ["3DVAR-Incr", "Incr3DVAR"]:
196             NumericObjects.multi3dvar(self, Xb, Y, U, HO, EM, CM, R, B, Q, NumericObjects.incr3dvar)
197         #
198         elif self._parameters["Variant"] == "3DVAR-PSAS":
199             NumericObjects.multi3dvar(self, Xb, Y, U, HO, EM, CM, R, B, Q, NumericObjects.psas3dvar)
200         #
201         #--------------------------
202         elif self._parameters["Variant"] == "OneCycle3DVAR-Std":
203             NumericObjects.std3dvar(self, Xb, Y, U, HO, EM, CM, R, B, Q)
204         #
205         #--------------------------
206         else:
207             raise ValueError("Error in Variant name: %s"%self._parameters["Variant"])
208         #
209         self._post_run(HO)
210         return 0
211
212 # ==============================================================================
213 if __name__ == "__main__":
214     print('\n AUTODIAGNOSTIC\n')