Salome HOME
Documentation update with features and review corrections
[modules/adao.git] / src / daComposant / daAlgorithms / InputValuesTest.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 numpy
24 from daCore import BasicObjects
25
26 # ==============================================================================
27 class ElementaryAlgorithm(BasicObjects.Algorithm):
28     def __init__(self):
29         BasicObjects.Algorithm.__init__(self, "INPUTVALUESTEST")
30         self.defineRequiredParameter(
31             name     = "NumberOfPrintedDigits",
32             default  = 5,
33             typecast = int,
34             message  = "Nombre de chiffres affichés pour les impressions de réels",
35             minval   = 0,
36         )
37         self.defineRequiredParameter(
38             name     = "PrintAllValuesFor",
39             default  = [],
40             typecast = tuple,
41             message  = "Liste de noms de vecteurs dont les valeurs détaillées sont à imprimer",
42             listval  = [
43                 "Background",
44                 "CheckingPoint",
45                 "Observation",
46             ]
47         )
48         self.defineRequiredParameter(
49             name     = "ShowInformationOnlyFor",
50             default  = ["Background", "CheckingPoint", "Observation"],
51             typecast = tuple,
52             message  = "Liste de noms de vecteurs dont les informations synthétiques sont à imprimer",
53             listval  = [
54                 "Background",
55                 "CheckingPoint",
56                 "Observation",
57             ]
58         )
59         self.defineRequiredParameter(
60             name     = "SetDebug",
61             default  = False,
62             typecast = bool,
63             message  = "Activation du mode debug lors de l'exécution",
64         )
65         self.requireInputArguments(
66             mandatory= (),
67         )
68         self.setAttributes(
69             tags=(
70                 "Checking",
71             ),
72             features=(
73                 "DerivativeFree",
74             ),
75         )
76
77     def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
78         self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q)
79         #
80         _p = self._parameters["NumberOfPrintedDigits"]
81         numpy.set_printoptions(precision=_p)
82
83         def __buildPrintableVectorProperties( __name, __vector ):
84             if __vector is None:
85                 return ""
86             if len(__vector) == 0:
87                 return ""
88             if hasattr(__vector, "name") and __name != __vector.name():
89                 return ""
90             if __name not in self._parameters["ShowInformationOnlyFor"]:
91                 return ""
92             #
93             if hasattr(__vector, "mins"):
94                 __title = "Information for %svector series:"%(str(__name) + " ",)
95             else:
96                 __title = "Information for %svector:"%(str(__name) + " ",)
97             msgs = "\n"
98             msgs += ("===> " + __title + "\n")
99             msgs += ("     " + ("-" * len(__title)) + "\n")
100             msgs += ("     Main characteristics of the vector:\n")
101             if hasattr(__vector, "basetype"):
102                 msgs += ("       Python base type..........: %s\n")%( __vector.basetype(), )
103                 msgs += ("       Shape of data.............: %s\n")%( __vector.shape(), )
104             else:
105                 msgs += ("       Python base type..........: %s\n")%type( __vector )
106                 msgs += ("       Shape of serie of vectors.: %s\n")%( __vector.shape, )
107             try:
108                 msgs += ("       Number of data............: %s\n")%( len(__vector), )
109             except Exception:
110                 pass
111             if hasattr(__vector, "mins"):
112                 msgs += ("       Serie of minimum values...: %s\n")%numpy.array(__vector.mins())
113             else:
114                 msgs += ("       Minimum of vector.........: %12." + str(_p) + "e\n")%__vector.min()
115             if hasattr(__vector, "means"):
116                 msgs += ("       Serie of mean values......: %s\n")%numpy.array(__vector.means())
117             else:
118                 msgs += ("       Mean of vector............: %12." + str(_p) + "e\n")%__vector.mean()
119             if hasattr(__vector, "maxs"):
120                 msgs += ("       Serie of maximum values...: %s\n")%numpy.array(__vector.maxs())
121             else:
122                 msgs += ("       Maximum of vector.........: %12." + str(_p) + "e\n")%__vector.max()
123             if self._parameters["SetDebug"] or __name in self._parameters["PrintAllValuesFor"]:
124                 msgs += ("\n")
125                 msgs += ("     Printing all values :\n")
126                 msgs += ("%s"%(__vector,))
127             print(msgs)
128             return msgs
129         #
130         __buildPrintableVectorProperties( "Background", Xb )
131         __buildPrintableVectorProperties( "CheckingPoint", Xb )
132         __buildPrintableVectorProperties( "Observation", Y )
133         #
134         self._post_run(HO, EM)
135         return 0
136
137 # ==============================================================================
138 if __name__ == "__main__":
139     print("\n AUTODIAGNOSTIC\n")