Salome HOME
Add parameter 'id' in log of Exec method
[samples/genericsolver.git] / src / GENERICSOLVER / DEVIATION.py
index bb5414a4b67fa5f48bdc5750dc873dadf467b165..88d864d4e8b9abc55c37e3009b00140f6778ed9b 100644 (file)
@@ -1,4 +1,4 @@
-#  Copyright (C) 2009-2010 EDF R&D
+#  Copyright (C) 2009-2011 EDF R&D
 #
 #  This library is free software; you can redistribute it and/or
 #  modify it under the terms of the GNU Lesser General Public
@@ -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,33 +163,27 @@ 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)
-            if len(paramInput.inputValues) != len(paramInput.inputVarList):
-                raise Exception("Size mismatch between inputVarList and point to evaluate")
 
-            evalPoint = self.deterministicValues
-            for i in range(len(paramInput.inputVarList)):
-                evalPoint[paramInput.inputVarList[i]] = paramInput.inputValues[i][0][0]
-            logger.debug("evalPoint = %s" % evalPoint)
+            # Get id
+            id = ""
+            for parameter in paramInput.specificParameters:
+                if parameter.name == "id":
+                    id = parameter.value
+            logger.debug("ID: %s" % id)
+
+            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.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()
 
@@ -200,7 +196,21 @@ class DEVIATION(GENERICSOLVER_ORB__POA.DEVIATION_Gen,
             logger.info("Finalize: " + self._getIdMessage())
         except:
             self._raiseSalomeError()
-        
+
+    def GetFilesToTransfer(self, studyId, detCaseEntry):
+        """
+        This method can be used to specify files to transfer to the
+        computation resource. It is not useful for DEVIATION since it only
+        uses values from Salome study.
+        """
+        try:
+            logger.info("GetFilesToTransfer: " + self._getIdMessage())
+            inputFiles = []
+            outputFiles = []
+            return (inputFiles, outputFiles)
+        except:
+            self._raiseSalomeError()
+
 ######################################################################
 # This is the computation part of the GENERICSOLVER module, ie
 # the following method realizes what the solver is intended to do.