Salome HOME
Minor source update for OM compatibility
[modules/adao.git] / src / daComposant / daAlgorithms / KalmanFilter.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2024 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 from daCore import BasicObjects, NumericObjects
24 from daAlgorithms.Atoms import ecwstdkf
25
26 # ==============================================================================
27 class ElementaryAlgorithm(BasicObjects.Algorithm):
28     def __init__(self):
29         BasicObjects.Algorithm.__init__(self, "KALMANFILTER")
30         self.defineRequiredParameter(
31             name     = "Variant",
32             default  = "KalmanFilter",
33             typecast = str,
34             message  = "Variant ou formulation de la méthode",
35             listval  = [
36                 "KalmanFilter",
37             ],
38             listadv  = [
39                 "OneCorrection",
40             ],
41         )
42         self.defineRequiredParameter(
43             name     = "EstimationOf",
44             default  = "State",
45             typecast = str,
46             message  = "Estimation d'état ou de paramètres",
47             listval  = ["State", "Parameters"],
48         )
49         self.defineRequiredParameter(
50             name     = "StoreInternalVariables",
51             default  = False,
52             typecast = bool,
53             message  = "Stockage des variables internes ou intermédiaires du calcul",
54         )
55         self.defineRequiredParameter(
56             name     = "StoreSupplementaryCalculations",
57             default  = [],
58             typecast = tuple,
59             message  = "Liste de calculs supplémentaires à stocker et/ou effectuer",
60             listval  = [
61                 "Analysis",
62                 "APosterioriCorrelations",
63                 "APosterioriCovariance",
64                 "APosterioriStandardDeviations",
65                 "APosterioriVariances",
66                 "BMA",
67                 "CostFunctionJ",
68                 "CostFunctionJAtCurrentOptimum",
69                 "CostFunctionJb",
70                 "CostFunctionJbAtCurrentOptimum",
71                 "CostFunctionJo",
72                 "CostFunctionJoAtCurrentOptimum",
73                 "CurrentOptimum",
74                 "CurrentState",
75                 "CurrentStepNumber",
76                 "ForecastCovariance",
77                 "ForecastState",
78                 "IndexOfOptimum",
79                 "InnovationAtCurrentAnalysis",
80                 "InnovationAtCurrentState",
81                 "SimulatedObservationAtCurrentAnalysis",
82                 "SimulatedObservationAtCurrentOptimum",
83                 "SimulatedObservationAtCurrentState",
84             ]
85         )
86         self.requireInputArguments(
87             mandatory= ("Xb", "Y", "HO", "R", "B"),
88             optional = ("U", "EM", "CM", "Q"),
89         )
90         self.setAttributes(
91             tags=(
92                 "DataAssimilation",
93                 "Linear",
94                 "Filter",
95                 "Dynamic",
96             ),
97             features=(
98                 "LocalOptimization",
99                 "DerivativeNeeded",
100                 "ParallelDerivativesOnly",
101                 "ConvergenceOnStatic",
102             ),
103         )
104
105     def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
106         self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q)
107         #
108         # --------------------------
109         if self._parameters["Variant"] == "KalmanFilter":
110             NumericObjects.multiXOsteps(self, Xb, Y, U, HO, EM, CM, R, B, Q, ecwstdkf.ecwstdkf, True)
111         #
112         # --------------------------
113         elif self._parameters["Variant"] == "OneCorrection":
114             ecwstdkf.ecwstdkf(self, Xb, Y, U, HO, CM, R, B)
115         #
116         # --------------------------
117         else:
118             raise ValueError("Error in Variant name: %s"%self._parameters["Variant"])
119         #
120         self._post_run(HO, EM)
121         return 0
122
123 # ==============================================================================
124 if __name__ == "__main__":
125     print("\n AUTODIAGNOSTIC\n")