]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
Hook added
authorAndré Ribes <andre.ribes@edf.fr>
Wed, 7 Mar 2012 09:13:42 +0000 (10:13 +0100)
committerAndré Ribes <andre.ribes@edf.fr>
Wed, 7 Mar 2012 09:13:42 +0000 (10:13 +0100)
src/daSalome/daYacsIntegration/daOptimizerLoop.py
src/daSalome/daYacsIntegration/daStudy.py

index 32a62d78438ecf956751645b9abe9444b864bdc4..565cf4c97c3d4920c5d2306a312e4902e48f421f 100644 (file)
@@ -286,6 +286,12 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync):
       # Set ObservationOperator
       self.ADD.setObservationOperator(asFunction = {"Direct":direct, "Tangent":tangent, "Adjoint":adjoint})
 
+      # Set Observers
+      for observer_name in self.da_study.observers_dict.keys():
+        if observers_dict[observer_name]["scheduler"] != "":
+          self.ADD.setDataObserver(observer_name, HookFunction=self.obs, Scheduler = observers_dict[observer_name]["scheduler"], HookParameters = observer_name)
+        else:
+          self.ADD.setDataObserver(observer_name, HookFunction=self.obs, HookParameters = observer_name)
 
     # Start Assimilation Study
     #print "ADD analyze"
@@ -294,6 +300,11 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync):
     # Assimilation Study is finished
     self.pool.destroyAll()
 
+  def obs(self, var, info):
+    print "Hook observer called with:"
+    print "var %s" % var
+    print "inof %s" % info
+
   def getAlgoResult(self):
     #print "getAlgoResult"
     self.ADD.prepare_to_pickle()
index e8feb00ad8ca1536ff2517b62eea0570dc344a47..8631e9b5826b658f1c5b427737b451cffb8d60bf 100644 (file)
@@ -152,9 +152,9 @@ class daStudy:
       self.FunctionObservationOperator[Name] = ObservationOperator
 
   def addObserver(self, name, scheduler, info):
-    observers_dict[name] = {}
-    observers_dict[name]["scheduler"] = scheduler
-    observers_dict[name]["info"] = info
+    self.observers_dict[name] = {}
+    self.observers_dict[name]["scheduler"] = scheduler
+    self.observers_dict[name]["info"] = info
 
   def getObservers(self):
     return self.observers_dict