From 995443c9b4812208d74cfdc9a471c801d7783dd3 Mon Sep 17 00:00:00 2001 From: Alexandre SCOTTO DI PERROTOLO Date: Mon, 20 Nov 2023 13:18:08 +0100 Subject: [PATCH 1/4] Add file. --- .../mda/plot_acceleration_methods.py | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 doc_src/_examples/mda/plot_acceleration_methods.py 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 0000000000..0c769a82a6 --- /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 configure_logger +from gemseo import create_discipline +from gemseo import create_mda +from gemseo.algos.sequence_transformer.acceleration import AccelerationMethod + +configure_logger() + +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 could be +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`. + +At instanciation: +""" + +mda = create_mda( + "MDAJacobi", + disciplines, + acceleration_method=AccelerationMethod.SECANT, + over_relaxation_factor=0.95, +) +""" +Or via the corresponding attributed: +""" + +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, save=False, show=True) +""" +With secant acceleration: +""" +mda.cache.clear() +mda.acceleration_method = AccelerationMethod.SECANT + +mda.execute() +mda.plot_residual_history(n_iterations=10, save=False, show=True) +""" +With relaxation: +""" +mda.cache.clear() +mda.acceleration_method = AccelerationMethod.NONE +mda.over_relaxation_factor = 0.9 + +mda.execute() +mda.plot_residual_history(n_iterations=10, save=False, show=True) -- GitLab From fbf851a16e1d0920878415dae3356482b4a0286c Mon Sep 17 00:00:00 2001 From: Alexandre SCOTTO DI PERROTOLO Date: Tue, 21 Nov 2023 16:51:35 +0100 Subject: [PATCH 2/4] Turn text to in-line comments. --- .../mda/plot_acceleration_methods.py | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/doc_src/_examples/mda/plot_acceleration_methods.py b/doc_src/_examples/mda/plot_acceleration_methods.py index 0c769a82a6..36df4a7cbc 100644 --- a/doc_src/_examples/mda/plot_acceleration_methods.py +++ b/doc_src/_examples/mda/plot_acceleration_methods.py @@ -23,13 +23,10 @@ techniques. from __future__ import annotations -from gemseo import configure_logger from gemseo import create_discipline from gemseo import create_mda from gemseo.algos.sequence_transformer.acceleration import AccelerationMethod -configure_logger() - disciplines = create_discipline( [ "SobieskiStructure", @@ -38,18 +35,19 @@ disciplines = create_discipline( "SobieskiMission", ] ) -""" -%% -Acceleration methods integration within MDAs --------------------------------------------- -The user can specify an over-relaxation factor and an acceleration method. This could be -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`. - -At instanciation: -""" + +# %% +# 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", @@ -57,38 +55,40 @@ mda = create_mda( acceleration_method=AccelerationMethod.SECANT, over_relaxation_factor=0.95, ) -""" -Or via the corresponding attributed: -""" + +# %% +# 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: -""" +# %% +# 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, save=False, show=True) -""" -With secant acceleration: -""" +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, save=False, show=True) -""" -With relaxation: -""" +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.NONE mda.over_relaxation_factor = 0.9 mda.execute() -mda.plot_residual_history(n_iterations=10, save=False, show=True) +mda.plot_residual_history(n_iterations=10, fig_size=(2, 4), save=False, show=True) -- GitLab From 4bc6f8ec95e4d063d681f3a8cf3fc3360c830e83 Mon Sep 17 00:00:00 2001 From: Alexandre SCOTTO DI PERROTOLO Date: Wed, 22 Nov 2023 09:12:56 +0100 Subject: [PATCH 3/4] Fix typo. --- doc_src/_examples/mda/plot_acceleration_methods.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc_src/_examples/mda/plot_acceleration_methods.py b/doc_src/_examples/mda/plot_acceleration_methods.py index 36df4a7cbc..34617fb6e7 100644 --- a/doc_src/_examples/mda/plot_acceleration_methods.py +++ b/doc_src/_examples/mda/plot_acceleration_methods.py @@ -84,7 +84,7 @@ mda.execute() mda.plot_residual_history(n_iterations=10, fig_size=(2, 4), save=False, show=True) # %% -# With secant acceleration alone: +# With relaxation alone: mda.cache.clear() mda.acceleration_method = AccelerationMethod.NONE -- GitLab From 06e493b18942d68fef82552d5c26a6016715c6da Mon Sep 17 00:00:00 2001 From: Alexandre SCOTTO DI PERROTOLO Date: Tue, 28 Nov 2023 14:09:50 +0100 Subject: [PATCH 4/4] Apply suggestions from reviewer. --- .../mda/plot_acceleration_methods.py | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/doc_src/_examples/mda/plot_acceleration_methods.py b/doc_src/_examples/mda/plot_acceleration_methods.py index 34617fb6e7..f921fab362 100644 --- a/doc_src/_examples/mda/plot_acceleration_methods.py +++ b/doc_src/_examples/mda/plot_acceleration_methods.py @@ -68,27 +68,27 @@ mda.over_relaxation_factor = 1.5 # # Without acceleration and relaxation: -mda.acceleration_method = AccelerationMethod.NONE -mda.over_relaxation_factor = 1.0 +# 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) +# 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.cache.clear() +# mda.acceleration_method = AccelerationMethod.SECANT -mda.execute() -mda.plot_residual_history(n_iterations=10, fig_size=(2, 4), save=False, show=True) +# 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.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) +# mda.execute() +# mda.plot_residual_history(n_iterations=10, fig_size=(2, 4), save=False, show=True) -- GitLab