Commit 15bb2005 authored by Petar Mlinarić's avatar Petar Mlinarić Committed by René Fritze

[demos] add order parameters to sys-mor demos

parent d1c338b4
......@@ -7,20 +7,21 @@
import matplotlib.pyplot as plt
import numpy as np
import scipy.linalg as spla
from typer import run
from typer import Option, run
from pymor.models.iosys import TransferFunction
from pymor.reductors.interpolation import TFBHIReductor
from pymor.reductors.h2 import TFIRKAReductor
def main():
def main(
tau: float = Option(0.1, help='The time delay.'),
r: int = Option(10, help='Order of the TF-IRKA ROM.'),
):
"""Delay demo
Cascade of delay and integrator
"""
tau = 0.1
def H(s):
return np.array([[np.exp(-s) / (tau * s + 1)]])
......@@ -29,7 +30,6 @@ def main():
tf = TransferFunction(1, 1, H, dH)
r = 10
tf_irka_reductor = TFIRKAReductor(tf)
rom = tf_irka_reductor.reduce(r, maxit=1000)
......
......@@ -5,7 +5,7 @@
import numpy as np
import matplotlib.pyplot as plt
from typer import run
from typer import Option, run
from pymor.basic import (InstationaryProblem, StationaryProblem, RectDomain, ConstantFunction, ExpressionFunction,
discretize_instationary_cg, BTReductor, IRKAReductor)
......@@ -15,7 +15,10 @@ import logging
logging.getLogger('pymor.algorithms.gram_schmidt.gram_schmidt').setLevel(logging.ERROR)
def main():
def main(
diameter: float = Option(0.1, help='Diameter option for the domain discretizer.'),
r: int = Option(5, help='Order of the ROMs.'),
):
r"""2D heat equation demo
Discretization of the PDE:
......@@ -47,7 +50,7 @@ def main():
T=1.
)
fom, _ = discretize_instationary_cg(p, diameter=1/10, nt=100)
fom, _ = discretize_instationary_cg(p, diameter=diameter, nt=100)
fom.visualize(fom.solve())
......@@ -87,7 +90,6 @@ def main():
print(f'FOM Hankel-norm: {lti.hankel_norm():e}')
# Balanced Truncation
r = 5
reductor = BTReductor(lti)
rom_bt = reductor.reduce(r, tol=1e-5)
err_bt = lti - rom_bt
......
......@@ -10,12 +10,12 @@ import numpy as np
import scipy.linalg as spla
import matplotlib as mpl
import matplotlib.pyplot as plt
from typer import run
from typer import Option, run
from pymor.basic import *
def main():
def main(r: int = Option(10, help='Order of the TF-IRKA ROM.')):
# # Model
# In[ ]:
......@@ -89,7 +89,6 @@ def main():
# In[ ]:
r = 10
roms_tf_irka = []
for mu in mu_list_short:
tf_irka = TFIRKAReductor(fom, mu=mu)
......
......@@ -15,7 +15,7 @@ import numpy as np
import scipy.linalg as spla
import matplotlib.pyplot as plt
import matplotlib as mpl
from typer import run
from typer import Option, run
from pymor.basic import *
from pymor.core.config import config
......@@ -23,7 +23,10 @@ from pymor.core.config import config
from pymor.core.logger import set_log_levels
def main():
def main(
diameter: float = Option(0.01, help='Diameter option for the domain discretizer.'),
r: int = Option(5, help='Order of the ROMs.'),
):
set_log_levels({'pymor.algorithms.gram_schmidt.gram_schmidt': 'WARNING'})
set_defaults({'pymor.discretizers.builtin.gui.jupyter.get_visualizer.backend': 'not pythreejs'})
......@@ -48,7 +51,7 @@ def main():
T=3.
)
fom, _ = discretize_instationary_cg(p, diameter=1/100, nt=100)
fom, _ = discretize_instationary_cg(p, diameter=diameter, nt=100)
# In[ ]:
......@@ -196,7 +199,6 @@ def main():
# In[ ]:
r = 5
mu_fine = np.logspace(-1, 1, 10)
h2_bt_err_mu, hinf_bt_err_mu, hankel_bt_err_mu = reduction_errors(lti, r, mu_fine, BTReductor)
......
......@@ -13,7 +13,7 @@
import numpy as np
import scipy.sparse as sps
import matplotlib.pyplot as plt
from typer import run
from typer import Option, run
from pymor.basic import *
from pymor.core.config import config
......@@ -21,7 +21,10 @@ from pymor.core.config import config
from pymor.core.logger import set_log_levels
def main():
def main(
n: int = Option(101, help='Order of the full second-order model (odd number).'),
r: int = Option(5, help='Order of the ROMs.'),
):
set_log_levels({'pymor.algorithms.gram_schmidt.gram_schmidt': 'WARNING'})
......@@ -30,8 +33,9 @@ def main():
# In[ ]:
n2 = 50
n = 2 * n2 - 1 # dimension of the system
assert n % 2 == 1, 'The order has to be an odd integer.'
n2 = (n + 1) // 2
k = 0.01 # stiffness
......@@ -147,7 +151,6 @@ def main():
# In[ ]:
r = 5
roms_sobtp = []
for mu in mu_list:
sobtp_reductor = SOBTpReductor(so_sys, mu=mu)
......@@ -205,7 +208,6 @@ def main():
# In[ ]:
r = 5
roms_sobtv = []
for mu in mu_list:
sobtv_reductor = SOBTvReductor(so_sys, mu=mu)
......@@ -263,7 +265,6 @@ def main():
# In[ ]:
r = 5
roms_sobtpv = []
for mu in mu_list:
sobtpv_reductor = SOBTpvReductor(so_sys, mu=mu)
......@@ -321,7 +322,6 @@ def main():
# In[ ]:
r = 5
roms_sobtvp = []
for mu in mu_list:
sobtvp_reductor = SOBTvpReductor(so_sys, mu=mu)
......@@ -379,7 +379,6 @@ def main():
# In[ ]:
r = 5
roms_sobtfv = []
for mu in mu_list:
sobtfv_reductor = SOBTfvReductor(so_sys, mu=mu)
......@@ -437,7 +436,6 @@ def main():
# In[ ]:
r = 5
roms_sobt = []
for mu in mu_list:
sobt_reductor = SOBTReductor(so_sys, mu=mu)
......@@ -495,7 +493,6 @@ def main():
# In[ ]:
r = 5
roms_bt = []
for mu in mu_list:
bt_reductor = BTReductor(so_sys.to_lti(), mu=mu)
......@@ -553,7 +550,6 @@ def main():
# In[ ]:
r = 5
roms_irka = []
for mu in mu_list:
irka_reductor = IRKAReductor(so_sys.to_lti(), mu=mu)
......@@ -611,7 +607,6 @@ def main():
# In[ ]:
r = 5
roms_sor_irka = []
for mu in mu_list:
sor_irka_reductor = SORIRKAReductor(so_sys, mu=mu)
......
......@@ -11,7 +11,7 @@ import scipy.linalg as spla
import scipy.sparse as sps
import matplotlib.pyplot as plt
import matplotlib as mpl
from typer import run
from typer import Option, run
from pymor.core.config import config
from pymor.models.iosys import LTIModel
......@@ -21,16 +21,16 @@ from pymor.reductors.bt import BTReductor
from pymor.reductors.h2 import IRKAReductor
def main():
def main(
n: int = Option(100, help='Order of the FOM.'),
r: int = Option(20, help='Order of the ROMs.'),
):
# # Model
#
# https://morwiki.mpi-magdeburg.mpg.de/morwiki/index.php/Synthetic_parametric_model
# In[ ]:
n = 100 # order of the resulting system
# set coefficients
a = -np.linspace(1e1, 1e3, n // 2)
b = np.linspace(1e1, 1e3, n // 2)
......@@ -179,7 +179,6 @@ def main():
# In[ ]:
r = 20
mu_fine = np.linspace(1/50, 1, 10)
(
h2_bt_err_mu,
......
......@@ -6,7 +6,7 @@
import matplotlib.pyplot as plt
import numpy as np
import scipy.sparse as sps
from typer import run
from typer import Option, run
from pymor.core.config import config
from pymor.models.iosys import SecondOrderModel
......@@ -20,11 +20,15 @@ import logging
logging.getLogger('pymor.algorithms.gram_schmidt.gram_schmidt').setLevel(logging.ERROR)
def main():
def main(
n: int = Option(101, help='Order of the full second-order model (odd number).'),
r: int = Option(5, help='Order of the ROMs.'),
):
"""String equation example."""
# Assemble matrices
n2 = 50
n = 2 * n2 - 1 # dimension of the system
assert n % 2 == 1, 'The order has to be an odd integer.'
n2 = (n + 1) // 2
d = 10 # damping
k = 0.01 # stiffness
......@@ -83,7 +87,6 @@ def main():
print(f'FOM Hankel-norm: {so_sys.hankel_norm():e}')
# Position Second-Order Balanced Truncation (SOBTp)
r = 5
sobtp_reductor = SOBTpReductor(so_sys)
rom_sobtp = sobtp_reductor.reduce(r)
......@@ -113,7 +116,6 @@ def main():
plt.show()
# Velocity Second-Order Balanced Truncation (SOBTv)
r = 5
sobtv_reductor = SOBTvReductor(so_sys)
rom_sobtv = sobtv_reductor.reduce(r)
......@@ -143,7 +145,6 @@ def main():
plt.show()
# Position-Velocity Second-Order Balanced Truncation (SOBTpv)
r = 5
sobtpv_reductor = SOBTpvReductor(so_sys)
rom_sobtpv = sobtpv_reductor.reduce(r)
......@@ -173,7 +174,6 @@ def main():
plt.show()
# Velocity-Position Second-Order Balanced Truncation (SOBTvp)
r = 5
sobtvp_reductor = SOBTvpReductor(so_sys)
rom_sobtvp = sobtvp_reductor.reduce(r)
......@@ -203,7 +203,6 @@ def main():
plt.show()
# Free-Velocity Second-Order Balanced Truncation (SOBTfv)
r = 5
sobtfv_reductor = SOBTfvReductor(so_sys)
rom_sobtfv = sobtfv_reductor.reduce(r)
......@@ -233,7 +232,6 @@ def main():
plt.show()
# Second-Order Balanced Truncation (SOBT)
r = 5
sobt_reductor = SOBTReductor(so_sys)
rom_sobt = sobt_reductor.reduce(r)
......@@ -263,7 +261,6 @@ def main():
plt.show()
# Balanced Truncation (BT)
r = 5
bt_reductor = BTReductor(so_sys.to_lti())
rom_bt = bt_reductor.reduce(r)
......@@ -293,7 +290,6 @@ def main():
plt.show()
# Iterative Rational Krylov Algorithm (IRKA)
r = 5
irka_reductor = IRKAReductor(so_sys.to_lti())
rom_irka = irka_reductor.reduce(r)
......@@ -328,7 +324,6 @@ def main():
plt.show()
# Second-Order Reduced Iterative Rational Krylov Algorithm (SOR-IRKA)
r = 5
sor_irka_reductor = SORIRKAReductor(so_sys)
rom_sor_irka = sor_irka_reductor.reduce(r)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment