gemseo.mda.base_mda module#

Base class for all Multi-disciplinary Design Analyses (MDA).

class BaseMDA(disciplines, settings_model=None, **settings)[source]#

Bases: ProcessDiscipline

A base class for multidisciplinary analysis (MDA).

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

Parameters:
  • disciplines (Sequence[Discipline]) -- The disciplines from which to compute the MDA.

  • settings_model (BaseMDASettings | None) -- The MDA settings as a Pydantic model. If None, use **settings.

  • **settings (Any) -- The MDA settings. These arguments are ignored when settings_model is not None.

class ResidualScaling(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: LowercaseStrEnum

The scaling method applied to MDA residuals for convergence monitoring.

INITIAL_RESIDUAL_COMPONENT = 'initial_residual_component'#

k`-th residual is scaled component-wise. Each component is scaled by the corresponding component of the initial residual (if not null, else it is not scaled). The MDA is considered converged when each component satisfies,

\[\max_i \left| \frac{(R_k)_i}{(R_0)_i} \right| \leq \text{tol}.\]
Type:

The

Type:

math

INITIAL_RESIDUAL_NORM = 'initial_residual_norm'#

k`-th residual vector is scaled by the Euclidean norm of the initial residual (if not null, else it is not scaled). The MDA is considered converged when its Euclidean norm satisfies,

\[\frac{ \|R_k\|_2 }{ \|R_0\|_2 } \leq \text{tol}.\]
Type:

The

Type:

math

INITIAL_SUBRESIDUAL_NORM = 'initial_subresidual_norm'#

k`-th residual vector is scaled discipline-wise. The sub-residual associated wich each discipline is scaled by the Euclidean norm of the initial sub-residual (if not null, else it is not scaled). The MDA is considered converged when the Euclidean norm of each sub-residual satisfies,

\[\max_i \left| \frac{\|r^i_k\|_2}{\|r^i_0\|_2} \right| \leq \text{tol}.\]
Type:

The

Type:

math

NO_SCALING = 'no_scaling'#

The residual vector is not scaled. The MDA is considered converged when its Euclidean norm satisfies,

\[\|R_k\|_2 \leq \text{tol}.\]
N_COUPLING_VARIABLES = 'n_coupling_variables'#

k`-th residual vector is scaled using the number of coupling variables. The MDA is considered converged when its Euclidean norm satisfies, .. math:

\frac{ \|R_k\|_2 }{ \sqrt{n_\text{coupl.}} } \leq \text{tol}.
Type:

The

Type:

math

SCALED_INITIAL_RESIDUAL_COMPONENT = 'scaled_initial_residual_component'#

k`-th residual vector is scaled component-wise and by the number coupling variables. If \(\div\) denotes the component-wise division between two vectors, then the MDA is considered converged when the residual vector satisfies,

\[\frac{1}{\sqrt{n_\text{coupl.}}} \| R_k \div R_0 \|_2 \leq \text{tol}.\]
Type:

The

Type:

math

execute(input_data=mappingproxy({}))[source]#

Execute the discipline, i.e. compute output data from input data.

If virtual_execution is True, this method returns the default_output_data. Otherwise, it calls the _run() method performing the true execution and returns the corresponding output data. This _run() method must be implemented in subclasses.

Parameters:

input_data (StrKeyMapping) --

The input data. Complete this dictionary with the default_input_data.

By default it is set to {}.

Returns:

The input and output data.

Return type:

DisciplineData

plot_residual_history(show=False, save=True, n_iterations=None, logscale=(), filename='', fig_size=())[source]#

Generate a plot of the residual history.

The first iteration of each new execution is marked with a red dot.

Parameters:
  • show (bool) --

    Whether to display the plot on screen.

    By default it is set to False.

  • save (bool) --

    Whether to save the plot as a PDF file.

    By default it is set to True.

  • n_iterations (int | None) -- The number of iterations on the x axis. If None, use all the iterations.

  • logscale (tuple[float, float]) --

    The limits of the y axis. If empty, do not change the limits of the y axis.

    By default it is set to ().

  • filename (Path | str) --

    The name of the file to save the figure. If empty, use "{mda.name}_residual_history.pdf".

    By default it is set to "".

  • fig_size (FigSizeType) --

    The width and height of the figure in inches, e.g. (w, h).

    By default it is set to ().

Returns:

The figure, to be customized if not closed.

Return type:

Figure

NORMALIZED_RESIDUAL_NORM: Final[str] = 'MDA residuals norm'#
Settings: ClassVar[type[BaseMDASettings]]#

The Pydantic model for the settings.

assembly: JacobianAssembly#

The Jacobian assembly.

coupling_structure: CouplingStructure#

The coupling structure to be used by the MDA.

default_cache_type: ClassVar[_CacheType] = 'SimpleCache'#

The default type of cache.

lin_cache_tol_fact: float#

The tolerance factor to cache the Jacobian.

matrix_type: JacobianAssembly.JacobianType#

The type of the matrix.

norm0: float | None#

The reference residual, if any.

normed_residual: float#

The normed residual.

reset_history_each_run: bool#

Whether to reset the history of MDA residuals before each run.

residual_history: list[float]#

The history of the MDA residuals.

property scaling: ResidualScaling#

The scaling method applied to MDA residuals for convergence monitoring.

settings: BaseMDASettings#

The settings of the MDA.