Salome HOME
Adaptations to new KERNEL functions for parametric studies
authorRenaud Barate <renaud.barate@edf.fr>
Fri, 22 Apr 2011 14:04:07 +0000 (14:04 +0000)
committerRenaud Barate <renaud.barate@edf.fr>
Fri, 22 Apr 2011 14:04:07 +0000 (14:04 +0000)
src/GENERICSOLVER/DEVIATION.py
src/GENERICSOLVERGUI/GENERICSOLVERGUI.py

index f2ddb8de4d6939ade02ff7d2fba107746413e119..0fce1a95f15d049583530b7bf4c3938a6979f666 100644 (file)
@@ -32,13 +32,15 @@ import GENERICSOLVER_ORB__POA
 import SALOME_ComponentPy
 import SALOME_DriverPy
 import SALOME
-import SALOME_TYPES
 
 from salome.kernel.logger import Logger
 from salome.kernel import termcolor
 logger = Logger("DEVIATION", color = termcolor.RED_FG)
 logger.setLevel(logging.INFO)
 
+from salome.kernel.parametric.compo_utils import \
+    create_input_dict, create_normal_parametric_output, create_error_parametric_output
+
 VARIABLE_ID = 1030
 
 ###
@@ -161,34 +163,20 @@ class DEVIATION(GENERICSOLVER_ORB__POA.DEVIATION_Gen,
             logger.debug("inputVarList: %s" % paramInput.inputVarList)
             logger.debug("outputVarList: %s" % paramInput.outputVarList)
             logger.debug("inputValues: %s" % paramInput.inputValues)
-            inputPoint = paramInput.inputValues[0][0] # No time series, single observation
-            if len(inputPoint) != len(paramInput.inputVarList):
-                raise Exception("Size mismatch between inputVarList and point to evaluate")
-
-            evalPoint = self.deterministicValues
-            for i in range(len(inputPoint)):
-                evalPoint[paramInput.inputVarList[i]] = inputPoint[i][0]
-            logger.debug("evalPoint = %s" % evalPoint)
+
+            inputDict = create_input_dict(self.deterministicValues, paramInput)
+            logger.debug("inputDict = %s" % inputDict)
             
             # Test for an invalid parameter and return an error in this case
-            if evalPoint["L"] <= 0:
-                return SALOME_TYPES.ParametricOutput(
-                        outputValues = [],
-                        specificOutputInfos = [],
-                        returnCode = 1,
-                        errorMessage = "Invalid value: L must be positive")
-
-            resDict = {}
-            resDict["dev"] = self.BeamModel(**evalPoint)
-
-            outputValues = [[[]]]
-            for outputVar in paramInput.outputVarList:
-                outputValues[0][0].append([resDict[outputVar]])
-            logger.debug("paramOutput: %s" % outputValues)
-            return SALOME_TYPES.ParametricOutput(outputValues,
-                                                 specificOutputInfos = [],
-                                                 returnCode = 0,
-                                                 errorMessage = "")
+            if inputDict["L"] <= 0:
+                return create_error_parametric_output("Invalid value: L must be positive")
+
+            outputDict = {}
+            outputDict["dev"] = self.BeamModel(**inputDict)
+
+            paramOutput = create_normal_parametric_output(outputDict, paramInput)
+            logger.debug("outputValues: %s" % paramOutput.outputValues)
+            return paramOutput
         except:
             self._raiseSalomeError()
 
index 3a5b889656f6c0e322602172097e80dc6e0f26dc..843afd0d9533b418b0ba212340bdd6bb5ef1f417 100644 (file)
@@ -28,6 +28,7 @@ from PyQt4.QtCore import *
 import salome
 import SALOMEDS
 import GENERICSOLVER_ORB
+from salome.kernel.parametric import study_exchange_vars
 
 salome.salome_init()
 
@@ -569,13 +570,13 @@ def CreateCase():
     varI = addObjectInStudy( builder, case, "I", GUIcontext.VARIABLE_ID )
     setValueToVariable( builder, varI, 2.e-6 )
     
-    from salome.kernel import varlist
-    exchVars = varlist.ExchangeVariables(inputVarList = [varlist.Variable("E"),
-                                                         varlist.Variable("F"),
-                                                         varlist.Variable("L"),
-                                                         varlist.Variable("I")],
-                                         outputVarList = [varlist.Variable("dev")])
-    varlist.createSObjectForExchangeVariables(case, exchVars, icon = VARS_ICON)
+    inputVarList = [study_exchange_vars.Variable("E"),
+                    study_exchange_vars.Variable("F"),
+                    study_exchange_vars.Variable("L"),
+                    study_exchange_vars.Variable("I")]
+    outputVarList = [study_exchange_vars.Variable("dev")]
+    exchVars = study_exchange_vars.ExchangeVariables(inputVarList, outputVarList)
+    study_exchange_vars.createSObjectForExchangeVariables(case, exchVars, icon = VARS_ICON)
 
     sg.updateObjBrowser( True )
     print "GENERICSOLVERGUI.CreateCase : exit"