Skip to content

Commit 282e2ee

Browse files
committed
Run complete flake8 check and fix
1 parent facb057 commit 282e2ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+459
-418
lines changed

.flake8

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# flake8 does not support pyproject.toml, see:
22
# https://github.com/PyCQA/flake8/issues/234
33
[flake8]
4+
ignore = F405, W504, W503, F403, F401
45
exclude = __init__.py, _build
56
max-line-length = 120

src/oasismove/NSCoupled.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
__license__ = 'GNU Lesser GPL version 3 or any later version'
55

66
import importlib
7+
78
from oasismove.common import *
89

910
"""
@@ -32,10 +33,10 @@
3233
if problemspec is None:
3334
problemspec = importlib.util.find_spec(problemname)
3435
if problemspec is None:
35-
raise RuntimeError(problemname+' not found')
36+
raise RuntimeError(problemname + ' not found')
3637

3738
# Import the problem module
38-
print('Importing problem module '+problemname+':\n'+problemspec.origin)
39+
print('Importing problem module ' + problemname + ':\n' + problemspec.origin)
3940
problemmod = importlib.util.module_from_spec(problemspec)
4041
problemspec.loader.exec_module(problemmod)
4142

@@ -49,7 +50,7 @@
4950

5051
# Import chosen functionality from solvers
5152
solver = importlib.import_module('.'.join(('oasis.solvers.NSCoupled', solver)))
52-
vars().update({name:solver.__dict__[name] for name in solver.__all__})
53+
vars().update({name: solver.__dict__[name] for name in solver.__all__})
5354

5455
# Create lists of components solved for
5556
u_components = ['u']
@@ -73,7 +74,7 @@
7374
# MINI element has bubble, add to V
7475
if bubble:
7576
B = VectorElement("Bubble", mesh.ufl_cell(), mesh.geometry().dim() + 1)
76-
VQ = FunctionSpace(mesh, MixedElement(V+B, Q),
77+
VQ = FunctionSpace(mesh, MixedElement(V + B, Q),
7778
constrained_domain=constrained_domain)
7879

7980
else:
@@ -97,14 +98,14 @@
9798
q_1 = dict((ui, Function(VV[ui], name=ui + '_1')) for ui in sys_comp)
9899

99100
# Short forms
100-
up_ = q_['up'] # Solution at next iteration
101+
up_ = q_['up'] # Solution at next iteration
101102
up_1 = q_1['up'] # Solution at previous iteration
102103
u_, p_ = split(up_)
103104
u_1, p_1 = split(up_1)
104105

105106
# Create short forms for accessing the solution vectors
106-
x_ = dict((ui, q_ [ui].vector()) for ui in sys_comp) # Solution vectors
107-
x_1 = dict((ui, q_1[ui].vector()) for ui in sys_comp) # Solution vectors previous iteration
107+
x_ = dict((ui, q_[ui].vector()) for ui in sys_comp) # Solution vectors
108+
x_1 = dict((ui, q_1[ui].vector()) for ui in sys_comp) # Solution vectors previous iteration
108109

109110
# Create vectors to hold rhs of equations
110111
b = dict((ui, Vector(x_[ui])) for ui in sys_comp)
@@ -158,6 +159,7 @@ def iterate(iters=max_iter):
158159

159160
iter += 1
160161

162+
161163
def iterate_scalar(iters=max_iter, errors=max_error):
162164
# Newton iterations for scalars
163165
if len(scalar_components) > 0:
@@ -175,7 +177,6 @@ def iterate_scalar(iters=max_iter, errors=max_error):
175177
citer += 1
176178

177179

178-
179180
timer = OasisTimer('Start Newton iterations flow', True)
180181
# Assemble rhs once, before entering iterations (velocity components)
181182
b['up'] = assemble(Fs['up'], tensor=b['up'])
@@ -205,7 +206,7 @@ def iterate_scalar(iters=max_iter, errors=max_error):
205206
info_red('Memory use for importing dolfin = {} MB (RSS)'.format(
206207
total_initial_dolfin_memory))
207208
info_red('Total memory use of solver = ' +
208-
str(oasis_memory.memory - total_initial_dolfin_memory) + ' MB (RSS)')
209+
str(oasis_memory.memory - total_initial_dolfin_memory) + ' MB (RSS)')
209210

210211
# Final hook
211212
theend_hook(**vars())

src/oasismove/NSfracStep.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
3434
"""
3535
import importlib
36+
3637
from oasismove.common import *
3738

3839
commandline_kwargs = parse_command_line()
@@ -44,10 +45,10 @@
4445
if problemspec is None:
4546
problemspec = importlib.util.find_spec(problemname)
4647
if problemspec is None:
47-
raise RuntimeError(problemname+' not found')
48+
raise RuntimeError(problemname + ' not found')
4849

4950
# Import the problem module
50-
print('Importing problem module '+problemname+':\n'+problemspec.origin)
51+
print('Importing problem module ' + problemname + ':\n' + problemspec.origin)
5152
problemmod = importlib.util.module_from_spec(problemspec)
5253
problemspec.loader.exec_module(problemmod)
5354

@@ -69,7 +70,7 @@
6970

7071
# Import chosen functionality from solvers
7172
solver = importlib.import_module('.'.join(('oasis.solvers.NSfracStep', solver)))
72-
vars().update({name:solver.__dict__[name] for name in solver.__all__})
73+
vars().update({name: solver.__dict__[name] for name in solver.__all__})
7374

7475
# Create lists of components solved for
7576
dim = mesh.geometry().dim()
@@ -97,34 +98,34 @@
9798
VV['p'] = Q
9899

99100
# Create dictionaries for the solutions at three timesteps
100-
q_ = dict((ui, Function(VV[ui], name=ui)) for ui in sys_comp)
101+
q_ = dict((ui, Function(VV[ui], name=ui)) for ui in sys_comp)
101102
q_1 = dict((ui, Function(VV[ui], name=ui + "_1")) for ui in sys_comp)
102103
q_2 = dict((ui, Function(V, name=ui + "_2")) for ui in u_components)
103104

104105
# Read in previous solution if restarting
105106
init_from_restart(**vars())
106107

107108
# Create vectors of the segregated velocity components
108-
u_ = as_vector([q_ [ui] for ui in u_components]) # Velocity vector at t
109-
u_1 = as_vector([q_1[ui] for ui in u_components]) # Velocity vector at t - dt
110-
u_2 = as_vector([q_2[ui] for ui in u_components]) # Velocity vector at t - 2*dt
109+
u_ = as_vector([q_[ui] for ui in u_components]) # Velocity vector at t
110+
u_1 = as_vector([q_1[ui] for ui in u_components]) # Velocity vector at t - dt
111+
u_2 = as_vector([q_2[ui] for ui in u_components]) # Velocity vector at t - 2*dt
111112

112113
# Adams Bashforth projection of velocity at t - dt/2
113114
U_AB = 1.5 * u_1 - 0.5 * u_2
114115

115116
# Create short forms for accessing the solution vectors
116-
x_ = dict((ui, q_[ui].vector()) for ui in sys_comp) # Solution vectors t
117-
x_1 = dict((ui, q_1[ui].vector()) for ui in sys_comp) # Solution vectors t - dt
117+
x_ = dict((ui, q_[ui].vector()) for ui in sys_comp) # Solution vectors t
118+
x_1 = dict((ui, q_1[ui].vector()) for ui in sys_comp) # Solution vectors t - dt
118119
x_2 = dict((ui, q_2[ui].vector()) for ui in u_components) # Solution vectors t - 2*dt
119120

120121
# Create vectors to hold rhs of equations
121-
b = dict((ui, Vector(x_[ui])) for ui in sys_comp) # rhs vectors (final)
122+
b = dict((ui, Vector(x_[ui])) for ui in sys_comp) # rhs vectors (final)
122123
b_tmp = dict((ui, Vector(x_[ui])) for ui in sys_comp) # rhs temp storage vectors
123124

124125
# Short forms pressure and scalars
125-
p_ = q_['p'] # pressure at t
126-
p_1 = q_1['p'] # pressure at t - dt
127-
dp_ = Function(Q) # pressure correction
126+
p_ = q_['p'] # pressure at t
127+
p_1 = q_1['p'] # pressure at t - dt
128+
dp_ = Function(Q) # pressure correction
128129
for ci in scalar_components:
129130
exec("{}_ = q_ ['{}']".format(ci, ci))
130131
exec("{}_1 = q_1['{}']".format(ci, ci))
@@ -138,16 +139,16 @@
138139
bcs = create_bcs(**vars())
139140

140141
# LES setup
141-
#exec("from oasis.solvers.NSfracStep.LES.{} import *".format(les_model))
142+
# exec("from oasis.solvers.NSfracStep.LES.{} import *".format(les_model))
142143
lesmodel = importlib.import_module('.'.join(('oasis.solvers.NSfracStep.LES', les_model)))
143-
vars().update({name:lesmodel.__dict__[name] for name in lesmodel.__all__})
144+
vars().update({name: lesmodel.__dict__[name] for name in lesmodel.__all__})
144145

145146
vars().update(les_setup(**vars()))
146147

147148
# Non-Newtonian setup
148-
#exec("from oasis.solvers.NSfracStep.NNModel.{} import *".format(nn_model))
149+
# exec("from oasis.solvers.NSfracStep.NNModel.{} import *".format(nn_model))
149150
nnmodel = importlib.import_module('.'.join(('oasis.solvers.NSfracStep.NNModel', nn_model)))
150-
vars().update({name:nnmodel.__dict__[name] for name in nnmodel.__all__})
151+
vars().update({name: nnmodel.__dict__[name] for name in nnmodel.__all__})
151152

152153
vars().update(nn_setup(**vars()))
153154

@@ -159,13 +160,13 @@
159160

160161
# Get constant body forces
161162
f = body_force(**vars())
162-
assert(isinstance(f, Coefficient))
163+
assert (isinstance(f, Coefficient))
163164
b0 = dict((ui, assemble(v * f[i] * dx)) for i, ui in enumerate(u_components))
164165

165166
# Get scalar sources
166167
fs = scalar_source(**vars())
167168
for ci in scalar_components:
168-
assert(isinstance(fs[ci], Coefficient))
169+
assert (isinstance(fs[ci], Coefficient))
169170
b0[ci] = assemble(v * fs[ci] * dx)
170171

171172
# Preassemble and allocate
@@ -244,7 +245,7 @@
244245
# Print some information
245246
if tstep % print_intermediate_info == 0:
246247
toc = tx.stop()
247-
info_green( 'Time = {0:2.4e}, timestep = {1:6d}, End time = {2:2.4e}'.format(t, tstep, T))
248+
info_green('Time = {0:2.4e}, timestep = {1:6d}, End time = {2:2.4e}'.format(t, tstep, T))
248249
info_red('Total computing time on previous {0:d} timesteps = {1:f}'.format(
249250
print_intermediate_info, toc))
250251
list_timings(TimingClear.clear, [TimingType.wall])

src/oasismove/common/io.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
__copyright__ = "Copyright (C) 2013 " + __author__
44
__license__ = "GNU Lesser GPL version 3 or any later version"
55

6-
from os import makedirs, getcwd, listdir, remove, system, path
7-
from xml.etree import ElementTree as ET
6+
import glob
87
import pickle
98
import time
10-
import glob
11-
from dolfin import (MPI, Function, XDMFFile, HDF5File,
12-
VectorFunctionSpace, FunctionAssigner)
9+
from os import makedirs, listdir, remove, system, path
10+
from xml.etree import ElementTree as ET
11+
12+
from dolfin import (MPI, XDMFFile, HDF5File)
13+
1314
from oasismove.problems import info_red
1415

1516
__all__ = ["create_initial_folders", "save_solution", "save_tstep_solution_h5",
@@ -37,17 +38,17 @@ def create_initial_folders(folder, restart_folder, sys_comp, tstep, info_red,
3738
if not path.exists(newfolder):
3839
newfolder = path.join(newfolder, '1')
3940
else:
40-
#previous = listdir(newfolder)
41+
# previous = listdir(newfolder)
4142
previous = [f for f in listdir(newfolder) if not f.startswith('.')]
4243
previous = max(map(eval, previous)) if previous else 0
4344
newfolder = path.join(newfolder, str(previous + 1))
4445

4546
MPI.barrier(MPI.comm_world)
4647
if MPI.rank(MPI.comm_world) == 0:
4748
if not restart_folder:
48-
#makedirs(path.join(newfolder, "Voluviz"))
49-
#makedirs(path.join(newfolder, "Stats"))
50-
#makedirs(path.join(newfolder, "VTK"))
49+
# makedirs(path.join(newfolder, "Voluviz"))
50+
# makedirs(path.join(newfolder, "Stats"))
51+
# makedirs(path.join(newfolder, "VTK"))
5152
makedirs(path.join(newfolder, "Timeseries"))
5253
makedirs(path.join(newfolder, "Checkpoint"))
5354

@@ -121,7 +122,7 @@ def save_tstep_solution_h5(tstep, q_, u_, newfolder, tstepfiles, constrained_dom
121122
if MPI.rank(MPI.comm_world) == 0:
122123
if not path.exists(path.join(timefolder, "params.dat")):
123124
f = open(path.join(timefolder, 'params.dat'), 'wb')
124-
pickle.dump(NS_parameters, f)
125+
pickle.dump(NS_parameters, f)
125126

126127

127128
def save_checkpoint_solution_h5(tstep, q_, q_1, newfolder, u_components,
@@ -142,7 +143,7 @@ def save_checkpoint_solution_h5(tstep, q_, q_1, newfolder, u_components,
142143
system('cp {0} {1}'.format(path.join(checkpointfolder, "params.dat"),
143144
path.join(checkpointfolder, "params_old.dat")))
144145
f = open(path.join(checkpointfolder, "params.dat"), 'wb')
145-
pickle.dump(NS_parameters, f)
146+
pickle.dump(NS_parameters, f)
146147

147148
MPI.barrier(MPI.comm_world)
148149
for ui in q_:
@@ -196,7 +197,8 @@ def check_if_pause(folder):
196197
collective = MPI.sum(MPI.comm_world, found)
197198
if collective > 0:
198199
if MPI.rank(MPI.comm_world) == 0:
199-
info_red('pauseoasis Found! Simulations paused. Remove ' + path.join(folder, 'pauseoasis') + ' to resume simulations...')
200+
info_red('pauseoasis Found! Simulations paused. Remove '
201+
+ path.join(folder, 'pauseoasis') + ' to resume simulations...')
200202
return True
201203
else:
202204
return False

src/oasismove/common/utilities.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def __call__(self, assemb_rhs=True):
154154
"""
155155
Compute the projection
156156
"""
157-
timer = Timer("Projecting {}".format(self.name()))
157+
Timer("Projecting {}".format(self.name()))
158158

159159
if assemb_rhs:
160160
self.assemble_rhs()

src/oasismove/problems/Cylinder.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
__copyright__ = "Copyright (C) 2014 " + __author__
44
__license__ = "GNU Lesser GPL version 3 or any later version"
55

6-
from dolfin import Mesh, AutoSubDomain, near
76
import os
87
import platform
98

9+
from dolfin import Mesh, AutoSubDomain, near
10+
1011
if not os.path.isfile("cylinder.xml"):
1112
if platform.system() == "Linux":
1213
os.system("wget -O cylinder.xml https://www.dropbox.com/s/d78g4cyjxl3ylay/cylinder.xml?dl=0")
@@ -16,12 +17,12 @@
1617
raise ImportError("Could not determine platform")
1718

1819
# try:
19-
#os.system("gmsh mesh/cylinder.geo -2 -o mesh/cylinder.msh")
20-
#os.system("dolfin-convert mesh/cylinder.msh mesh/cylinder.xml")
21-
#os.system("rm mesh/cylinder.msh")
20+
# os.system("gmsh mesh/cylinder.geo -2 -o mesh/cylinder.msh")
21+
# os.system("dolfin-convert mesh/cylinder.msh mesh/cylinder.xml")
22+
# os.system("rm mesh/cylinder.msh")
2223
# except RuntimeError:
23-
#os.system("wget -O cylinder.xml https://www.dropbox.com/s/d78g4cyjxl3ylay/cylinder.xml?dl=0")
24-
##raise "Gmsh is required to run this demo"
24+
# os.system("wget -O cylinder.xml https://www.dropbox.com/s/d78g4cyjxl3ylay/cylinder.xml?dl=0")
25+
# raise "Gmsh is required to run this demo"
2526

2627
mesh = Mesh("cylinder.xml")
2728

@@ -41,7 +42,7 @@
4142
Inlet = AutoSubDomain(lambda x, on_bnd: on_bnd and x[0] < 1e-8)
4243
Wall = AutoSubDomain(lambda x, on_bnd: on_bnd and near(x[1] * (H - x[1]), 0))
4344
Cyl = AutoSubDomain(lambda x, on_bnd: (on_bnd and x[0] > 1e-6 and x[0] < 1
44-
and x[1] < 3 * H / 4 and x[1] > H / 4))
45+
and x[1] < 3 * H / 4 and x[1] > H / 4))
4546
Outlet = AutoSubDomain(lambda x, on_bnd: on_bnd and x[0] > L - 1e-8)
4647

4748

src/oasismove/problems/DrivenCavity.py

-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44
__license__ = "GNU Lesser GPL version 3 or any later version"
55

66
from dolfin import UnitSquareMesh
7-
from numpy import cos, pi
87

98

109
# Create a mesh
1110
def mesh(Nx=50, Ny=50, **params):
1211
m = UnitSquareMesh(Nx, Ny)
13-
x = m.coordinates()
14-
#x[:] = (x - 0.5) * 2
15-
#x[:] = 0.5*(cos(pi*(x-1.) / 2.) + 1.)
1612
return m
1713

1814

src/oasismove/problems/NSCoupled/Cylinder.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from __future__ import print_function
2+
23
__author__ = "Mikael Mortensen <[email protected]>"
34
__date__ = "2014-04-04"
45
__copyright__ = "Copyright (C) 2014 " + __author__
56
__license__ = "GNU Lesser GPL version 3 or any later version"
67

7-
from ..NSCoupled import *
88
from ..Cylinder import *
9+
from ..NSCoupled import *
10+
911

1012
# Override some problem specific parameters
1113
def problem_parameters(NS_parameters, scalar_components, **NS_namespace):
@@ -40,9 +42,9 @@ def create_bcs(VQ, Um, CG, V, element, **NS_namespace):
4042
bc2 = DirichletBC(VQ.sub(0), (0, 0), Wall)
4143
return dict(up=[bc0, bc1, bc2],
4244
c=[DirichletBC(CG, 1, Cyl),
43-
DirichletBC(CG, 0, Inlet)],
45+
DirichletBC(CG, 0, Inlet)],
4446
d=[DirichletBC(CG, 2, Cyl),
45-
DirichletBC(CG, 0, Inlet)])
47+
DirichletBC(CG, 0, Inlet)])
4648

4749

4850
def theend_hook(u_, p_, up_, mesh, ds, VQ, nu, Umean, c_, testing, **NS_namespace):
@@ -58,7 +60,7 @@ def theend_hook(u_, p_, up_, mesh, ds, VQ, nu, Umean, c_, testing, **NS_namespac
5860
Cyl.mark(ff, 1)
5961
n = FacetNormal(mesh)
6062
ds = ds(subdomain_data=ff)
61-
forces = assemble(dot(dot(tau, n), c) * ds(1)).get_local() * 2 / Umean**2 / D
63+
forces = assemble(dot(dot(tau, n), c) * ds(1)).get_local() * 2 / Umean ** 2 / D
6264

6365
try:
6466
print("Cd = {0:2.6e}, CL = {1:2.6e}".format(*forces))

src/oasismove/problems/NSCoupled/DrivenCavity.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
__copyright__ = "Copyright (C) 2014 " + __author__
44
__license__ = "GNU Lesser GPL version 3 or any later version"
55

6-
from ..NSCoupled import *
76
from ..DrivenCavity import *
7+
from ..NSCoupled import *
8+
89

910
# Override some problem specific parameters
1011
def problem_parameters(NS_parameters, **NS_namespace):
@@ -30,5 +31,5 @@ def theend_hook(u_, p_, mesh, **NS_namespace):
3031
psi = StreamFunction(u_, [], mesh, use_strong_bc=True)
3132
plot(psi, title='Streamfunction')
3233
plt.show()
33-
except:
34+
except ImportError:
3435
pass

0 commit comments

Comments
 (0)