]> SALOME platform Git repositories - modules/adao.git/blob - src/daComposant/daAlgorithms/LocalSensitivityTest.py
Salome HOME
Minor source update for OM compatibility
[modules/adao.git] / src / daComposant / daAlgorithms / LocalSensitivityTest.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2024 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 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
22
23 import logging, numpy
24 from daCore import BasicObjects
25
26 # ==============================================================================
27 class ElementaryAlgorithm(BasicObjects.Algorithm):
28     def __init__(self):
29         BasicObjects.Algorithm.__init__(self, "LOCALSENSITIVITYTEST")
30         self.defineRequiredParameter(
31             name     = "SetDebug",
32             default  = False,
33             typecast = bool,
34             message  = "Activation du mode debug lors de l'exécution",
35         )
36         self.defineRequiredParameter(
37             name     = "StoreSupplementaryCalculations",
38             default  = ["JacobianMatrixAtCurrentState",],
39             typecast = tuple,
40             message  = "Liste de calculs supplémentaires à stocker et/ou effectuer",
41             listval  = [
42                 "CurrentState",
43                 "JacobianMatrixAtCurrentState",
44                 "SimulatedObservationAtCurrentState",
45             ]
46         )
47         self.requireInputArguments(
48             mandatory= ("Xb", "Y", "HO"),
49         )
50         self.setAttributes(
51             tags=(
52                 "Checking",
53             ),
54             features=(
55                 "DerivativeNeeded",
56                 "ParallelDerivativesOnly",
57             ),
58         )
59
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)
62         #
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,))
68         #
69         # ----------
70         Ht = HO["Tangent"].asMatrix( Xb )
71         Ht = Ht.reshape(Y.size, Xb.size)  # ADAO & check shape
72         # ----------
73         #
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)
78         #
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"]
86             else:
87                 HXb = Ht @ Xb
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 )
94         #
95         self._post_run(HO, EM)
96         return 0
97
98 # ==============================================================================
99 if __name__ == "__main__":
100     print("\n AUTODIAGNOSTIC\n")