Skip to content

Commit 1edc216

Browse files
committed
added b-helpers to pep8-tests again
1 parent d190975 commit 1edc216

File tree

5 files changed

+55
-50
lines changed

5 files changed

+55
-50
lines changed

pySDC/implementations/problem_classes/boussinesq_helpers/build2DFDMatrix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import sys
2-
3-
sys.path.append('../')
41
import numpy as np
52
import scipy.sparse as sp
63
from pySDC.implementations.problem_classes.boussinesq_helpers.buildFDMatrix import getMatrix, getUpwindMatrix, \
@@ -19,13 +16,16 @@ def get2DUpwindMatrix(N, dx, order):
1916
#
2017
#
2118
def get2DMesh(N, x_b, z_b, bc_hor, bc_ver):
19+
2220
assert np.size(N) == 2, 'N needs to be an array with two entries: N[0]=Nx and N[1]=Nz'
2321
assert np.size(
2422
x_b) == 2, 'x_b needs to be an array with two entries: x_b[0] = left boundary, x_b[1] = right boundary'
2523
assert np.size(
2624
z_b) == 2, 'z_b needs to be an array with two entries: z_b[0] = lower boundary, z_b[1] = upper boundary'
2725

2826
h = np.zeros(2)
27+
x = None
28+
z = None
2929

3030
if bc_hor[0] in ['periodic']:
3131
assert bc_hor[1] in ['periodic'], 'Periodic boundary conditions must be prescribed at both boundaries'
Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,60 @@
11
import numpy as np
22
import scipy.sparse as sp
33
from pySDC.implementations.problem_classes.boussinesq_helpers.build2DFDMatrix import get2DMatrix, getBCHorizontal, \
4-
getBCVertical, get2DUpwindMatrix
4+
get2DUpwindMatrix
5+
56

67
def getBoussinesq2DUpwindMatrix(N, dx, u_adv, order):
8+
Dx = get2DUpwindMatrix(N, dx, order)
9+
10+
# Note: In the equations it is u_t + u_adv* D_x u = ... so in order to comply with the form u_t = M u,
11+
# add a minus sign in front of u_adv
12+
13+
Zero = np.zeros((N[0] * N[1], N[0] * N[1]))
14+
M1 = sp.hstack((-u_adv * Dx, Zero, Zero, Zero), format="csr")
15+
M2 = sp.hstack((Zero, -u_adv * Dx, Zero, Zero), format="csr")
16+
M3 = sp.hstack((Zero, Zero, -u_adv * Dx, Zero), format="csr")
17+
M4 = sp.hstack((Zero, Zero, Zero, -u_adv * Dx), format="csr")
18+
M = sp.vstack((M1, M2, M3, M4), format="csr")
19+
20+
return sp.csc_matrix(M)
21+
722

8-
Dx = get2DUpwindMatrix(N, dx, order)
9-
10-
# Note: In the equations it is u_t + u_adv* D_x u = ... so in order to comply with the form u_t = M u,
11-
# add a minus sign in front of u_adv
12-
13-
Zero = np.zeros((N[0]*N[1], N[0]*N[1]))
14-
M1 = sp.hstack((-u_adv*Dx, Zero, Zero, Zero), format="csr")
15-
M2 = sp.hstack(( Zero, -u_adv*Dx, Zero, Zero), format="csr")
16-
M3 = sp.hstack(( Zero, Zero, -u_adv*Dx, Zero), format="csr")
17-
M4 = sp.hstack(( Zero, Zero, Zero, -u_adv*Dx), format="csr")
18-
M = sp.vstack((M1,M2,M3,M4), format="csr")
19-
20-
return sp.csc_matrix(M)
21-
2223
def getBoussinesq2DMatrix(N, h, bc_hor, bc_ver, c_s, Nfreq, order):
24+
Dx_u, Dz_u = get2DMatrix(N, h, bc_hor[0], bc_ver[0], order)
25+
Dx_w, Dz_w = get2DMatrix(N, h, bc_hor[1], bc_ver[1], order)
26+
# Dx_b, Dz_b = get2DMatrix(N, h, bc_hor[2], bc_ver[2], order)
27+
Dx_p, Dz_p = get2DMatrix(N, h, bc_hor[3], bc_ver[3], order)
2328

24-
Dx_u, Dz_u = get2DMatrix(N, h, bc_hor[0], bc_ver[0], order)
25-
Dx_w, Dz_w = get2DMatrix(N, h, bc_hor[1], bc_ver[1], order)
26-
Dx_b, Dz_b = get2DMatrix(N, h, bc_hor[2], bc_ver[2], order)
27-
Dx_p, Dz_p = get2DMatrix(N, h, bc_hor[3], bc_ver[3], order)
29+
# Id_N = sp.eye(N[0] * N[1])
2830

29-
Id_N = sp.eye(N[0]*N[1])
31+
Zero = np.zeros((N[0] * N[1], N[0] * N[1]))
32+
Id_w = sp.eye(N[0] * N[1])
3033

31-
Zero = np.zeros((N[0]*N[1],N[0]*N[1]))
32-
Id_w = sp.eye(N[0]*N[1])
34+
# Note: Bring all terms to right hand side, therefore a couple of minus signs
35+
# are needed
3336

34-
# Note: Bring all terms to right hand side, therefore a couple of minus signs
35-
# are needed
37+
M1 = sp.hstack((Zero, Zero, Zero, -Dx_p), format="csr")
38+
M2 = sp.hstack((Zero, Zero, Id_w, -Dz_p), format="csr")
39+
M3 = sp.hstack((Zero, -Nfreq ** 2 * Id_w, Zero, Zero), format="csr")
40+
M4 = sp.hstack((-c_s ** 2 * Dx_u, -c_s ** 2 * Dz_w, Zero, Zero), format="csr")
41+
M = sp.vstack((M1, M2, M3, M4), format="csr")
3642

37-
M1 = sp.hstack(( Zero, Zero, Zero, -Dx_p), format="csr")
38-
M2 = sp.hstack(( Zero, Zero, Id_w, -Dz_p), format="csr")
39-
M3 = sp.hstack(( Zero, -Nfreq**2*Id_w, Zero, Zero), format="csr")
40-
M4 = sp.hstack((-c_s**2*Dx_u, -c_s**2*Dz_w, Zero, Zero), format="csr")
41-
M = sp.vstack((M1,M2,M3,M4), format="csr")
43+
Id = sp.eye(4 * N[0] * N[1])
4244

43-
Id = sp.eye(4*N[0]*N[1])
45+
return sp.csc_matrix(Id), sp.csc_matrix(M)
4446

45-
return sp.csc_matrix(Id), sp.csc_matrix(M)
4647

4748
def getBoussinesqBCHorizontal(value, N, dx, bc_hor):
48-
49-
bu_left, bu_right = getBCHorizontal( value[0], N, dx, bc_hor[0] )
50-
bw_left, bw_right = getBCHorizontal( value[1], N, dx, bc_hor[1] )
51-
bb_left, bb_right = getBCHorizontal( value[2], N, dx, bc_hor[2] )
52-
bp_left, bp_right = getBCHorizontal( value[3], N, dx, bc_hor[3] )
53-
54-
b_left = np.concatenate(( bp_left, bp_left, bu_left + bw_left))
55-
b_right = np.concatenate(( bp_right, bp_right, bu_right + bw_right))
56-
return b_left, b_right
49+
bu_left, bu_right = getBCHorizontal(value[0], N, dx, bc_hor[0])
50+
bw_left, bw_right = getBCHorizontal(value[1], N, dx, bc_hor[1])
51+
# bb_left, bb_right = getBCHorizontal(value[2], N, dx, bc_hor[2])
52+
bp_left, bp_right = getBCHorizontal(value[3], N, dx, bc_hor[3])
53+
54+
b_left = np.concatenate((bp_left, bp_left, bu_left + bw_left))
55+
b_right = np.concatenate((bp_right, bp_right, bu_right + bw_right))
56+
return b_left, b_right
57+
5758

5859
def getBoussinesqBCVertical():
59-
return 0.0
60+
return 0.0

pySDC/implementations/problem_classes/boussinesq_helpers/buildFDMatrix.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ def getMatrix(N, dx, bc_left, bc_right, order):
124124
A[N - 1, :] = np.zeros(N)
125125
A[N - 1, N - 2] = -6.0
126126

127-
A = coeff * (1.0 / dx) * A
127+
A *= coeff * (1.0 / dx)
128+
128129
return sp.csc_matrix(A)
129130

130131

@@ -138,11 +139,13 @@ def getBCLeft(value, N, dx, type, order):
138139
coeff = 1.0 / 2.0
139140
elif order == 4:
140141
coeff = 1.0 / 12.0
142+
else:
143+
raise NotImplementedError('wrong order, got %s' % order)
141144

142145
b = np.zeros(N)
143146
if type in ['dirichlet']:
144147
if order == 2:
145-
b[0] = -value;
148+
b[0] = -value
146149
elif order == 4:
147150
b[0] = -6.0 * value
148151
b[1] = 1.0 * value
@@ -167,6 +170,8 @@ def getBCRight(value, N, dx, type, order):
167170
coeff = 1.0 / 2.0
168171
elif order == 4:
169172
coeff = 1.0 / 12.0
173+
else:
174+
raise NotImplementedError('wrong order, got %s' % order)
170175

171176
b = np.zeros(N)
172177
if type in ['dirichlet']:

pySDC/implementations/problem_classes/boussinesq_helpers/helper_classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ def __init__(self):
2121

2222
def __call__(self, residuals):
2323
self.counter += 1
24-
self.residual = residuals
24+
self.residual = residuals

tests/test_pep8.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ def check_files(dir):
1212
style.options.max_line_length = 120
1313
python_files = []
1414
for root, _, files in os.walk(dir):
15-
if root != 'pySDC/implementations/problem_classes/boussinesq_helpers':
16-
python_files += [os.path.join(root, f) for f in files if f.endswith('.py')]
17-
# python_files = [os.path.join(dir, f) for f in os.listdir(dir) if f.endswith('.py') and f != '__init__.py']
15+
# if root != 'pySDC/implementations/problem_classes/boussinesq_helpers':
16+
python_files += [os.path.join(root, f) for f in files if f.endswith('.py')]
1817
print(python_files)
1918

2019
for file in python_files:

0 commit comments

Comments
 (0)