Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
school-material
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pyMOR
school-material
Commits
378edfb6
Unverified
Commit
378edfb6
authored
5 years ago
by
René Fritze
Browse files
Options
Downloads
Patches
Plain Diff
init
parent
afe237bb
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Makefile
+9
-0
9 additions, 0 deletions
Makefile
README.md
+1
-0
1 addition, 0 deletions
README.md
index.html
+4
-0
4 additions, 0 deletions
index.html
index.md
+4
-0
4 additions, 0 deletions
index.md
monday/parametric_delay.ipynb
+211
-0
211 additions, 0 deletions
monday/parametric_delay.ipynb
with
229 additions
and
0 deletions
Makefile
0 → 100644
+
9
−
0
View file @
378edfb6
.PHONY
:
index.html
index
:
index.html
index.html
:
index.md
pandoc
-t
html
$<
>
$@
This diff is collapsed.
Click to expand it.
README.md
+
1
−
0
View file @
378edfb6
# school-material
This diff is collapsed.
Click to expand it.
index.html
0 → 100644
+
4
−
0
View file @
378edfb6
<h1
id=
"school-material"
>
school-material
</h1>
<ul>
<li><a
href=
"monday/"
>
monday excercises
</a></li>
</ul>
This diff is collapsed.
Click to expand it.
index.md
0 → 100644
+
4
−
0
View file @
378edfb6
# school-material
-
[
monday excercises
](
monday/
)
This diff is collapsed.
Click to expand it.
monday/parametric_delay.ipynb
0 → 100644
+
211
−
0
View file @
378edfb6
{
"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
}
%% Cell type:raw id: tags:
This file is part of the pyMOR project (http://www.pymor.org).
Copyright 2013-2019 pyMOR developers and contributors. All rights reserved.
License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
%% Cell type:code id: tags:
```
python
import
numpy
as
np
import
scipy.linalg
as
spla
import
matplotlib
as
mpl
import
matplotlib.pyplot
as
plt
from
pymor.basic
import
*
```
%% Cell type:markdown id: tags:
# Model
%% Cell type:code id: tags:
```
python
def
H
(
s
,
mu
):
tau
=
mu
[
'
tau
'
]
return
np
.
array
([[
np
.
exp
(
-
s
)
/
(
tau
*
s
+
1
)]])
def
dH
(
s
,
mu
):
tau
=
mu
[
'
tau
'
]
return
np
.
array
([[
-
(
tau
*
s
+
tau
+
1
)
*
np
.
exp
(
-
s
)
/
(
tau
*
s
+
1
)
**
2
]])
```
%% Cell type:code id: tags:
```
python
f
=
ProjectionParameterFunctional
(
'
tau
'
,
())
parameter_space
=
CubicParameterSpace
(
f
.
parameter_type
,
0.01
,
1
)
fom
=
TransferFunction
(
NumpyVectorSpace
(
1
),
NumpyVectorSpace
(
1
),
H
,
dH
,
parameter_space
=
parameter_space
)
```
%% Cell type:markdown id: tags:
# Magnitude plot
%% Cell type:code id: tags:
```
python
mu_list_short
=
[
0.01
,
0.1
,
1
]
```
%% Cell type:code id: tags:
```
python
w
=
np
.
logspace
(
-
2
,
4
,
100
)
fig
,
ax
=
plt
.
subplots
()
for
mu
in
mu_list_short
:
fom
.
mag_plot
(
w
,
ax
=
ax
,
mu
=
mu
,
label
=
fr
'
$\tau =
{
mu
}
$
'
)
ax
.
legend
()
plt
.
show
()
```
%% Cell type:code id: tags:
```
python
w_list
=
np
.
logspace
(
-
2
,
4
,
100
)
mu_list
=
np
.
logspace
(
-
2
,
0
,
50
)
fom_w_mu
=
np
.
zeros
((
len
(
w_list
),
len
(
mu_list
)))
for
i
,
mu
in
enumerate
(
mu_list
):
fom_w_mu
[:,
i
]
=
spla
.
norm
(
fom
.
freq_resp
(
w_list
,
mu
=
mu
),
axis
=
(
1
,
2
))
```
%% Cell type:code id: tags:
```
python
fig
,
ax
=
plt
.
subplots
()
out
=
ax
.
contourf
(
w_list
,
mu_list
,
fom_w_mu
.
T
,
norm
=
mpl
.
colors
.
LogNorm
(),
levels
=
np
.
logspace
(
np
.
log10
(
fom_w_mu
.
min
()),
np
.
log10
(
fom_w_mu
.
max
()),
100
))
ax
.
set_xlabel
(
r
'
Frequency $\omega$
'
)
ax
.
set_ylabel
(
r
'
Parameter $\mu$
'
)
ax
.
set_xscale
(
'
log
'
)
ax
.
set_yscale
(
'
log
'
)
fig
.
colorbar
(
out
,
ticks
=
np
.
logspace
(
-
4
,
1
,
6
))
plt
.
show
()
```
%% Cell type:markdown id: tags:
# TF-IRKA
%% Cell type:code id: tags:
```
python
r
=
10
roms_tf_irka
=
[]
for
mu
in
mu_list_short
:
tf_irka
=
TFIRKAReductor
(
fom
,
mu
=
mu
)
rom
=
tf_irka
.
reduce
(
r
,
conv_crit
=
'
h2
'
,
maxit
=
1000
,
num_prev
=
5
)
roms_tf_irka
.
append
(
rom
)
```
%% Cell type:code id: tags:
```
python
fig
,
ax
=
plt
.
subplots
()
for
mu
,
rom
in
zip
(
mu_list_short
,
roms_tf_irka
):
poles
=
rom
.
poles
()
ax
.
plot
(
poles
.
real
,
poles
.
imag
,
'
.
'
,
label
=
fr
'
$\tau =
{
mu
}
$
'
)
ax
.
set_title
(
"
Poles of TF-IRKA
'
s ROMs
"
)
ax
.
legend
()
plt
.
show
()
```
%% Cell type:code id: tags:
```
python
fig
,
ax
=
plt
.
subplots
()
for
mu
,
rom
in
zip
(
mu_list_short
,
roms_tf_irka
):
rom
.
mag_plot
(
w
,
ax
=
ax
,
label
=
fr
'
$\tau =
{
mu
}
$
'
)
ax
.
set_title
(
"
Magnitude plot of TF-IRKA
'
s ROMs
"
)
ax
.
legend
()
plt
.
show
()
```
%% Cell type:code id: tags:
```
python
fig
,
ax
=
plt
.
subplots
()
for
mu
,
rom
in
zip
(
mu_list_short
,
roms_tf_irka
):
(
fom
-
rom
).
mag_plot
(
w
,
ax
=
ax
,
mu
=
mu
,
label
=
fr
'
$\tau =
{
mu
}
$
'
)
ax
.
set_title
(
"
Magnitude plot of error systems
"
)
ax
.
legend
()
plt
.
show
()
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment