gemseo / core

jacobian_assembly module

Coupled derivatives calculations

class gemseo.core.jacobian_assembly.CoupledSystem[source]

Bases: object

This class contains methods that compute coupled (total) derivatives of a system of residuals, using several methods: - direct or adjoint - factorized for multiple RHS

Constructor

adjoint_mode(functions, dres_dx, dres_dy_t, dfun_dx, dfun_dy, linear_solver, use_lu_fact, **kwargs)[source]

Computation of total derivative Jacobian in adjoint mode

Parameters
  • functions – functions to differentiate

  • dres_dx – Jacobian of residuals wrt design variables

  • dres_dy – Jacobian of residuals wrt coupling variables

  • dfun_dx – Jacobian of functions wrt design variables

  • dfun_dy – Jacobian of functions wrt coupling variables

  • linear_solver – name of the linear solver

  • use_lu_fact – if True, factorize dres_dy_t once

  • kwargs (dict) – optional parameters

  • dres_dy_t – param kwargs

direct_mode(functions, n_variables, n_couplings, dres_dx, dres_dy, dfun_dx, dfun_dy, linear_solver, use_lu_fact, **kwargs)[source]

Computation of total derivative Jacobian in direct mode

Parameters
  • functions – functions to differentiate

  • n_variables – number of variables

  • n_couplings – number of couplings

  • dres_dx – Jacobian of residuals wrt design variables

  • dres_dy – Jacobian of residuals wrt coupling variables

  • dfun_dx – Jacobian of functions wrt design variables

  • dfun_dy – Jacobian of functions wrt coupling variables

  • linear_solver – name of the linear solver

  • use_lu_fact – if True, factorize dres_dy once

  • kwargs (dict) – optional parameters

class gemseo.core.jacobian_assembly.JacobianAssembly(coupling_structure)[source]

Bases: object

Assembly of Jacobians Typically, assemble disciplines’s Jacobians into a system Jacobian

Constructor of the assembly

Parameters

coupling_structure – the disciplines that form the coupled system

ADJOINT_MODE = 'adjoint'
AUTO_MODE = 'auto'
AVAILABLE_MAT_TYPES = ['sparse', 'linear_operator']
AVAILABLE_MODES = ('direct', 'adjoint', 'auto', 'reverse')
AVAILABLE_SOLVERS = {'lgmres': <function lgmres>}
DIRECT_MODE = 'direct'
LINEAR_OPERATOR = 'linear_operator'
REVERSE_MODE = 'reverse'
SPARSE = 'sparse'
compute_dimension(names)[source]

Compute the total number of functions/variables/couplings of the whole system

Parameters

names – list of names of inputs or outputs

compute_newton_step(in_data, couplings, relax_factor, linear_solver='lgmres', matrix_type='linear_operator', **kwargs)[source]

Compute Newton step for the the coupled system of residuals formed by the disciplines

Parameters
  • in_data – input data dict

  • couplings – the coupling variables

  • relax_factor – the relaxation factor

  • linear_solver – the name of the linear solver (Default value = ‘lgmres’)

  • matrix_type – representation of the matrix dR/dy (sparse or linear operator) (Default value = LINEAR_OPERATOR)

  • kwargs – optional parameters for the linear solver

Returns

The Newton step -[dR/dy]^-1 . R as a dict of steps per coupling variable

compute_sizes(functions, variables, couplings)[source]

Computes the number of scalar functions, variables and couplings

Parameters
  • functions – the functions to differentiate

  • variables – the differentiation variables

  • couplings – the coupling variables

dfun_dvar(function, variables, n_variables)[source]

Forms the matrix of partial derivatives of a function Given disciplinary Jacobians dJi(v0…vn)/dvj, fill the sparse Jacobian: | | | dJi/dvj | | |

Parameters
  • function – the function to differentiate

  • variables – the differentiation variables

  • n_variables – number of variables

Returns

the full Jacobian matrix

dres_dvar(residuals, variables, n_residuals, n_variables, matrix_type='sparse', transpose=False)[source]

Forms the matrix of partial derivatives of residuals Given disciplinary Jacobians dYi(Y0…Yn)/dvj, fill the sparse Jacobian: | | | dRi/dvj | | | (Default value = False)

Parameters
  • residuals – the residuals (R)

  • variables – the differentiation variables

  • n_residuals – number of residuals

  • n_variables – number of variables

  • matrix_type – type of the matrix (Default value = SPARSE)

  • transpose – if True, transpose the matrix

plot_dependency_jacobian(functions=None, variables=None, save=True, show=False, filepath=None, markersize=None)[source]

Plot the Jacobian matrix Nonzero elements of the sparse matrix are represented by blue squares

Parameters
  • functions – list of variables (Default value = None)

  • variables – list of variables (Default value = None)

  • show – if True, the plot is displayed (Default value = False)

  • save – if True, the plot is saved in a PDF file (Default value = True)

  • filepath – file path of the saved PDF

residuals(in_data, var_names)[source]

Forms the matrix of residuals wrt coupling variables Given disciplinary explicit calculations Yi(Y0_t,…Yn_t), fill the residual matrix:

[Y0(Y0_t,...Yn_t) - Y0_t]
[                       ]
[Yn(Y0_t,...Yn_t) - Yn_t]
Parameters
  • in_data – dictionary of values prescribed for the calculation of the residuals (Y0_t,…Yn_t)

  • var_names – names of variables associated with the residuals (R)

split_jac(coupled_system, variables)[source]

Splits a Jacobian dict into a dict of dict

Parameters
  • coupled_system – the derivatives to split

  • variables – variables wrt wich the differentiation is performed

Returns

the Jacobian as a dict of dict

total_derivatives(in_data, functions, variables, couplings, linear_solver='lgmres', mode='auto', matrix_type='sparse', use_lu_fact=False, exec_cache_tol=None, force_no_exec=False, **kwargs)[source]

Computes the Jacobian of total derivatives of the coupled system formed by the disciplines

Parameters
  • in_data – input data dict

  • functions – the functions to differentiate

  • variables – the differentiation variables

  • couplings – the coupling variables

  • linear_solver – name of the linear solver (Default value = ‘lgmres’)

  • mode – linearization mode (auto, direct or adjoint) (Default value = AUTO_MODE)

  • matrix_type – representation of the matrix dR/dy (sparse or linear operator) (Default value = SPARSE)

  • use_lu_fact – if True, factorize dres_dy once (Default value = False), unsupported for linear operator mode

  • force_no_exec – if True, the discipline is not re executed, cache is loaded anyway

  • kwargs – dict of optional parameters

Returns

the dictionary of dictionary of coupled (total) derivatives

gemseo.core.jacobian_assembly.default_dict_factory()[source]

Instantiates a defaultdict(None) object

gemseo.core.jacobian_assembly.none_factory()[source]

Returns None… To be used for defaultdict