From 32a803a44f902d2f0cedab6673788a1c278b303c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Ribes?= Date: Wed, 7 Mar 2012 10:13:42 +0100 Subject: [PATCH] Hook added --- src/daSalome/daYacsIntegration/daOptimizerLoop.py | 11 +++++++++++ src/daSalome/daYacsIntegration/daStudy.py | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/daSalome/daYacsIntegration/daOptimizerLoop.py b/src/daSalome/daYacsIntegration/daOptimizerLoop.py index 32a62d7..565cf4c 100644 --- a/src/daSalome/daYacsIntegration/daOptimizerLoop.py +++ b/src/daSalome/daYacsIntegration/daOptimizerLoop.py @@ -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() diff --git a/src/daSalome/daYacsIntegration/daStudy.py b/src/daSalome/daYacsIntegration/daStudy.py index e8feb00..8631e9b 100644 --- a/src/daSalome/daYacsIntegration/daStudy.py +++ b/src/daSalome/daYacsIntegration/daStudy.py @@ -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 -- 2.39.2