Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
pyMOR
pymor
Commits
4aef2182
Commit
4aef2182
authored
May 31, 2022
by
Patrick Buchfink
Committed by
Stephan Rave
Jun 10, 2022
Browse files
Move test to model.py
parent
b7415e17
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/pymortests/model.py
View file @
4aef2182
...
...
@@ -3,12 +3,18 @@
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)
import
numpy
as
np
import
pytest
from
pymor.algorithms.basic
import
almost_equal
from
pymor.algorithms.timestepping
import
ImplicitMidpointTimeStepper
from
pymor.analyticalproblems.functions
import
ExpressionFunction
,
ConstantFunction
from
pymor.analyticalproblems.thermalblock
import
thermal_block_problem
from
pymor.discretizers.builtin
import
discretize_stationary_cg
from
pymor.core.pickle
import
dumps
,
loads
from
pymor.models.symplectic
import
QuadraticHamiltonianModel
from
pymor.operators.block
import
BlockDiagonalOperator
from
pymor.operators.constructions
import
IdentityOperator
from
pymor.vectorarrays.numpy
import
NumpyVectorSpace
from
pymortests.base
import
runmodule
from
pymortests.pickling
import
assert_picklable
,
assert_picklable_without_dumps_function
...
...
@@ -49,5 +55,30 @@ def test_StationaryModel_deaffinize():
assert
np
.
allclose
(
m
.
output
(
mu
),
m_deaff
.
output
(
mu
))
@
pytest
.
mark
.
parametrize
(
'block_phase_space'
,
(
False
,
True
))
def
test_quadratic_hamiltonian_model
(
block_phase_space
):
"""Check QuadraticHamiltonianModel with implicit midpoint rule."""
if
block_phase_space
:
H_op
=
BlockDiagonalOperator
([
IdentityOperator
(
NumpyVectorSpace
(
1
))]
*
2
)
else
:
phase_space
=
NumpyVectorSpace
(
2
)
H_op
=
IdentityOperator
(
phase_space
)
model
=
QuadraticHamiltonianModel
(
3
,
H_op
.
source
.
ones
(),
H_op
,
time_stepper
=
ImplicitMidpointTimeStepper
(
3
),
name
=
'test_mass_spring_model'
)
res
=
model
.
solve
()
ham
=
model
.
eval_hamiltonian
(
res
).
to_numpy
()
# check preservation of the Hamiltonian
assert
np
.
allclose
(
ham
,
ham
[
0
])
if
__name__
==
"__main__"
:
runmodule
(
filename
=
__file__
)
src/pymortests/models/__init__.py
deleted
100644 → 0
View file @
b7415e17
# 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)
src/pymortests/models/symplectic.py
deleted
100644 → 0
View file @
b7415e17
import
numpy
as
np
import
pytest
from
pymor.algorithms.timestepping
import
ImplicitMidpointTimeStepper
from
pymor.models.symplectic
import
QuadraticHamiltonianModel
from
pymor.operators.block
import
BlockDiagonalOperator
from
pymor.operators.constructions
import
IdentityOperator
from
pymor.vectorarrays.numpy
import
NumpyVectorSpace
@
pytest
.
mark
.
parametrize
(
'block_phase_space'
,
(
False
,
True
))
def
test_quadratic_hamiltonian_model
(
block_phase_space
):
"""Check QuadraticHamiltonianModel with implicit midpoint rule."""
if
block_phase_space
:
H_op
=
BlockDiagonalOperator
([
IdentityOperator
(
NumpyVectorSpace
(
1
))]
*
2
)
else
:
phase_space
=
NumpyVectorSpace
(
2
)
H_op
=
IdentityOperator
(
phase_space
)
model
=
QuadraticHamiltonianModel
(
3
,
H_op
.
source
.
ones
(),
H_op
,
time_stepper
=
ImplicitMidpointTimeStepper
(
3
),
name
=
'test_mass_spring_model'
)
res
=
model
.
solve
()
ham
=
model
.
eval_hamiltonian
(
res
).
to_numpy
()
# check preservation of the Hamiltonian
assert
np
.
allclose
(
ham
,
ham
[
0
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment