1 # Copyright (C) 2011-2016 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 compo_utils compo_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 %SALOME
25 # components to use these functions. If the computation code is implemented as a
26 # Python script or function, 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 SALOME
33 components to use these functions. If the computation code is implemented as a
34 Python script or function, use module
35 :mod:`salome.kernel.parametric.pyscript_utils` instead.
40 ## This function returns a dictionary containing the input values to be used
41 # in the computation code.
43 # \param deterministic_dict (dict) dictionary containing the fixed values (i.e.
44 # non-parametric). This dictionary can be empty if all variables are parametric.
46 # \param parametric_input (SALOME_TYPES/ParametricInput) structure containing
47 # the description and values of the parametric variables.
49 # \return a dictionary containing the input values for the computation code.
50 # \ingroup compo_utils
51 def create_input_dict(deterministic_dict, parametric_input):
53 This function returns a dictionary containing the input values to be used
54 in the computation code.
56 :type deterministic_dict: dict
57 :param deterministic_dict: dictionary containing the fixed values (i.e.
58 non-parametric). This dictionary can be empty
59 if all variables are parametric.
61 :type parametric_input: SALOME_TYPES/ParametricInput
62 :param parametric_input: structure containing the description and values
63 of the parametric variables.
65 :return: a dictionary containing the input values for the computation code.
67 # Simply get the first point from input (no time series, single observation)
68 input_point = parametric_input.inputValues[0][0]
70 if len(input_point) != len(parametric_input.inputVarList):
71 raise Exception("Size mismatch between inputVarList and point to evaluate")
73 input_dict = deterministic_dict.copy()
74 for i in range(len(input_point)):
75 input_dict[parametric_input.inputVarList[i]] = input_point[i][0]
79 ## This function returns a structure describing the output of the computation
80 # code in parametric studies.
82 # \param output_dict (dict) dictionary containing the output values of the
83 # computation code (the keys are the variable names, the values are the variable values).
85 # \param parametric_input (SALOME_TYPES/ParametricInput) structure containing
86 # the description and values of the parametric variables.
88 # \return a structure of type SALOME_TYPES/ParametricOutput containing the
89 # output of the computation code.
90 # \ingroup compo_utils
91 def create_normal_parametric_output(output_dict, parametric_input):
93 This function returns a structure describing the output of the computation
94 code in parametric studies.
96 :type output_dict: dict
97 :param output_dict: dictionary containing the output values of the
98 computation code (the keys are the variable names, the
99 values are the variable values).
101 :type parametric_input: SALOME_TYPES/ParametricInput
102 :param parametric_input: structure containing the description and values
103 of the parametric variables.
105 :return: a structure of type SALOME_TYPES/ParametricOutput containing the
106 output of the computation code.
108 output_values = [[[]]]
109 for output_var in parametric_input.outputVarList:
110 output_values[0][0].append([output_dict[output_var]])
111 return SALOME_TYPES.ParametricOutput(outputValues = output_values,
112 specificOutputInfos = [],
116 ## This function returns a structure describing the output of the computation
117 # code in parametric studies in case of error.
119 # \param error_message (string) the error message.
121 # \return a structure of type SALOME_TYPES/ParametricOutput describing the error.
122 # \ingroup compo_utils
123 def create_error_parametric_output(error_message):
125 This function returns a structure describing the output of the computation
126 code in parametric studies in case of error.
128 :type error_message: string
129 :param error_message: the error message.
131 :return: a structure of type SALOME_TYPES/ParametricOutput describing the
134 return SALOME_TYPES.ParametricOutput(outputValues = [],
135 specificOutputInfos = [],
137 errorMessage = error_message)