Skip to content

Commit

Permalink
Merge pull request #1558 from pymor/irka-init-fix
Browse files Browse the repository at this point in the history
IRKA initialization fixes
  • Loading branch information
pmli committed Feb 10, 2022
2 parents d69e1be + 79ed066 commit a0b0a8e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/pymor/reductors/h2.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _check_rom0_params(self, rom0_params):
elif isinstance(rom0_params, np.ndarray):
assert rom0_params.ndim == 1
elif isinstance(rom0_params, dict):
assert ('sigma', 'b', 'c') in rom0_params
assert {'sigma', 'b', 'c'} <= rom0_params.keys()
assert isinstance(rom0_params['sigma'], np.ndarray)
assert isinstance(rom0_params['b'], np.ndarray)
assert isinstance(rom0_params['c'], np.ndarray)
Expand All @@ -77,7 +77,7 @@ def _check_rom0_params(self, rom0_params):
elif isinstance(rom0_params, LTIModel):
assert rom0_params.order > 0
if hasattr(self.fom, 'order'): # self.fom can be a TransferFunction
assert rom0_params < self.fom.order
assert rom0_params.order < self.fom.order
assert rom0_params.dim_input == self.fom.dim_input
assert rom0_params.dim_output == self.fom.dim_output
else:
Expand Down
4 changes: 4 additions & 0 deletions src/pymortests/reductors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file is part of the pyMOR project (https://www.pymor.org).
# Copyright pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)

32 changes: 32 additions & 0 deletions src/pymortests/reductors/h2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file is part of the pyMOR project (https://www.pymor.org).
# Copyright pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)

import numpy as np

from pymor.models.iosys import LTIModel
from pymor.reductors.h2 import IRKAReductor


def test_irka():
A = np.array([[-1, 0], [0, -2]])
B = np.array([[1], [2]])
C = np.array([[2, 1]])
fom = LTIModel.from_matrices(A, B, C)
irka = IRKAReductor(fom)

rom = irka.reduce(1)
assert isinstance(rom, LTIModel) and rom.order == 1

rom = irka.reduce(np.array([1]))
assert isinstance(rom, LTIModel) and rom.order == 1

rom = irka.reduce({'sigma': np.array([1]),
'b': np.array([[1]]),
'c': np.array([[1]])})
assert isinstance(rom, LTIModel) and rom.order == 1

rom = irka.reduce(LTIModel.from_matrices(np.array([[-1]]),
np.array([[1]]),
np.array([[1]])))
assert isinstance(rom, LTIModel) and rom.order == 1

0 comments on commit a0b0a8e

Please sign in to comment.