]> SALOME platform Git repositories - samples/genericsolver.git/blobdiff - resources/yacsgen_example.py
Salome HOME
Updated YACSGEN example
[samples/genericsolver.git] / resources / yacsgen_example.py
index ca27be03953dcbeb0aa8eaecddc4167b82d31376..53e3247abf60410c3f52dafd3b9175897a7fd0b8 100755 (executable)
@@ -1,4 +1,25 @@
 #!/usr/bin/env python
+#
+#  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
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+#  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+#  $Id$
+#
 
 from module_generator import *
 
@@ -10,6 +31,7 @@ from module_generator import *
 prerequisites_script_path = "/path/to/prerequisites.sh"
 kernel_path = "/path/to/KERNEL_install" 
 openturns_module_path = "/path/to/OPENTURNS_install" 
+eficas_module_path = "/path/to/EFICAS_install" 
 
 c1 = PYComponent("EXAMPLE_COMPONENT",
                  services=[
@@ -28,33 +50,22 @@ self.deterministicValues = {'E' : 210.e9,
                            Service("Exec",
                                    inport=[("paramInput", "SALOME_TYPES/ParametricInput"),],
                                    outport=[("paramOutput", "SALOME_TYPES/ParametricOutput")],
-                                   defs = "import SALOME_TYPES",
+                                   defs = "from salome.kernel.parametric.compo_utils import \
+    create_input_dict, create_normal_parametric_output, create_error_parametric_output",
                                    body="""
-# This section creates the point to evaluate "evalPoint" 
-evalPoint = self.deterministicValues
-for i in range(len(paramInput.inputVarList)):
-    evalPoint[paramInput.inputVarList[i]] = paramInput.inputValues[i][0][0]
+# This section creates the point to evaluate "inputDict" 
+inputDict = create_input_dict(self.deterministicValues, paramInput)
 
 # This section should be modified according to your needs (it's the evaluation itself)
-if evalPoint["L"] <= 0: # Test for an invalid parameter and return an error in this case
-    paramOutput = SALOME_TYPES.ParametricOutput(
-            outputValues = [],
-            specificOutputInfos = [],
-            returnCode = 1,
-            errorMessage = "Invalid value: L must be positive")
+if inputDict["L"] <= 0: # Test for an invalid parameter and return an error in this case
+    paramOutput = create_error_parametric_output("Invalid value: L must be positive")
 else:
-    resDict = {}
-    resDict["dev"] = (evalPoint["F"] * evalPoint["L"] * evalPoint["L"] * evalPoint["L"]) / \
-                     (3. * evalPoint["E"] * evalPoint["I"])
+    outputDict = {}
+    outputDict["dev"] = (inputDict["F"] * inputDict["L"] * inputDict["L"] * inputDict["L"]) / \
+                        (3. * inputDict["E"] * inputDict["I"])
 
 # This section builds the returned object
-    outputValues = []
-    for outputVar in paramInput.outputVarList:
-        outputValues.append([[resDict[outputVar]]])
-    paramOutput = SALOME_TYPES.ParametricOutput(outputValues,
-                                                specificOutputInfos = [],
-                                                returnCode = 0,
-                                                errorMessage = "")
+    paramOutput = create_normal_parametric_output(outputDict, paramInput)
 """,
                                   ),
                            Service("Finalize"),
@@ -74,4 +85,5 @@ g.configure()
 g.make()
 g.install()
 g.make_appli("example_appli",
-             altmodules={"OPENTURNS":openturns_module_path})
+             altmodules={"OPENTURNS":openturns_module_path,
+                         "EFICAS":eficas_module_path})