Skip to content

Commit cfaf2e7

Browse files
committed
Changed default 2D RBC setup
1 parent 303c2f0 commit cfaf2e7

File tree

3 files changed

+56
-27
lines changed

3 files changed

+56
-27
lines changed

pySDC/implementations/problem_classes/RayleighBenard.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def __init__(
5858
BCs=None,
5959
dealiasing=3 / 2,
6060
comm=None,
61-
Lx=8,
61+
Lx=4,
62+
Lz=1,
6263
**kwargs,
6364
):
6465
"""
@@ -77,7 +78,7 @@ def __init__(
7778
BCs = {} if BCs is None else BCs
7879
BCs = {
7980
'T_top': 0,
80-
'T_bottom': 2,
81+
'T_bottom': 1,
8182
'v_top': 0,
8283
'v_bottom': 0,
8384
'u_top': 0,
@@ -101,11 +102,15 @@ def __init__(
101102
'dealiasing',
102103
'comm',
103104
'Lx',
105+
'Lz',
104106
localVars=locals(),
105107
readOnly=True,
106108
)
107109

108-
bases = [{'base': 'fft', 'N': nx, 'x0': 0, 'x1': self.Lx}, {'base': 'ultraspherical', 'N': nz}]
110+
bases = [
111+
{'base': 'fft', 'N': nx, 'x0': 0, 'x1': self.Lx},
112+
{'base': 'ultraspherical', 'N': nz, 'x0': 0, 'x1': self.Lz},
113+
]
109114
components = ['u', 'v', 'T', 'p']
110115
super().__init__(bases, components, comm=comm, **kwargs)
111116

@@ -370,12 +375,13 @@ def compute_vorticity(self, u):
370375
u_hat = u.copy()
371376
else:
372377
u_hat = self.transform(u)
378+
373379
Dz = self.Dz
374380
Dx = self.Dx
375381
iu, iv = self.index(['u', 'v'])
376382

377383
vorticity_hat = self.spectral.u_init_forward
378-
vorticity_hat[0] = (Dx * u_hat[iv].flatten() + Dz @ u_hat[iu].flatten()).reshape(u[iu].shape)
384+
vorticity_hat[0] = (Dx * u_hat[iv].flatten() + Dz @ u_hat[iu].flatten()).reshape(u_hat[iu].shape)
379385
return self.itransform(vorticity_hat)[0].real
380386

381387
def getOutputFile(self, fileName):
@@ -418,14 +424,14 @@ def compute_Nusselt_numbers(self, u):
418424
dict: Nusselt number averaged over the entire volume and horizontally averaged at the top and bottom.
419425
"""
420426
iv, iT = self.index(['v', 'T'])
421-
422-
DzT_hat = self.spectral.u_init_forward
427+
zAxis = self.spectral.axes[-1]
423428

424429
if self.spectral_space:
425430
u_hat = u.copy()
426431
else:
427432
u_hat = self.transform(u)
428433

434+
DzT_hat = self.spectral.u_init_forward
429435
DzT_hat[iT] = (self.Dz @ u_hat[iT].flatten()).reshape(DzT_hat[iT].shape)
430436

431437
# compute vT with dealiasing
@@ -435,21 +441,25 @@ def compute_Nusselt_numbers(self, u):
435441
_me[0] = u_pad[iv] * u_pad[iT]
436442
vT_hat = self.transform(_me, padding=padding)[0]
437443

438-
# nusselt_hat = (vT_hat - DzT_hat[iT]) / self.nx
444+
if not hasattr(self, '_zInt'):
445+
self._zInt = zAxis.get_integration_matrix()
446+
439447
nusselt_hat = (vT_hat / self.kappa - DzT_hat) * self.axes[-1].L
440448

441-
integral_z = self.xp.sum(nusselt_hat * self.spectral.axes[1].get_BC(kind='integral'), axis=-1).real
442-
integral_V = (
443-
integral_z[0] * self.axes[0].L
444-
) # only the first Fourier mode has non-zero integral with periodic BCs
445-
Nusselt_V = self.comm.bcast(integral_V / self.spectral.V, root=0)
449+
# get coefficients for evaluation on the boundary
450+
top = zAxis.get_BC(kind='Dirichlet', x=1)
451+
bot = zAxis.get_BC(kind='Dirichlet', x=-1)
446452

447-
Nusselt_t = self.comm.bcast(
448-
self.xp.sum(nusselt_hat * self.spectral.axes[1].get_BC(kind='Dirichlet', x=1), axis=-1).real[0], root=0
449-
)
450-
Nusselt_b = self.comm.bcast(
451-
self.xp.sum(nusselt_hat * self.spectral.axes[1].get_BC(kind='Dirichlet', x=-1), axis=-1).real[0], root=0
452-
)
453+
integral_V = 0
454+
if self.comm.rank == 0:
455+
456+
integral_z = (self._zInt @ nusselt_hat[0, 0]).real
457+
integral_z[0] = zAxis.get_integration_constant(integral_z, axis=-1)
458+
integral_V = ((top - bot) * integral_z).sum() * self.axes[0].L / self.nx
459+
460+
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)
453463

454464
return {
455465
'V': Nusselt_V,

pySDC/tests/test_hooks/test_log_to_file.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ def test_logging(tmpdir, use_pickle, ODE=True):
126126

127127
for us, uf in zip(u, u_file):
128128
assert us[0] == uf[0], 'time does not match'
129-
assert np.allclose(us[1], uf[1]), 'solution does not match'
129+
if ODE:
130+
assert np.allclose(us[1], uf[1]), 'solution does not match'
131+
else:
132+
assert np.allclose(us[1], uf[1][:4]), 'solution does not match'
130133

131134

132135
@pytest.mark.base

pySDC/tests/test_problems/test_RayleighBenard.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,34 @@ def test_Nusselt_numbers(v, nx=6, nz=4):
110110
from pySDC.implementations.problem_classes.RayleighBenard import RayleighBenard
111111

112112
BCs = {
113-
'v_top': v,
114-
'v_bottom': v,
113+
'v_top': 0,
114+
'v_bottom': 0,
115115
}
116116

117-
P = RayleighBenard(nx=nx, nz=nz, BCs=BCs, dealiasing=1.5)
117+
P = RayleighBenard(nx=nx, nz=nz, BCs=BCs, dealiasing=1.0, Rayleigh=1)
118+
prob = P
119+
xp = prob.xp
120+
iv, iT = prob.index(['v', 'T'])
118121

119122
u = P.u_exact(noise_level=0)
120123

121-
nusselt = P.compute_Nusselt_numbers(u)
122-
expect = {'V': 1 + v, 't': 1, 'b': +1 + 2 * v, 'b_no_v': 1, 't_no_v': 1}
123-
for key in nusselt.keys():
124-
assert np.isclose(nusselt[key], expect[key]), key
124+
u = prob.u_init
125+
u[iT, ...] = 3 * prob.Z**2 + 1
126+
u[iv] = v * (1 + xp.sin(prob.X / prob.axes[0].L * 2 * xp.pi))
127+
Nu = prob.compute_Nusselt_numbers(u)
128+
for key, expect in zip(['t', 'b', 'V'], [prob.Lz * (3 + 1) * v - 6, v, v * (1 + 1) - 3]):
129+
assert xp.isclose(Nu[key], expect), f'Expected Nu_{key}={expect}, but got {Nu[key]}'
130+
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
125141

126142

127143
def test_viscous_dissipation(nx=2**5 + 1, nz=2**3 + 1):
@@ -318,7 +334,7 @@ def test_apply_BCs():
318334
# test_Poisson_problem(1, 'T')
319335
# test_Poisson_problem_v()
320336
# test_apply_BCs()
321-
test_Nusselt_numbers(3.14)
337+
test_Nusselt_numbers(1)
322338
# test_buoyancy_computation()
323339
# test_viscous_dissipation()
324340
# test_CFL()

0 commit comments

Comments
 (0)