1 # Copyright (C) 2011-2012 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 SALOME
23 components to use these functions. If the computation code is implemented as a
24 Python script or function, use module
25 :mod:`salome.kernel.parametric.pyscript_utils` instead.
30 def create_input_dict(deterministic_dict, parametric_input):
32 This function returns a dictionary containing the input values to be used
33 in the computation code.
35 :type deterministic_dict: dict
36 :param deterministic_dict: dictionary containing the fixed values (i.e.
37 non-parametric). This dictionary can be empty
38 if all variables are parametric.
40 :type parametric_input: SALOME_TYPES/ParametricInput
41 :param parametric_input: structure containing the description and values
42 of the parametric variables.
44 :return: a dictionary containing the input values for the computation code.
46 # Simply get the first point from input (no time series, single observation)
47 input_point = parametric_input.inputValues[0][0]
49 if len(input_point) != len(parametric_input.inputVarList):
50 raise Exception("Size mismatch between inputVarList and point to evaluate")
52 input_dict = deterministic_dict.copy()
53 for i in range(len(input_point)):
54 input_dict[parametric_input.inputVarList[i]] = input_point[i][0]
58 def create_normal_parametric_output(output_dict, parametric_input):
60 This function returns a structure describing the output of the computation
61 code in parametric studies.
63 :type output_dict: dict
64 :param output_dict: dictionary containing the output values of the
65 computation code (the keys are the variable names, the
66 values are the variable values).
68 :type parametric_input: SALOME_TYPES/ParametricInput
69 :param parametric_input: structure containing the description and values
70 of the parametric variables.
72 :return: a structure of type SALOME_TYPES/ParametricOutput containing the
73 output of the computation code.
75 output_values = [[[]]]
76 for output_var in parametric_input.outputVarList:
77 output_values[0][0].append([output_dict[output_var]])
78 return SALOME_TYPES.ParametricOutput(outputValues = output_values,
79 specificOutputInfos = [],
83 def create_error_parametric_output(error_message):
85 This function returns a structure describing the output of the computation
86 code in parametric studies in case of error.
88 :type error_message: string
89 :param error_message: the error message.
91 :return: a structure of type SALOME_TYPES/ParametricOutput describing the
94 return SALOME_TYPES.ParametricOutput(outputValues = [],
95 specificOutputInfos = [],
97 errorMessage = error_message)