From 08b0844e52f38d4ce1c7a52c108063033c5182cd Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Wed, 29 May 2019 10:44:35 -0500 Subject: [PATCH 01/10] skipping slow tests always for now since we don't have the new marker yet --- test.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test.py b/test.py index 146e052..2748ded 100644 --- a/test.py +++ b/test.py @@ -13,6 +13,7 @@ import setup_fixtures as setup import kernel_fixtures as kernel import comparison_fixtures as compare + def test_matvec(ctx_factory): queue = device.get_queue(ctx_factory) prg = program.get_weno() @@ -25,6 +26,7 @@ def test_matvec(ctx_factory): compare.arrays(a@b, c) +@pytest.mark.skip("slow") def test_compute_flux_derivatives(ctx_factory): queue = device.get_queue(ctx_factory) prg = program.get_weno() @@ -36,6 +38,7 @@ def test_compute_flux_derivatives(ctx_factory): kernel.compute_flux_derivatives(queue, prg, params, arrays) +@pytest.mark.skip("slow") def test_compute_flux_derivatives_gpu(ctx_factory): queue = device.get_queue(ctx_factory) prg = program.get_weno() -- GitLab From 5ae0def2bcabbe6a4505045c0901e3c37a2660a7 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Wed, 29 May 2019 10:53:54 -0500 Subject: [PATCH 02/10] bring in array parsing fixtures from another project --- setup_fixtures.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/setup_fixtures.py b/setup_fixtures.py index bcecb9e..d1705f5 100644 --- a/setup_fixtures.py +++ b/setup_fixtures.py @@ -74,3 +74,42 @@ def random_flux_derivative_arrays_on_device(ctx_factory, params): metric_jacobians = random_array_on_device(queue, *params.jacobian_bounds()) return FluxDerivativeArrays(states, fluxes, metrics, metric_jacobians) + + +def arrays_from_string(string_arrays): + return split_map_to_list(string_arrays, array_from_string, ":") + + +def array_from_string(string_array): + if ";" not in string_array: + if "," not in string_array: + return array_from_string_1d(string_array) + else: + return array_from_string_2d(string_array) + else: + return array_from_string_3d(string_array) + + +def array_from_string_3d(string_array): + if string_array[0] == ";": + return array_from_string_1d(string_array[1:]).reshape((-1, 1, 1)) + else: + return np.array(split_map_to_list(string_array, array_from_string_2d, ";")) + + +def array_from_string_2d(string_array): + if string_array[0] == ",": + return array_from_string_1d(string_array[1:]).reshape((-1, 1)) + else: + return np.array(split_map_to_list(string_array, array_from_string_1d, ",")) + + +def array_from_string_1d(string_array): + if string_array[0] == "i": + return np.array(split_map_to_list(string_array[1:], int, " ")) + else: + return np.array(split_map_to_list(string_array, float, " ")) + + +def split_map_to_list(string, map_func, splitter): + return list(map(map_func, string.split(splitter))) -- GitLab From 80d89b0ea04da54cbb8855d29f63bb460f58f522 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Wed, 29 May 2019 11:31:33 -0500 Subject: [PATCH 03/10] added Roe identity check -- exposes broken implementation --- comparison_fixtures.py | 5 +++++ kernel_fixtures.py | 13 +++++++++++++ setup_fixtures.py | 31 +++++++++++++++++++++++++++---- test.py | 16 ++++++++++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/comparison_fixtures.py b/comparison_fixtures.py index e21ec0c..402f9be 100644 --- a/comparison_fixtures.py +++ b/comparison_fixtures.py @@ -3,3 +3,8 @@ from pytest import approx def arrays(a, b): assert a == approx(b) + + +def roe_identity(states, R, Rinv): + dState = states[:,1] - states[:,0] + arrays(R@(Rinv@dState), dState) diff --git a/kernel_fixtures.py b/kernel_fixtures.py index 1ff71ac..7f3dff4 100644 --- a/kernel_fixtures.py +++ b/kernel_fixtures.py @@ -15,6 +15,19 @@ def with_root_kernel(prg, root_name): return new_prg +def roe_eigensystem(queue, prg, params, states, metrics_frozen): + R_dev = setup.empty_array_on_device(queue, params.mat_bounds()) + Rinv_dev = setup.empty_array_on_device(queue, params.mat_bounds()) + lam_dev = setup.empty_array_on_device(queue, params.vec_bounds()) + + prg = with_root_kernel(prg, "roe_eigensystem") + prg(queue, nvars=params.nvars, ndim=params.ndim, d=params.d, + states=states, metrics_frozen=metrics_frozen, + R=R_dev, R_inv=Rinv_dev, lambda_roe=lam_dev) + + return R_dev.get(), Rinv_dev.get(), lam_dev.get() + + def mult_mat_vec(queue, prg, alpha, a, b): c_dev = setup.empty_array_on_device(queue, b.shape) diff --git a/setup_fixtures.py b/setup_fixtures.py index d1705f5..6f1debc 100644 --- a/setup_fixtures.py +++ b/setup_fixtures.py @@ -5,6 +5,19 @@ import pyopencl.array # noqa import device_fixtures as device +class RoeParams: + def __init__(self, nvars, ndim, d): + self.nvars = nvars + self.ndim = ndim + self.d = d + + def mat_bounds(self): + return self.nvars, self.nvars + + def vec_bounds(self): + return self.nvars + + class FluxDerivativeParams: def __init__(self, nvars, ndim, nx, ny, nz): self.nvars = nvars @@ -40,6 +53,11 @@ class FluxDerivativeArrays: self.metric_jacobians = metric_jacobians +def roe_params(nvars, ndim, direction): + dirs = {"x" : 1, "y" : 2, "z" : 3} + return RoeParams(nvars, ndim, dirs[direction]) + + def flux_derivative_params(nvars, ndim, n): return FluxDerivativeParams(nvars, ndim, n, n, n) @@ -48,6 +66,10 @@ def empty_array_on_device(queue, shape): return cl.array.empty(queue, shape, dtype=np.float32, order="F") +def identity(n): + return np.identity(n).astype(np.float32).copy(order="F") + + def random_array(*shape): return np.random.random_sample(shape).astype(np.float32).copy(order="F") @@ -83,11 +105,12 @@ def arrays_from_string(string_arrays): def array_from_string(string_array): if ";" not in string_array: if "," not in string_array: - return array_from_string_1d(string_array) + array = array_from_string_1d(string_array) else: - return array_from_string_2d(string_array) + array = array_from_string_2d(string_array) else: - return array_from_string_3d(string_array) + array = array_from_string_3d(string_array) + return array.copy(order="F") def array_from_string_3d(string_array): @@ -108,7 +131,7 @@ def array_from_string_1d(string_array): if string_array[0] == "i": return np.array(split_map_to_list(string_array[1:], int, " ")) else: - return np.array(split_map_to_list(string_array, float, " ")) + return np.array(split_map_to_list(string_array, float, " "), dtype=np.float32) def split_map_to_list(string, map_func, splitter): diff --git a/test.py b/test.py index 2748ded..ab3af8c 100644 --- a/test.py +++ b/test.py @@ -2,6 +2,7 @@ import sys import logging import pytest +import pyopencl as cl from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests) @@ -14,6 +15,21 @@ import kernel_fixtures as kernel import comparison_fixtures as compare +def test_roe(ctx_factory): + queue = device.get_queue(ctx_factory) + prg = program.get_weno() + + params = setup.roe_params(nvars=5, ndim=3, direction="x") + states = setup.array_from_string("2 1,4 1,4 1,4 1,20 5.5") + metrics_frozen = setup.identity(params.ndim) + R, Rinv, lam = kernel.roe_eigensystem(queue, prg, params, states, metrics_frozen) + + compare.roe_identity(states, R, Rinv) + + #fluxes = setup.array_from_string("4 11.2 8 8 46.4,1 2.6 1 1 7.1") + #compare.roe_property(states, fluxes, R, Rinv, lam) + + def test_matvec(ctx_factory): queue = device.get_queue(ctx_factory) prg = program.get_weno() -- GitLab From eb96634bc3a2da98ecbdfd7d9dab4e7deefe73e1 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Wed, 29 May 2019 17:52:40 -0500 Subject: [PATCH 04/10] Fix bug in Roe eigensystem computation --- WENO.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WENO.F90 b/WENO.F90 index e8618ef..0299251 100644 --- a/WENO.F90 +++ b/WENO.F90 @@ -350,7 +350,7 @@ subroutine roe_eigensystem(nvars, ndim, d, states, metrics_frozen, R, R_inv, lam c = sqrt((1.4 - 1.0)*(H - 0.5*q)) b1 = (1.4 - 1.0)/(c**2) - b2 = 1.0 + b1*q**2 - b1*H + b2 = 1.0 + b1*q - b1*H u_tilde(1) = 0.0 do i=1,ndim -- GitLab From 2f24f12522165c465d758dd99e8086ddf7e5a1a3 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Wed, 29 May 2019 18:19:36 -0500 Subject: [PATCH 05/10] add Roe property check --- comparison_fixtures.py | 10 ++++++++++ test.py | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/comparison_fixtures.py b/comparison_fixtures.py index 402f9be..04c7432 100644 --- a/comparison_fixtures.py +++ b/comparison_fixtures.py @@ -1,3 +1,4 @@ +import numpy as np from pytest import approx @@ -8,3 +9,12 @@ def arrays(a, b): def roe_identity(states, R, Rinv): dState = states[:,1] - states[:,0] arrays(R@(Rinv@dState), dState) + + +def roe_property(states, fluxes, R, Rinv, lam): + dState = states[:,1] - states[:,0] + dFlux = fluxes[:,1] - fluxes[:,0] + + temp = Rinv@dState + temp = np.multiply(lam, temp) + arrays(R@temp, dFlux) diff --git a/test.py b/test.py index ab3af8c..d71231e 100644 --- a/test.py +++ b/test.py @@ -26,8 +26,8 @@ def test_roe(ctx_factory): compare.roe_identity(states, R, Rinv) - #fluxes = setup.array_from_string("4 11.2 8 8 46.4,1 2.6 1 1 7.1") - #compare.roe_property(states, fluxes, R, Rinv, lam) + fluxes = setup.array_from_string("4 1,11.2 2.6,8 1,8 1,46.4 7.1") + compare.roe_property(states, fluxes, R, Rinv, lam) def test_matvec(ctx_factory): -- GitLab From 49ca1d1476848698f274f2b57865afefdcdc6007 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Wed, 29 May 2019 18:20:20 -0500 Subject: [PATCH 06/10] rename Roe test --- test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.py b/test.py index d71231e..257046f 100644 --- a/test.py +++ b/test.py @@ -15,7 +15,7 @@ import kernel_fixtures as kernel import comparison_fixtures as compare -def test_roe(ctx_factory): +def test_roe_uniform_grid(ctx_factory): queue = device.get_queue(ctx_factory) prg = program.get_weno() -- GitLab From bbc1da42d47a23b55e5b601a564091a9acbc67d3 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Wed, 29 May 2019 21:54:47 -0500 Subject: [PATCH 07/10] add more values for Roe test -- exposed another bug --- test.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test.py b/test.py index 257046f..e72d34e 100644 --- a/test.py +++ b/test.py @@ -14,19 +14,29 @@ import setup_fixtures as setup import kernel_fixtures as kernel import comparison_fixtures as compare - -def test_roe_uniform_grid(ctx_factory): +@pytest.mark.parametrize("states_str,fluxes_str,direction", [ + ("2 1,4 1,4 1,4 1,20 5.5", "4 1,11.2 2.6,8 1,8 1,46.4 7.1", "x"), + ("2 1,4 1,4 1,4 1,20 5.5", "4 1,8 1,11.2 2.6,8 1,46.4 7.1", "y"), + ("2 1,4 1,4 1,4 1,20 5.5", "4 1,8 1,8 1,11.2 2.6,46.4 7.1", "z"), + ("1 2,-1 -4,-1 -4,-1 -4,5.5 20", "-1 -4,2.6 11.2,1 8,1 8,-7.1 -46.4", "x"), + ("1 2,-1 -4,-1 -4,-1 -4,5.5 20", "-1 -4,1 8,2.6 11.2,1 8,-7.1 -46.4", "y"), + ("1 2,-1 -4,-1 -4,-1 -4,5.5 20", "-1 -4,1 8,1 8,2.6 11.2,-7.1 -46.4", "z"), + ("2 1,4 1,8 2,12 3,64 11", "4 1,11.2 2.6,16 2,24 3,134.4 12.6", "x"), + ("2 1,4 1,8 2,12 3,64 11", "8 2,16 2,35.2 5.6,48 6,268.8 25.2", "y"), + ("2 1,4 1,8 2,12 3,64 11", "12 3,24 3,48 6,75.2 10.6,403.2 37.8", "z") + ]) +def test_roe_uniform_grid(ctx_factory, states_str, fluxes_str, direction): queue = device.get_queue(ctx_factory) prg = program.get_weno() - params = setup.roe_params(nvars=5, ndim=3, direction="x") - states = setup.array_from_string("2 1,4 1,4 1,4 1,20 5.5") + params = setup.roe_params(nvars=5, ndim=3, direction=direction) + states = setup.array_from_string(states_str) metrics_frozen = setup.identity(params.ndim) R, Rinv, lam = kernel.roe_eigensystem(queue, prg, params, states, metrics_frozen) compare.roe_identity(states, R, Rinv) - fluxes = setup.array_from_string("4 1,11.2 2.6,8 1,8 1,46.4 7.1") + fluxes = setup.array_from_string(fluxes_str) compare.roe_property(states, fluxes, R, Rinv, lam) -- GitLab From 094b2b214f7a97ff816e53061c9a4187521a3ce0 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Thu, 30 May 2019 12:13:34 -0500 Subject: [PATCH 08/10] using new strategy for marking slow tests --- test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.py b/test.py index e72d34e..f213723 100644 --- a/test.py +++ b/test.py @@ -52,7 +52,7 @@ def test_matvec(ctx_factory): compare.arrays(a@b, c) -@pytest.mark.skip("slow") +@pytest.mark.slow def test_compute_flux_derivatives(ctx_factory): queue = device.get_queue(ctx_factory) prg = program.get_weno() @@ -64,7 +64,7 @@ def test_compute_flux_derivatives(ctx_factory): kernel.compute_flux_derivatives(queue, prg, params, arrays) -@pytest.mark.skip("slow") +@pytest.mark.slow def test_compute_flux_derivatives_gpu(ctx_factory): queue = device.get_queue(ctx_factory) prg = program.get_weno() -- GitLab From 49a446518be0e8f643a3571c03fb15bb70d74bde Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Thu, 30 May 2019 13:18:53 -0500 Subject: [PATCH 09/10] mark roe tests as expected to fail --- test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test.py b/test.py index f213723..924171f 100644 --- a/test.py +++ b/test.py @@ -14,6 +14,7 @@ import setup_fixtures as setup import kernel_fixtures as kernel import comparison_fixtures as compare +@pytest.mark.xfail @pytest.mark.parametrize("states_str,fluxes_str,direction", [ ("2 1,4 1,4 1,4 1,20 5.5", "4 1,11.2 2.6,8 1,8 1,46.4 7.1", "x"), ("2 1,4 1,4 1,4 1,20 5.5", "4 1,8 1,11.2 2.6,8 1,46.4 7.1", "y"), -- GitLab From 6e213784fb0cf5e6e24776d34f27f902e7eeaf72 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 31 May 2019 10:40:11 -0500 Subject: [PATCH 10/10] fix an apparent bug in Roe eigenvalues, tests still not passing --- WENO.F90 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/WENO.F90 b/WENO.F90 index 0299251..995d3b7 100644 --- a/WENO.F90 +++ b/WENO.F90 @@ -370,11 +370,11 @@ subroutine roe_eigensystem(nvars, ndim, d, states, metrics_frozen, R, R_inv, lam alpha = rho/(2.0*c) beta = 1.0/(2.0*alpha) - lambda_roe(1) = u(1) - lambda_roe(2) = u(1) - lambda_roe(3) = u(1) - lambda_roe(4) = u(1) + c - lambda_roe(5) = u(1) - c + lambda_roe(1) = u_tilde(1)*metric_norm(ik) + lambda_roe(2) = u_tilde(1)*metric_norm(ik) + lambda_roe(3) = u_tilde(1)*metric_norm(ik) + lambda_roe(4) = u_tilde(1)*metric_norm(ik) + c*metric_norm(ik) + lambda_roe(5) = u_tilde(1)*metric_norm(ik) - c*metric_norm(ik) R(1,1) = 1.0 R(2,1) = u(1) -- GitLab