Skip to content

Commit 42d04ed

Browse files
committed
Fixed problem tests for 2D RBC
1 parent cfaf2e7 commit 42d04ed

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

pySDC/implementations/problem_classes/RayleighBenard.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,7 @@ def compute_Nusselt_numbers(self, u):
431431
else:
432432
u_hat = self.transform(u)
433433

434-
DzT_hat = self.spectral.u_init_forward
435-
DzT_hat[iT] = (self.Dz @ u_hat[iT].flatten()).reshape(DzT_hat[iT].shape)
434+
DzT_hat = (self.Dz @ u_hat[iT].flatten()).reshape(u_hat[iT].shape)
436435

437436
# compute vT with dealiasing
438437
padding = (self.dealiasing, self.dealiasing)
@@ -453,13 +452,13 @@ def compute_Nusselt_numbers(self, u):
453452
integral_V = 0
454453
if self.comm.rank == 0:
455454

456-
integral_z = (self._zInt @ nusselt_hat[0, 0]).real
455+
integral_z = (self._zInt @ nusselt_hat[0]).real
457456
integral_z[0] = zAxis.get_integration_constant(integral_z, axis=-1)
458457
integral_V = ((top - bot) * integral_z).sum() * self.axes[0].L / self.nx
459458

460459
Nusselt_V = self.comm.bcast(integral_V / self.spectral.V, root=0)
461-
Nusselt_t = self.comm.bcast(self.xp.sum(nusselt_hat.real[0, 0] * top, axis=-1) / self.nx, root=0)
462-
Nusselt_b = self.comm.bcast(self.xp.sum(nusselt_hat.real[0, 0] * bot, axis=-1) / self.nx, root=0)
460+
Nusselt_t = self.comm.bcast(self.xp.sum(nusselt_hat.real[0] * top, axis=-1) / self.nx, root=0)
461+
Nusselt_b = self.comm.bcast(self.xp.sum(nusselt_hat.real[0] * bot, axis=-1) / self.nx, root=0)
463462

464463
return {
465464
'V': Nusselt_V,
@@ -536,8 +535,8 @@ def compute_max_step_size(P, u):
536535
grid_spacing_x = P.X[1, 0] - P.X[0, 0]
537536

538537
cell_wallz = P.xp.zeros(P.nz + 1)
539-
cell_wallz[0] = 1
540-
cell_wallz[-1] = -1
538+
cell_wallz[0] = P.Lz
539+
cell_wallz[-1] = 0
541540
cell_wallz[1:-1] = (P.Z[0, :-1] + P.Z[0, 1:]) / 2
542541
grid_spacing_z = cell_wallz[:-1] - cell_wallz[1:]
543542

pySDC/tests/test_problems/test_RayleighBenard.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_vorticity(nx, nz, direction):
105105

106106
@pytest.mark.mpi4py
107107
@pytest.mark.parametrize('v', [0, 3.14])
108-
def test_Nusselt_numbers(v, nx=6, nz=4):
108+
def test_Nusselt_numbers(v, nx=1, nz=10):
109109
import numpy as np
110110
from pySDC.implementations.problem_classes.RayleighBenard import RayleighBenard
111111

@@ -114,12 +114,22 @@ def test_Nusselt_numbers(v, nx=6, nz=4):
114114
'v_bottom': 0,
115115
}
116116

117-
P = RayleighBenard(nx=nx, nz=nz, BCs=BCs, dealiasing=1.0, Rayleigh=1)
117+
P = RayleighBenard(nx=nx, nz=nz, BCs=BCs, dealiasing=1.0, Rayleigh=1, spectral_space=False)
118118
prob = P
119119
xp = prob.xp
120120
iv, iT = prob.index(['v', 'T'])
121121

122-
u = P.u_exact(noise_level=0)
122+
u = prob.u_init
123+
u[iT, ...] = prob.Z
124+
Nu = prob.compute_Nusselt_numbers(u)
125+
for key, expect in zip(['t', 'b', 'V'], [-1, -1, -1]):
126+
assert xp.isclose(Nu[key], expect), f'Expected Nu_{key}={expect}, but got {Nu[key]}'
127+
128+
u = prob.u_init
129+
u[iT, ...] = 3 * prob.Z**2 + 1
130+
Nu = prob.compute_Nusselt_numbers(u)
131+
for key, expect in zip(['t', 'b', 'V'], [-6, 0, -3]):
132+
assert xp.isclose(Nu[key], expect), f'Expected Nu_{key}={expect}, but got {Nu[key]}'
123133

124134
u = prob.u_init
125135
u[iT, ...] = 3 * prob.Z**2 + 1
@@ -128,17 +138,6 @@ def test_Nusselt_numbers(v, nx=6, nz=4):
128138
for key, expect in zip(['t', 'b', 'V'], [prob.Lz * (3 + 1) * v - 6, v, v * (1 + 1) - 3]):
129139
assert xp.isclose(Nu[key], expect), f'Expected Nu_{key}={expect}, but got {Nu[key]}'
130140

131-
return None
132-
133-
# for key, expect in zip(['t', 'b', 'V'], [prob.Lz * (3 + 1) * w - 6, w, w * (1 + 1) - 3]):
134-
# assert xp.isclose(Nu[key], expect), f'Expected Nu_{key}={expect}, but got {Nu[key]}'
135-
136-
# nusselt = P.compute_Nusselt_numbers(u)
137-
# expect = {'V':v, 't': 0, 'b': + 2 * v}
138-
# print(nusselt, expect)
139-
# for key in nusselt.keys():
140-
# assert np.isclose(nusselt[key], expect[key]), key
141-
142141

143142
def test_viscous_dissipation(nx=2**5 + 1, nz=2**3 + 1):
144143
import numpy as np
@@ -198,7 +197,7 @@ def test_Poisson_problems(nx, component):
198197
'T_bottom': 0,
199198
}
200199
P = RayleighBenard(
201-
nx=nx, nz=6, BCs=BCs, Rayleigh=(max([abs(BCs['T_top'] - BCs['T_bottom']), np.finfo(float).eps]) * 2**3)
200+
nx=nx, nz=6, BCs=BCs, Rayleigh=(max([abs(BCs['T_top'] - BCs['T_bottom']), np.finfo(float).eps]) * 2**3), Lz=2
202201
)
203202
rhs = P.u_init
204203

@@ -237,7 +236,7 @@ def test_Poisson_problem_v():
237236
'v_top': 0,
238237
'v_bottom': 0,
239238
'T_top': 0,
240-
'T_bottom': 2,
239+
'T_bottom': 1,
241240
}
242241
P = RayleighBenard(nx=2, nz=2**3, BCs=BCs, Rayleigh=1.0)
243242
iv = P.index('v')
@@ -272,7 +271,7 @@ def test_CFL():
272271
from pySDC.implementations.problem_classes.RayleighBenard import RayleighBenard, CFLLimit
273272
import numpy as np
274273

275-
P = RayleighBenard(nx=5, nz=2, spectral_space=False)
274+
P = RayleighBenard(nx=5, nz=2, spectral_space=False, Lz=2)
276275
iu, iv = P.index(['u', 'v'])
277276

278277
u = P.u_init
@@ -331,11 +330,11 @@ def test_apply_BCs():
331330

332331
if __name__ == '__main__':
333332
# test_eval_f(2**0, 2**2, 'z', True)
334-
# test_Poisson_problem(1, 'T')
333+
# test_Poisson_problems(1, 'T')
335334
# test_Poisson_problem_v()
336335
# test_apply_BCs()
337-
test_Nusselt_numbers(1)
336+
# test_Nusselt_numbers(1)
338337
# test_buoyancy_computation()
339338
# test_viscous_dissipation()
340-
# test_CFL()
339+
test_CFL()
341340
# test_Nyquist_mode_elimination()

pySDC/tests/test_problems/test_RayleighBenard3D.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def test_heterogeneous_implementation():
294294

295295
@pytest.mark.mpi4py
296296
@pytest.mark.parametrize('w', [0, 1, 3.14])
297-
def test_Nusselt_number_computation(w, N=4):
297+
def test_Nusselt_number_computation(w, N=6):
298298
from pySDC.implementations.problem_classes.RayleighBenard3D import RayleighBenard3D
299299

300300
prob = RayleighBenard3D(nx=N, ny=N, nz=N, dealiasing=1.0, spectral_space=False)

0 commit comments

Comments
 (0)