diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000000000000000000000000000000000000..30a7e19e04c97518de57186cff681736162905bf --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +markers = + slow: marks tests as slow (deselect with '--runslow') diff --git a/test.py b/test.py index b64ddfbb36cf1752f95ed9de35b6369c897f82f7..23ce5f8d4c6b3fe08522b47c5bf7d5b412a1cf76 100644 --- a/test.py +++ b/test.py @@ -18,6 +18,74 @@ from pyopencl.tools import ( # noqa import utilities as u +@pytest.mark.slow +@pytest.mark.parametrize(("states_str,fluxes_str,R_inv_str,wavespeeds_str," + "fluxes_pos_expected_str,fluxes_neg_expected_str"), [ + ("2 4 4 4 20,1 1 1 1 5.5", "4 11.2 8 8 46.4,1 2.6 1 1 7.1", + ("0.367521364 0.265894836 0.265894836 0.265894836 -0.167673798," + "-1.12132034 0 0.707106781 0 0," + "-1.12132034 0 0 0.707106781 0," + "-0.430558632 0.416709665 -0.290397116 -0.290397116 0.183124984," + "1.81208206 -0.997503897 -0.290397116 -0.290397116 0.183124984"), + "2.2 2.2 2.2 3.84632925 0.55367075", + ("1.09071563 1.23015152 1.23015152 7.52305259 0.232956271," + "0.467376796 -0.6627417 -0.6627417 1.47953026 0.312527304"), + ("-0.168354897 -0.0585786438 -0.0585786438 -0.727493464 -0.306026299," + "-0.0672231577 0.248528137 0.248528137 -0.107250611 -0.374562227")), + ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "-1 2.6 1 1 -7.1,-4 11.2 8 8 -46.4", + ("0.367521364 -0.265894836 -0.265894836 -0.265894836 -0.167673798," + "1.12132034 0 0.707106781 0 0," + "1.12132034 0 0 0.707106781 0," + "1.81208206 0.997503897 0.290397116 0.290397116 0.183124984," + "-0.430558632 -0.416709665 0.290397116 0.290397116 0.183124984"), + "2.2 2.2 2.2 0.55367075 3.84632925", + ("0.0672231577 0.248528137 0.248528137 0.374562227 0.107250611," + "0.168354897 -0.0585786438 -0.0585786438 0.306026299 0.727493464"), + ("-0.467376796 -0.6627417 -0.6627417 -0.312527304 -1.47953026," + "-1.09071563 1.23015152 1.23015152 -0.232956271 -7.52305259")), + ("2 4 8 12 64,1 1 2 3 11", "4 11.2 16 24 134.4,1 2.6 2 3 12.6", + ("-1.41187463 0.217276117 0.434552233 0.65182835 -0.13701474," + "-2.24264069 0 0.707106781 0 0," + "-3.36396103 0 0 0.707106781 0," + "1.79265641 0.444598298 -0.525016967 -0.78752545 0.165538358," + "4.03529709 -0.969615265 -0.525016967 -0.78752545 0.165538358"), + "2.2 2.2 2.2 3.84632925 0.55367075", + ("1.1162114 2.46030304 3.69045456 7.98692488 0.429010898," + "0.260735274 -1.3254834 -1.9882251 2.05242289 0.501788756"), + ("-0.148282372 -0.117157288 -0.175735931 -0.889325254 -0.200040418," + "-0.00948821371 0.497056275 0.745584412 -0.430637881 -0.314318322")), + ]) +def test_flux_splitting_uniform_grid( + ctx_factory, states_str, fluxes_str, R_inv_str, wavespeeds_str, + fluxes_pos_expected_str, fluxes_neg_expected_str): + prg = u.get_weno_program_with_root_kernel("split_characteristic_fluxes") + queue = u.get_queue(ctx_factory) + + nvars = 5 + + states = u.expand_to_6(u.transposed_array_from_string(states_str)) + fluxes = u.expand_to_6(u.transposed_array_from_string(fluxes_str)) + R_inv = u.array_from_string(R_inv_str) + wavespeeds = u.array_from_string(wavespeeds_str) + fluxes_pos_dev = u.empty_array_on_device(queue, nvars, 6) + fluxes_neg_dev = u.empty_array_on_device(queue, nvars, 6) + + prg(queue, nvars=nvars, + generalized_states_frozen=states, + generalized_fluxes_frozen=fluxes, + R_inv=R_inv, + wavespeeds=wavespeeds, + characteristic_fluxes_pos=fluxes_pos_dev, + characteristic_fluxes_neg=fluxes_neg_dev) + + fluxes_pos_expected = u.expand_to_6(u.transposed_array_from_string(fluxes_pos_expected_str)) + u.compare_arrays(fluxes_pos_dev.get(), fluxes_pos_expected) + + fluxes_neg_expected = u.expand_to_6(u.transposed_array_from_string(fluxes_neg_expected_str)) + u.compare_arrays(fluxes_neg_dev.get(), fluxes_neg_expected) + + +@pytest.mark.slow @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"), @@ -43,6 +111,7 @@ def test_lax_wavespeeds( u.compare_arrays(lam_dev.get(), lam_expected) +@pytest.mark.slow @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"), @@ -87,6 +156,7 @@ def test_pointwise_eigenvalues_ideal_gas( u.compare_arrays(lam_dev.get(), lam_expected) +@pytest.mark.slow @pytest.mark.parametrize("states_str,fluxes_str,direction", [ ("2 4 4 4 20,1 1 1 1 5.5", "4 11.2 8 8 46.4,1 2.6 1 1 7.1", "x"), ("2 4 4 4 20,1 1 1 1 5.5", "4 8 11.2 8 46.4,1 1 2.6 1 7.1", "y"), @@ -146,6 +216,7 @@ def test_roe_uniform_grid_ideal_gas(ctx_factory, states_str, fluxes_str, directi check_roe_property(states, fluxes, R, Rinv, lam) +@pytest.mark.slow def test_matvec(ctx_factory): prg = u.get_weno_program_with_root_kernel("mult_mat_vec") queue = u.get_queue(ctx_factory) diff --git a/utilities.py b/utilities.py index c619310ed0ff59c260744f5b08a8590f5997a7d6..9ae61793b7025717f76a4e52d40abf09a17ace27 100644 --- a/utilities.py +++ b/utilities.py @@ -11,7 +11,7 @@ from pytest import approx # {{{ arrays def compare_arrays(a, b): - assert a == approx(b) + assert a == approx(b, rel=1e-5) def random_array_on_device(queue, *shape):