diff --git a/doc_src/_examples/mda/plot_acceleration_methods.py b/doc_src/_examples/mda/plot_acceleration_methods.py new file mode 100644 index 0000000000000000000000000000000000000000..f921fab362fa3d47323ad82060827a6eb537d71e --- /dev/null +++ b/doc_src/_examples/mda/plot_acceleration_methods.py @@ -0,0 +1,94 @@ +# Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com +# +# This work is licensed under a BSD 0-Clause License. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING +# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION +# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +""" +Acceleration/relaxation for MDA +=============================== + +Convergence rate and/or stability of MDAs can be improved vie sequence transformation +techniques. +""" + +from __future__ import annotations + +from gemseo import create_discipline +from gemseo import create_mda +from gemseo.algos.sequence_transformer.acceleration import AccelerationMethod + +disciplines = create_discipline( + [ + "SobieskiStructure", + "SobieskiPropulsion", + "SobieskiAerodynamics", + "SobieskiMission", + ] +) + +# %% +# Acceleration methods integration within MDAs +# -------------------------------------------- +# The user can specify an over-relaxation factor and an acceleration method. This +# is done either at instanciation via the arguments `over_relaxation_factor` and +# `acceleration_method` respecitevely, or modified later via the attributes of +# same name. +# +# The available acceleration methods can be found in +# :mod:`~gemseo.algos.sequence_transformer.acceleration`. +# +# Definition at instanciation: + +mda = create_mda( + "MDAJacobi", + disciplines, + acceleration_method=AccelerationMethod.SECANT, + over_relaxation_factor=0.95, +) + +# %% +# Definition via the MDA's attributes: + +mda.acceleration_method = AccelerationMethod.ALTERNATE_2_DELTA +mda.over_relaxation_factor = 1.5 + +# %% +# Effect of the sequence transformations +# -------------------------------------- +# +# Without acceleration and relaxation: + +# mda.acceleration_method = AccelerationMethod.NONE +# mda.over_relaxation_factor = 1.0 + +# mda.execute() +# mda.plot_residual_history(n_iterations=10, fig_size=(2, 4), save=False, show=True) + +# %% +# With secant acceleration alone: + +# mda.cache.clear() +# mda.acceleration_method = AccelerationMethod.SECANT + +# mda.execute() +# mda.plot_residual_history(n_iterations=10, fig_size=(2, 4), save=False, show=True) + +# %% +# With relaxation alone: + +# mda.cache.clear() +# mda.acceleration_method = AccelerationMethod.NONE +# mda.over_relaxation_factor = 0.9 + +# mda.execute() +# mda.plot_residual_history(n_iterations=10, fig_size=(2, 4), save=False, show=True)