Salome HOME
Minor documentation and code review corrections (39)
[modules/adao.git] / doc / fr / scripts / simple_3DVAR.py
index 3416f83def1bf84710843262992549644f97b4f4..88c307cdae1f1d5ee4be9512bd5a515dd4f8e3a6 100644 (file)
@@ -3,7 +3,7 @@
 from numpy import array, ravel
 def QuadFunction( coefficients ):
     """
-    Simulation : y = a x^2 + b x + c
+    Simulation quadratique aux points x : y = a x^2 + b x + c
     """
     a, b, c = list(ravel(coefficients))
     x_points = (-5, 0, 1, 3, 10)
@@ -15,11 +15,11 @@ def QuadFunction( coefficients ):
 Xb   = array([1., 1., 1.])
 Yobs = array([57, 2, 3, 17, 192])
 #
-print("Résolution itérative du problème de calage")
-print("------------------------------------------")
+print("Résolution du problème de calage")
+print("--------------------------------")
 print("")
 from adao import adaoBuilder
-case = adaoBuilder.New('')
+case = adaoBuilder.New()
 case.setBackground( Vector = Xb, Stored=True )
 case.setBackgroundError( ScalarSparseMatrix = 1.e6 )
 case.setObservation( Vector = Yobs, Stored=True )
@@ -28,6 +28,7 @@ case.setObservationOperator( OneFunction = QuadFunction )
 case.setAlgorithmParameters(
     Algorithm='3DVAR',
     Parameters={
+        'MaximumNumberOfIterations': 100,
         'StoreSupplementaryCalculations': [
             'CurrentState',
             ],
@@ -54,4 +55,20 @@ print("État d'ébauche a priori...........:", ravel(case.get('Background')))
 print("")
 print("Coefficients théoriques attendus..:", ravel((2,-1,2)))
 print("")
+print("Nombre d'itérations...............:", len(case.get('CurrentState')))
+print("Nombre de simulations.............:", len(case.get('CurrentState'))*4)
 print("Coefficients résultants du calage.:", ravel(case.get('Analysis')[-1]))
+#
+Xa = case.get('Analysis')[-1]
+import matplotlib.pyplot as plt
+plt.rcParams['figure.figsize'] = (10, 4)
+#
+plt.figure()
+plt.plot((-5,0,1,3,10),QuadFunction(Xb),'b-',label="Simulation à l'ébauche")
+plt.plot((-5,0,1,3,10),Yobs,            'kX',label='Observation',markersize=10)
+plt.plot((-5,0,1,3,10),QuadFunction(Xa),'r-',label="Simulation à l'optimum")
+plt.legend()
+plt.title('Calage de coefficients', fontweight='bold')
+plt.xlabel('Coordonnée arbitraire')
+plt.ylabel('Observations')
+plt.savefig("simple_3DVAR.png")