]> SALOME platform Git repositories - modules/adao.git/blob - doc/fr/scripts/simple_3DVAR.py
Salome HOME
Adding elementary TUI examples to algorithms doc
[modules/adao.git] / doc / fr / scripts / simple_3DVAR.py
1 # -*- coding: utf-8 -*-
2 #
3 from numpy import array, ravel
4 def QuadFunction( coefficients ):
5     """
6     Fonction : y = a x^2 + b x + c
7     """
8     a, b, c = list(ravel(coefficients))
9     x_points = (-5, 0, 1, 3, 10)
10     y_points = []
11     for x in x_points:
12         y_points.append( a*x*x + b*x + c )
13     return array(y_points)
14 #
15 print("Résolution itérative du problème de calibration")
16 print("-----------------------.-----------------------")
17 print("")
18 from adao import adaoBuilder
19 case = adaoBuilder.New('')
20 case.setBackground( Vector = array([1., 1., 1.]), Stored=True )
21 case.setBackgroundError( ScalarSparseMatrix = 1.e6 )
22 case.setObservation( Vector=array([57, 2, 3, 17, 192]), Stored=True )
23 case.setObservationError( ScalarSparseMatrix = 1. )
24 case.setObservationOperator( OneFunction = QuadFunction )
25 case.setAlgorithmParameters(
26     Algorithm='3DVAR',
27     Parameters={
28         'StoreSupplementaryCalculations': [
29             'CurrentState',
30             ],
31         },
32     )
33 case.setObserver(
34     Info="  État intermédiaire en itération courante :",
35     Template='ValuePrinter',
36     Variable='CurrentState',
37     )
38 case.execute()
39 print("")
40 #
41 #-------------------------------------------------------------------------------
42 #
43 print("Calibration de %i coefficients pour une forme quadratique 1D sur %i mesures"%(
44     len(case.get('Background')),
45     len(case.get('Observation')),
46     ))
47 print("------------------------------------------------------------------------")
48 print("")
49 print("Vecteur observation.......................:", ravel(case.get('Observation')))
50 print("État ébauche a priori.....................:", ravel(case.get('Background')))
51 print("")
52 print("Coefficients théoriques attendus..........:", ravel((2,-1,2)))
53 print("")
54 print("Coefficients résultants de la calibration.:", ravel(case.get('Analysis')[-1]))