Salome HOME
Increment version: 9.4.0
[samples/genericsolver.git] / resources / yacsgen_example.py
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2009-2019  EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 from module_generator import *
23
24 # This example shows how to create a component used as a calculation code for OpenTURNS
25 # with YACSGEN tool. This example is very basic. See YACSGEN documentation and DEVIATION
26 # component for more advanced features.
27
28 # edit those values to reflect your environment:
29 prerequisites_script_path = "/path/to/prerequisites.sh"
30 kernel_path = "/path/to/KERNEL_install" 
31 openturns_module_path = "/path/to/OPENTURNS_install" 
32 eficas_module_path = "/path/to/EFICAS_install" 
33
34 c1 = PYComponent("EXAMPLE_COMPONENT",
35                  services=[
36                            Service("Init",
37                                    inport=[("studyID", "long"),
38                                            ("detCaseEntry", "string")],
39                                    body="""
40 # Those values should be initialized from the deterministic case in the study
41 # (see component DEVIATION for an example)
42 self.deterministicValues = {'E' : 210.e9,
43                             'F' : 1000.,
44                             'L' : 1.5,
45                             'I' : 2.e-6}
46 """,
47                                   ),
48                            Service("Exec",
49                                    inport=[("paramInput", "SALOME_TYPES/ParametricInput"),],
50                                    outport=[("paramOutput", "SALOME_TYPES/ParametricOutput")],
51                                    defs = "from salome.kernel.parametric.compo_utils import \
52     create_input_dict, create_normal_parametric_output, create_error_parametric_output",
53                                    body="""
54 # This section creates the point to evaluate "inputDict" 
55 inputDict = create_input_dict(self.deterministicValues, paramInput)
56
57 # This section should be modified according to your needs (it's the evaluation itself)
58 if inputDict["L"] <= 0: # Test for an invalid parameter and return an error in this case
59     paramOutput = create_error_parametric_output("Invalid value: L must be positive")
60 else:
61     outputDict = {}
62     outputDict["dev"] = (inputDict["F"] * inputDict["L"] * inputDict["L"] * inputDict["L"]) / \
63                         (3. * inputDict["E"] * inputDict["I"])
64
65 # This section builds the returned object
66     paramOutput = create_normal_parametric_output(outputDict, paramInput)
67 """,
68                                   ),
69                            Service("Finalize"),
70                            Service("GetFilesToTransfer",
71                                    inport=[("studyID", "long"),
72                                            ("detCaseEntry", "string")],
73                                    outport=[("inputFiles", "stringvec"),
74                                             ("outputFiles", "stringvec")],
75                                    body="""
76 inputFiles = []
77 outputFiles = []
78 return (inputFiles, outputFiles)
79 """,
80                                   ),
81                           ]
82                 )
83
84 m = Module("EXAMPLE_MODULE",components=[c1],prefix="./EXAMPLE_MODULE_INSTALL")
85
86 context={'update':1,
87          "prerequisites":prerequisites_script_path,
88          "kernel":kernel_path
89          }
90 g=Generator(m,context)
91 g.generate()
92 g.bootstrap()
93 g.configure()
94 g.make()
95 g.install()
96 g.make_appli("example_appli",
97              altmodules={"OPENTURNS":openturns_module_path,
98                          "EFICAS":eficas_module_path})