From 498c6d4c076d9b5b5365092e13f82883d95cbcdf Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Wed, 26 Jun 2019 13:03:23 -0500 Subject: [PATCH 1/5] initial lax wavespeed test with no parametrization --- test.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test.py b/test.py index ce10501..10e5425 100644 --- a/test.py +++ b/test.py @@ -18,6 +18,26 @@ from pyopencl.tools import ( # noqa from utilities import * +def test_lax_wavespeeds( + ctx_factory, lam_pointwise_str, lam_roe_str, lam_expected_str): + def expand_to_6(pair): + return np.repeat(pair, 3, axis=1).copy(order="F") + prg = get_weno_program_with_root_kernel("lax_wavespeeds") + queue = get_queue(ctx_factory) + + nvars = 5 + + lam_pointwise = expand_to_6(transposed_array_from_string(lam_pointwise_str)) + lam_roe = array_from_string(lam_roe_str) + lam_dev = empty_array_on_device(queue, nvars) + + prg(queue, nvars=nvars, lambda_pointwise=lam_pointwise, + lambda_roe=lam_roe, lambda=lam_dev) + + lam_expected = array_from_string(lam_expected_str) + compare_arrays(lam_dev.get(), lam_expected) + + @pytest.mark.parametrize("states_str,direction,lam_expected_str", [ ("2 4 4 4 20,1 1 1 1 5.5", "x", "2 2 2 3.49666295 0.503337045,1 1 1 2.49666295 -0.496662955"), -- GitLab From 8b83fe7b0c07f437461241aaf385c56b8d5f30bf Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Wed, 26 Jun 2019 13:09:10 -0500 Subject: [PATCH 2/5] added first set of test values --- test.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test.py b/test.py index 10e5425..f44fe02 100644 --- a/test.py +++ b/test.py @@ -18,6 +18,9 @@ from pyopencl.tools import ( # noqa from utilities import * +@pytest.mark.parametrize("lam_pointwise_str,lam_roe_str,lam_expected_str", [ + ("1 2 3 4 5,2 4 6 8 10", "1.5 3 4.5 6 7.5", "2.2 4.4 6.6 8.8 11") + ]) def test_lax_wavespeeds( ctx_factory, lam_pointwise_str, lam_roe_str, lam_expected_str): def expand_to_6(pair): -- GitLab From 6c187a27fa5431a6b06df9ae12c663f32c896c89 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Wed, 26 Jun 2019 13:11:46 -0500 Subject: [PATCH 3/5] change lambda to wavespeeds because lambda is a reserved keyword in Python --- WENO.F90 | 32 ++++++++++++++++---------------- test.py | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/WENO.F90 b/WENO.F90 index 829080e..f829dfe 100644 --- a/WENO.F90 +++ b/WENO.F90 @@ -38,7 +38,7 @@ subroutine compute_flux_derivatives(nvars, ndim, nx, ny, nz, & real metric_solve_tmp(ndim) real R(nvars, nvars), R_inv(nvars, nvars), lambda_roe(nvars) real lambda_pointwise(nvars, -2:3) - real lambda(nvars) + real wavespeeds(nvars) integer i, j, k real delta_xi, delta_eta, delta_zeta real characteristic_fluxes_pos(nvars, -2:3) @@ -89,13 +89,13 @@ subroutine compute_flux_derivatives(nvars, ndim, nx, ny, nz, & call roe_eigensystem(nvars, ndim, 1, states(:, i:i+1, j, k), & metrics_frozen, R, R_inv, lambda_roe) - call lax_wavespeeds(nvars, lambda_pointwise, lambda_roe, lambda) + call lax_wavespeeds(nvars, lambda_pointwise, lambda_roe, wavespeeds) call split_characteristic_fluxes(nvars, & generalized_states_frozen, & generalized_fluxes_frozen(:, 1, :), & R_inv, & - lambda, & + wavespeeds, & characteristic_fluxes_pos, & characteristic_fluxes_neg) @@ -139,13 +139,13 @@ subroutine compute_flux_derivatives(nvars, ndim, nx, ny, nz, & call roe_eigensystem(nvars, ndim, 2, states(:, i, j:j+1, k), & metrics_frozen, R, R_inv, lambda_roe) - call lax_wavespeeds(nvars, lambda_pointwise, lambda_roe, lambda) + call lax_wavespeeds(nvars, lambda_pointwise, lambda_roe, wavespeeds) call split_characteristic_fluxes(nvars, & generalized_states_frozen, & generalized_fluxes_frozen(:, 2, :), & R_inv, & - lambda, & + wavespeeds, & characteristic_fluxes_pos, & characteristic_fluxes_neg) @@ -190,13 +190,13 @@ subroutine compute_flux_derivatives(nvars, ndim, nx, ny, nz, & call roe_eigensystem(nvars, ndim, 3, states(:, i, j, k:k+1), & metrics_frozen, R, R_inv, lambda_roe) - call lax_wavespeeds(nvars, lambda_pointwise, lambda_roe, lambda) + call lax_wavespeeds(nvars, lambda_pointwise, lambda_roe, wavespeeds) call split_characteristic_fluxes(nvars, & generalized_states_frozen, & generalized_fluxes_frozen(:, 3, :), & R_inv, & - lambda, & + wavespeeds, & characteristic_fluxes_pos, & characteristic_fluxes_neg) @@ -437,13 +437,13 @@ subroutine roe_eigensystem(nvars, ndim, d, states, metrics_frozen, R, R_inv, lam R_inv(5,5) = beta*b1 end subroutine -subroutine lax_wavespeeds(nvars, lambda_pointwise, lambda_roe, lambda) +subroutine lax_wavespeeds(nvars, lambda_pointwise, lambda_roe, wavespeeds) implicit none integer, intent(in) :: nvars real, intent(in) :: lambda_pointwise(nvars, -2:3) real, intent(in) :: lambda_roe(nvars) - real, intent(out) :: lambda(nvars) + real, intent(out) :: wavespeeds(nvars) real kappa integer v @@ -452,11 +452,11 @@ subroutine lax_wavespeeds(nvars, lambda_pointwise, lambda_roe, lambda) kappa = 1.1 do v=1,nvars - lambda(v) = abs(lambda_roe(v)) + wavespeeds(v) = abs(lambda_roe(v)) do k=-2,3 - lambda(v) = max(lambda(v), abs(lambda_pointwise(v,k))) + wavespeeds(v) = max(wavespeeds(v), abs(lambda_pointwise(v,k))) end do - lambda(v) = kappa*lambda(v) + wavespeeds(v) = kappa*wavespeeds(v) end do end subroutine @@ -615,7 +615,7 @@ subroutine split_characteristic_fluxes(nvars, & generalized_states_frozen, & generalized_fluxes_frozen, & R_inv, & - lambda, & + wavespeeds, & characteristic_fluxes_pos, & characteristic_fluxes_neg) implicit none @@ -624,7 +624,7 @@ subroutine split_characteristic_fluxes(nvars, & real, intent(in) :: generalized_states_frozen(nvars, -2:3) real, intent(in) :: generalized_fluxes_frozen(nvars, -2:3) real, intent(in) :: R_inv(nvars, nvars) - real, intent(in) :: lambda(nvars) + real, intent(in) :: wavespeeds(nvars) real, intent(out) :: characteristic_fluxes_pos(nvars, -2:3) real, intent(out) :: characteristic_fluxes_neg(nvars, -2:3) @@ -638,10 +638,10 @@ subroutine split_characteristic_fluxes(nvars, & do l=1,nvars characteristic_fluxes_pos(m,k) = characteristic_fluxes_pos(m,k) & + 0.5*R_inv(m,l) & - *(generalized_fluxes_frozen(l,k) + lambda(m)*generalized_states_frozen(l,k)) + *(generalized_fluxes_frozen(l,k) + wavespeeds(m)*generalized_states_frozen(l,k)) characteristic_fluxes_neg(m,k) = characteristic_fluxes_neg(m,k) & + 0.5*R_inv(m,l) & - *(generalized_fluxes_frozen(l,k) - lambda(m)*generalized_states_frozen(l,k)) + *(generalized_fluxes_frozen(l,k) - wavespeeds(m)*generalized_states_frozen(l,k)) end do end do end do diff --git a/test.py b/test.py index f44fe02..f1727e2 100644 --- a/test.py +++ b/test.py @@ -35,7 +35,7 @@ def test_lax_wavespeeds( lam_dev = empty_array_on_device(queue, nvars) prg(queue, nvars=nvars, lambda_pointwise=lam_pointwise, - lambda_roe=lam_roe, lambda=lam_dev) + lambda_roe=lam_roe, wavespeeds=lam_dev) lam_expected = array_from_string(lam_expected_str) compare_arrays(lam_dev.get(), lam_expected) -- GitLab From ad7a4d089269c0ec5309713337cfe953280879eb Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Wed, 26 Jun 2019 13:13:18 -0500 Subject: [PATCH 4/5] move common utility expand_to_6 to utilities.py --- test.py | 5 ----- utilities.py | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/test.py b/test.py index f1727e2..f6d0f36 100644 --- a/test.py +++ b/test.py @@ -23,8 +23,6 @@ from utilities import * ]) def test_lax_wavespeeds( ctx_factory, lam_pointwise_str, lam_roe_str, lam_expected_str): - def expand_to_6(pair): - return np.repeat(pair, 3, axis=1).copy(order="F") prg = get_weno_program_with_root_kernel("lax_wavespeeds") queue = get_queue(ctx_factory) @@ -69,9 +67,6 @@ def test_lax_wavespeeds( ]) def test_pointwise_eigenvalues( ctx_factory, states_str, direction, lam_expected_str): - def expand_to_6(pair): - return np.repeat(pair, 3, axis=1).copy(order="F") - prg = get_weno_program_with_root_kernel("pointwise_eigenvalues") queue = get_queue(ctx_factory) diff --git a/utilities.py b/utilities.py index b825fcb..c619310 100644 --- a/utilities.py +++ b/utilities.py @@ -64,6 +64,10 @@ def array_from_string(string_array): def split_map_to_list(string, map_func, splitter): return list(map(map_func, string.split(splitter))) + +def expand_to_6(pair): + return np.repeat(pair, 3, axis=1).copy(order="F") + # }}} # {{{ device -- GitLab From 7f83ea3f7ca7afd79d86330429525d08c300db5b Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Wed, 26 Jun 2019 13:18:35 -0500 Subject: [PATCH 5/5] finish adding test parameters for lax wavespeed test --- test.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test.py b/test.py index f6d0f36..1bfe9c8 100644 --- a/test.py +++ b/test.py @@ -19,7 +19,11 @@ from utilities import * @pytest.mark.parametrize("lam_pointwise_str,lam_roe_str,lam_expected_str", [ - ("1 2 3 4 5,2 4 6 8 10", "1.5 3 4.5 6 7.5", "2.2 4.4 6.6 8.8 11") + ("1 2 3 4 5,2 4 6 8 10", "1.5 3 4.5 6 7.5", "2.2 4.4 6.6 8.8 11"), + ("1 2 3 4 5,-2 -4 -6 -8 -10", "1.5 3 4.5 6 7.5", "2.2 4.4 6.6 8.8 11"), + ("1 2 3 4 5,-2 -4 -6 -8 -10", "3 6 9 12 15", "3.3 6.6 9.9 13.2 16.5"), + ("1 2 3 4 5,2 4 6 8 10", "-3 -6 -9 -12 -15", "3.3 6.6 9.9 13.2 16.5"), + ("3 2 9 4 5,2 6 6 12 10", "-1 -4 -3 -8 -15", "3.3 6.6 9.9 13.2 16.5") ]) def test_lax_wavespeeds( ctx_factory, lam_pointwise_str, lam_roe_str, lam_expected_str): -- GitLab