Note
Click here to download the full example code
MDA¶
In this example, we will discover the different functions of the API
related to MDAs, which are the GEMSEO’ objects dedicated to the
feasibility of the multidisciplinary coupling. All classes
implementing MDAs inherit from MDA
which is an abstract class.
from __future__ import absolute_import, division, print_function, unicode_literals
from future import standard_library
from gemseo.api import (
configure_logger,
create_discipline,
create_mda,
get_available_mdas,
get_mda_options_schema,
)
configure_logger()
standard_library.install_aliases()
Get available MDA¶
The get_available_mdas()
function returns the list
of MDAs available in GEMSEO or in external modules
print(get_available_mdas())
Out:
['GSNewtonMDA', 'MDAChain', 'MDAGaussSeidel', 'MDAJacobi', 'MDANewtonRaphson', 'MDAQuasiNewton', 'MDARoot', 'MDASequential', 'SobieskiMDAGaussSeidel', 'SobieskiMDAJacobi']
Get MDA options schema¶
For a given MDA algorithm, e.g. "MDAGaussSeidel"
,
we can get the options; e.g.
print(get_mda_options_schema("MDAGaussSeidel"))
Out:
{'type': 'object', 'properties': {'name': {'description': 'the name of the chain\n:type name: str\n'}, 'max_mda_iter': {'type': 'integer', 'description': 'maximum number of iterations\n:type max_mda_iter: int\n'}, 'grammar_type': {'type': 'string', 'description': 'the type of grammar to use for IO declaration\neither JSON_GRAMMAR_TYPE or SIMPLE_GRAMMAR_TYPE\n:type grammar_type: str\n'}, 'tolerance': {'type': 'number', 'description': 'tolerance of the iterative direct coupling solver,\nnorm of the current residuals divided by initial residuals norm\nshall be lower than the tolerance to stop iterating\n:type tolerance: float\n'}, 'linear_solver_tolerance': {'type': 'number', 'description': 'Tolerance of the linear solver\nin the adjoint equation\n:type linear_solver_tolerance: float\n'}, 'warm_start': {'type': 'boolean', 'description': 'if True, the second iteration and ongoing\nstart from the previous coupling solution\n:type warm_start: bool\n'}, 'use_lu_fact': {'type': 'boolean', 'description': 'if True, when using adjoint/forward\ndifferenciation, store a LU factorization of the matrix\nto solve faster multiple RHS problem\n:type use_lu_fact: bool\n'}, 'norm0': {'description': 'reference value of the norm of the residual to compute\nthe decrease stop criteria.\nIterations stops when norm(residual)/norm0<tolerance\n:type norm0: float'}}, 'required': ['grammar_type', 'linear_solver_tolerance', 'max_mda_iter', 'tolerance', 'use_lu_fact', 'warm_start']}
Create a MDA¶
The API function create_mda()
can be used
to create a scenario:
disciplines = create_discipline(["Sellar1", "Sellar2"])
mda = create_mda("MDAGaussSeidel", disciplines)
output_data = mda.execute()
print(output_data)
Out:
{'x_local': array([0.+0.j]), 'x_shared': array([1.+0.j, 0.+0.j]), 'y_1': array([1.79999995+0.j]), 'y_0': array([0.79999995+0.j])}
Total running time of the script: ( 0 minutes 0.018 seconds)