Salome HOME
Debut de l'utilisation de daStudy dans les schemas
[modules/adao.git] / src / daComposant / daAlgorithms / Blue.py
1 #-*-coding:iso-8859-1-*-
2 #
3 #  Copyright (C) 2008-2009  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 __doc__ = """
22     Algorithme de Kalman simple (BLUE)
23 """
24 __author__ = "Jean-Philippe ARGAUD - Mars 2008"
25
26 import sys
27 import logging
28 from daCore import Persistence
29 from daCore.BasicObjects import Algorithm
30 from daCore import PlatformInfo ; m = PlatformInfo.SystemUsage()
31
32 # ==============================================================================
33 class ElementaryAlgorithm(Algorithm):
34     def __init__(self):
35         Algorithm.__init__(self)
36         self._name = "BLUE"
37         logging.debug("%s Initialisation"%self._name)
38
39     def run(self, Xb=None, Y=None, H=None, M=None, R=None, B=None, Q=None, Par=None):
40         """
41         Calcul de l'estimateur BLUE (ou Kalman simple, ou Interpolation Optimale)
42         """
43         logging.debug("%s Lancement"%self._name)
44         logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("Mo")))
45         #
46         Hm = H["Direct"].asMatrix()
47         Ht = H["Adjoint"].asMatrix()
48         #
49         # Utilisation éventuelle d'un vecteur H(Xb) précalculé
50         # ----------------------------------------------------
51         if H["AppliedToX"] is not None and H["AppliedToX"].has_key("HXb"):
52             logging.debug("%s Utilisation de HXb"%self._name)
53             HXb = H["AppliedToX"]["HXb"]
54         else:
55             logging.debug("%s Calcul de Hm * Xb"%self._name)
56             HXb = Hm * Xb
57         
58         # Calcul de la matrice de gain dans l'espace le plus petit
59         if Y.size <= Xb.size:
60             logging.debug("%s Calcul de K dans l'espace des observations"%self._name)
61             K  = B * Ht * (Hm * B * Ht + R).I
62         else:
63             logging.debug("%s Calcul de K dans l'espace d'ébauche"%self._name)
64             K = (Ht * R.I * Hm + B.I).I * Ht * R.I
65         #
66         # Calcul de l'innovation et de l'analyse
67         # --------------------------------------
68         d  = Y - HXb
69         logging.debug("%s Innovation d = %s"%(self._name, d))
70         Xa = Xb + K*d
71         logging.debug("%s Analyse Xa = %s"%(self._name, Xa))
72         #
73         self.StoredVariables["Analysis"].store( Xa.A1 )
74         self.StoredVariables["Innovation"].store( d.A1 )
75         #
76         logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("MB")))
77         logging.debug("%s Terminé"%self._name)
78         #
79         return 0
80
81 # ==============================================================================
82 if __name__ == "__main__":
83     print '\n AUTODIAGNOSTIC \n'