]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
test017 Ok
authorAndré Ribes <andre.ribes@edf.fr>
Fri, 1 Apr 2011 11:22:41 +0000 (13:22 +0200)
committerAndré Ribes <andre.ribes@edf.fr>
Fri, 1 Apr 2011 11:22:41 +0000 (13:22 +0200)
Maintenant il faut le cas Aster qui décrit plusieurs variables

resources/ADAOSchemaCatalog.xml
src/daSalome/daYacsIntegration/daOptimizerLoop.py
src/daSalome/daYacsSchemaCreator/methods.py
src/tests/daSalome/test017_3DVAR_function_script.py

index 64742bcf0a600cb45badb4b4a252c421d58b368b..e6883b31e05a4c672e846951fb79024904d48ea9 100644 (file)
@@ -222,7 +222,7 @@ print "Entering in FakeOptimizerLoopNode"
 result = None
 ]]></code></script>
     <inport name="computation" type="SALOME_TYPES/ParametricInput"/>
-    <outport name="result" type="pyobj"/>
+    <outport name="result" type="SALOME_TYPES/ParametricOutput"/>
   </inline>
 
   <inline name="CreateDictFromScript">
index dfa5a4f114faf1ed8346a61a668fd51f90bbc272..7487d9d8ff179499a6bc7f56e8ff6e79ae4541cc 100644 (file)
@@ -67,6 +67,20 @@ class OptimizerHooks:
 
     return sample
 
+  def get_data_from_any(self, any_data):
+    error = any_data["returnCode"].getIntValue()
+    if error != 0:
+      self.optim_algo.setError(any_data["errorMessage"].getStringValue())
+
+    data = []
+    outputValues = any_data["outputValues"]
+    for param in outputValues[0]:
+      for i in range(param.size()):
+        data.append(param[i].getDoubleValue())
+
+    matrix = numpy.matrix(data).T
+    return matrix
+
   def Direct(self, X, sync = 1):
     print "Call Direct OptimizerHooks"
     if sync == 1:
@@ -92,15 +106,13 @@ class OptimizerHooks:
           sample_id = self.optim_algo.pool.getCurrentId()
           if sample_id == local_counter:
             # 4: Data is ready
-            matrix_from_pool = self.optim_algo.pool.getOutSample(local_counter).getStringValue()
+            any_data = self.optim_algo.pool.getOutSample(local_counter)
+            Y = self.get_data_from_any(any_data)
 
             # 5: Release lock
             # Have to be done before but need a new implementation
             # of the optimizer loop
             self.counter_lock.release()
-
-            # 6: return results
-            Y = pickle.loads(matrix_from_pool)
             return Y
     else:
       print "sync false is not yet implemented"
@@ -129,15 +141,13 @@ class OptimizerHooks:
           sample_id = self.optim_algo.pool.getCurrentId()
           if sample_id == local_counter:
             # 4: Data is ready
-            matrix_from_pool = self.optim_algo.pool.getOutSample(local_counter).getStringValue()
+            any_data = self.optim_algo.pool.getOutSample(local_counter)
+            Y = self.get_data_from_any(any_data)
 
             # 5: Release lock
             # Have to be done before but need a new implementation
             # of the optimizer loop
             self.counter_lock.release()
-
-            # 6: return results
-            Y = pickle.loads(matrix_from_pool)
             return Y
     else:
       print "sync false is not yet implemented"
@@ -168,15 +178,13 @@ class OptimizerHooks:
           sample_id = self.optim_algo.pool.getCurrentId()
           if sample_id == local_counter:
             # 4: Data is ready
-            matrix_from_pool = self.optim_algo.pool.getOutSample(local_counter).getStringValue()
+            any_data = self.optim_algo.pool.getOutSample(local_counter)
+            Z = self.get_data_from_any(any_data)
 
             # 5: Release lock
             # Have to be done before but need a new implementation
             # of the optimizer loop
             self.counter_lock.release()
-
-            # 6: return results
-            Z = pickle.loads(matrix_from_pool)
             return Z
     else:
       print "sync false is not yet implemented"
@@ -190,8 +198,9 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync):
     self.runtime = SALOMERuntime.getSALOMERuntime()
 
     # Definission des types d'entres et de sorties pour le code de calcul
-    self.tin  = self.runtime.getTypeCode("SALOME_TYPES/ParametricInput")
-    self.tout = self.runtime.getTypeCode("pyobj")
+    self.tin      = self.runtime.getTypeCode("SALOME_TYPES/ParametricInput")
+    self.tout     = self.runtime.getTypeCode("SALOME_TYPES/ParametricOutput")
+    self.pyobject = self.runtime.getTypeCode("pyobj")
 
     self.optim_hooks = OptimizerHooks(self)
 
@@ -254,7 +263,7 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync):
   def getTCForOut(self):
     return self.tout
   def getTCForAlgoInit(self):
-    return self.tout
+    return self.pyobject
   def getTCForAlgoResult(self):
-    return self.tout
+    return self.pyobject
 
index d5fc4a2d055e9f1f4e27d1d1039786574811874b..bc58afc8f4a49c65de9076e6f99c5f4321db9b4f 100644 (file)
@@ -50,9 +50,11 @@ def create_yacs_proc(study_config):
   proc = runtime.createProc("proc")
   proc.setTypeCode("pyobj", runtime.getTypeCode("pyobj"))
   proc.setTypeCode("SALOME_TYPES/ParametricInput", catalogAd._typeMap["SALOME_TYPES/ParametricInput"])
+  proc.setTypeCode("SALOME_TYPES/ParametricOutput", catalogAd._typeMap["SALOME_TYPES/ParametricOutput"])
   t_pyobj  = proc.getTypeCode("pyobj")
   t_string = proc.getTypeCode("string")
-  t_param_input = proc.getTypeCode("SALOME_TYPES/ParametricInput")
+  t_param_input  = proc.getTypeCode("SALOME_TYPES/ParametricInput")
+  t_param_output = proc.getTypeCode("SALOME_TYPES/ParametricOutput")
   repertory = False
   base_repertory = ""
   if "Repertory" in study_config.keys():
@@ -228,7 +230,7 @@ def create_yacs_proc(study_config):
         sys.exit(1)
       opt_script_node.setScript(script_str.read())
       opt_script_node.edAddInputPort("computation", t_param_input)
-      opt_script_node.edAddOutputPort("result", t_pyobj)
+      opt_script_node.edAddOutputPort("result", t_param_output)
 
       # Add it
       computation_bloc = runtime.createBloc("computation_bloc")
index 09f2e4ca035a37f11aa7ef5dd52f63f5fa95f22c..3581d9e953b8a782333b9c44cada39192fb11cda 100644 (file)
@@ -18,12 +18,27 @@ def AdjointH( (X, Y) ):
     return H.T * Y
 
 if method == "Direct":
-  result = FunctionH(numpy.matrix(computation["inputValues"][0][0]).T)
+  data = FunctionH(numpy.matrix(computation["inputValues"][0][0]).T)
 
 if method == "Tangent":
-  result = FunctionH(numpy.matrix(computation["inputValues"][0][0]).T)
+  data = FunctionH(numpy.matrix(computation["inputValues"][0][0]).T)
 
 if method == "Adjoint":
-  result = AdjointH((numpy.matrix(computation["inputValues"][0][0]).T, numpy.matrix(computation["inputValues"][0][1]).T))
+  data = AdjointH((numpy.matrix(computation["inputValues"][0][0]).T, numpy.matrix(computation["inputValues"][0][1]).T))
 
+
+outputValues = [[[]]]
+it = data.flat
+for val in it:
+  outputValues[0][0].append(val)
+
+print outputValues
+
+result = {}
+result["outputValues"] = outputValues
+result["specificOutputInfos"] = []
+result["returnCode"] = 0
+result["errorMessage"] = ""
+
+print result
 print "Computation end"