Skip to content

Commit 5b87055

Browse files
committed
blackened
1 parent 5b5add1 commit 5b87055

File tree

12 files changed

+368
-240
lines changed

12 files changed

+368
-240
lines changed

.ci/make_env_file.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import os
44
from os.path import expanduser
55
from shlex import quote
6+
67
home = expanduser("~")
78

8-
prefixes = os.environ.get('ENV_PREFIXES', 'TRAVIS CI encrypt TOKEN TESTS').split(' ')
9-
blacklist = ['TRAVIS_COMMIT_MESSAGE']
10-
env_file = os.environ.get('ENV_FILE', os.path.join(home, 'env'))
11-
with open(env_file, 'wt') as env:
12-
for k,v in os.environ.items():
9+
prefixes = os.environ.get("ENV_PREFIXES", "TRAVIS CI encrypt TOKEN TESTS").split(" ")
10+
blacklist = ["TRAVIS_COMMIT_MESSAGE"]
11+
env_file = os.environ.get("ENV_FILE", os.path.join(home, "env"))
12+
with open(env_file, "wt") as env:
13+
for k, v in os.environ.items():
1314
for pref in prefixes:
1415
if k.startswith(pref) and k not in blacklist:
15-
env.write('{}={}\n'.format(k,quote(v)))
16+
env.write("{}={}\n".format(k, quote(v)))

lib/test_bindings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
import pydealii_bindings as dealii
88

9+
910
def test_vector():
1011
v = dealii.Vector(10)
1112
u = dealii.Vector(10)
@@ -38,9 +39,10 @@ def test_vector():
3839
ddones[:] = np.ones((100,), np.double)
3940
npdd = np.array(ddones, copy=False)
4041
assert np.allclose(npdd, np.ones((100,), dtype=np.double))
41-
npdd += 1.
42-
ddones /= 2.
42+
npdd += 1.0
43+
ddones /= 2.0
4344
assert np.allclose(npdd, ddones)
4445

46+
4547
if __name__ == "__main__":
4648
test_vector()

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,5 @@ relative_files = True
6868
source =
6969
src/pymor_dealii
7070
src/test
71-
omit =
71+
omit =
7272
src/pymor_dealii/version.py

setup.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import pathlib
55
import sys
6+
67
# versioneer (+dependencies) does not work in a pep518/7 context w/o modification here
78
sys.path.append(os.path.dirname(__file__))
89
import versioneer # noqa
@@ -13,14 +14,12 @@
1314

1415

1516
class CMakeExtension(Extension):
16-
1717
def __init__(self, name):
1818
# don't invoke the original build_ext for this special extension
1919
super().__init__(name, sources=[])
2020

2121

2222
class build_ext(build_ext_orig):
23-
2423
def run(self):
2524
for ext in self.extensions:
2625
self.build_cmake(ext)
@@ -37,39 +36,37 @@ def build_cmake(self, ext):
3736
extdir.mkdir(parents=True, exist_ok=True)
3837

3938
# example of cmake args
40-
config = 'Debug' if self.debug else 'Release'
39+
config = "Debug" if self.debug else "Release"
4140
cmake_args = [
42-
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + str(extdir.parent.absolute()),
43-
'-DCMAKE_BUILD_TYPE=' + config
41+
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + str(extdir.parent.absolute()),
42+
"-DCMAKE_BUILD_TYPE=" + config,
4443
]
4544

4645
# example of build args
47-
build_args = [
48-
'--config', config,
49-
'--', '-j4'
50-
]
46+
build_args = ["--config", config, "--", "-j4"]
5147

5248
os.chdir(str(build_temp))
53-
self.spawn(['cmake', str(cwd)] + cmake_args)
49+
self.spawn(["cmake", str(cwd)] + cmake_args)
5450
if not self.dry_run:
55-
self.spawn(['cmake', '--build', '.'] + build_args)
51+
self.spawn(["cmake", "--build", "."] + build_args)
5652
os.chdir(str(cwd))
5753

58-
cmdclass=versioneer.get_cmdclass()
59-
cmdclass['build_ext'] = build_ext
54+
55+
cmdclass = versioneer.get_cmdclass()
56+
cmdclass["build_ext"] = build_ext
6057

6158
setup(
6259
version=versioneer.get_version(),
63-
name='pymor_dealii',
64-
author='pyMOR developers',
65-
author_email='[email protected]',
66-
python_requires='>=3.7',
67-
maintainer='Rene Fritze',
68-
maintainer_email='[email protected]',
60+
name="pymor_dealii",
61+
author="pyMOR developers",
62+
author_email="[email protected]",
63+
python_requires=">=3.7",
64+
maintainer="Rene Fritze",
65+
maintainer_email="[email protected]",
6966
install_requires=[],
70-
package_dir={'': 'src'},
71-
packages=find_packages('src'),
67+
package_dir={"": "src"},
68+
packages=find_packages("src"),
7269
include_package_data=True,
73-
ext_modules=[CMakeExtension('pymor_dealii')],
70+
ext_modules=[CMakeExtension("pymor_dealii")],
7471
cmdclass=cmdclass,
7572
)

src/pymor_dealii/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
21
from .version import get_versions
3-
__version__ = get_versions()['version']
2+
3+
__version__ = get_versions()["version"]
44
del get_versions

src/pymor_dealii/pymor/demo.py

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# instantiate deal.II model
88
from dealii_elasticity import ElasticityExample
9+
910
cpp_disc = ElasticityExample(refine_steps=7)
1011

1112

@@ -17,55 +18,66 @@
1718

1819
def run(plot_error=True):
1920
d = StationaryModel(
20-
operator=LincombOperator([DealIIMatrixOperator(cpp_disc.lambda_mat()), DealIIMatrixOperator(cpp_disc.mu_mat())],
21-
[ProjectionParameterFunctional('lambda'), ProjectionParameterFunctional('mu')]),
22-
21+
operator=LincombOperator(
22+
[
23+
DealIIMatrixOperator(cpp_disc.lambda_mat()),
24+
DealIIMatrixOperator(cpp_disc.mu_mat()),
25+
],
26+
[
27+
ProjectionParameterFunctional("lambda"),
28+
ProjectionParameterFunctional("mu"),
29+
],
30+
),
2331
rhs=VectorOperator(DealIIVectorSpace.make_array([cpp_disc.rhs()])),
24-
25-
products={'energy': DealIIMatrixOperator(cpp_disc.mu_mat())},
26-
27-
visualizer=DealIIVisualizer(cpp_disc)
32+
products={"energy": DealIIMatrixOperator(cpp_disc.mu_mat())},
33+
visualizer=DealIIVisualizer(cpp_disc),
2834
)
29-
parameter_space = d.parameters.space((1,10))
30-
35+
parameter_space = d.parameters.space((1, 10))
3136

3237
# choose reduction method
3338
reductor = CoerciveRBReductor(
3439
d,
3540
product=d.energy_product,
36-
coercivity_estimator=ExpressionParameterFunctional("max(mu)", d.parameters)
41+
coercivity_estimator=ExpressionParameterFunctional("max(mu)", d.parameters),
3742
)
3843

39-
4044
# greedy basis generation
41-
greedy_data = rb_greedy(d, reductor, parameter_space.sample_uniformly(3),
42-
extension_params={'method': 'gram_schmidt'}, max_extensions=5)
43-
45+
greedy_data = rb_greedy(
46+
d,
47+
reductor,
48+
parameter_space.sample_uniformly(3),
49+
extension_params={"method": "gram_schmidt"},
50+
max_extensions=5,
51+
)
4452

4553
# get reduced order model
46-
rd = greedy_data['rom']
47-
54+
rd = greedy_data["rom"]
4855

4956
# validate reduced order model
50-
result = reduction_error_analysis(rd, d, reductor,
51-
test_mus=parameter_space.sample_randomly(10),
52-
basis_sizes=reductor.bases['RB'].dim + 1,
53-
condition=True, error_norms=[d.energy_norm],
54-
plot=plot_error)
55-
57+
result = reduction_error_analysis(
58+
rd,
59+
d,
60+
reductor,
61+
test_mus=parameter_space.sample_randomly(10),
62+
basis_sizes=reductor.bases["RB"].dim + 1,
63+
condition=True,
64+
error_norms=[d.energy_norm],
65+
plot=plot_error,
66+
)
5667

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

6374

64-
if __name__ == '__main__':
75+
if __name__ == "__main__":
6576
# print/plot results of validation
6677
from matplotlib import pyplot as plt
78+
6779
result, U, U_rb, d = run()
68-
print(result['summary'])
80+
print(result["summary"])
6981
ERR = U - U_rb
70-
d.visualize([U, U_rb, ERR], legend=['fom', 'rom', 'error'])
82+
d.visualize([U, U_rb, ERR], legend=["fom", "rom", "error"])
7183
plt.show()

src/pymor_dealii/pymor/gui.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@
77

88

99
class DealIIVisualizer(ImmutableObject):
10-
1110
def __init__(self, impl):
1211
self.impl = impl
1312

14-
def visualize(self, U, discretization, title=None, legend=None, separate_colorbars=True, filename=None):
13+
def visualize(
14+
self,
15+
U,
16+
discretization,
17+
title=None,
18+
legend=None,
19+
separate_colorbars=True,
20+
filename=None,
21+
):
1522
if isinstance(U, VectorArray):
1623
U = [U]
1724
if any(len(u) != 1 for u in U):
@@ -21,12 +28,12 @@ def visualize(self, U, discretization, title=None, legend=None, separate_colorba
2128
assert title is None or filename is None
2229
assert legend is None or len(legend) == len(U)
2330

24-
base_name = title or filename or 'out'
31+
base_name = title or filename or "out"
2532
if len(U) == 1 and not legend:
2633
filenames = [base_name]
2734
else:
2835
legend = legend or list(map(str, list(range(len(U)))))
29-
filenames = ['_'.join((base_name, l)) for l in legend]
36+
filenames = ["_".join((base_name, l)) for l in legend]
3037

3138
for u, n in zip(U, filenames):
32-
self.impl.visualize(u._list[0].impl, n + '.vtk')
39+
self.impl.visualize(u._list[0].impl, n + ".vtk")

src/pymor_dealii/pymor/operator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def apply_inverse(self, V, mu=None, least_squares=False):
4343
return R
4444

4545
def assemble_lincomb(self, operators, coefficients, solver_options=None, name=None):
46-
if not all(isinstance(op, (DealIIMatrixOperator, ZeroOperator)) for op in operators):
46+
if not all(
47+
isinstance(op, (DealIIMatrixOperator, ZeroOperator)) for op in operators
48+
):
4749
return None
4850
assert not solver_options # linear solver is not yet configurable
4951

src/pymor_dealii/pymor/vectorarray.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
try:
66
import pymor_dealii_bindings as pd2
7+
78
HAVE_DEALII = True
89
except ImportError:
910
HAVE_DEALII = False
@@ -46,7 +47,7 @@ def _axpy(self, alpha, x):
4647
if x.dim == 0:
4748
return
4849
if x is self:
49-
self.impl *= 1. + alpha
50+
self.impl *= 1.0 + alpha
5051
else:
5152
self.impl.axpy(alpha, x.impl)
5253

@@ -61,7 +62,7 @@ def norm(self):
6162
return 0 if self.dim == 0 else self.impl.l2_norm()
6263

6364
def norm2(self):
64-
return 0 if self.dim == 0 else self.impl.l2_norm()**2
65+
return 0 if self.dim == 0 else self.impl.l2_norm() ** 2
6566

6667
def sup_norm(self):
6768
return 0 if self.dim == 0 else self.impl.linfty_norm()
@@ -103,12 +104,15 @@ def __neg__(self):
103104

104105

105106
class DealIIVectorSpace(ListVectorSpace):
106-
107107
def __init__(self, dim, id=None):
108108
self.__auto_init(locals())
109109

110110
def __eq__(self, other):
111-
return type(other) is DealIIVectorSpace and self.dim == other.dim and self.id == other.id
111+
return (
112+
type(other) is DealIIVectorSpace
113+
and self.dim == other.dim
114+
and self.id == other.id
115+
)
112116

113117
@classmethod
114118
def space_from_vector_obj(cls, vec, id):

0 commit comments

Comments
 (0)