]> SALOME platform Git repositories - modules/adao.git/blob - test/test6703/Doc_TUI_Exemple_03.py
Salome HOME
Add tests for salome test
[modules/adao.git] / test / test6703 / Doc_TUI_Exemple_03.py
1 #-*-coding:iso-8859-1-*-
2 #
3 # Copyright (C) 2008-2016 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 "Vérification d'un exemple de la documentation"
23
24 # ==============================================================================
25
26 #
27 # Construction artificielle d'un exemple de données utilisateur
28 # -------------------------------------------------------------
29 alpha = 5.
30 beta = 7
31 gamma = 9.0
32 #
33 alphamin, alphamax = 0., 10.
34 betamin,  betamax  = 3, 13
35 gammamin, gammamax = 1.5, 15.5
36 #
37 def simulation(x):
38     "Fonction de simulation H pour effectuer Y=H(X)"
39     import numpy
40     __x = numpy.matrix(numpy.ravel(numpy.matrix(x))).T
41     __H = numpy.matrix("1 0 0;0 2 0;0 0 3; 1 2 3")
42     return __H * __x
43 #
44 # Observations obtenues par simulation
45 # ------------------------------------
46 observations = simulation((2, 3, 4))
47
48 # ==============================================================================
49 def test1():
50     "Test"
51     import numpy
52     import adaoBuilder
53     #
54     # Mise en forme des entrées
55     # -------------------------
56     Xb = (alpha, beta, gamma)
57     Bounds = (
58         (alphamin, alphamax),
59         (betamin,  betamax ),
60         (gammamin, gammamax))
61     #
62     # TUI ADAO
63     # --------
64     case = adaoBuilder.New()
65     case.set(
66         'AlgorithmParameters',
67         Algorithm = '3DVAR',
68         Parameters = {
69             "Bounds":Bounds,
70             "MaximumNumberOfSteps":100,
71             "StoreSupplementaryCalculations":[
72                 "CostFunctionJ",
73                 "CurrentState",
74                 "SimulatedObservationAtOptimum",
75                 ],
76             }
77         )
78     case.set( 'Background', Vector = numpy.array(Xb), Stored = True )
79     case.set( 'Observation', Vector = numpy.array(observations) )
80     case.set( 'BackgroundError', ScalarSparseMatrix = 1.0e10 )
81     case.set( 'ObservationError', ScalarSparseMatrix = 1.0 )
82     case.set(
83         'ObservationOperator',
84         OneFunction = simulation,
85         Parameters  = {"DifferentialIncrement":0.0001},
86         )
87     case.set( 'Observer', Variable="CurrentState", Template="ValuePrinter" )
88     case.execute()
89     #
90     # Exploitation indépendante
91     # -------------------------
92     Xbackground   = case.get("Background")
93     Xoptimum      = case.get("Analysis")[-1]
94     FX_at_optimum = case.get("SimulatedObservationAtOptimum")[-1]
95     J_values      = case.get("CostFunctionJ")[:]
96     print
97     print "Nombre d'itérations internes...: %i"%len(J_values)
98     print "Etat initial...................:",numpy.ravel(Xbackground)
99     print "Etat optimal...................:",numpy.ravel(Xoptimum)
100     print "Simulation à l'état optimal....:",numpy.ravel(FX_at_optimum)
101     print
102
103 # ==============================================================================
104 if __name__ == "__main__":
105     print '\n AUTODIAGNOSTIC \n'
106     print """Exemple de la doc :
107
108     Exploitation indépendante des résultats d'un cas de calcul
109     ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
110     """
111     test1()