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