1 # Copyright (C) 2011-2013 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.
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
21 This module provides utility functions for the computation codes intended for
22 use in parametric studies. The computation codes must be implemented as a
23 Python script or function to use these functions. If the computation code is
24 implemented as a SALOME component, use module
25 :mod:`salome.kernel.parametric.compo_utils` instead.
28 def create_input_dict(deterministic_dict, parametric_input):
30 This function returns a dictionary containing the input values to be used
31 in the computation code.
33 :type deterministic_dict: dict
34 :param deterministic_dict: dictionary containing the fixed values (i.e.
35 non-parametric). This dictionary can be empty
36 if all variables are parametric.
38 :type parametric_input: dict
39 :param parametric_input: dictionary containing the description and values
40 of the parametric variables.
42 :return: a dictionary containing the input values for the computation code.
44 # Simply get the first point from input (no time series, single observation)
45 input_point = parametric_input["inputValues"][0][0]
47 if len(input_point) != len(parametric_input["inputVarList"]):
48 raise Exception("Size mismatch between inputVarList and point to evaluate")
50 input_dict = deterministic_dict.copy()
51 for i in range(len(input_point)):
52 input_dict[parametric_input["inputVarList"][i]] = input_point[i][0]
56 def create_normal_parametric_output(output_dict, parametric_input):
58 This function returns a dictionary describing the output of the
59 computation code in parametric studies.
61 :type output_dict: dict
62 :param output_dict: dictionary containing the output values of the
63 computation code (the keys are the variable names, the
64 values are the variable values).
66 :type parametric_input: dict
67 :param parametric_input: dictionary containing the description and values
68 of the parametric variables.
70 :return: a dictionary containing the representation of the output of the
73 output_values = [[[]]]
74 for output_var in parametric_input["outputVarList"]:
75 output_values[0][0].append([output_dict[output_var]])
76 return {"outputValues" : output_values,
77 "specificOutputInfos" : [],
81 def create_error_parametric_output(error_message):
83 This function returns a dictionary describing the output of the
84 computation code in parametric studies in case of error.
86 :type error_message: string
87 :param error_message: the error message.
89 :return: a dictionary describing the error.
91 return {"outputValues" : [],
92 "specificOutputInfos" : [],
94 "errorMessage" : error_message}