1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008-2023 EDF R&D
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.
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.
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
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
24 from daCore import BasicObjects, NumericObjects
25 from daAlgorithms.Atoms import std3dvar, van3dvar, incr3dvar, psas3dvar
27 # ==============================================================================
28 class ElementaryAlgorithm(BasicObjects.Algorithm):
30 BasicObjects.Algorithm.__init__(self, "3DVAR")
31 self.defineRequiredParameter(
35 message = "Variant ou formulation de la méthode",
48 self.defineRequiredParameter(
52 message = "Minimiseur utilisé",
61 self.defineRequiredParameter(
62 name = "EstimationOf",
63 default = "Parameters",
65 message = "Estimation d'état ou de paramètres",
66 listval = ["State", "Parameters"],
68 self.defineRequiredParameter(
69 name = "MaximumNumberOfIterations",
72 message = "Nombre maximal de pas d'optimisation",
74 oldname = "MaximumNumberOfSteps",
76 self.defineRequiredParameter(
77 name = "CostDecrementTolerance",
80 message = "Diminution relative minimale du coût lors de l'arrêt",
83 self.defineRequiredParameter(
84 name = "ProjectedGradientTolerance",
87 message = "Maximum des composantes du gradient projeté lors de l'arrêt",
90 self.defineRequiredParameter(
91 name = "GradientNormTolerance",
94 message = "Maximum des composantes du gradient lors de l'arrêt",
97 self.defineRequiredParameter(
98 name = "StoreInternalVariables",
101 message = "Stockage des variables internes ou intermédiaires du calcul",
103 self.defineRequiredParameter(
104 name = "StoreSupplementaryCalculations",
107 message = "Liste de calculs supplémentaires à stocker et/ou effectuer",
110 "APosterioriCorrelations",
111 "APosterioriCovariance",
112 "APosterioriStandardDeviations",
113 "APosterioriVariances",
116 "CostFunctionJAtCurrentOptimum",
118 "CostFunctionJbAtCurrentOptimum",
120 "CostFunctionJoAtCurrentOptimum",
121 "CurrentIterationNumber",
128 "InnovationAtCurrentAnalysis",
129 "InnovationAtCurrentState",
130 "JacobianMatrixAtBackground",
131 "JacobianMatrixAtOptimum",
132 "KalmanGainAtOptimum",
133 "MahalanobisConsistency",
136 "SampledStateForQuantiles",
138 "SimulatedObservationAtBackground",
139 "SimulatedObservationAtCurrentOptimum",
140 "SimulatedObservationAtCurrentState",
141 "SimulatedObservationAtOptimum",
142 "SimulationQuantiles",
145 self.defineRequiredParameter(
149 message = "Liste des valeurs de quantiles",
153 self.defineRequiredParameter(
155 typecast = numpy.random.seed,
156 message = "Graine fixée pour le générateur aléatoire",
158 self.defineRequiredParameter(
159 name = "NumberOfSamplesForQuantiles",
162 message = "Nombre d'échantillons simulés pour le calcul des quantiles",
165 self.defineRequiredParameter(
166 name = "SimulationForQuantiles",
169 message = "Type de simulation en estimation des quantiles",
170 listval = ["Linear", "NonLinear"]
172 self.defineRequiredParameter( # Pas de type
174 message = "Liste des paires de bornes",
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",
180 self.defineRequiredParameter(
181 name = "InitializationPoint",
182 typecast = numpy.ravel,
183 message = "État initial imposé (par défaut, c'est l'ébauche si None)",
185 self.requireInputArguments(
186 mandatory= ("Xb", "Y", "HO", "R", "B"),
187 optional = ("U", "EM", "CM", "Q"),
189 self.setAttributes(tags=(
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)
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)
202 elif self._parameters["Variant"] == "3DVAR-VAN":
203 NumericObjects.multiXOsteps(self, Xb, Y, U, HO, EM, CM, R, B, Q, van3dvar.van3dvar)
205 elif self._parameters["Variant"] in ["3DVAR-Incr", "Incr3DVAR"]:
206 NumericObjects.multiXOsteps(self, Xb, Y, U, HO, EM, CM, R, B, Q, incr3dvar.incr3dvar)
208 elif self._parameters["Variant"] == "3DVAR-PSAS":
209 NumericObjects.multiXOsteps(self, Xb, Y, U, HO, EM, CM, R, B, Q, psas3dvar.psas3dvar)
211 #--------------------------
212 elif self._parameters["Variant"] == "OneCorrection":
213 std3dvar.std3dvar(self, Xb, Y, U, HO, CM, R, B)
215 #--------------------------
217 raise ValueError("Error in Variant name: %s"%self._parameters["Variant"])
222 # ==============================================================================
223 if __name__ == "__main__":
224 print('\n AUTODIAGNOSTIC\n')