-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
64 lines (51 loc) · 1.45 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import subprocess
from pathlib import Path
import numpy as np
from pymor.models.iosys import LTIModel
def gab08():
"""Return the model from Gugercin/Antoulas/Beattie '08.
This is order-3 example from:
S. Gugercin, A. C. Antoulas, C. A. Beattie,
H2 Model Reduction for Large-Scale Linear Dynamical Systems,
SIAM J. Matrix Anal. Appl.,
2008,
doi: 10.1137/060666123
"""
A = np.array([[0, 1, 0], [0, 0, 1], [-15 / 32, -17 / 16, -2]])
B = np.array([[0], [0], [1]])
C = np.array([[5 / 4, 7 / 4, -1]])
return LTIModel.from_matrices(A, B, C)
def slicot_model(name):
"""Load SLICOT model.
Parameters
----------
name : str
Model name.
Returns
-------
m : LTIModel
Model.
"""
name_list = [
'CDplayer',
'beam',
'build',
'eady',
'fom',
'heat-cont',
'iss',
'pde',
'random',
'tline',
]
if name not in name_list:
raise ValueError(f'Unknown model name ({name})')
if not Path(name + '.mat').exists():
_download_slicot_model(name)
return LTIModel.from_mat_file(name)
def _download_slicot_model(name):
url = f'https://www.slicot.org/objects/software/shared/bench-data/{name}.zip'
zip_file_name = f'{name}.zip'
subprocess.run(['wget', url], check=True)
subprocess.run(['unzip', zip_file_name], check=True)
subprocess.run(['rm', zip_file_name], check=True)