diff --git a/comparison_fixtures.py b/comparison_fixtures.py index e21ec0c2b9d40bcc8c45dca96a9b2eddf5c9e193..402f9beccc3480ec5725cf8358b2d97797ef268d 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 1ff71ac5ab413959f8f27e4a1509e1638a2a66e6..7f3dff465c30ab8fc9101ab092ef4c134bcfa951 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 d1705f59aeed4e079973e069128d10c467e5d982..6f1debcb3e2bc1b8acb16f45d58bd3a16771a25a 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 2748ded40e9f6f7ecdf99361ebc50074325a7269..ab3af8c16ac425faedddc0b5374b0f8426e0be05 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()