Salome HOME
Improving test outputs
[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         self.defineRequiredParameter(
40             name     = "SetDebug",
41             default  = True,
42             typecast = bool,
43             message  = "Activation du mode debug lors de l'exécution",
44             )
45
46     def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
47         logging.debug("%s Lancement"%self._name)
48         logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M")))
49         #
50         self.setParameters(Parameters)
51         #
52         Hm = HO["Direct"].appliedTo
53         #
54         Xn = numpy.asmatrix(numpy.ravel( Xb )).T
55         #
56         # ----------
57         if len(self._parameters["ResultTitle"]) > 0:
58             msg  = "     ====" + "="*len(self._parameters["ResultTitle"]) + "====\n"
59             msg += "        " + self._parameters["ResultTitle"] + "\n"
60             msg += "     ====" + "="*len(self._parameters["ResultTitle"]) + "====\n"
61             print("%s"%msg)
62         #
63         msg  = "===> Information before launching:\n"
64         msg += "     -----------------------------\n"
65         msg += "     Characteristics of input parameter X, internally converted:\n"
66         msg += "       Type...............: %s\n"%type( Xn )
67         msg += "       Lenght of vector...: %i\n"%max(numpy.matrix( Xn ).shape)
68         msg += "       Minimum value......: %.5e\n"%numpy.min( Xn )
69         msg += "       Maximum value......: %.5e\n"%numpy.max( Xn )
70         msg += "       Mean of vector.....: %.5e\n"%numpy.mean( Xn )
71         msg += "       Standard error.....: %.5e\n"%numpy.std( Xn )
72         msg += "       L2 norm of vector..: %.5e\n"%numpy.linalg.norm( Xn )
73         print(msg)
74         #
75         if self._parameters["SetDebug"]:
76             CUR_LEVEL = logging.getLogger().getEffectiveLevel()
77             logging.getLogger().setLevel(logging.DEBUG)
78             print("===> Beginning of evaluation, activating debug\n")
79         else:
80             print("===> Beginning of evaluation, without activating debug\n")
81         print("     %s\n"%("-"*75,))
82         #
83         print("===> Launching direct operator evaluation\n")
84         Y = Hm( Xn )
85         print("\n===> End of direct operator evaluation\n")
86         #
87         msg  = "===> Information after launching:\n"
88         msg += "     ----------------------------\n"
89         msg += "     Characteristics of output parameter Y, to compare to observation:\n"
90         msg += "       Type...............: %s\n"%type( Y )
91         msg += "       Lenght of vector...: %i\n"%max(numpy.matrix( Y ).shape)
92         msg += "       Minimum value......: %.5e\n"%numpy.min( Y )
93         msg += "       Maximum value......: %.5e\n"%numpy.max( Y )
94         msg += "       Mean of vector.....: %.5e\n"%numpy.mean( Y )
95         msg += "       Standard error.....: %.5e\n"%numpy.std( Y )
96         msg += "       L2 norm of vector..: %.5e\n"%numpy.linalg.norm( Y )
97         print(msg)
98         #
99         print("     %s\n"%("-"*75,))
100         if self._parameters["SetDebug"]:
101             print("===> End evaluation, deactivating debug if necessary\n")
102             logging.getLogger().setLevel(CUR_LEVEL)
103         #
104         logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M")))
105         logging.debug("%s Terminé"%self._name)
106         #
107         return 0
108
109 # ==============================================================================
110 if __name__ == "__main__":
111     print '\n AUTODIAGNOSTIC \n'