1 # Copyright (C) 2011-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 ## \defgroup pyscript_utils pyscript_utils
23 # This module provides utility functions for the computation codes intended for
24 # use in parametric studies. The computation codes must be implemented as a
25 # Python script or function to use these functions. If the computation code is
26 # implemented as a %SALOME component, use module
27 # <a href="group__compo__utils.html">salome.kernel.parametric.compo_utils</a> instead.
31 This module provides utility functions for the computation codes intended for
32 use in parametric studies. The computation codes must be implemented as a
33 Python script or function to use these functions. If the computation code is
34 implemented as a SALOME component, use module
35 :mod:`salome.kernel.parametric.compo_utils` instead.
38 ## This function returns a dictionary containing the input values to be used
39 # in the computation code.
41 # \param deterministic_dict (dict) dictionary containing the fixed values (i.e.
42 # non-parametric). This dictionary can be empty if all variables are parametric.
44 # \param parametric_input (dict) dictionary containing the description and values
45 # of the parametric variables.
47 # \return a dictionary containing the input values for the computation code.
48 # \ingroup pyscript_utils
49 def create_input_dict(deterministic_dict, parametric_input):
51 This function returns a dictionary containing the input values to be used
52 in the computation code.
54 :type deterministic_dict: dict
55 :param deterministic_dict: dictionary containing the fixed values (i.e.
56 non-parametric). This dictionary can be empty
57 if all variables are parametric.
59 :type parametric_input: dict
60 :param parametric_input: dictionary containing the description and values
61 of the parametric variables.
63 :return: a dictionary containing the input values for the computation code.
65 # Simply get the first point from input (no time series, single observation)
66 input_point = parametric_input["inputValues"][0][0]
68 if len(input_point) != len(parametric_input["inputVarList"]):
69 raise Exception("Size mismatch between inputVarList and point to evaluate")
71 input_dict = deterministic_dict.copy()
72 for i in range(len(input_point)):
73 input_dict[parametric_input["inputVarList"][i]] = input_point[i][0]
77 ## This function returns a dictionary describing the output of the
78 # computation code in parametric studies.
80 # \param output_dict (dict) dictionary containing the output values of the
81 # computation code (the keys are the variable names, the
82 # values are the variable values).
84 # \param parametric_input (dict) dictionary containing the description and values
85 # of the parametric variables.
87 # \return a dictionary containing the representation of the output of the
89 # \ingroup pyscript_utils
90 def create_normal_parametric_output(output_dict, parametric_input):
92 This function returns a dictionary describing the output of the
93 computation code in parametric studies.
95 :type output_dict: dict
96 :param output_dict: dictionary containing the output values of the
97 computation code (the keys are the variable names, the
98 values are the variable values).
100 :type parametric_input: dict
101 :param parametric_input: dictionary containing the description and values
102 of the parametric variables.
104 :return: a dictionary containing the representation of the output of the
107 output_values = [[[]]]
108 for output_var in parametric_input["outputVarList"]:
109 output_values[0][0].append([output_dict[output_var]])
110 return {"outputValues" : output_values,
111 "specificOutputInfos" : [],
115 ## This function returns a dictionary describing the output of the
116 # computation code in parametric studies in case of error.
118 # \param error_message (string) the error message.
120 # \return a dictionary describing the error.
121 # \ingroup pyscript_utils
122 def create_error_parametric_output(error_message):
124 This function returns a dictionary describing the output of the
125 computation code in parametric studies in case of error.
127 :type error_message: string
128 :param error_message: the error message.
130 :return: a dictionary describing the error.
132 return {"outputValues" : [],
133 "specificOutputInfos" : [],
135 "errorMessage" : error_message}