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