Skip to content

Commit 0d5e60f

Browse files
committed
Added spectrum computation to 3D RBC (Parallel-in-Time#581)
* Added spectrum computation to 3D RBC * Added documentation
1 parent 3811232 commit 0d5e60f

File tree

2 files changed

+22
-55
lines changed

2 files changed

+22
-55
lines changed

pySDC/implementations/problem_classes/RayleighBenard3D.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class RayleighBenard3D(GenericSpectralLinear):
2828
2929
The domain, vertical boundary conditions and pressure gauge are
3030
31-
Omega = [0, 8) x (-1, 1)
31+
Omega = [0, Lx) x [0, Ly] x (0, Lz)
3232
T(z=+1) = 0
33-
T(z=-1) = 2
33+
T(z=-1) = Lz
3434
u(z=+-1) = v(z=+-1) = 0
3535
integral over p = 0
3636
@@ -53,16 +53,16 @@ class RayleighBenard3D(GenericSpectralLinear):
5353
def __init__(
5454
self,
5555
Prandtl=1,
56-
Rayleigh=2e6,
56+
Rayleigh=1e6,
5757
nx=64,
5858
ny=64,
59-
nz=64,
59+
nz=32,
6060
BCs=None,
6161
dealiasing=1.5,
6262
comm=None,
6363
Lz=1,
64-
Lx=1,
65-
Ly=1,
64+
Lx=4,
65+
Ly=4,
6666
useGPU=False,
6767
**kwargs,
6868
):
@@ -375,24 +375,22 @@ def get_vertical_profiles(self, u, components):
375375

376376
return avgs
377377

378-
def get_Reynolds_number(self, u):
379-
raise # compute RMS velocity incorrectly
380-
if self.spectral_space:
381-
u = self.itransform(u)
382-
else:
383-
u = u.copy()
378+
def get_frequency_spectrum(self, u):
379+
"""
380+
Compute the frequency spectrum of the velocities in x and y direction in the horizontal plane for every point in
381+
z. If the problem is well resolved, the coefficients will decay quickly with the wave number, and the reverse
382+
indicates that the resolution is too low.
384383
385-
indices = list(self.index(['u', 'v', 'w']))
386-
vels = u[indices, ...]
387-
vels *= vels
388-
vels_mean = self.xp.sum(vels, axis=(1, 2, 3)) / self.xp.prod(self.spectral.global_shape[1:])
389-
vels_mean = self.comm.allreduce(vels_mean, MPI.SUM)
390-
v_RMS = (self.xp.sum(vels_mean)) ** (1 / 2)
384+
The returned spectrum has three dimensions. The first is for component (i.e. u or v), the second is for every
385+
point in z and the third is the energy in every wave number.
391386
392-
Re = v_RMS * self.axes[-1].L / self.nu
393-
return Re
387+
Args:
388+
u: The solution you want to compute the spectrum of
394389
395-
def get_frequency_spectrum(self, u):
390+
Returns:
391+
RayleighBenard3D.xp.ndarray: wave numbers
392+
RayleighBenard3D.xp.ndarray: spectrum
393+
"""
396394
xp = self.xp
397395
indices = slice(0, 2)
398396

pySDC/tests/test_problems/test_RayleighBenard3D.py

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def test_eval_f(nx, nz, direction, spectral_space):
1111
import numpy as np
1212
from pySDC.implementations.problem_classes.RayleighBenard3D import RayleighBenard3D
1313

14-
P = RayleighBenard3D(nx=nx, ny=nx, nz=nz, Rayleigh=1, spectral_space=spectral_space)
14+
P = RayleighBenard3D(nx=nx, ny=nx, nz=nz, Rayleigh=1, spectral_space=spectral_space, Lx=1, Ly=1, Lz=1)
1515
iu, iv, iw, ip, iT = P.index(['u', 'v', 'w', 'p', 'T'])
1616
X, Y, Z = P.X, P.Y, P.Z
1717
cos, sin = np.cos, np.sin
@@ -297,7 +297,7 @@ def test_heterogeneous_implementation(N=8, useGPU=True):
297297
def test_Nusselt_number_computation(w, N=4):
298298
from pySDC.implementations.problem_classes.RayleighBenard3D import RayleighBenard3D
299299

300-
prob = RayleighBenard3D(nx=N, ny=N, nz=N, dealiasing=1.0, spectral_space=False, Rayleigh=1.0)
300+
prob = RayleighBenard3D(nx=N, ny=N, nz=N, dealiasing=1.0, spectral_space=False, Rayleigh=1.0, Prandtl=1.0)
301301
xp = prob.xp
302302
iw, iT = prob.index(['w', 'T'])
303303

@@ -341,36 +341,6 @@ def test_Nusselt_number_computation(w, N=4):
341341
assert xp.isclose(Nu[key], w), f'Expected Nu_{key}={w}, but got {Nu[key]} with constant T and perturbed w!'
342342

343343

344-
@pytest.mark.mpi4py
345-
@pytest.mark.mpi(ranks=[1, 4])
346-
def test_Reynolds_number_computation(mpi_ranks):
347-
from pySDC.implementations.problem_classes.RayleighBenard3D import RayleighBenard3D
348-
349-
N = 4
350-
prob = RayleighBenard3D(nx=N, ny=N, nz=N, dealiasing=1.0, spectral_space=False, Rayleigh=1.0)
351-
xp = prob.xp
352-
iu, iv, iw = prob.index(['u', 'v', 'w'])
353-
354-
u = prob.u_exact()
355-
u[iu] = 1
356-
u[iv] = 1
357-
u[iw] = 1
358-
Re = prob.get_Reynolds_number(u)
359-
assert xp.isclose(Re, xp.sqrt(3))
360-
361-
u = prob.u_exact()
362-
u[iv] = (2 * prob.Z) ** (1 / 2)
363-
Re = prob.get_Reynolds_number(u)
364-
assert xp.isclose(Re, 1)
365-
366-
u = prob.u_exact()
367-
u[iv] = (2 * prob.Z) ** (1 / 2)
368-
u[iu] = (2 * prob.Z) ** (1 / 2)
369-
u[iw] = (2 * prob.Z) ** (1 / 2)
370-
Re = prob.get_Reynolds_number(u)
371-
assert xp.isclose(Re, xp.sqrt(3))
372-
373-
374344
@pytest.mark.mpi4py
375345
def test_CFL():
376346
from pySDC.implementations.problem_classes.RayleighBenard3D import RayleighBenard3D
@@ -452,7 +422,7 @@ def test_spectrum_computation(mpi_ranks):
452422

453423

454424
if __name__ == '__main__':
455-
# test_eval_f(2**2, 2**1, 'x', False)
425+
test_eval_f(2**2, 2**1, 'x', False)
456426
# test_libraries()
457427
# test_Poisson_problems(4, 'u')
458428
# test_Poisson_problem_w()
@@ -461,5 +431,4 @@ def test_spectrum_computation(mpi_ranks):
461431
# test_heterogeneous_implementation()
462432
# test_Nusselt_number_computation(N=4, w=3.14)
463433
test_spectrum_computation(None)
464-
# test_Reynolds_number_computation(None)
465434
# test_CFL()

0 commit comments

Comments
 (0)