Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .ci/make_env_file.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from os.path import expanduser
from shlex import quote

home = expanduser("~")
home = expanduser('~')

prefixes = os.environ.get("ENV_PREFIXES", "TRAVIS CI encrypt TOKEN TESTS").split(" ")
blacklist = ["TRAVIS_COMMIT_MESSAGE"]
env_file = os.environ.get("ENV_FILE", os.path.join(home, "env"))
with open(env_file, "wt") as env:
prefixes = os.environ.get('ENV_PREFIXES', 'TRAVIS CI encrypt TOKEN TESTS').split(' ')
blacklist = ['TRAVIS_COMMIT_MESSAGE']
env_file = os.environ.get('ENV_FILE', os.path.join(home, 'env'))
with open(env_file, 'w') as env:
for k, v in os.environ.items():
for pref in prefixes:
if k.startswith(pref) and k not in blacklist:
env.write("{}={}\n".format(k, quote(v)))
env.write(f'{k}={quote(v)}\n')
37 changes: 23 additions & 14 deletions src/pymor_dealii/pymor/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
# Copyright 2013-2018 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

from pymor.basic import *
from dealii_elasticity import ElasticityExample
from pymor.basic import (
CoerciveRBReductor,
ExpressionParameterFunctional,
LincombOperator,
ProjectionParameterFunctional,
StationaryModel,
VectorOperator,
rb_greedy,
reduction_error_analysis,
)

from pymor_dealii.pymor.gui import DealIIVisualizer
from pymor_dealii.pymor.operator import DealIIMatrixOperator
from pymor_dealii.pymor.vectorarray import DealIIVectorSpace
from pymor_dealii.pymor.gui import DealIIVisualizer
from dealii_elasticity import ElasticityExample

cpp_disc = ElasticityExample(refine_steps=7)

Expand All @@ -20,12 +29,12 @@ def run(plot_error=True):
DealIIMatrixOperator(cpp_disc.mu_mat()),
],
[
ProjectionParameterFunctional("lambda"),
ProjectionParameterFunctional("mu"),
ProjectionParameterFunctional('lambda'),
ProjectionParameterFunctional('mu'),
],
),
rhs=VectorOperator(DealIIVectorSpace.make_array([cpp_disc.rhs()])),
products={"energy": DealIIMatrixOperator(cpp_disc.mu_mat())},
products={'energy': DealIIMatrixOperator(cpp_disc.mu_mat())},
visualizer=DealIIVisualizer(cpp_disc),
)
parameter_space = d.parameters.space((1, 10))
Expand All @@ -34,46 +43,46 @@ def run(plot_error=True):
reductor = CoerciveRBReductor(
d,
product=d.energy_product,
coercivity_estimator=ExpressionParameterFunctional("max(mu)", d.parameters),
coercivity_estimator=ExpressionParameterFunctional('max(mu)', d.parameters),
)

# greedy basis generation
greedy_data = rb_greedy(
d,
reductor,
parameter_space.sample_uniformly(3),
extension_params={"method": "gram_schmidt"},
extension_params={'method': 'gram_schmidt'},
max_extensions=5,
)

# get reduced order model
rd = greedy_data["rom"]
rd = greedy_data['rom']

# validate reduced order model
result = reduction_error_analysis(
rd,
d,
reductor,
test_mus=parameter_space.sample_randomly(10),
basis_sizes=reductor.bases["RB"].dim + 1,
basis_sizes=reductor.bases['RB'].dim + 1,
condition=True,
error_norms=[d.energy_norm],
plot=plot_error,
)

# visualize solution for parameter with maximum reduction error
mu_max = result["max_error_mus"][0, -1]
mu_max = result['max_error_mus'][0, -1]
U = d.solve(mu_max)
U_rb = reductor.reconstruct(rd.solve(mu_max))
return result, U, U_rb, d


if __name__ == "__main__":
if __name__ == '__main__':
# print/plot results of validation
from matplotlib import pyplot as plt

result, U, U_rb, d = run()
print(result["summary"])
print(result['summary'])
ERR = U - U_rb
d.visualize([U, U_rb, ERR], legend=["fom", "rom", "error"])
d.visualize([U, U_rb, ERR], legend=['fom', 'rom', 'error'])
plt.show()
8 changes: 4 additions & 4 deletions src/pymor_dealii/pymor/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def visualize(
assert title is None or filename is None
assert legend is None or len(legend) == len(U)

base_name = title or filename or "out"
base_name = title or filename or 'out'
if len(U) == 1 and not legend:
filenames = [base_name]
else:
legend = legend or list(map(str, list(range(len(U)))))
filenames = ["_".join((base_name, l)) for l in legend]
filenames = ['_'.join((base_name, l)) for l in legend]

for u, n in zip(U, filenames):
uu = u.vectors[0]
if uu.imag_part is not None:
self.logger.warning("Imaginary part ignored.")
self.impl.visualize(uu.real_part.impl, n + ".vtk")
self.logger.warning('Imaginary part ignored.')
self.impl.visualize(uu.real_part.impl, n + '.vtk')
2 changes: 1 addition & 1 deletion src/pymor_dealii/pymor/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Copyright 2013-2018 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

import pymor_dealii_bindings as pd2
from pymor.operators.list import LinearComplexifiedListVectorArrayOperatorBase

from pymor_dealii.pymor.vectorarray import DealIIVectorSpace
import pymor_dealii_bindings as pd2


class DealIIMatrixOperator(LinearComplexifiedListVectorArrayOperatorBase):
Expand Down
1 change: 0 additions & 1 deletion src/pymor_dealii/pymor/vectorarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
HAVE_DEALII = False

import numpy as np

from pymor.vectorarrays.list import ComplexifiedListVectorSpace, CopyOnWriteVector


Expand Down
2 changes: 1 addition & 1 deletion test/test_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ def test_vector():
assert np.allclose(npdd, ddones)


if __name__ == "__main__":
if __name__ == '__main__':
test_vector()
2 changes: 1 addition & 1 deletion test/test_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ def test_demo_results(ndarrays_regression):

result, _, _, _ = run(plot_error=False)

compare = ["errors", "basis_sizes", "rel_errors"]
compare = ['errors', 'basis_sizes', 'rel_errors']
ndarrays_regression.check({k: v for k, v in result.items() if k in compare})
Loading