gemseo / disciplines

Show inherited members

linear_combination module

Discipline computing a linear combination of its inputs.

class gemseo.disciplines.linear_combination.LinearCombination(input_names, output_name, input_coefficients=None, offset=0.0, input_size=None)[source]

Bases: MDODiscipline

Discipline computing a linear combination of its inputs.

The user can specify the coefficients related to the variables as well as the offset.

E.g., a discipline computing the output \(y\) from \(d\) inputs \(x_1,\ldots,x_d\) with the function \(f(x_1,\ldots,x_d)=a_0+\sum_{i=1}^d a_i x_i\).

When the offset \(a_0\) is equal to 0 and the coefficients \(a_1,\ldots,a_d\) are equal to 1, the discipline simply sums the inputs.


By default, the LinearCombination simply sums the inputs.


>>> discipline = LinearCombination(["alpha", "beta", "gamma"], "delta",
        input_coefficients={"alpha": 1.,"beta": 2.,"gamma": 3.})
>>> input_data = {"alpha": array([1.0]), "beta": array([1.0]),
        "gamma": array([1.0])}
>>> discipline.execute(input_data)
>>> delta = discipline.local_data["delta"]  # delta = array([6.])

Initialize self. See help(type(self)) for accurate signature.

  • input_names (Iterable[str]) – The names of input variables.

  • output_name (str) – The name of the output variable.

  • input_coefficients (dict[str, float] | None) – The coefficients related to the input variables. If None, use 1 for all the input variables.

  • offset (float) –

    The output value when all the input variables are equal to zero.

    By default it is set to 0.0.

  • input_size (int | None) – The size of the inputs. If None, the default inputs are initialized with size 1 arrays.

cache: AbstractCache | None

The cache containing one or several executions of the discipline according to the cache policy.

data_processor: DataProcessor

A tool to pre- and post-process discipline data.

exec_for_lin: bool

Whether the last execution was due to a linearization.

input_grammar: BaseGrammar

The input grammar.

jac: MutableMapping[str, MutableMapping[str, ndarray | csr_array | JacobianOperator]]

The Jacobians of the outputs wrt inputs.

The structure is {output: {input: matrix}}.

name: str

The name of the discipline.

output_grammar: BaseGrammar

The output grammar.

re_exec_policy: ReExecutionPolicy

The policy to re-execute the same discipline.

residual_variables: dict[str, str]

The output variables mapping to their inputs, to be considered as residuals; they shall be equal to zero.

run_solves_residuals: bool

Whether the run method shall solve the residuals.