1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008-2019 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
27 # ==============================================================================
28 class ElementaryAlgorithm(BasicObjects.Algorithm):
30 BasicObjects.Algorithm.__init__(self, "LINEARLEASTSQUARES")
31 self.defineRequiredParameter(
32 name = "StoreInternalVariables",
35 message = "Stockage des variables internes ou intermédiaires du calcul",
37 self.defineRequiredParameter(
38 name = "StoreSupplementaryCalculations",
41 message = "Liste de calculs supplémentaires à stocker et/ou effectuer",
44 "CostFunctionJAtCurrentOptimum",
46 "CostFunctionJbAtCurrentOptimum",
48 "CostFunctionJoAtCurrentOptimum",
52 "SimulatedObservationAtCurrentOptimum",
53 "SimulatedObservationAtCurrentState",
54 "SimulatedObservationAtOptimum",
57 self.requireInputArguments(
58 mandatory= ("Y", "HO", "R"),
61 def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
62 self._pre_run(Parameters, Xb, Y, R, B, Q)
64 Hm = HO["Tangent"].asMatrix(None)
65 Hm = Hm.reshape(Y.size,-1) # ADAO & check shape
66 Ha = HO["Adjoint"].asMatrix(None)
67 Ha = Ha.reshape(-1,Y.size) # ADAO & check shape
71 # Calcul de la matrice de gain et de l'analyse
72 # --------------------------------------------
73 K = (Ha * RI * Hm).I * Ha * RI
75 self.StoredVariables["Analysis"].store( Xa.A1 )
77 # Calcul de la fonction coût
78 # --------------------------
79 if self._parameters["StoreInternalVariables"] or \
80 self._toStore("CostFunctionJ") or self._toStore("CostFunctionJAtCurrentOptimum") or \
81 self._toStore("CostFunctionJb") or self._toStore("CostFunctionJbAtCurrentOptimum") or \
82 self._toStore("CostFunctionJo") or self._toStore("CostFunctionJoAtCurrentOptimum") or \
83 self._toStore("OMA") or \
84 self._toStore("SimulatedObservationAtCurrentOptimum") or \
85 self._toStore("SimulatedObservationAtCurrentState") or \
86 self._toStore("SimulatedObservationAtOptimum"):
89 if self._parameters["StoreInternalVariables"] or \
90 self._toStore("CostFunctionJ") or self._toStore("CostFunctionJAtCurrentOptimum") or \
91 self._toStore("CostFunctionJb") or self._toStore("CostFunctionJbAtCurrentOptimum") or \
92 self._toStore("CostFunctionJo") or self._toStore("CostFunctionJoAtCurrentOptimum"):
94 Jo = float( 0.5 * oma.T * RI * oma )
96 self.StoredVariables["CostFunctionJb"].store( Jb )
97 self.StoredVariables["CostFunctionJo"].store( Jo )
98 self.StoredVariables["CostFunctionJ" ].store( J )
99 self.StoredVariables["CostFunctionJbAtCurrentOptimum"].store( Jb )
100 self.StoredVariables["CostFunctionJoAtCurrentOptimum"].store( Jo )
101 self.StoredVariables["CostFunctionJAtCurrentOptimum" ].store( J )
103 # Calculs et/ou stockages supplémentaires
104 # ---------------------------------------
105 if self._parameters["StoreInternalVariables"] or self._toStore("CurrentState"):
106 self.StoredVariables["CurrentState"].store( numpy.ravel(Xa) )
107 if self._toStore("CurrentOptimum"):
108 self.StoredVariables["CurrentOptimum"].store( numpy.ravel(Xa) )
109 if self._toStore("OMA"):
110 self.StoredVariables["OMA"].store( numpy.ravel(oma) )
111 if self._toStore("SimulatedObservationAtBackground"):
112 self.StoredVariables["SimulatedObservationAtBackground"].store( numpy.ravel(HXb) )
113 if self._toStore("SimulatedObservationAtCurrentState"):
114 self.StoredVariables["SimulatedObservationAtCurrentState"].store( numpy.ravel(HXa) )
115 if self._toStore("SimulatedObservationAtCurrentOptimum"):
116 self.StoredVariables["SimulatedObservationAtCurrentOptimum"].store( numpy.ravel(HXa) )
117 if self._toStore("SimulatedObservationAtOptimum"):
118 self.StoredVariables["SimulatedObservationAtOptimum"].store( numpy.ravel(HXa) )
123 # ==============================================================================
124 if __name__ == "__main__":
125 print('\n AUTODIAGNOSTIC \n')