Commit 1b24f753 authored by Lambert Theisen's avatar Lambert Theisen 🔥

Add flake8 compliance

parent 6f2fe36a
Pipeline #307447 failed with stages
in 1 minute and 19 seconds
......@@ -69,6 +69,12 @@ build:docs:
tags:
- docker
test:flake8:
extends: .test
script:
- cd ${APP_DIRECTORY}
- flake8 fenicsR13 examples tests
test:pytest:
extends: .test
script:
......
......@@ -10,7 +10,7 @@ if not gui:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(x,y, "-o", label="Channel Flow")
ax.plot(x, y, "-o", label="Channel Flow")
ax.set_xscale("log")
plt.xlabel("Knudsen number")
......
......@@ -10,7 +10,7 @@ if not gui:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(x,y, "-o", label="Channel Flow")
ax.plot(x, y, "-o", label="Channel Flow")
ax.set_xscale("log")
plt.xlabel("Knudsen number")
......
......@@ -7,6 +7,7 @@ This file is executed by ``pytest`` to have good CI.
import subprocess
import pytest
class TestExamples(object):
"""
Class to bundle all examples tests.
......
......@@ -20,6 +20,7 @@ from fenicsR13.input import Input
from fenicsR13.solver import Solver
from fenicsR13.postprocessor import Postprocessor
def print_information():
r"""
Print program name and information.
......@@ -52,6 +53,7 @@ def print_information():
|_| \___|_| |_|_|\___|___/_| \_\_|____/
""")
def main():
"""
Execute the main program.
......@@ -76,7 +78,7 @@ def main():
print_information()
# Dolfin settings
df.set_log_level(100) # 1: all logs
df.set_log_level(100) # 1: all logs
df.parameters["ghost_mode"] = "shared_vertex"
inputfile = sys.argv[1] if len(sys.argv) == 2 else "input.yml"
......@@ -127,7 +129,7 @@ def main():
**errors
})
if p == len(mesh_names)-1: # after last mesh
if p == len(mesh_names) - 1: # after last mesh
postp = Postprocessor(data, params["output_folder"])
postp.write_errors()
postp.plot_errors(show_plot)
......@@ -135,5 +137,6 @@ def main():
solver = None
gc.collect()
if __name__ == '__main__':
main()
......@@ -28,6 +28,7 @@ import dolfin as df
GMSH_PATH = "gmsh"
GEO_NAME = "ring"
def geo_to_h5():
"Convert given geo-file to a h5-mesh."
......
......@@ -10,6 +10,7 @@ from json import dumps
import yaml
from cerberus import Validator
class Input:
"""
Class to handle the input file in YAML_ format.
......@@ -454,7 +455,7 @@ class Input:
"""
try:
return reduce(operator.getitem, map_list, self.dict)
except:
except Exception:
raise Exception("Dict has no entry with the key:", map_list)
def set_in_input(self, map_list, value):
......
......@@ -7,6 +7,7 @@ Currently, the only mesh format is h5.
import os
import dolfin as df
class H5Mesh:
"""
Mesh class.
......
......@@ -11,6 +11,7 @@ from math import sqrt, ceil, log, log10
import numpy as np
import matplotlib.pyplot as plt
class Postprocessor:
"""
The class for postprocessing.
......@@ -73,7 +74,7 @@ class Postprocessor:
matplotlib.use('pdf')
import matplotlib.pyplot as plt # pylint: disable=C0413
"""
filename = "convergence_plot_" + self.output_folder + ".pdf"
filename = "convergence_plot_" + self.output_folder + ".pdf"
if not show_popup:
plt.switch_backend('agg')
......@@ -87,12 +88,12 @@ class Postprocessor:
plt_sidelength_x = ceil(sqrt(num_fields))
plt_sidelength_y = plt_sidelength_x
while plt_sidelength_y * (plt_sidelength_x-1) >= num_fields:
while plt_sidelength_y * (plt_sidelength_x - 1) >= num_fields:
plt_sidelength_x -= 1
for i, key in enumerate(raw_data):
field = [df[key] for df in data]
plot_i = plt.subplot(plt_sidelength_x, plt_sidelength_y, (i+1))
plot_i = plt.subplot(plt_sidelength_x, plt_sidelength_y, (i + 1))
for j, etype in enumerate(field[0]):
values = [df[etype] for df in field]
......@@ -102,32 +103,33 @@ class Postprocessor:
# Add slope marker
use_top = j == 1
bot = np.array([
[h[-1], 0.5*values[-1]],
[h[-2], 0.5*values[-1]],
[h[-2], 0.5*values[-2]]
[h[-1], 0.5 * values[-1]],
[h[-2], 0.5 * values[-1]],
[h[-2], 0.5 * values[-2]]
])
top = np.array([
[h[-1], 2.0*values[-1]],
[h[-2], 2.0*values[-2]],
[h[-1], 2.0*values[-2]]
[h[-1], 2.0 * values[-1]],
[h[-2], 2.0 * values[-2]],
[h[-1], 2.0 * values[-2]]
])
tria = top if use_top else bot
slope_marker = plt.Polygon(
tria, color=plot_i.get_lines()[-1].get_color(),
alpha=1.5, fill=False
)
)
plot_i.add_patch(slope_marker)
conv_rate = (
(log(values[-2]) - log(values[-1]))
/ (log(h[-2]) - log(h[-1]))
)
delta_values = log(values[-2]) - log(values[-1])
delta_h = log(h[-2]) - log(h[-1])
conv_rate = delta_values / delta_h
anchor_x = h[-1] if use_top else h[-2]
anchor_y = (
10**(
(log10(2.0*values[-2])+log10(2.0*values[-1]))/2
(log10(2.0 * values[-2]) + log10(2.0 * values[-1])) / 2
) if use_top
else 10**((log10(0.5*values[-2])+log10(0.5*values[-1]))/2)
else 10**(
(log10(0.5 * values[-2]) + log10(0.5 * values[-1])
) / 2)
)
h_align = "left" if use_top else "right"
plot_i.text(
......@@ -136,9 +138,9 @@ class Postprocessor:
)
# Add order slopes
plt.loglog(h, np.array(2*np.power(h, 1)), "--", label="O(h^1)")
plt.loglog(h, np.array(0.02*np.power(h, 2)), "--", label="O(h^2)")
plt.loglog(h, np.array(0.02*np.power(h, 3)), "--", label="O(h^3)")
plt.loglog(h, np.array(2 * np.power(h, 1)), "--", label="O(h^1)")
plt.loglog(h, np.array(0.02 * np.power(h, 2)), "--", label="O(h^2)")
plt.loglog(h, np.array(0.02 * np.power(h, 3)), "--", label="O(h^3)")
# Add information
plt.xlabel("max(h)")
......@@ -178,7 +180,10 @@ class Postprocessor:
writer.writerow(
["h"] + list(
chain.from_iterable([
[first+"_"+second for second in data[0].get(first, "")]
[
first + "_" + second
for second in data[0].get(first, "")
]
for first in [
first for first in data[0] if first != "h"
]
......
This diff is collapsed.
......@@ -7,9 +7,9 @@ Module to gather all additional tensor operations not present in UFL.
This especially includes all 3D operations and operations on tensors with rank
above 2.
.. [STR2005] Struchtrup, H. (2005). Macroscopic transport equations for rarefied
gas flows. In Macroscopic Transport Equations for Rarefied Gas Flows.
Springer, Berlin, Heidelberg.
.. [STR2005] Struchtrup, H. (2005). Macroscopic transport equations for
rarefied gas flows. In Macroscopic Transport Equations for Rarefied Gas
Flows. Springer, Berlin, Heidelberg.
.. [TOR2018] Torrilhon, M. et al. (2018). “Kinetic Theory of Non-Equilibrium
Gas Flows:
......@@ -20,6 +20,7 @@ above 2.
import dolfin as df
import ufl
def stf3d2(rank2_2d):
r"""
Return the synthetic 3D symmetric and trace-free part of a 2D 2-tensor.
......@@ -38,8 +39,9 @@ def stf3d2(rank2_2d):
B &= (A)_\mathrm{dev} = \frac{1}{2} (A)_\mathrm{sym}
- \frac{1}{3} \mathrm{tr}(A) I_{2 \times 2}
"""
symm = 1/2 * (rank2_2d + ufl.transpose(rank2_2d))
return symm - (1/3) * ufl.tr(symm) * ufl.Identity(2)
symm = 1 / 2 * (rank2_2d + ufl.transpose(rank2_2d))
return symm - (1 / 3) * ufl.tr(symm) * ufl.Identity(2)
def sym3d3(rank3_3d):
r"""
......@@ -54,13 +56,14 @@ def sym3d3(rank3_3d):
\right)
"""
i, j, k = ufl.indices(3)
symm_ijk = 1/6 * (
symm_ijk = 1 / 6 * (
# All permutations
+ rank3_3d[i, j, k] + rank3_3d[i, k, j] + rank3_3d[j, i, k]
+ rank3_3d[j, k, i] + rank3_3d[k, i, j] + rank3_3d[k, j, i]
)
return ufl.as_tensor(symm_ijk, (i, j, k))
def stf3d3(rank3_3d):
r"""
Return the symmetric and trace-free part of a 3D 3-tensor.
......@@ -107,18 +110,19 @@ def stf3d3(rank3_3d):
\right) \delta_{i j}
\biggr]
"""
i, j, k, l = ufl.indices(4)
i, j, k, L = ufl.indices(4)
delta = df.Identity(3)
sym_ijk = sym3d3(rank3_3d)[i, j, k]
traces_ijk = 1/5 * (
+ sym3d3(rank3_3d)[i, l, l] * delta[j, k]
+ sym3d3(rank3_3d)[l, j, l] * delta[i, k]
+ sym3d3(rank3_3d)[l, l, k] * delta[i, j]
traces_ijk = 1 / 5 * (
+ sym3d3(rank3_3d)[i, L, L] * delta[j, k]
+ sym3d3(rank3_3d)[L, j, L] * delta[i, k]
+ sym3d3(rank3_3d)[L, L, k] * delta[i, j]
)
tracefree_ijk = sym_ijk - traces_ijk
return ufl.as_tensor(tracefree_ijk, (i, j, k))
def gen3dTF2(rank2_2d):
r"""
Generate a 3D tracefree 2-tensor from a 2D 2-tensor.
......@@ -162,9 +166,10 @@ def gen3dTF2(rank2_2d):
return df.as_tensor([
[rank2_2d[0, 0], rank2_2d[0, 1], 0],
[rank2_2d[1, 0], rank2_2d[1, 1], 0],
[0, 0, -rank2_2d[0, 0]-rank2_2d[1, 1]]
[0, 0, -rank2_2d[0, 0] - rank2_2d[1, 1]]
])
def gen3d2(rank2_2d):
r"""
Generate a 3D 2-tensor from a 2D 2-tensor (add zeros to last dimensions).
......@@ -212,6 +217,7 @@ def gen3d2(rank2_2d):
[0, 0, 0]
])
def grad3dOf2(rank2_3d):
r"""
Return 3D gradient of 3D 2-tensor.
......
[flake8]
ignore = E221
exclude = .git,__init__.py
max-complexity = 25
max-line-length = 80
per-file-ignores =
fenicsR13/solver.py:W503,W504
fenicsR13/tensoroperations.py:W503,W504
......@@ -7,6 +7,7 @@ This file is executed by ``pytest`` to have good CI.
import subprocess
import pytest
class TestHeatConvergence(object):
"""
Class to bundle all stress convergence tests.
......
......@@ -7,6 +7,7 @@ This file is executed by ``pytest`` to have good CI.
import subprocess
import pytest
class TestR13Convergence(object):
"""
Class to bundle all stress convergence tests.
......
......@@ -7,6 +7,7 @@ This file is executed by ``pytest`` to have good CI.
import subprocess
import pytest
class TestStressConvergence(object):
"""
Class to bundle all stress convergence tests.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment