Salome HOME
Improving information output of existing test algorithms
[modules/adao.git] / src / daComposant / daAlgorithms / FunctionTest.py
1 #-*-coding:iso-8859-1-*-
2 #
3 #  Copyright (C) 2008-2013 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
24 from daCore import BasicObjects, PlatformInfo
25 m = PlatformInfo.SystemUsage()
26
27 import numpy
28
29 # ==============================================================================
30 class ElementaryAlgorithm(BasicObjects.Algorithm):
31     def __init__(self):
32         BasicObjects.Algorithm.__init__(self, "FUNCTIONTEST")
33         self.defineRequiredParameter(
34             name     = "ResultTitle",
35             default  = "",
36             typecast = str,
37             message  = "Titre du tableau et de la figure",
38             )
39
40     def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
41         logging.debug("%s Lancement"%self._name)
42         logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M")))
43         #
44         # Paramètres de pilotage
45         # ----------------------
46         self.setParameters(Parameters)
47         #
48         # Opérateur
49         # ---------
50         Hm = HO["Direct"].appliedTo
51         #
52         # Calcul du point nominal
53         # -----------------------
54         Xn = numpy.asmatrix(numpy.ravel( Xb )).T
55         #
56         # Test
57         # ----
58         if len(self._parameters["ResultTitle"]) > 0:
59             msg  = "     ====" + "="*len(self._parameters["ResultTitle"]) + "====\n"
60             msg += "        " + self._parameters["ResultTitle"] + "\n"
61             msg += "     ====" + "="*len(self._parameters["ResultTitle"]) + "====\n"
62             print("%s"%msg)
63         #
64         msg  = "===> Information before launching:\n"
65         msg += "     -----------------------------\n"
66         msg += "     Characteristics of input parameter X, internally converted:\n"
67         msg += "       Type...............: %s\n"%type( Xn )
68         msg += "       Lenght of vector...: %i\n"%max(numpy.matrix( Xn ).shape)
69         msg += "       Minimum value......: %.5e\n"%numpy.min( Xn )
70         msg += "       Maximum value......: %.5e\n"%numpy.max( Xn )
71         msg += "       Mean of vector.....: %.5e\n"%numpy.mean( Xn )
72         msg += "       Standard error.....: %.5e\n"%numpy.std( Xn )
73         msg += "       L2 norm of vector..: %.5e\n"%numpy.linalg.norm( Xn )
74         print(msg)
75         #
76         CUR_LEVEL = logging.getLogger().getEffectiveLevel()
77         logging.getLogger().setLevel(logging.DEBUG)
78         print(  "===> Launching direct operator evaluation, activating debug\n")
79         Y = Hm( Xn )
80         print("\n===> End of direct operator evaluation, deactivating debug\n")
81         logging.getLogger().setLevel(CUR_LEVEL)
82         #
83         msg  = "===> Information after launching:\n"
84         msg += "     ----------------------------\n"
85         msg += "     Characteristics of output parameter Y, to compare to observation:\n"
86         msg += "       Type...............: %s\n"%type( Y )
87         msg += "       Lenght of vector...: %i\n"%max(numpy.matrix( Y ).shape)
88         msg += "       Minimum value......: %.5e\n"%numpy.min( Y )
89         msg += "       Maximum value......: %.5e\n"%numpy.max( Y )
90         msg += "       Mean of vector.....: %.5e\n"%numpy.mean( Y )
91         msg += "       Standard error.....: %.5e\n"%numpy.std( Y )
92         msg += "       L2 norm of vector..: %.5e\n"%numpy.linalg.norm( Y )
93         print(msg)
94         #
95         logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M")))
96         logging.debug("%s Terminé"%self._name)
97         #
98         return 0
99
100 # ==============================================================================
101 if __name__ == "__main__":
102     print '\n AUTODIAGNOSTIC \n'