@@ -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():
297297def 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 )
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,12 +341,58 @@ 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 , 2 , 5 ])
346+ def test_spectrum_computation (mpi_ranks ):
347+ from pySDC .implementations .problem_classes .RayleighBenard3D import RayleighBenard3D
348+
349+ N = 5
350+ prob = RayleighBenard3D (nx = N , ny = N , nz = 2 , dealiasing = 1.0 , spectral_space = False , Rayleigh = 1.0 )
351+ xp = prob .xp
352+ iu , iv = prob .index (['u' , 'v' ])
353+
354+ num_k = int (N // 2 ) + 1
355+
356+ u = prob .u_exact () * 0
357+ u [iu ] = 1
358+ ks , spectrum = prob .get_frequency_spectrum (u )
359+
360+ expect_spectrum = xp .zeros ((prob .nz , num_k ))
361+ expect_spectrum [:, 0 ] = 1
362+
363+ assert len (ks ) == num_k
364+ assert xp .allclose (spectrum [iv ], 0 )
365+ assert xp .allclose (spectrum [iu ], expect_spectrum )
366+
367+ assert N >= 5
368+ u = prob .u_exact () * 0
369+ u [iu ] = xp .sin (prob .Y * 2 * xp .pi / prob .axes [1 ].L )
370+ ks , spectrum = prob .get_frequency_spectrum (u )
371+ assert xp .allclose (spectrum [iu , :, 2 :], 0 )
372+ assert not xp .allclose (spectrum [iu , :, :2 ], 0 )
373+
374+ assert N >= 5
375+ u = prob .u_exact () * 0
376+ u [iu ] = xp .sin (prob .X * 2 * xp .pi / prob .axes [0 ].L ) * xp .sin (prob .Y * 2 * xp .pi / prob .axes [1 ].L )
377+ ks , spectrum = prob .get_frequency_spectrum (u )
378+ assert xp .allclose (spectrum [iu , :, 2 :], 0 )
379+ assert xp .allclose (spectrum [iu , :, 0 ], 0 )
380+ assert not xp .allclose (spectrum [iu , :, 1 ], 0 )
381+
382+ assert N >= 5
383+ u = prob .u_exact () * 0
384+ u [iu ] = xp .sin (prob .X * 4 * xp .pi / prob .axes [0 ].L ) * xp .sin (prob .Y * 2 * xp .pi / prob .axes [1 ].L )
385+ ks , spectrum = prob .get_frequency_spectrum (u )
386+ assert not xp .allclose (spectrum [iu , :, 1 :], 0 )
387+ assert xp .allclose (spectrum [iu , :, 0 ], 0 )
388+
389+
344390if __name__ == '__main__' :
345- # test_eval_f(2**2, 2**1, 'x', False)
391+ test_eval_f (2 ** 2 , 2 ** 1 , 'x' , False )
346392 # test_libraries()
347393 # test_Poisson_problems(4, 'u')
348394 # test_Poisson_problem_w()
349395 # test_solver_convergence('bicgstab+ilu', 32, False, True)
350396 # test_banded_matrix(False)
351397 # test_heterogeneous_implementation()
352- test_Nusselt_number_computation (N = 4 , w = 3.14 )
398+ # test_Nusselt_number_computation(N=4, w=3.14)
0 commit comments