1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008-2024 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
26 # ==============================================================================
27 class ElementaryAlgorithm(BasicObjects.Algorithm):
29 BasicObjects.Algorithm.__init__(self, "LOCALSENSITIVITYTEST")
30 self.defineRequiredParameter(
34 message = "Activation du mode debug lors de l'exécution",
36 self.defineRequiredParameter(
37 name = "StoreSupplementaryCalculations",
38 default = ["JacobianMatrixAtCurrentState",],
40 message = "Liste de calculs supplémentaires à stocker et/ou effectuer",
43 "JacobianMatrixAtCurrentState",
44 "SimulatedObservationAtCurrentState",
47 self.requireInputArguments(
48 mandatory= ("Xb", "Y", "HO"),
56 "ParallelDerivativesOnly",
60 def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
61 self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q)
63 if self._parameters["SetDebug"]:
64 CUR_LEVEL = logging.getLogger().getEffectiveLevel()
65 logging.getLogger().setLevel(logging.DEBUG)
66 print("===> Beginning of evaluation, activating debug\n")
67 print(" %s\n"%("-" * 75,))
70 Ht = HO["Tangent"].asMatrix( Xb )
71 Ht = Ht.reshape(Y.size, Xb.size) # ADAO & check shape
74 if self._parameters["SetDebug"]:
75 print("\n %s\n"%("-" * 75,))
76 print("===> End evaluation, deactivating debug if necessary\n")
77 logging.getLogger().setLevel(CUR_LEVEL)
79 if self._toStore("CurrentState"):
80 self.StoredVariables["CurrentState"].store( Xb )
81 if self._toStore("JacobianMatrixAtCurrentState"):
82 self.StoredVariables["JacobianMatrixAtCurrentState"].store( Ht )
83 if self._toStore("SimulatedObservationAtCurrentState"):
84 if HO["AppliedInX"] is not None and "HXb" in HO["AppliedInX"]:
85 HXb = HO["AppliedInX"]["HXb"]
88 HXb = numpy.ravel( HXb ).reshape((-1, 1))
89 if Y.size != HXb.size:
90 raise ValueError("The size %i of observations Yobs and %i of observed calculation F(X) are different, they have to be identical."%(Y.size, HXb.size)) # noqa: E501
91 if max(Y.shape) != max(HXb.shape):
92 raise ValueError("The shapes %s of observations Yobs and %s of observed calculation F(X) are different, they have to be identical."%(Y.shape, HXb.shape)) # noqa: E501
93 self.StoredVariables["SimulatedObservationAtCurrentState"].store( HXb )
95 self._post_run(HO, EM)
98 # ==============================================================================
99 if __name__ == "__main__":
100 print("\n AUTODIAGNOSTIC\n")