Salome HOME
Update copyrights
[samples/genericsolver.git] / resources / yacsgen_example.py
index ca27be03953dcbeb0aa8eaecddc4167b82d31376..569d15b6162d75efc0bdc64d16be95ff1da058f3 100755 (executable)
@@ -1,4 +1,23 @@
 #!/usr/bin/env python
+#
+# Copyright (C) 2009-2019  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, or (at your option) any later version.
+#
+# 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
+#
 
 from module_generator import *
 
@@ -10,6 +29,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,36 +48,36 @@ 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"),
+                           Service("GetFilesToTransfer",
+                                   inport=[("studyID", "long"),
+                                           ("detCaseEntry", "string")],
+                                   outport=[("inputFiles", "stringvec"),
+                                            ("outputFiles", "stringvec")],
+                                   body="""
+inputFiles = []
+outputFiles = []
+return (inputFiles, outputFiles)
+""",
+                                  ),
                           ]
                 )
 
@@ -74,4 +94,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})