1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2013 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, PlatformInfo
25 m = PlatformInfo.SystemUsage()
29 # ==============================================================================
30 class ElementaryAlgorithm(BasicObjects.Algorithm):
32 BasicObjects.Algorithm.__init__(self, "LINEARLEASTSQUARES")
33 self.defineRequiredParameter(
34 name = "StoreInternalVariables",
37 message = "Stockage des variables internes ou intermédiaires du calcul",
39 self.defineRequiredParameter(
40 name = "StoreSupplementaryCalculations",
43 message = "Liste de calculs supplémentaires à stocker et/ou effectuer",
47 def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
48 logging.debug("%s Lancement"%self._name)
49 logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M")))
51 # Paramètres de pilotage
52 # ----------------------
53 self.setParameters(Parameters)
55 # Opérateur d'observation
56 # -----------------------
57 Hm = HO["Tangent"].asMatrix(None)
58 Hm = Hm.reshape(Y.size,-1) # ADAO & check shape
59 Ha = HO["Adjoint"].asMatrix(None)
60 Ha = Ha.reshape(-1,Y.size) # ADAO & check shape
64 elif self._parameters["R_scalar"] is not None:
65 RI = 1.0 / self._parameters["R_scalar"]
67 raise ValueError("Observation error covariance matrix has to be properly defined!")
69 # Calcul de la matrice de gain et de l'analyse
70 # --------------------------------------------
71 K = (Ha * RI * Hm ).I * Ha * RI
73 self.StoredVariables["Analysis"].store( Xa.A1 )
75 # Calcul de la fonction coût
76 # --------------------------
77 if self._parameters["StoreInternalVariables"] or "OMA" in self._parameters["StoreSupplementaryCalculations"]:
79 if self._parameters["StoreInternalVariables"]:
81 Jo = 0.5 * oma.T * RI * oma
82 J = float( Jb ) + float( Jo )
83 self.StoredVariables["CostFunctionJb"].store( Jb )
84 self.StoredVariables["CostFunctionJo"].store( Jo )
85 self.StoredVariables["CostFunctionJ" ].store( J )
87 # Calculs et/ou stockages supplémentaires
88 # ---------------------------------------
89 if "OMA" in self._parameters["StoreSupplementaryCalculations"]:
90 self.StoredVariables["OMA"].store( numpy.ravel(oma) )
92 logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M")))
93 logging.debug("%s Terminé"%self._name)
97 # ==============================================================================
98 if __name__ == "__main__":
99 print '\n AUTODIAGNOSTIC \n'