diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..8ebc8d55edf504270de78436c3fe7068409472e8 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ + +.PHONY: index.html + + +index: index.html + +index.html: index.md + pandoc -t html $< > $@ + diff --git a/README.md b/README.md index 75a671c7e25ee85ab28c1f567fa196dfd0bb7a8e..de7e29f56fa18a550d03441aa95c0da8886ffd3c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # school-material + diff --git a/index.html b/index.html new file mode 100644 index 0000000000000000000000000000000000000000..fc93023c190561cd1bdb8b3f85696aeda0fb4937 --- /dev/null +++ b/index.html @@ -0,0 +1,4 @@ +<h1 id="school-material">school-material</h1> +<ul> +<li><a href="monday/">monday excercises</a></li> +</ul> diff --git a/index.md b/index.md new file mode 100644 index 0000000000000000000000000000000000000000..94bab12a0ae336320949c2abe7f3e4dd80a6c2fd --- /dev/null +++ b/index.md @@ -0,0 +1,4 @@ +# school-material + +- [monday excercises](monday/) + diff --git a/monday/parametric_delay.ipynb b/monday/parametric_delay.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..3fd86279169c35837677e6259c25b03225e22655 --- /dev/null +++ b/monday/parametric_delay.ipynb @@ -0,0 +1,211 @@ +{ + "cells": [ + { + "cell_type": "raw", + "metadata": {}, + "source": [ + "This file is part of the pyMOR project (http://www.pymor.org).\n", + "Copyright 2013-2019 pyMOR developers and contributors. All rights reserved.\n", + "License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import scipy.linalg as spla\n", + "import matplotlib as mpl\n", + "import matplotlib.pyplot as plt\n", + "\n", + "from pymor.basic import *" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def H(s, mu):\n", + " tau = mu['tau']\n", + " return np.array([[np.exp(-s) / (tau * s + 1)]])\n", + "\n", + "def dH(s, mu):\n", + " tau = mu['tau']\n", + " return np.array([[-(tau * s + tau + 1) * np.exp(-s) / (tau * s + 1) ** 2]])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "f = ProjectionParameterFunctional('tau', ())\n", + "parameter_space = CubicParameterSpace(f.parameter_type, 0.01, 1)\n", + "\n", + "fom = TransferFunction(NumpyVectorSpace(1), NumpyVectorSpace(1),\n", + " H, dH,\n", + " parameter_space=parameter_space)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Magnitude plot" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "mu_list_short = [0.01, 0.1, 1]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "w = np.logspace(-2, 4, 100)\n", + "\n", + "fig, ax = plt.subplots()\n", + "for mu in mu_list_short:\n", + " fom.mag_plot(w, ax=ax, mu=mu, label=fr'$\\tau = {mu}$')\n", + "ax.legend()\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "w_list = np.logspace(-2, 4, 100)\n", + "mu_list = np.logspace(-2, 0, 50)\n", + "\n", + "fom_w_mu = np.zeros((len(w_list), len(mu_list)))\n", + "for i, mu in enumerate(mu_list):\n", + " fom_w_mu[:, i] = spla.norm(fom.freq_resp(w_list, mu=mu), axis=(1, 2))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = plt.subplots()\n", + "out = ax.contourf(w_list, mu_list, fom_w_mu.T,\n", + " norm=mpl.colors.LogNorm(),\n", + " levels=np.logspace(np.log10(fom_w_mu.min()), np.log10(fom_w_mu.max()), 100))\n", + "ax.set_xlabel(r'Frequency $\\omega$')\n", + "ax.set_ylabel(r'Parameter $\\mu$')\n", + "ax.set_xscale('log')\n", + "ax.set_yscale('log')\n", + "fig.colorbar(out, ticks=np.logspace(-4, 1, 6))\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# TF-IRKA" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "r = 10\n", + "roms_tf_irka = []\n", + "for mu in mu_list_short:\n", + " tf_irka = TFIRKAReductor(fom, mu=mu)\n", + " rom = tf_irka.reduce(r, conv_crit='h2', maxit=1000, num_prev=5)\n", + " roms_tf_irka.append(rom)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = plt.subplots()\n", + "for mu, rom in zip(mu_list_short, roms_tf_irka):\n", + " poles = rom.poles()\n", + " ax.plot(poles.real, poles.imag, '.', label=fr'$\\tau = {mu}$')\n", + "ax.set_title(\"Poles of TF-IRKA's ROMs\")\n", + "ax.legend()\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = plt.subplots()\n", + "for mu, rom in zip(mu_list_short, roms_tf_irka):\n", + " rom.mag_plot(w, ax=ax, label=fr'$\\tau = {mu}$')\n", + "ax.set_title(\"Magnitude plot of TF-IRKA's ROMs\")\n", + "ax.legend()\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = plt.subplots()\n", + "for mu, rom in zip(mu_list_short, roms_tf_irka):\n", + " (fom - rom).mag_plot(w, ax=ax, mu=mu, label=fr'$\\tau = {mu}$')\n", + "ax.set_title(\"Magnitude plot of error systems\")\n", + "ax.legend()\n", + "plt.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}