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, PlatformInfo
27 # ==============================================================================
28 class ElementaryAlgorithm(BasicObjects.Algorithm):
30 BasicObjects.Algorithm.__init__(self, "LOCALSENSITIVITYTEST")
31 self.defineRequiredParameter(
35 message = "Activation du mode debug lors de l'exécution",
37 self.defineRequiredParameter(
38 name = "StoreSupplementaryCalculations",
39 default = ["JacobianMatrixAtCurrentState",],
41 message = "Liste de calculs supplémentaires à stocker et/ou effectuer",
44 "JacobianMatrixAtCurrentState",
45 "SimulatedObservationAtCurrentState",
48 self.requireInputArguments(
49 mandatory= ("Xb", "Y", "HO"),
52 def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
53 self._pre_run(Parameters, Xb, Y, R, B, Q)
55 if self._parameters["SetDebug"]:
56 CUR_LEVEL = logging.getLogger().getEffectiveLevel()
57 logging.getLogger().setLevel(logging.DEBUG)
58 print("===> Beginning of evaluation, activating debug\n")
59 print(" %s\n"%("-"*75,))
62 Ht = HO["Tangent"].asMatrix( Xb )
63 Ht = Ht.reshape(Y.size,Xb.size) # ADAO & check shape
66 if self._parameters["SetDebug"]:
67 print("\n %s\n"%("-"*75,))
68 print("===> End evaluation, deactivating debug if necessary\n")
69 logging.getLogger().setLevel(CUR_LEVEL)
71 if self._toStore("CurrentState"):
72 self.StoredVariables["CurrentState"].store( Xb )
73 if self._toStore("JacobianMatrixAtCurrentState"):
74 self.StoredVariables["JacobianMatrixAtCurrentState"].store( Ht )
75 if self._toStore("SimulatedObservationAtCurrentState"):
76 if HO["AppliedInX"] is not None and "HXb" in HO["AppliedInX"]:
77 HXb = HO["AppliedInX"]["HXb"]
80 HXb = numpy.asmatrix(numpy.ravel( HXb )).T
81 if Y.size != HXb.size:
82 raise ValueError("The size %i of observations Y and %i of observed calculation H(X) are different, they have to be identical."%(Y.size,HXb.size))
83 if max(Y.shape) != max(HXb.shape):
84 raise ValueError("The shapes %s of observations Y and %s of observed calculation H(X) are different, they have to be identical."%(Y.shape,HXb.shape))
85 self.StoredVariables["SimulatedObservationAtCurrentState"].store( HXb )
90 # ==============================================================================
91 if __name__ == "__main__":
92 print('\n AUTODIAGNOSTIC \n')