]> SALOME platform Git repositories - modules/adao.git/blob - test/test6702/Doc_TUI_Exemple_02.py
Salome HOME
0877647c3494e44a93647c17604bf11d817017e8
[modules/adao.git] / test / test6702 / Doc_TUI_Exemple_02.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2019 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 def test1():
28     """Test"""
29     from numpy import array, matrix
30     from adao import adaoBuilder
31     case = adaoBuilder.New()
32     case.set( 'AlgorithmParameters', Algorithm='3DVAR' )
33     case.set( 'Background',          Vector=[0, 1, 2] )
34     case.set( 'BackgroundError',     ScalarSparseMatrix=1.0 )
35     case.set( 'Observation',         Vector=array([0.5, 1.5, 2.5]) )
36     case.set( 'ObservationError',    DiagonalSparseMatrix='1 1 1' )
37     case.set( 'ObservationOperator', Matrix='1 0 0;0 2 0;0 0 3' )
38     case.set( 'Observer',            Variable="Analysis", Template="ValuePrinter" )
39     case.execute()
40     #
41     return case.get("Analysis")[-1]
42
43 def test2():
44     """Test"""
45     from numpy import array, matrix
46     from adao import adaoBuilder
47     case = adaoBuilder.New()
48     case.set( 'AlgorithmParameters', Algorithm='3DVAR' )
49     case.set( 'Background',          Vector=[0, 1, 2] )
50     case.set( 'BackgroundError',     ScalarSparseMatrix=1.0 )
51     case.set( 'Observation',         Vector=array([0.5, 1.5, 2.5]) )
52     case.set( 'ObservationError',    DiagonalSparseMatrix='1 1 1' )
53     def simulation(x):
54         import numpy
55         __x = numpy.matrix(numpy.ravel(numpy.matrix(x))).T
56         __H = numpy.matrix("1 0 0;0 2 0;0 0 3")
57         return __H * __x
58     #
59     case.set( 'ObservationOperator',
60         OneFunction = simulation,
61         Parameters  = {"DifferentialIncrement":0.01},
62         )
63     case.set( 'Observer',            Variable="Analysis", Template="ValuePrinter" )
64     case.execute()
65     #
66     return case.get("Analysis")[-1]
67
68 # ==============================================================================
69 if __name__ == "__main__":
70     print('\nAUTODIAGNOSTIC\n')
71     print("""Exemple de la doc :
72
73     Creation detaillee d'un cas de calcul TUI ADAO
74     ++++++++++++++++++++++++++++++++++++++++++++++
75     Les deux resultats sont testes pour etre identiques.
76     """)
77     xa1 = test1()
78     xa2 = test2()
79     ecart = assertAlmostEqualArrays(xa1, xa2, places = 15)
80     print("")
81     print("  L'écart absolu maximal obtenu lors du test est de %.2e."%ecart)
82     print("  Les résultats obtenus sont corrects.")
83     print("")