1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2015 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",
42 listval = ["OMA", "CurrentState", "CostFunctionJ", "SimulatedObservationAtCurrentState", "SimulatedObservationAtOptimum"]
45 def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
48 # Paramètres de pilotage
49 # ----------------------
50 self.setParameters(Parameters)
52 # Opérateur d'observation
53 # -----------------------
54 Hm = HO["Tangent"].asMatrix(None)
55 Hm = Hm.reshape(Y.size,-1) # ADAO & check shape
56 Ha = HO["Adjoint"].asMatrix(None)
57 Ha = Ha.reshape(-1,Y.size) # ADAO & check shape
61 # Calcul de la matrice de gain et de l'analyse
62 # --------------------------------------------
63 K = (Ha * RI * Hm).I * Ha * RI
65 self.StoredVariables["Analysis"].store( Xa.A1 )
67 # Calcul de la fonction coût
68 # --------------------------
69 if self._parameters["StoreInternalVariables"] or \
70 "CostFunctionJ" in self._parameters["StoreSupplementaryCalculations"] or \
71 "OMA" in self._parameters["StoreSupplementaryCalculations"] or \
72 "SimulatedObservationAtOptimum" in self._parameters["StoreSupplementaryCalculations"]:
75 if self._parameters["StoreInternalVariables"] or \
76 "CostFunctionJ" in self._parameters["StoreSupplementaryCalculations"]:
78 Jo = 0.5 * oma.T * RI * oma
79 J = float( Jb ) + float( Jo )
80 self.StoredVariables["CostFunctionJb"].store( Jb )
81 self.StoredVariables["CostFunctionJo"].store( Jo )
82 self.StoredVariables["CostFunctionJ" ].store( J )
84 # Calculs et/ou stockages supplémentaires
85 # ---------------------------------------
86 if self._parameters["StoreInternalVariables"] or "CurrentState" in self._parameters["StoreSupplementaryCalculations"]:
87 self.StoredVariables["CurrentState"].store( numpy.ravel(Xa) )
88 if "OMA" in self._parameters["StoreSupplementaryCalculations"]:
89 self.StoredVariables["OMA"].store( numpy.ravel(oma) )
90 if "SimulatedObservationAtCurrentState" in self._parameters["StoreSupplementaryCalculations"]:
91 self.StoredVariables["SimulatedObservationAtCurrentState"].store( numpy.ravel(HXa) )
92 if "SimulatedObservationAtOptimum" in self._parameters["StoreSupplementaryCalculations"]:
93 self.StoredVariables["SimulatedObservationAtOptimum"].store( numpy.ravel(HXa) )
98 # ==============================================================================
99 if __name__ == "__main__":
100 print '\n AUTODIAGNOSTIC \n'