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