From 2e704f72531a04eb25f2799826acdec97831a7e0 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 23 Aug 2019 11:32:24 -0500 Subject: [PATCH 01/43] mark tests as slow and focus on case a:x --- data_for_test.py | 10 +++++----- test.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index bde2cd9..13232d3 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -926,11 +926,11 @@ single_data["Case d:z"] = FluxDataSingle( @pytest.fixture(scope="session", params=[ - "Case flat:x", "Case flat:y", "Case flat:z", - "Case a:x", "Case a:y", "Case a:z", - "Case b:x", "Case b:y", "Case b:z", - "Case c:x", "Case c:y", "Case c:z", - "Case d:x", "Case d:y", "Case d:z"]) + #"Case flat:x", "Case flat:y", "Case flat:z", + "Case a:x"])#, "Case a:y", "Case a:z", + #"Case b:x", "Case b:y", "Case b:z", + #"Case c:x", "Case c:y", "Case c:z", + #"Case d:x", "Case d:y", "Case d:z"]) def flux_test_data_fixture(request): return single_data[request.param] diff --git a/test.py b/test.py index ed0a436..5e465ea 100644 --- a/test.py +++ b/test.py @@ -18,6 +18,7 @@ import utilities as u from data_for_test import flux_test_data_fixture # noqa: F401 +@pytest.mark.slow def test_weno_flux_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -37,6 +38,7 @@ def test_weno_flux_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(flux_dev.get(), data.weno_flux) +@pytest.mark.slow def test_consistent_part_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -52,6 +54,7 @@ def test_consistent_part_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(consistent_dev.get(), data.consistent) +@pytest.mark.slow def test_dissipation_part_pos_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -69,6 +72,7 @@ def test_dissipation_part_pos_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(dissipation_dev.get(), data.dissipation_pos) +@pytest.mark.slow def test_dissipation_part_neg_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -86,6 +90,7 @@ def test_dissipation_part_neg_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(dissipation_dev.get(), data.dissipation_neg) +@pytest.mark.slow def test_weno_weights_pos_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -105,6 +110,7 @@ def test_weno_weights_pos_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(weights_dev.get(), data.weno_weights_pos) +@pytest.mark.slow def test_weno_weights_neg_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -124,6 +130,7 @@ def test_weno_weights_neg_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(weights_dev.get(), data.weno_weights_neg) +@pytest.mark.slow def test_oscillation_pos_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -139,6 +146,7 @@ def test_oscillation_pos_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(oscillation_dev.get(), data.oscillation_pos) +@pytest.mark.slow def test_oscillation_neg_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -154,6 +162,7 @@ def test_oscillation_neg_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(oscillation_dev.get(), data.oscillation_neg) +@pytest.mark.slow def test_flux_splitting_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -175,6 +184,7 @@ def test_flux_splitting_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(fluxes_neg_dev.get(), data.char_fluxes_neg) +@pytest.mark.slow def test_pointwise_eigenvalues_ideal_gas(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -189,6 +199,7 @@ def test_pointwise_eigenvalues_ideal_gas(ctx_factory, flux_test_data_fixture): u.compare_arrays(lam_dev.get(), data.lam_pointwise) +@pytest.mark.slow def test_roe_uniform_grid_ideal_gas(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -228,6 +239,7 @@ def test_roe_uniform_grid_ideal_gas(ctx_factory, flux_test_data_fixture): check_roe_property(data.state_pair, data.flux_pair, R, R_inv, lam) +@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"), @@ -253,6 +265,7 @@ def test_lax_wavespeeds( u.compare_arrays(lam_dev.get(), lam_expected) +@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) -- GitLab From 648ec71cc64b893b6b5073840b131fc8e8ce2546 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 23 Aug 2019 11:34:58 -0500 Subject: [PATCH 02/43] add skeleton test to double-check if weno weight computation with expected data --- test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test.py b/test.py index 5e465ea..79b4b89 100644 --- a/test.py +++ b/test.py @@ -18,6 +18,10 @@ import utilities as u from data_for_test import flux_test_data_fixture # noqa: F401 +def test_weno_weight_computation(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture + + @pytest.mark.slow def test_weno_flux_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture -- GitLab From 14bdf2b4e0b654a564432f1c8dc501e7276de6e2 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 23 Aug 2019 19:47:45 -0500 Subject: [PATCH 03/43] Revert "mark tests as slow and focus on case a:x" This reverts commit 2e704f72531a04eb25f2799826acdec97831a7e0. --- data_for_test.py | 10 +++++----- test.py | 13 ------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index 13232d3..bde2cd9 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -926,11 +926,11 @@ single_data["Case d:z"] = FluxDataSingle( @pytest.fixture(scope="session", params=[ - #"Case flat:x", "Case flat:y", "Case flat:z", - "Case a:x"])#, "Case a:y", "Case a:z", - #"Case b:x", "Case b:y", "Case b:z", - #"Case c:x", "Case c:y", "Case c:z", - #"Case d:x", "Case d:y", "Case d:z"]) + "Case flat:x", "Case flat:y", "Case flat:z", + "Case a:x", "Case a:y", "Case a:z", + "Case b:x", "Case b:y", "Case b:z", + "Case c:x", "Case c:y", "Case c:z", + "Case d:x", "Case d:y", "Case d:z"]) def flux_test_data_fixture(request): return single_data[request.param] diff --git a/test.py b/test.py index a3eeb17..53ab820 100644 --- a/test.py +++ b/test.py @@ -25,7 +25,6 @@ def test_weno_weight_computation(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture -@pytest.mark.slow def test_weno_flux_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -45,7 +44,6 @@ def test_weno_flux_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(flux_dev.get(), data.weno_flux) -@pytest.mark.slow def test_consistent_part_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -61,7 +59,6 @@ def test_consistent_part_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(consistent_dev.get(), data.consistent) -@pytest.mark.slow def test_dissipation_part_pos_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -79,7 +76,6 @@ def test_dissipation_part_pos_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(dissipation_dev.get(), data.dissipation_pos) -@pytest.mark.slow def test_dissipation_part_neg_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -97,7 +93,6 @@ def test_dissipation_part_neg_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(dissipation_dev.get(), data.dissipation_neg) -@pytest.mark.slow def test_weno_weights_pos_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -117,7 +112,6 @@ def test_weno_weights_pos_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(weights_dev.get(), data.weno_weights_pos) -@pytest.mark.slow def test_weno_weights_neg_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -137,7 +131,6 @@ def test_weno_weights_neg_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(weights_dev.get(), data.weno_weights_neg) -@pytest.mark.slow def test_oscillation_pos_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -153,7 +146,6 @@ def test_oscillation_pos_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(oscillation_dev.get(), data.oscillation_pos) -@pytest.mark.slow def test_oscillation_neg_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -169,7 +161,6 @@ def test_oscillation_neg_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(oscillation_dev.get(), data.oscillation_neg) -@pytest.mark.slow def test_flux_splitting_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -191,7 +182,6 @@ def test_flux_splitting_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(fluxes_neg_dev.get(), data.char_fluxes_neg) -@pytest.mark.slow def test_pointwise_eigenvalues_ideal_gas(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -206,7 +196,6 @@ def test_pointwise_eigenvalues_ideal_gas(ctx_factory, flux_test_data_fixture): u.compare_arrays(lam_dev.get(), data.lam_pointwise) -@pytest.mark.slow def test_roe_uniform_grid_ideal_gas(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture @@ -246,7 +235,6 @@ def test_roe_uniform_grid_ideal_gas(ctx_factory, flux_test_data_fixture): check_roe_property(data.state_pair, data.flux_pair, R, R_inv, lam) -@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"), @@ -272,7 +260,6 @@ def test_lax_wavespeeds( u.compare_arrays(lam_dev.get(), lam_expected) -@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) -- GitLab From 23a454442a1ffcdf7dca26c3afd4cb92c46b549d Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 23 Aug 2019 23:04:41 -0500 Subject: [PATCH 04/43] introduce new test to check whether bug is in WENO.F90 or Mathematica script --- test.py | 43 +++++++++++++++++++++++++++++++++++++++++++ utilities.py | 3 ++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/test.py b/test.py index 53ab820..d8ae1bf 100644 --- a/test.py +++ b/test.py @@ -24,6 +24,49 @@ from data_for_test import ( # noqa: F401 def test_weno_weight_computation(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture + def weno_weights(oscillation): + linear = np.array([0.1, 0.6, 0.3]) + eps = 1e-6 + + raw_weights = np.empty((5,3)) + for i in range(5): + for j in range(3): + raw_weights[i,j] = linear[j]/(oscillation[i,j] + eps)**2 + + weight_sum = raw_weights.sum(axis=1) + weights = np.empty((5,3)) + for i in range(5): + for j in range(3): + weights[i,j] = raw_weights[i,j]/weight_sum[i] + + return weights + + prg = u.get_weno_program_with_root_kernel("weno_weights_pos") + queue = u.get_queue(ctx_factory) + + weights_dev = u.empty_array_on_device(queue, data.nvars, 3) + + prg(queue, nvars=data.nvars, + characteristic_fluxes=data.char_fluxes_pos, + combined_frozen_metrics=1.0, + w=weights_dev) + + w = weno_weights(data.oscillation_pos) + u.compare_arrays(weights_dev.get(), w) + + prg = u.get_weno_program_with_root_kernel("weno_weights_neg") + queue = u.get_queue(ctx_factory) + + weights_dev = u.empty_array_on_device(queue, data.nvars, 3) + + prg(queue, nvars=data.nvars, + characteristic_fluxes=data.char_fluxes_neg, + combined_frozen_metrics=1.0, + w=weights_dev) + + w = weno_weights(data.oscillation_neg) + u.compare_arrays(weights_dev.get(), w) + def test_weno_flux_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture diff --git a/utilities.py b/utilities.py index c8bde8a..927763f 100644 --- a/utilities.py +++ b/utilities.py @@ -11,7 +11,8 @@ from pytest import approx # {{{ arrays def compare_arrays(a, b): - assert a == approx(b, rel=1e-5, abs=2e-5) + #assert a == approx(b, rel=1e-5, abs=2e-5) + assert a == approx(b, rel=1e-12, abs=1e-14) def random_array_on_device(queue, *shape): -- GitLab From 61c2b092f42dfc2a16e513faf460250bc6282388 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 23 Aug 2019 23:06:50 -0500 Subject: [PATCH 05/43] create new file for Python reference implementation --- reference_implementation.py | 56 +++++++++++++++++++++++++++++++++++++ test.py | 47 ------------------------------- 2 files changed, 56 insertions(+), 47 deletions(-) create mode 100644 reference_implementation.py diff --git a/reference_implementation.py b/reference_implementation.py new file mode 100644 index 0000000..24f4a0c --- /dev/null +++ b/reference_implementation.py @@ -0,0 +1,56 @@ +import numpy as np +import numpy.linalg as la # noqa: F401 +import pyopencl as cl # noqa: F401 +import pyopencl.array # noqa +import pyopencl.tools # noqa +import pyopencl.clrandom # noqa +import loopy as lp # noqa + + +def test_weno_weight_computation(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture + + def weno_weights(oscillation): + linear = np.array([0.1, 0.6, 0.3]) + eps = 1e-6 + + raw_weights = np.empty((5,3)) + for i in range(5): + for j in range(3): + raw_weights[i,j] = linear[j]/(oscillation[i,j] + eps)**2 + + weight_sum = raw_weights.sum(axis=1) + weights = np.empty((5,3)) + for i in range(5): + for j in range(3): + weights[i,j] = raw_weights[i,j]/weight_sum[i] + + return weights + + prg = u.get_weno_program_with_root_kernel("weno_weights_pos") + queue = u.get_queue(ctx_factory) + + weights_dev = u.empty_array_on_device(queue, data.nvars, 3) + + prg(queue, nvars=data.nvars, + characteristic_fluxes=data.char_fluxes_pos, + combined_frozen_metrics=1.0, + w=weights_dev) + + w = weno_weights(data.oscillation_pos) + u.compare_arrays(weights_dev.get(), w) + + prg = u.get_weno_program_with_root_kernel("weno_weights_neg") + queue = u.get_queue(ctx_factory) + + weights_dev = u.empty_array_on_device(queue, data.nvars, 3) + + prg(queue, nvars=data.nvars, + characteristic_fluxes=data.char_fluxes_neg, + combined_frozen_metrics=1.0, + w=weights_dev) + + w = weno_weights(data.oscillation_neg) + u.compare_arrays(weights_dev.get(), w) + + diff --git a/test.py b/test.py index d8ae1bf..671b7fe 100644 --- a/test.py +++ b/test.py @@ -21,53 +21,6 @@ from data_for_test import ( # noqa: F401 ) -def test_weno_weight_computation(ctx_factory, flux_test_data_fixture): - data = flux_test_data_fixture - - def weno_weights(oscillation): - linear = np.array([0.1, 0.6, 0.3]) - eps = 1e-6 - - raw_weights = np.empty((5,3)) - for i in range(5): - for j in range(3): - raw_weights[i,j] = linear[j]/(oscillation[i,j] + eps)**2 - - weight_sum = raw_weights.sum(axis=1) - weights = np.empty((5,3)) - for i in range(5): - for j in range(3): - weights[i,j] = raw_weights[i,j]/weight_sum[i] - - return weights - - prg = u.get_weno_program_with_root_kernel("weno_weights_pos") - queue = u.get_queue(ctx_factory) - - weights_dev = u.empty_array_on_device(queue, data.nvars, 3) - - prg(queue, nvars=data.nvars, - characteristic_fluxes=data.char_fluxes_pos, - combined_frozen_metrics=1.0, - w=weights_dev) - - w = weno_weights(data.oscillation_pos) - u.compare_arrays(weights_dev.get(), w) - - prg = u.get_weno_program_with_root_kernel("weno_weights_neg") - queue = u.get_queue(ctx_factory) - - weights_dev = u.empty_array_on_device(queue, data.nvars, 3) - - prg(queue, nvars=data.nvars, - characteristic_fluxes=data.char_fluxes_neg, - combined_frozen_metrics=1.0, - w=weights_dev) - - w = weno_weights(data.oscillation_neg) - u.compare_arrays(weights_dev.get(), w) - - def test_weno_flux_uniform_grid(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture -- GitLab From 9b53a87882ad81f8f251747fff12208f6f5f0959 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 23 Aug 2019 23:14:56 -0500 Subject: [PATCH 06/43] change combined_frozen_metrics so it is set in FluxDataSingle constructor --- data_for_test.py | 2 ++ test.py | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index bde2cd9..7970a62 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -44,6 +44,8 @@ class FluxDataSingle: self.oscillation_pos = u.transposed_array_from_string(oscillation_pos_str) self.oscillation_neg = u.transposed_array_from_string(oscillation_neg_str) + self.combined_frozen_metrics = 1.0 + self.weno_weights_pos = u.transposed_array_from_string(weno_weights_pos_str) self.weno_weights_neg = u.transposed_array_from_string(weno_weights_neg_str) diff --git a/test.py b/test.py index 671b7fe..da3abad 100644 --- a/test.py +++ b/test.py @@ -33,7 +33,7 @@ def test_weno_flux_uniform_grid(ctx_factory, flux_test_data_fixture): generalized_fluxes=data.fluxes, characteristic_fluxes_pos=data.char_fluxes_pos, characteristic_fluxes_neg=data.char_fluxes_neg, - combined_frozen_metrics=1.0, + combined_frozen_metrics=data.combined_frozen_metrics, R=data.R, flux=flux_dev) @@ -65,7 +65,7 @@ def test_dissipation_part_pos_uniform_grid(ctx_factory, flux_test_data_fixture): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_pos, - combined_frozen_metrics=1.0, + combined_frozen_metrics=data.combined_frozen_metrics, R=data.R, dissipation_pos=dissipation_dev) @@ -82,7 +82,7 @@ def test_dissipation_part_neg_uniform_grid(ctx_factory, flux_test_data_fixture): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_neg, - combined_frozen_metrics=1.0, + combined_frozen_metrics=data.combined_frozen_metrics, R=data.R, dissipation_neg=dissipation_dev) @@ -99,7 +99,7 @@ def test_weno_weights_pos_uniform_grid(ctx_factory, flux_test_data_fixture): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_pos, - combined_frozen_metrics=1.0, + combined_frozen_metrics=data.combined_frozen_metrics, w=weights_dev) sum_weights = np.sum(weights_dev.get(), axis=1) @@ -118,7 +118,7 @@ def test_weno_weights_neg_uniform_grid(ctx_factory, flux_test_data_fixture): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_neg, - combined_frozen_metrics=1.0, + combined_frozen_metrics=data.combined_frozen_metrics, w=weights_dev) sum_weights = np.sum(weights_dev.get(), axis=1) -- GitLab From 8941ae59ad2c7dccc85916aebd7d2dd43c3da558 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 23 Aug 2019 23:51:48 -0500 Subject: [PATCH 07/43] added reference implementation for weno_weights --- data_for_test.py | 10 ++++-- reference_implementation.py | 63 ++++++++++--------------------------- 2 files changed, 24 insertions(+), 49 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index 7970a62..47b437f 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -1,5 +1,6 @@ import pytest import utilities as u +import reference_implementation as ref # {{{ FluxDataSingle @@ -46,13 +47,18 @@ class FluxDataSingle: self.combined_frozen_metrics = 1.0 - self.weno_weights_pos = u.transposed_array_from_string(weno_weights_pos_str) - self.weno_weights_neg = u.transposed_array_from_string(weno_weights_neg_str) + #self.weno_weights_pos = u.transposed_array_from_string(weno_weights_pos_str) + #self.weno_weights_neg = u.transposed_array_from_string(weno_weights_neg_str) + self.weno_weights_pos = ref.weno_weights( + self.oscillation_pos, self.combined_frozen_metrics) + self.weno_weights_neg = ref.weno_weights( + self.oscillation_neg, self.combined_frozen_metrics) self.consistent = self.swap_array( u.array_from_string(consistent_str), self.direction) self.dissipation_pos = self.swap_array( u.array_from_string(dissipation_pos_str), self.direction) + self.dissipation_neg = self.swap_array( u.array_from_string(dissipation_neg_str), self.direction) diff --git a/reference_implementation.py b/reference_implementation.py index 24f4a0c..6552295 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -7,50 +7,19 @@ import pyopencl.clrandom # noqa import loopy as lp # noqa -def test_weno_weight_computation(ctx_factory, flux_test_data_fixture): - data = flux_test_data_fixture - - def weno_weights(oscillation): - linear = np.array([0.1, 0.6, 0.3]) - eps = 1e-6 - - raw_weights = np.empty((5,3)) - for i in range(5): - for j in range(3): - raw_weights[i,j] = linear[j]/(oscillation[i,j] + eps)**2 - - weight_sum = raw_weights.sum(axis=1) - weights = np.empty((5,3)) - for i in range(5): - for j in range(3): - weights[i,j] = raw_weights[i,j]/weight_sum[i] - - return weights - - prg = u.get_weno_program_with_root_kernel("weno_weights_pos") - queue = u.get_queue(ctx_factory) - - weights_dev = u.empty_array_on_device(queue, data.nvars, 3) - - prg(queue, nvars=data.nvars, - characteristic_fluxes=data.char_fluxes_pos, - combined_frozen_metrics=1.0, - w=weights_dev) - - w = weno_weights(data.oscillation_pos) - u.compare_arrays(weights_dev.get(), w) - - prg = u.get_weno_program_with_root_kernel("weno_weights_neg") - queue = u.get_queue(ctx_factory) - - weights_dev = u.empty_array_on_device(queue, data.nvars, 3) - - prg(queue, nvars=data.nvars, - characteristic_fluxes=data.char_fluxes_neg, - combined_frozen_metrics=1.0, - w=weights_dev) - - w = weno_weights(data.oscillation_neg) - u.compare_arrays(weights_dev.get(), w) - - +def weno_weights(oscillation, frozen_metric): + linear = np.array([0.1, 0.6, 0.3]) + eps = 1e-6*frozen_metric + + raw_weights = np.empty((5,3)) + for i in range(5): + for j in range(3): + raw_weights[i,j] = linear[j]/(oscillation[i,j] + eps)**2 + + weight_sum = raw_weights.sum(axis=1) + weights = np.empty((5,3)) + for i in range(5): + for j in range(3): + weights[i,j] = raw_weights[i,j]/weight_sum[i] + + return weights -- GitLab From 8de4a6d3e3179429b7af00195877317698b0ca06 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Sat, 24 Aug 2019 00:10:43 -0500 Subject: [PATCH 08/43] add reference implementation for positive dissipation part --- data_for_test.py | 6 ++++-- reference_implementation.py | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index 47b437f..cdfab73 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -56,8 +56,10 @@ class FluxDataSingle: self.consistent = self.swap_array( u.array_from_string(consistent_str), self.direction) - self.dissipation_pos = self.swap_array( - u.array_from_string(dissipation_pos_str), self.direction) + #self.dissipation_pos = self.swap_array( + # u.array_from_string(dissipation_pos_str), self.direction) + self.dissipation_pos = ref.dissipation_part( + self.R, self.char_fluxes_pos, self.weno_weights_pos) self.dissipation_neg = self.swap_array( u.array_from_string(dissipation_neg_str), self.direction) diff --git a/reference_implementation.py b/reference_implementation.py index 6552295..1428c0f 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -23,3 +23,29 @@ def weno_weights(oscillation, frozen_metric): weights[i,j] = raw_weights[i,j]/weight_sum[i] return weights + + +def flux_differences(f): + w = np.array([-1, 3, -3, 1]) + res = np.empty((5, 3)) + for j in range(res.shape[1]): + res[:,j] = f[:,j:j+4]@w + return res + + +def combination_weighting(w): + return np.array( + [20*w[:,0] - 1, -10*(w[:,0] + w[:,1]) + 5, np.ones(w.shape[0])] + ).T + + +def combine_fluxes(w, f): + cw = combination_weighting(w) + return np.sum(np.multiply(cw, f), axis=1) + + +def dissipation_part(R, char_fluxes, w): + flux_diff = flux_differences(char_fluxes) + flux_comb = combine_fluxes(w, flux_diff) + + return -R@flux_comb/60 -- GitLab From 470a5c259c67a1afc31da41ef96ab745612a8691 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Sat, 24 Aug 2019 00:17:13 -0500 Subject: [PATCH 09/43] added dissipation_part_neg reference implementation --- data_for_test.py | 8 +++++--- reference_implementation.py | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index cdfab73..55a683a 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -59,10 +59,12 @@ class FluxDataSingle: #self.dissipation_pos = self.swap_array( # u.array_from_string(dissipation_pos_str), self.direction) self.dissipation_pos = ref.dissipation_part( - self.R, self.char_fluxes_pos, self.weno_weights_pos) + self.R, self.char_fluxes_pos, self.weno_weights_pos, 1) - self.dissipation_neg = self.swap_array( - u.array_from_string(dissipation_neg_str), self.direction) + #self.dissipation_neg = self.swap_array( + # u.array_from_string(dissipation_neg_str), self.direction) + self.dissipation_neg = ref.dissipation_part( + self.R, self.char_fluxes_neg, self.weno_weights_neg, -1) self.weno_flux = self.swap_array( u.array_from_string(weno_flux_str), self.direction) diff --git a/reference_implementation.py b/reference_implementation.py index 1428c0f..154cd55 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -44,8 +44,8 @@ def combine_fluxes(w, f): return np.sum(np.multiply(cw, f), axis=1) -def dissipation_part(R, char_fluxes, w): - flux_diff = flux_differences(char_fluxes) +def dissipation_part(R, char_fluxes, w, sign): + flux_diff = flux_differences(char_fluxes)[:,::sign] flux_comb = combine_fluxes(w, flux_diff) - return -R@flux_comb/60 + return -sign*R@flux_comb/60 -- GitLab From 888b3746fc42466bab905ba94eedd9ae83add2af Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Sat, 24 Aug 2019 00:19:28 -0500 Subject: [PATCH 10/43] add reference implementation of weno flux --- data_for_test.py | 6 ++++-- reference_implementation.py | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index 55a683a..a541679 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -66,8 +66,10 @@ class FluxDataSingle: self.dissipation_neg = ref.dissipation_part( self.R, self.char_fluxes_neg, self.weno_weights_neg, -1) - self.weno_flux = self.swap_array( - u.array_from_string(weno_flux_str), self.direction) + #self.weno_flux = self.swap_array( + # u.array_from_string(weno_flux_str), self.direction) + self.weno_flux = ref.weno_flux( + self.consistent, self.dissipation_pos, self.dissipation_neg) def swap_array(self, arr, d): p = self.permutation(d) diff --git a/reference_implementation.py b/reference_implementation.py index 154cd55..419bb9d 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -49,3 +49,7 @@ def dissipation_part(R, char_fluxes, w, sign): flux_comb = combine_fluxes(w, flux_diff) return -sign*R@flux_comb/60 + + +def weno_flux(consistent, dissipation_pos, dissipation_neg): + return consistent + dissipation_pos + dissipation_neg -- GitLab From 8b965c6dbdce834bc9a74bb3d4c82b40df819853 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 26 Aug 2019 23:31:04 -0500 Subject: [PATCH 11/43] added reference implementation for oscillation indicators --- data_for_test.py | 7 +++++-- reference_implementation.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index a541679..baf9412 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -42,8 +42,11 @@ class FluxDataSingle: self.char_fluxes_neg = u.expand_to_6( u.transposed_array_from_string(char_fluxes_neg_str)) - self.oscillation_pos = u.transposed_array_from_string(oscillation_pos_str) - self.oscillation_neg = u.transposed_array_from_string(oscillation_neg_str) + #self.oscillation_pos = u.transposed_array_from_string(oscillation_pos_str) + #self.oscillation_neg = u.transposed_array_from_string(oscillation_neg_str) + + self.oscillation_pos = ref.oscillation(self.char_fluxes_pos) + self.oscillation_neg = ref.oscillation(self.char_fluxes_neg[:,::-1]) self.combined_frozen_metrics = 1.0 diff --git a/reference_implementation.py b/reference_implementation.py index 419bb9d..7eb7a3e 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -7,6 +7,22 @@ import pyopencl.clrandom # noqa import loopy as lp # noqa +def oscillation(fluxes): + sum1 = np.empty((fluxes.shape[0], 3)) + sum2 = np.empty((fluxes.shape[0], 3)) + + sum1[:,0] = fluxes[:,0] - 4*fluxes[:,1] + 3*fluxes[:,2] + sum1[:,1] = -fluxes[:,1] + fluxes[:,3] + sum1[:,2] = -3*fluxes[:,2] + 4*fluxes[:,3] - fluxes[:,4] + + for i in range(3): + sum2[:,i] = fluxes[:,i] - 2*fluxes[:,i+1] + fluxes[:,i+2] + + result = (1.0/4)*(sum1**2) + (13.0/12)*(sum2**2) + + return result + + def weno_weights(oscillation, frozen_metric): linear = np.array([0.1, 0.6, 0.3]) eps = 1e-6*frozen_metric -- GitLab From 5cecb85ade31a3c6c3f2a64393923f1cba8e3462 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Thu, 29 Aug 2019 23:58:05 -0500 Subject: [PATCH 12/43] added reference implementation for characteristic flux splitting --- data_for_test.py | 20 +++++++--- reference_implementation.py | 76 +++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 6 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index baf9412..959e0df 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -1,3 +1,4 @@ +import numpy as np import pytest import utilities as u import reference_implementation as ref @@ -28,6 +29,11 @@ class FluxDataSingle: u.transposed_array_from_string(fluxes_str), self.direction) self.fluxes = u.expand_to_6(self.flux_pair) + self.frozen_metrics = np.zeros(3) + self.frozen_metrics[self.direction-1] = 1.0 + self.frozen_jacobian = 1.0 + self.combined_frozen_metrics = 1.0 + self.lam_pointwise = u.expand_to_6( u.transposed_array_from_string(lam_str)) @@ -37,10 +43,14 @@ class FluxDataSingle: u.array_from_string(R_inv_str), self.direction) self.wavespeeds = u.array_from_string(wavespeeds_str) - self.char_fluxes_pos = u.expand_to_6( - u.transposed_array_from_string(char_fluxes_pos_str)) - self.char_fluxes_neg = u.expand_to_6( - u.transposed_array_from_string(char_fluxes_neg_str)) + #self.char_fluxes_pos = u.expand_to_6( + # u.transposed_array_from_string(char_fluxes_pos_str)) + #self.char_fluxes_neg = u.expand_to_6( + # u.transposed_array_from_string(char_fluxes_neg_str)) + + self.char_fluxes_pos, self.char_fluxes_neg = ref.split_char_fluxes( + self.states, self.wavespeeds, + self.frozen_metrics, self.frozen_jacobian, self.R_inv) #self.oscillation_pos = u.transposed_array_from_string(oscillation_pos_str) #self.oscillation_neg = u.transposed_array_from_string(oscillation_neg_str) @@ -48,8 +58,6 @@ class FluxDataSingle: self.oscillation_pos = ref.oscillation(self.char_fluxes_pos) self.oscillation_neg = ref.oscillation(self.char_fluxes_neg[:,::-1]) - self.combined_frozen_metrics = 1.0 - #self.weno_weights_pos = u.transposed_array_from_string(weno_weights_pos_str) #self.weno_weights_neg = u.transposed_array_from_string(weno_weights_neg_str) self.weno_weights_pos = ref.weno_weights( diff --git a/reference_implementation.py b/reference_implementation.py index 7eb7a3e..7d08ed4 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -7,6 +7,82 @@ import pyopencl.clrandom # noqa import loopy as lp # noqa +# FIXME: add new file ideal_gas.py that has flux, pressure, etc. (any +# computation that depends on EOS + +def pressure(state): + # FIXME: for ideal gas stuff, make nvars, ndim, gamma, etc module level + # constants + # FIXME: also split out velocity, rho, energy into separate routines + gamma = 1.4 + ndim = state.size - 2 + + rho = state[0] + energy = state[ndim+1] + + ke = 0.0 + for i in range(ndim): + ke += (state[i+1]/rho)**2 + ke = 0.5*rho*ke + + return (gamma - 1)*(energy - ke) + + +def flux(state): + nvars = state.size + ndim = nvars - 2 + result = np.empty((nvars, ndim)) + + rho = state[0] + u = state[1:ndim+1]/rho + energy = state[ndim+1] + p = pressure(state) + + for i in range(ndim): + result[:,i] = u[i]*state + result[i+1,i] += p + result[ndim+1,i] += u[i]*p + + return result + + +def pointwise_fluxes(states): + nvars, npoints = states.shape + ndim = 3 + result = np.empty((nvars, ndim, npoints)) + + for k in range(npoints): + result[:,:,k] = flux(states[:,k]) + + return result + + +def split_char_fluxes(states, wavespeeds, frozen_metrics, frozen_jacobian, R_inv): + nvars, npoints = states.shape + ndim = frozen_metrics.size + + fluxes = pointwise_fluxes(states) + + char_fluxes_pos = np.empty((nvars, npoints)) + char_fluxes_neg = np.empty((nvars, npoints)) + for k in range(npoints): + generalized_fluxes = np.zeros(nvars) + for i in range(ndim): + generalized_fluxes += frozen_metrics[i]*fluxes[:,i,k] + + generalized_states = states[:,k]/frozen_jacobian + + combination_pos = np.empty((nvars, nvars)) + combination_neg = np.empty((nvars, nvars)) + for i in range(nvars): + char_fluxes_pos[i,k] = 0.5*np.dot(R_inv[i,:], + (generalized_fluxes + wavespeeds[i]*generalized_states)) + char_fluxes_neg[i,k] = 0.5*np.dot(R_inv[i,:], + (generalized_fluxes - wavespeeds[i]*generalized_states)) + + return char_fluxes_pos, char_fluxes_neg + + def oscillation(fluxes): sum1 = np.empty((fluxes.shape[0], 3)) sum2 = np.empty((fluxes.shape[0], 3)) -- GitLab From 48687dc22250b0b3ce069918dfea4e7e1b73ecdb Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 30 Aug 2019 00:20:04 -0500 Subject: [PATCH 13/43] not using ref implementation of characteristic flux splitting since it seems to cause dimensional issues --- data_for_test.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index 959e0df..bd3425f 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -43,14 +43,14 @@ class FluxDataSingle: u.array_from_string(R_inv_str), self.direction) self.wavespeeds = u.array_from_string(wavespeeds_str) - #self.char_fluxes_pos = u.expand_to_6( - # u.transposed_array_from_string(char_fluxes_pos_str)) - #self.char_fluxes_neg = u.expand_to_6( - # u.transposed_array_from_string(char_fluxes_neg_str)) - - self.char_fluxes_pos, self.char_fluxes_neg = ref.split_char_fluxes( - self.states, self.wavespeeds, - self.frozen_metrics, self.frozen_jacobian, self.R_inv) + self.char_fluxes_pos = u.expand_to_6( + u.transposed_array_from_string(char_fluxes_pos_str)) + self.char_fluxes_neg = u.expand_to_6( + u.transposed_array_from_string(char_fluxes_neg_str)) + + #self.char_fluxes_pos, self.char_fluxes_neg = ref.split_char_fluxes( + # self.states, self.wavespeeds, + # self.frozen_metrics, self.frozen_jacobian, self.R_inv) #self.oscillation_pos = u.transposed_array_from_string(oscillation_pos_str) #self.oscillation_neg = u.transposed_array_from_string(oscillation_neg_str) -- GitLab From e8acc37dd2d83765208740a86afaf15a9a569709 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 30 Aug 2019 14:00:23 -0500 Subject: [PATCH 14/43] introduce utility for generating empty arrays --- data_for_test.py | 3 +-- reference_implementation.py | 24 ++++++++++++------------ utilities.py | 16 ++++++++++++---- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index bd3425f..1f5fa95 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -1,4 +1,3 @@ -import numpy as np import pytest import utilities as u import reference_implementation as ref @@ -29,7 +28,7 @@ class FluxDataSingle: u.transposed_array_from_string(fluxes_str), self.direction) self.fluxes = u.expand_to_6(self.flux_pair) - self.frozen_metrics = np.zeros(3) + self.frozen_metrics = u.zero_array(3) self.frozen_metrics[self.direction-1] = 1.0 self.frozen_jacobian = 1.0 self.combined_frozen_metrics = 1.0 diff --git a/reference_implementation.py b/reference_implementation.py index 7d08ed4..116da09 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -31,7 +31,7 @@ def pressure(state): def flux(state): nvars = state.size ndim = nvars - 2 - result = np.empty((nvars, ndim)) + result = u.empty_array(nvars, ndim) rho = state[0] u = state[1:ndim+1]/rho @@ -49,7 +49,7 @@ def flux(state): def pointwise_fluxes(states): nvars, npoints = states.shape ndim = 3 - result = np.empty((nvars, ndim, npoints)) + result = u.empty_array(nvars, ndim, npoints) for k in range(npoints): result[:,:,k] = flux(states[:,k]) @@ -63,17 +63,17 @@ def split_char_fluxes(states, wavespeeds, frozen_metrics, frozen_jacobian, R_inv fluxes = pointwise_fluxes(states) - char_fluxes_pos = np.empty((nvars, npoints)) - char_fluxes_neg = np.empty((nvars, npoints)) + char_fluxes_pos = u.empty_array(nvars, npoints) + char_fluxes_neg = u.empty_array(nvars, npoints) for k in range(npoints): - generalized_fluxes = np.zeros(nvars) + generalized_fluxes = u.zero_array(nvars) for i in range(ndim): generalized_fluxes += frozen_metrics[i]*fluxes[:,i,k] generalized_states = states[:,k]/frozen_jacobian - combination_pos = np.empty((nvars, nvars)) - combination_neg = np.empty((nvars, nvars)) + combination_pos = u.empty_array(nvars, nvars) + combination_neg = u.empty_array(nvars, nvars) for i in range(nvars): char_fluxes_pos[i,k] = 0.5*np.dot(R_inv[i,:], (generalized_fluxes + wavespeeds[i]*generalized_states)) @@ -84,8 +84,8 @@ def split_char_fluxes(states, wavespeeds, frozen_metrics, frozen_jacobian, R_inv def oscillation(fluxes): - sum1 = np.empty((fluxes.shape[0], 3)) - sum2 = np.empty((fluxes.shape[0], 3)) + sum1 = u.empty_array(fluxes.shape[0], 3) + sum2 = u.empty_array(fluxes.shape[0], 3) sum1[:,0] = fluxes[:,0] - 4*fluxes[:,1] + 3*fluxes[:,2] sum1[:,1] = -fluxes[:,1] + fluxes[:,3] @@ -103,13 +103,13 @@ def weno_weights(oscillation, frozen_metric): linear = np.array([0.1, 0.6, 0.3]) eps = 1e-6*frozen_metric - raw_weights = np.empty((5,3)) + raw_weights = u.empty_array(5,3) for i in range(5): for j in range(3): raw_weights[i,j] = linear[j]/(oscillation[i,j] + eps)**2 weight_sum = raw_weights.sum(axis=1) - weights = np.empty((5,3)) + weights = u.empty_array(5,3) for i in range(5): for j in range(3): weights[i,j] = raw_weights[i,j]/weight_sum[i] @@ -119,7 +119,7 @@ def weno_weights(oscillation, frozen_metric): def flux_differences(f): w = np.array([-1, 3, -3, 1]) - res = np.empty((5, 3)) + res = u.empty_array(5, 3) for j in range(res.shape[1]): res[:,j] = f[:,j:j+4]@w return res diff --git a/utilities.py b/utilities.py index 927763f..2f3b949 100644 --- a/utilities.py +++ b/utilities.py @@ -15,16 +15,24 @@ def compare_arrays(a, b): assert a == approx(b, rel=1e-12, abs=1e-14) -def random_array_on_device(queue, *shape): - ary = empty_array_on_device(queue, *shape) - cl.clrandom.fill_rand(ary) - return ary +def zero_array(*shape): + return np.zeros(shape, dtype=np.float64, order="F") + + +def empty_array(*shape): + return np.empty(shape, dtype=np.float64, order="F") def empty_array_on_device(queue, *shape): return cl.array.empty(queue, shape, dtype=np.float64, order="F") +def random_array_on_device(queue, *shape): + ary = empty_array_on_device(queue, *shape) + cl.clrandom.fill_rand(ary) + return ary + + def arrays_from_string(string_arrays): return split_map_to_list(string_arrays, array_from_string, ":") -- GitLab From 9667dcfed548ff896732e2df772a050705256b81 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 30 Aug 2019 14:05:45 -0500 Subject: [PATCH 15/43] bugfix in reference implementation imports/naming --- reference_implementation.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/reference_implementation.py b/reference_implementation.py index 116da09..496e17d 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -6,6 +6,8 @@ import pyopencl.tools # noqa import pyopencl.clrandom # noqa import loopy as lp # noqa +import utilities as u + # FIXME: add new file ideal_gas.py that has flux, pressure, etc. (any # computation that depends on EOS @@ -34,14 +36,14 @@ def flux(state): result = u.empty_array(nvars, ndim) rho = state[0] - u = state[1:ndim+1]/rho + vel = state[1:ndim+1]/rho energy = state[ndim+1] p = pressure(state) for i in range(ndim): - result[:,i] = u[i]*state + result[:,i] = vel[i]*state result[i+1,i] += p - result[ndim+1,i] += u[i]*p + result[ndim+1,i] += vel[i]*p return result -- GitLab From ce20282ed0ae0e44a59bb20002c8aaf33a4707e6 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 30 Aug 2019 14:10:47 -0500 Subject: [PATCH 16/43] using reference implementation for flux splitting --- data_for_test.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index 1f5fa95..ea1c778 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -42,14 +42,14 @@ class FluxDataSingle: u.array_from_string(R_inv_str), self.direction) self.wavespeeds = u.array_from_string(wavespeeds_str) - self.char_fluxes_pos = u.expand_to_6( - u.transposed_array_from_string(char_fluxes_pos_str)) - self.char_fluxes_neg = u.expand_to_6( - u.transposed_array_from_string(char_fluxes_neg_str)) - - #self.char_fluxes_pos, self.char_fluxes_neg = ref.split_char_fluxes( - # self.states, self.wavespeeds, - # self.frozen_metrics, self.frozen_jacobian, self.R_inv) + #self.char_fluxes_pos = u.expand_to_6( + # u.transposed_array_from_string(char_fluxes_pos_str)) + #self.char_fluxes_neg = u.expand_to_6( + # u.transposed_array_from_string(char_fluxes_neg_str)) + + self.char_fluxes_pos, self.char_fluxes_neg = ref.split_char_fluxes( + self.states, self.wavespeeds, + self.frozen_metrics, self.frozen_jacobian, self.R_inv) #self.oscillation_pos = u.transposed_array_from_string(oscillation_pos_str) #self.oscillation_neg = u.transposed_array_from_string(oscillation_neg_str) -- GitLab From ce4bb19e94a4d9eb058bca1900f4c581af3d2785 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 15:44:55 -0500 Subject: [PATCH 17/43] added reference implementation for pointwise eigenvalues --- data_for_test.py | 22 +++++++++++++++------- reference_implementation.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index ea1c778..5393cf6 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -1,3 +1,4 @@ +import numpy as np import pytest import utilities as u import reference_implementation as ref @@ -20,6 +21,16 @@ class FluxDataSingle: self.direction = self.dirs[direction] + self.metrics = np.array([np.identity(self.ndim) for i in range(6)], + dtype=np.float64, order="F") + self.jacobians = np.repeat(1.0, 6) + + # FIXME: should be computed directly from the metrics and jacobians + self.frozen_metrics = u.zero_array(3) + self.frozen_metrics[self.direction-1] = 1.0 + self.frozen_jacobian = 1.0 + self.combined_frozen_metrics = 1.0 + self.state_pair = self.swap_array_rows( u.transposed_array_from_string(states_str), self.direction) self.states = u.expand_to_6(self.state_pair) @@ -28,13 +39,10 @@ class FluxDataSingle: u.transposed_array_from_string(fluxes_str), self.direction) self.fluxes = u.expand_to_6(self.flux_pair) - self.frozen_metrics = u.zero_array(3) - self.frozen_metrics[self.direction-1] = 1.0 - self.frozen_jacobian = 1.0 - self.combined_frozen_metrics = 1.0 - - self.lam_pointwise = u.expand_to_6( - u.transposed_array_from_string(lam_str)) + #self.lam_pointwise = u.expand_to_6( + # u.transposed_array_from_string(lam_str)) + self.lam_pointwise = ref.lambda_pointwise( + self.states, self.metrics, self.direction) self.R = self.swap_array_rows( u.array_from_string(R_str), self.direction) diff --git a/reference_implementation.py b/reference_implementation.py index 496e17d..1e62853 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -30,6 +30,19 @@ def pressure(state): return (gamma - 1)*(energy - ke) +def sound_speed(state): + gamma = 1.4 + p = pressure(state) + rho = state[0] + + return np.sqrt(gamma*p/rho) + + +def velocity(state): + rho = state[0] + return state[1:4]/rho + + def flux(state): nvars = state.size ndim = nvars - 2 @@ -59,6 +72,23 @@ def pointwise_fluxes(states): return result +def lambda_pointwise(states, metrics, direction): + def lam(state, metric_norm, direction): + c = sound_speed(state) + c_norm = c*metric_norm[direction] + vel = velocity(state)[direction] + result = np.repeat(vel, state.size) + result[-2] += c_norm + result[-1] -= c_norm + + return result + + metric_norm = np.sqrt((metrics**2).sum(axis=1)) + + return np.array([lam(s, m, direction-1) + for s, m in zip(states.T, metric_norm)]).T.copy(order="F") + + def split_char_fluxes(states, wavespeeds, frozen_metrics, frozen_jacobian, R_inv): nvars, npoints = states.shape ndim = frozen_metrics.size -- GitLab From 0e24ac76f6192df809bef089fe7eb635b41b5765 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 16:05:24 -0500 Subject: [PATCH 18/43] add "reference" implementation for Roe eigensystem --- data_for_test.py | 19 +++++++++++-------- reference_implementation.py | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index 5393cf6..f05a2ff 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -26,9 +26,8 @@ class FluxDataSingle: self.jacobians = np.repeat(1.0, 6) # FIXME: should be computed directly from the metrics and jacobians - self.frozen_metrics = u.zero_array(3) - self.frozen_metrics[self.direction-1] = 1.0 - self.frozen_jacobian = 1.0 + self.frozen_metrics = np.mean(self.metrics[2:4], axis=0) + self.frozen_jacobian = np.mean(self.jacobians[2:4], axis=0) self.combined_frozen_metrics = 1.0 self.state_pair = self.swap_array_rows( @@ -44,10 +43,13 @@ class FluxDataSingle: self.lam_pointwise = ref.lambda_pointwise( self.states, self.metrics, self.direction) - self.R = self.swap_array_rows( - u.array_from_string(R_str), self.direction) - self.R_inv = self.swap_array_cols( - u.array_from_string(R_inv_str), self.direction) + #self.R = self.swap_array_rows( + # u.array_from_string(R_str), self.direction) + #self.R_inv = self.swap_array_cols( + # u.array_from_string(R_inv_str), self.direction) + self.R, self.R_inv, self.lam_roe = ref.roe_eigensystem( + self.state_pair, self.frozen_metrics, self.direction) + self.wavespeeds = u.array_from_string(wavespeeds_str) #self.char_fluxes_pos = u.expand_to_6( @@ -57,7 +59,8 @@ class FluxDataSingle: self.char_fluxes_pos, self.char_fluxes_neg = ref.split_char_fluxes( self.states, self.wavespeeds, - self.frozen_metrics, self.frozen_jacobian, self.R_inv) + self.frozen_metrics[self.direction-1], self.frozen_jacobian, + self.R_inv) #self.oscillation_pos = u.transposed_array_from_string(oscillation_pos_str) #self.oscillation_neg = u.transposed_array_from_string(oscillation_neg_str) diff --git a/reference_implementation.py b/reference_implementation.py index 1e62853..a4eec80 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -72,6 +72,24 @@ def pointwise_fluxes(states): return result +def roe_eigensystem(state_pair, frozen_metrics, direction): + nvars = state_pair.shape[0] + ndim = frozen_metrics.shape[0] + + prg = u.get_weno_program_with_root_kernel("roe_eigensystem") + queue = u.get_queue(cl._csc) + + R_dev = u.empty_array_on_device(queue, nvars, nvars) + R_inv_dev = u.empty_array_on_device(queue, nvars, nvars) + lam_dev = u.empty_array_on_device(queue, nvars) + + prg(queue, nvars=nvars, ndim=ndim, d=direction, + states=state_pair, metrics_frozen=frozen_metrics, + R=R_dev, R_inv=R_inv_dev, lambda_roe=lam_dev) + + return R_dev.get(), R_inv_dev.get(), lam_dev.get() + + def lambda_pointwise(states, metrics, direction): def lam(state, metric_norm, direction): c = sound_speed(state) -- GitLab From e8d851123437429468b95c61f2b2475e76977e92 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 20:45:55 -0500 Subject: [PATCH 19/43] use fluxes from reference implementation --- data_for_test.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index f05a2ff..881e2c3 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -34,9 +34,13 @@ class FluxDataSingle: u.transposed_array_from_string(states_str), self.direction) self.states = u.expand_to_6(self.state_pair) - self.flux_pair = self.swap_array_rows( - u.transposed_array_from_string(fluxes_str), self.direction) - self.fluxes = u.expand_to_6(self.flux_pair) + #self.flux_pair = self.swap_array_rows( + # u.transposed_array_from_string(fluxes_str), self.direction) + #self.fluxes = u.expand_to_6(self.flux_pair) + self.flux_pair = ref.pointwise_fluxes( + self.state_pair)[:,self.direction-1,:].copy(order="F") + self.fluxes = ref.pointwise_fluxes( + self.states)[:,self.direction-1,:].copy(order="F") #self.lam_pointwise = u.expand_to_6( # u.transposed_array_from_string(lam_str)) -- GitLab From 6f9c38a664ef480589d69b16022e2c26f7fdce77 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 20:57:48 -0500 Subject: [PATCH 20/43] added reference implementation for wavespeeds --- data_for_test.py | 3 ++- reference_implementation.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/data_for_test.py b/data_for_test.py index 881e2c3..c28171a 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -54,7 +54,8 @@ class FluxDataSingle: self.R, self.R_inv, self.lam_roe = ref.roe_eigensystem( self.state_pair, self.frozen_metrics, self.direction) - self.wavespeeds = u.array_from_string(wavespeeds_str) + #self.wavespeeds = u.array_from_string(wavespeeds_str) + self.wavespeeds = ref.wavespeeds(self.lam_pointwise, self.lam_roe) #self.char_fluxes_pos = u.expand_to_6( # u.transposed_array_from_string(char_fluxes_pos_str)) diff --git a/reference_implementation.py b/reference_implementation.py index a4eec80..289ea59 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -107,6 +107,11 @@ def lambda_pointwise(states, metrics, direction): for s, m in zip(states.T, metric_norm)]).T.copy(order="F") +def wavespeeds(pointwise, roe): + lam = np.c_[pointwise, roe] + return 1.1*np.max(np.abs(lam), axis=1) + + def split_char_fluxes(states, wavespeeds, frozen_metrics, frozen_jacobian, R_inv): nvars, npoints = states.shape ndim = frozen_metrics.size -- GitLab From 1d704c193c6a698dd3a4e799cc7224c839385c06 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 21:05:54 -0500 Subject: [PATCH 21/43] remove hard-coded data, broken because we forgot reference implementation for consistent part --- data_for_test.py | 877 +---------------------------------------------- 1 file changed, 17 insertions(+), 860 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index c28171a..625f6c9 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -11,13 +11,7 @@ class FluxDataSingle: ndim = 3 dirs = {"x": 1, "y": 2, "z": 3} - def __init__(self, states_str, fluxes_str, - lam_str, R_str, R_inv_str, wavespeeds_str, - char_fluxes_pos_str, char_fluxes_neg_str, - oscillation_pos_str, oscillation_neg_str, - weno_weights_pos_str, weno_weights_neg_str, - consistent_str, dissipation_pos_str, dissipation_neg_str, - weno_flux_str, direction): + def __init__(self, states_str, direction): self.direction = self.dirs[direction] @@ -34,47 +28,26 @@ class FluxDataSingle: u.transposed_array_from_string(states_str), self.direction) self.states = u.expand_to_6(self.state_pair) - #self.flux_pair = self.swap_array_rows( - # u.transposed_array_from_string(fluxes_str), self.direction) - #self.fluxes = u.expand_to_6(self.flux_pair) + # FIXME: these should be generalized fluxes self.flux_pair = ref.pointwise_fluxes( self.state_pair)[:,self.direction-1,:].copy(order="F") self.fluxes = ref.pointwise_fluxes( self.states)[:,self.direction-1,:].copy(order="F") - #self.lam_pointwise = u.expand_to_6( - # u.transposed_array_from_string(lam_str)) self.lam_pointwise = ref.lambda_pointwise( self.states, self.metrics, self.direction) - - #self.R = self.swap_array_rows( - # u.array_from_string(R_str), self.direction) - #self.R_inv = self.swap_array_cols( - # u.array_from_string(R_inv_str), self.direction) self.R, self.R_inv, self.lam_roe = ref.roe_eigensystem( self.state_pair, self.frozen_metrics, self.direction) - - #self.wavespeeds = u.array_from_string(wavespeeds_str) self.wavespeeds = ref.wavespeeds(self.lam_pointwise, self.lam_roe) - #self.char_fluxes_pos = u.expand_to_6( - # u.transposed_array_from_string(char_fluxes_pos_str)) - #self.char_fluxes_neg = u.expand_to_6( - # u.transposed_array_from_string(char_fluxes_neg_str)) - self.char_fluxes_pos, self.char_fluxes_neg = ref.split_char_fluxes( self.states, self.wavespeeds, self.frozen_metrics[self.direction-1], self.frozen_jacobian, self.R_inv) - #self.oscillation_pos = u.transposed_array_from_string(oscillation_pos_str) - #self.oscillation_neg = u.transposed_array_from_string(oscillation_neg_str) - self.oscillation_pos = ref.oscillation(self.char_fluxes_pos) self.oscillation_neg = ref.oscillation(self.char_fluxes_neg[:,::-1]) - #self.weno_weights_pos = u.transposed_array_from_string(weno_weights_pos_str) - #self.weno_weights_neg = u.transposed_array_from_string(weno_weights_neg_str) self.weno_weights_pos = ref.weno_weights( self.oscillation_pos, self.combined_frozen_metrics) self.weno_weights_neg = ref.weno_weights( @@ -82,18 +55,11 @@ class FluxDataSingle: self.consistent = self.swap_array( u.array_from_string(consistent_str), self.direction) - #self.dissipation_pos = self.swap_array( - # u.array_from_string(dissipation_pos_str), self.direction) self.dissipation_pos = ref.dissipation_part( self.R, self.char_fluxes_pos, self.weno_weights_pos, 1) - - #self.dissipation_neg = self.swap_array( - # u.array_from_string(dissipation_neg_str), self.direction) self.dissipation_neg = ref.dissipation_part( self.R, self.char_fluxes_neg, self.weno_weights_neg, -1) - #self.weno_flux = self.swap_array( - # u.array_from_string(weno_flux_str), self.direction) self.weno_flux = ref.weno_flux( self.consistent, self.dissipation_pos, self.dissipation_neg) @@ -120,849 +86,40 @@ class FluxDataSingle: single_data = {} -# {{{ Input data: "flat" case - single_data["Case flat:x"] = FluxDataSingle( - states_str="1 1 1 1 5.5,1 1 1 1 5.5", - fluxes_str="1 2.6 1 1 7.1,1 2.6 1 1 7.1", - lam_str=("1. 1. 1. 2.4966629547095764 -0.49666295470957644," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.3340765523905305 0.3340765523905305," - "1 0 0 0.8340765523905306 -0.1659234476094695," - "1 1 0 0.3340765523905305 0.3340765523905305," - "1 0 1 0.3340765523905305 0.3340765523905305," - "1.5000000000000009 1 1 2.8719435219727663 1.8719435219727667"), - R_inv_str=("0.7321428571428572 0.1785714285714286 0.1785714285714286 " - "0.1785714285714286 -0.1785714285714286," - "-1. 0 1. 0 0," - "-1. 0 0 1. 0," - "-0.5991081371313636 0.7327387580875756 -0.2672612419124244 " - "-0.2672612419124244 0.2672612419124244," - "1.4008918628686364 -1.2672612419124245 -0.2672612419124244 " - "-0.2672612419124244 0.2672612419124244"), - wavespeeds_str="1.1 1.1 1.1 2.7463292501805343 0.5463292501805341", - char_fluxes_pos_str=( - "0.30000000000000004 0. 0. 2.8024972160321826 0.026547751617514326," - "0.30000000000000004 0. 0. 2.8024972160321826 0.026547751617514326"), - char_fluxes_neg_str=( - "-0.014285714285714235 0. 0. -0.13345224838248493 -0.5575027839678178," - "-0.014285714285714235 0. 0. -0.13345224838248493 -0.5575027839678178"), - oscillation_pos_str=("0 0 0 0 0,0 0 0 0 0,0 0 0 0 0"), - oscillation_neg_str=("0 0 0 0 0,0 0 0 0 0,0 0 0 0 0"), - weno_weights_pos_str=("0.1 0.1 0.1 0.1 0.1," - "0.6 0.6 0.6 0.6 0.6,0.3 0.3 0.3 0.3 0.3"), - weno_weights_neg_str=("0.1 0.1 0.1 0.1 0.1," - "0.6 0.6 0.6 0.6 0.6,0.3 0.3 0.3 0.3 0.3"), - consistent_str="1 2.6 1 1 7.1", - dissipation_pos_str=("0 0 0 0 0"), - dissipation_neg_str=("0 0 0 0 0"), - weno_flux_str=("1 2.6 1 1 7.1"), - direction="x") + states_str="1 1 1 1 5.5,1 1 1 1 5.5", direction="x") single_data["Case flat:y"] = FluxDataSingle( - states_str="1 1 1 1 5.5,1 1 1 1 5.5", - fluxes_str="1 2.6 1 1 7.1,1 2.6 1 1 7.1", - lam_str=("1. 1. 1. 2.4966629547095764 -0.49666295470957644," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.3340765523905305 0.3340765523905305," - "1 0 0 0.8340765523905306 -0.1659234476094695," - "1 1 0 0.3340765523905305 0.3340765523905305," - "1 0 1 0.3340765523905305 0.3340765523905305," - "1.5000000000000009 1 1 2.8719435219727663 1.8719435219727667"), - R_inv_str=("0.7321428571428572 0.1785714285714286 0.1785714285714286 " - "0.1785714285714286 -0.1785714285714286," - "-1. 0 1. 0 0," - "-1. 0 0 1. 0," - "-0.5991081371313636 0.7327387580875756 -0.2672612419124244 " - "-0.2672612419124244 0.2672612419124244," - "1.4008918628686364 -1.2672612419124245 -0.2672612419124244 " - "-0.2672612419124244 0.2672612419124244"), - wavespeeds_str="1.1 1.1 1.1 2.7463292501805343 0.5463292501805341", - char_fluxes_pos_str=( - "0.30000000000000004 0. 0. 2.8024972160321826 0.026547751617514326," - "0.30000000000000004 0. 0. 2.8024972160321826 0.026547751617514326"), - char_fluxes_neg_str=( - "-0.014285714285714235 0. 0. -0.13345224838248493 -0.5575027839678178," - "-0.014285714285714235 0. 0. -0.13345224838248493 -0.5575027839678178"), - oscillation_pos_str=("0 0 0 0 0,0 0 0 0 0,0 0 0 0 0"), - oscillation_neg_str=("0 0 0 0 0,0 0 0 0 0,0 0 0 0 0"), - weno_weights_pos_str=("0.1 0.1 0.1 0.1 0.1," - "0.6 0.6 0.6 0.6 0.6,0.3 0.3 0.3 0.3 0.3"), - weno_weights_neg_str=("0.1 0.1 0.1 0.1 0.1," - "0.6 0.6 0.6 0.6 0.6,0.3 0.3 0.3 0.3 0.3"), - consistent_str="1 2.6 1 1 7.1", - dissipation_pos_str=("0 0 0 0 0"), - dissipation_neg_str=("0 0 0 0 0"), - weno_flux_str=("1 2.6 1 1 7.1"), - direction="y") + states_str="1 1 1 1 5.5,1 1 1 1 5.5", direction="y") single_data["Case flat:z"] = FluxDataSingle( - states_str="1 1 1 1 5.5,1 1 1 1 5.5", - fluxes_str="1 2.6 1 1 7.1,1 2.6 1 1 7.1", - lam_str=("1. 1. 1. 2.4966629547095764 -0.49666295470957644," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.3340765523905305 0.3340765523905305," - "1 0 0 0.8340765523905306 -0.1659234476094695," - "1 1 0 0.3340765523905305 0.3340765523905305," - "1 0 1 0.3340765523905305 0.3340765523905305," - "1.5000000000000009 1 1 2.8719435219727663 1.8719435219727667"), - R_inv_str=("0.7321428571428572 0.1785714285714286 0.1785714285714286 " - "0.1785714285714286 -0.1785714285714286," - "-1. 0 1. 0 0," - "-1. 0 0 1. 0," - "-0.5991081371313636 0.7327387580875756 -0.2672612419124244 " - "-0.2672612419124244 0.2672612419124244," - "1.4008918628686364 -1.2672612419124245 -0.2672612419124244 " - "-0.2672612419124244 0.2672612419124244"), - wavespeeds_str="1.1 1.1 1.1 2.7463292501805343 0.5463292501805341", - char_fluxes_pos_str=( - "0.30000000000000004 0. 0. 2.8024972160321826 0.026547751617514326," - "0.30000000000000004 0. 0. 2.8024972160321826 0.026547751617514326"), - char_fluxes_neg_str=( - "-0.014285714285714235 0. 0. -0.13345224838248493 -0.5575027839678178," - "-0.014285714285714235 0. 0. -0.13345224838248493 -0.5575027839678178"), - oscillation_pos_str=("0 0 0 0 0,0 0 0 0 0,0 0 0 0 0"), - oscillation_neg_str=("0 0 0 0 0,0 0 0 0 0,0 0 0 0 0"), - weno_weights_pos_str=("0.1 0.1 0.1 0.1 0.1," - "0.6 0.6 0.6 0.6 0.6,0.3 0.3 0.3 0.3 0.3"), - weno_weights_neg_str=("0.1 0.1 0.1 0.1 0.1," - "0.6 0.6 0.6 0.6 0.6,0.3 0.3 0.3 0.3 0.3"), - consistent_str="1 2.6 1 1 7.1", - dissipation_pos_str=("0 0 0 0 0"), - dissipation_neg_str=("0 0 0 0 0"), - weno_flux_str=("1 2.6 1 1 7.1"), - direction="z") - -# }}} - -# {{{ Input data: Case (a) + states_str="1 1 1 1 5.5,1 1 1 1 5.5", direction="z") single_data["Case a:x"] = FluxDataSingle( - states_str="2 4 4 4 20,1 1 1 1 5.5", - fluxes_str="4 11.2 8 8 46.4,1 2.6 1 1 7.1", - lam_str=("2. 2. 2. 3.4966629547095764 0.5033370452904236," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.45781245952886396 0.45781245952886396," - "1.5857864376269053 0 0 1.4330995704840366 0.018886008110941373," - "1.5857864376269053 1.4142135623730951 0 0.7259927892974889 " - "0.7259927892974889," - "1.5857864376269053 0 1.4142135623730951 0.7259927892974889 " - "0.7259927892974889," - "3.7720779386421466 2.2426406871192857 2.2426406871192857 " - "5.578600290173388 3.335959603054103"), - R_inv_str=("0.36752136386566203 0.265894835574803 0.265894835574803 " - "0.265894835574803 -0.16767379847989416," - "-1.1213203435596428 0 0.7071067811865475 0 0," - "-1.1213203435596428 0 0 0.7071067811865475 0," - "-0.43055863210991147 0.41670966546755195 -0.2903971157189956 " - "-0.2903971157189956 0.1831249838115456," - "1.8120820550093746 -0.9975038969055432 -0.2903971157189956 " - "-0.2903971157189956 0.1831249838115456"), - wavespeeds_str="2.2 2.2 2.2 3.8463292501805344 0.553670749819466", - char_fluxes_pos_str=("1.0907156303492833 1.2301515190164993 " - "1.2301515190164993 7.523052586013577 0.23295627081394965," - "0.4673767959969717 -0.6627416997969526 " - "-0.6627416997969526 1.4795302623674356 0.3125273038443238"), - char_fluxes_neg_str=("-0.16835489671908455 -0.05857864376269045 " - "-0.05857864376269045 -0.7274934638648571 -0.30602629876675014," - "-0.06722315769446469 0.24852813742385726 " - "0.24852813742385726 -0.10725061063772967 -0.37456222716537935"), - oscillation_pos_str=("0. 0. 0. 0. 0.," - "0.5180684032155981 4.777392983773268 4.777392983773268 " - "48.69888276854567 0.00844206573002786," - "1.2951710080389953 11.94348245943317 11.94348245943317 " - "121.7472069213642 0.02110516432506965"), - oscillation_neg_str=("0. 0. 0. 0. 0.," - "0.01363683818419176 0.12575276673434946 0.12575276673434946 " - "0.5129349293057707 0.006262897975282706," - "0.0340920954604794 0.31438191683587363 0.31438191683587363 " - "1.2823373232644266 0.015657244938206753"), - weno_weights_pos_str=("0.999999997585736 0.9999999999716082 " - "0.9999999999716082 0.9999999999997268 0.9999909282503908," - "2.2354258683870077e-9 2.6288602366075745e-11 " - "2.6288602366075745e-11 2.5299566294114733e-13 8.39888391917283e-6," - "1.788382117901561e-10 2.1030934718853924e-12 " - "2.1030934718853924e-12 2.0239658022589593e-14 6.728656898188601e-7"), - weno_weights_neg_str=("0.9999965203327451 0.999999959029252 " - "0.999999959029252 0.9999999975371708 0.9999835300215946," - "3.2217041402391125e-6 3.793560951911702e-8 " - "3.793560951911702e-8 2.2803933579018906e-9 0.000015247816238787948," - "2.579631146567429e-7 3.0351383606886035e-9 " - "3.0351383606886035e-9 1.824357365679662e-10 1.2221621667041045e-6"), - consistent_str="2.5 6.9 4.5 4.5 26.75", - dissipation_pos_str=("1.6768551393982627 4.8239743723334865 " - "3.997611768980551 3.997611768980551 22.145196359962693"), - dissipation_neg_str=("0.1768550804014161 0.523974175351619 " - "0.4976116690805634 0.4976116690805634 2.495196349669178"), - weno_flux_str=("4.353710219799678 12.247948547685105 8.995223438061114 " - "8.995223438061114 51.39039270963187"), - direction="x") + states_str="2 4 4 4 20,1 1 1 1 5.5", direction="x") single_data["Case a:y"] = FluxDataSingle( - states_str="2 4 4 4 20,1 1 1 1 5.5", - fluxes_str="4 11.2 8 8 46.4,1 2.6 1 1 7.1", - lam_str=("2. 2. 2. 3.4966629547095764 0.5033370452904236," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.45781245952886396 0.45781245952886396," - "1.5857864376269053 0 0 1.4330995704840366 0.018886008110941373," - "1.5857864376269053 1.4142135623730951 0 0.7259927892974889 " - "0.7259927892974889," - "1.5857864376269053 0 1.4142135623730951 0.7259927892974889 " - "0.7259927892974889," - "3.7720779386421466 2.2426406871192857 2.2426406871192857 " - "5.578600290173388 3.335959603054103"), - R_inv_str=("0.36752136386566203 0.265894835574803 0.265894835574803 " - "0.265894835574803 -0.16767379847989416," - "-1.1213203435596428 0 0.7071067811865475 0 0," - "-1.1213203435596428 0 0 0.7071067811865475 0," - "-0.43055863210991147 0.41670966546755195 -0.2903971157189956 " - "-0.2903971157189956 0.1831249838115456," - "1.8120820550093746 -0.9975038969055432 -0.2903971157189956 " - "-0.2903971157189956 0.1831249838115456"), - wavespeeds_str="2.2 2.2 2.2 3.8463292501805344 0.553670749819466", - char_fluxes_pos_str=("1.0907156303492833 1.2301515190164993 " - "1.2301515190164993 7.523052586013577 0.23295627081394965," - "0.4673767959969717 -0.6627416997969526 " - "-0.6627416997969526 1.4795302623674356 0.3125273038443238"), - char_fluxes_neg_str=("-0.16835489671908455 -0.05857864376269045 " - "-0.05857864376269045 -0.7274934638648571 -0.30602629876675014," - "-0.06722315769446469 0.24852813742385726 " - "0.24852813742385726 -0.10725061063772967 -0.37456222716537935"), - oscillation_pos_str=("0. 0. 0. 0. 0.," - "0.5180684032155981 4.777392983773268 4.777392983773268 " - "48.69888276854567 0.00844206573002786," - "1.2951710080389953 11.94348245943317 11.94348245943317 " - "121.7472069213642 0.02110516432506965"), - oscillation_neg_str=("0. 0. 0. 0. 0.," - "0.01363683818419176 0.12575276673434946 0.12575276673434946 " - "0.5129349293057707 0.006262897975282706," - "0.0340920954604794 0.31438191683587363 0.31438191683587363 " - "1.2823373232644266 0.015657244938206753"), - weno_weights_pos_str=("0.999999997585736 0.9999999999716082 " - "0.9999999999716082 0.9999999999997268 0.9999909282503908," - "2.2354258683870077e-9 2.6288602366075745e-11 " - "2.6288602366075745e-11 2.5299566294114733e-13 8.39888391917283e-6," - "1.788382117901561e-10 2.1030934718853924e-12 " - "2.1030934718853924e-12 2.0239658022589593e-14 6.728656898188601e-7"), - weno_weights_neg_str=("0.9999965203327451 0.999999959029252 " - "0.999999959029252 0.9999999975371708 0.9999835300215946," - "3.2217041402391125e-6 3.793560951911702e-8 " - "3.793560951911702e-8 2.2803933579018906e-9 0.000015247816238787948," - "2.579631146567429e-7 3.0351383606886035e-9 " - "3.0351383606886035e-9 1.824357365679662e-10 1.2221621667041045e-6"), - consistent_str="2.5 6.9 4.5 4.5 26.75", - dissipation_pos_str=("1.6768551393982627 4.8239743723334865 " - "3.997611768980551 3.997611768980551 22.145196359962693"), - dissipation_neg_str=("0.1768550804014161 0.523974175351619 " - "0.4976116690805634 0.4976116690805634 2.495196349669178"), - weno_flux_str=("4.353710219799678 12.247948547685105 8.995223438061114 " - "8.995223438061114 51.39039270963187"), - direction="y") + states_str="2 4 4 4 20,1 1 1 1 5.5", direction="y") single_data["Case a:z"] = FluxDataSingle( - states_str="2 4 4 4 20,1 1 1 1 5.5", - fluxes_str="4 11.2 8 8 46.4,1 2.6 1 1 7.1", - lam_str=("2. 2. 2. 3.4966629547095764 0.5033370452904236," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.45781245952886396 0.45781245952886396," - "1.5857864376269053 0 0 1.4330995704840366 0.018886008110941373," - "1.5857864376269053 1.4142135623730951 0 0.7259927892974889 " - "0.7259927892974889," - "1.5857864376269053 0 1.4142135623730951 0.7259927892974889 " - "0.7259927892974889," - "3.7720779386421466 2.2426406871192857 2.2426406871192857 " - "5.578600290173388 3.335959603054103"), - R_inv_str=("0.36752136386566203 0.265894835574803 0.265894835574803 " - "0.265894835574803 -0.16767379847989416," - "-1.1213203435596428 0 0.7071067811865475 0 0," - "-1.1213203435596428 0 0 0.7071067811865475 0," - "-0.43055863210991147 0.41670966546755195 -0.2903971157189956 " - "-0.2903971157189956 0.1831249838115456," - "1.8120820550093746 -0.9975038969055432 -0.2903971157189956 " - "-0.2903971157189956 0.1831249838115456"), - wavespeeds_str="2.2 2.2 2.2 3.8463292501805344 0.553670749819466", - char_fluxes_pos_str=("1.0907156303492833 1.2301515190164993 " - "1.2301515190164993 7.523052586013577 0.23295627081394965," - "0.4673767959969717 -0.6627416997969526 " - "-0.6627416997969526 1.4795302623674356 0.3125273038443238"), - char_fluxes_neg_str=("-0.16835489671908455 -0.05857864376269045 " - "-0.05857864376269045 -0.7274934638648571 -0.30602629876675014," - "-0.06722315769446469 0.24852813742385726 " - "0.24852813742385726 -0.10725061063772967 -0.37456222716537935"), - oscillation_pos_str=("0. 0. 0. 0. 0.," - "0.5180684032155981 4.777392983773268 4.777392983773268 " - "48.69888276854567 0.00844206573002786," - "1.2951710080389953 11.94348245943317 11.94348245943317 " - "121.7472069213642 0.02110516432506965"), - oscillation_neg_str=("0. 0. 0. 0. 0.," - "0.01363683818419176 0.12575276673434946 0.12575276673434946 " - "0.5129349293057707 0.006262897975282706," - "0.0340920954604794 0.31438191683587363 0.31438191683587363 " - "1.2823373232644266 0.015657244938206753"), - weno_weights_pos_str=("0.999999997585736 0.9999999999716082 " - "0.9999999999716082 0.9999999999997268 0.9999909282503908," - "2.2354258683870077e-9 2.6288602366075745e-11 " - "2.6288602366075745e-11 2.5299566294114733e-13 8.39888391917283e-6," - "1.788382117901561e-10 2.1030934718853924e-12 " - "2.1030934718853924e-12 2.0239658022589593e-14 6.728656898188601e-7"), - weno_weights_neg_str=("0.9999965203327451 0.999999959029252 " - "0.999999959029252 0.9999999975371708 0.9999835300215946," - "3.2217041402391125e-6 3.793560951911702e-8 " - "3.793560951911702e-8 2.2803933579018906e-9 0.000015247816238787948," - "2.579631146567429e-7 3.0351383606886035e-9 " - "3.0351383606886035e-9 1.824357365679662e-10 1.2221621667041045e-6"), - consistent_str="2.5 6.9 4.5 4.5 26.75", - dissipation_pos_str=("1.6768551393982627 4.8239743723334865 " - "3.997611768980551 3.997611768980551 22.145196359962693"), - dissipation_neg_str=("0.1768550804014161 0.523974175351619 " - "0.4976116690805634 0.4976116690805634 2.495196349669178"), - weno_flux_str=("4.353710219799678 12.247948547685105 8.995223438061114 " - "8.995223438061114 51.39039270963187"), - direction="z") - -# }}} - -# {{{ Input data: Case (b) + states_str="2 4 4 4 20,1 1 1 1 5.5", direction="z") single_data["Case b:x"] = FluxDataSingle( - states_str="1 -1 -1 -1 5.5,2 -4 -4 -4 20", - fluxes_str="-1 2.6 1 1 -7.1,-4 11.2 8 8 -46.4", - lam_str=("-1. -1. -1. 0.49666295470957644 -2.4966629547095764," - "-2. -2. -2. -0.5033370452904236 -3.4966629547095764"), - R_str=("1 0 0 0.45781245952886396 0.45781245952886396," - "-1.5857864376269053 0 0 -0.018886008110941373 " - "-1.4330995704840366," - "-1.5857864376269053 1.4142135623730951 0 -0.7259927892974889 " - "-0.7259927892974889," - "-1.5857864376269053 0 1.4142135623730951 -0.7259927892974889 " - "-0.7259927892974889," - "3.7720779386421466 -2.2426406871192857 -2.2426406871192857 " - "3.335959603054103 5.578600290173388"), - R_inv_str=("0.36752136386566203 -0.265894835574803 -0.265894835574803 " - "-0.265894835574803 -0.16767379847989416," - "1.1213203435596428 0 0.7071067811865475 0 0," - "1.1213203435596428 0 0 0.7071067811865475 0," - "1.8120820550093746 0.9975038969055432 0.2903971157189956 " - "0.2903971157189956 0.1831249838115456," - "-0.43055863210991147 -0.41670966546755195 0.2903971157189956 " - "0.2903971157189956 0.1831249838115456"), - wavespeeds_str="2.2 2.2 2.2 0.553670749819466 3.8463292501805344", - char_fluxes_pos_str=("0.06722315769446469 0.24852813742385726 " - "0.24852813742385726 0.37456222716537935 0.10725061063772967," - "0.16835489671908455 -0.05857864376269045 " - "-0.05857864376269045 0.30602629876675014 0.7274934638648571"), - char_fluxes_neg_str=("-0.4673767959969717 -0.6627416997969526 " - "-0.6627416997969526 -0.3125273038443238 -1.4795302623674356," - "-1.0907156303492833 1.2301515190164993 " - "1.2301515190164993 -0.23295627081394965 -7.523052586013577"), - oscillation_pos_str=("0. 0. 0. 0. 0.," - "0.01363683818419176 0.12575276673434946 0.12575276673434946 " - "0.006262897975282706 0.5129349293057707," - "0.0340920954604794 0.31438191683587363 0.31438191683587363 " - "0.015657244938206753 1.2823373232644266"), - oscillation_neg_str=("0. 0. 0. 0. 0.," - "0.5180684032155981 4.777392983773268 4.777392983773268 " - "0.00844206573002786 48.69888276854567," - "1.2951710080389953 11.94348245943317 11.94348245943317 " - "0.02110516432506965 121.7472069213642"), - weno_weights_pos_str=("0.9999965203327451 0.999999959029252 " - "0.999999959029252 0.9999835300215946 0.9999999975371708," - "3.2217041402391125e-6 3.793560951911702e-8 " - "3.793560951911702e-8 0.000015247816238787948 2.2803933579018906e-9," - "2.579631146567429e-7 3.0351383606886035e-9 " - "3.0351383606886035e-9 1.2221621667041045e-6 1.824357365679662e-10"), - weno_weights_neg_str=("0.999999997585736 0.9999999999716082 " - "0.9999999999716082 0.9999909282503908 0.9999999999997268," - "2.2354258683870077e-9 2.6288602366075745e-11 " - "2.6288602366075745e-11 8.39888391917283e-6 2.5299566294114733e-13," - "1.788382117901561e-10 2.1030934718853924e-12 " - "2.1030934718853924e-12 6.728656898188601e-7 2.0239658022589593e-14"), - consistent_str="-2.5 6.899999999999999 4.5 4.5 -26.75", - dissipation_pos_str=("-0.17685508040141606 0.523974175351619 " - "0.49761166908056337 0.49761166908056337 -2.495196349669178"), - dissipation_neg_str=("-1.6768551393982627 4.823974372333487 " - "3.9976117689805504 3.9976117689805504 -22.145196359962693"), - weno_flux_str=("-4.353710219799678 12.247948547685105 " - "8.995223438061114 8.995223438061114 -51.390392709631875"), - direction="x") + states_str="1 -1 -1 -1 5.5,2 -4 -4 -4 20", direction="x") single_data["Case b:y"] = FluxDataSingle( - states_str="1 -1 -1 -1 5.5,2 -4 -4 -4 20", - fluxes_str="-1 2.6 1 1 -7.1,-4 11.2 8 8 -46.4", - lam_str=("-1. -1. -1. 0.49666295470957644 -2.4966629547095764," - "-2. -2. -2. -0.5033370452904236 -3.4966629547095764"), - R_str=("1 0 0 0.45781245952886396 0.45781245952886396," - "-1.5857864376269053 0 0 -0.018886008110941373 " - "-1.4330995704840366," - "-1.5857864376269053 1.4142135623730951 0 -0.7259927892974889 " - "-0.7259927892974889," - "-1.5857864376269053 0 1.4142135623730951 -0.7259927892974889 " - "-0.7259927892974889," - "3.7720779386421466 -2.2426406871192857 -2.2426406871192857 " - "3.335959603054103 5.578600290173388"), - R_inv_str=("0.36752136386566203 -0.265894835574803 -0.265894835574803 " - "-0.265894835574803 -0.16767379847989416," - "1.1213203435596428 0 0.7071067811865475 0 0," - "1.1213203435596428 0 0 0.7071067811865475 0," - "1.8120820550093746 0.9975038969055432 0.2903971157189956 " - "0.2903971157189956 0.1831249838115456," - "-0.43055863210991147 -0.41670966546755195 0.2903971157189956 " - "0.2903971157189956 0.1831249838115456"), - wavespeeds_str="2.2 2.2 2.2 0.553670749819466 3.8463292501805344", - char_fluxes_pos_str=("0.06722315769446469 0.24852813742385726 " - "0.24852813742385726 0.37456222716537935 0.10725061063772967," - "0.16835489671908455 -0.05857864376269045 " - "-0.05857864376269045 0.30602629876675014 0.7274934638648571"), - char_fluxes_neg_str=("-0.4673767959969717 -0.6627416997969526 " - "-0.6627416997969526 -0.3125273038443238 -1.4795302623674356," - "-1.0907156303492833 1.2301515190164993 " - "1.2301515190164993 -0.23295627081394965 -7.523052586013577"), - oscillation_pos_str=("0. 0. 0. 0. 0.," - "0.01363683818419176 0.12575276673434946 0.12575276673434946 " - "0.006262897975282706 0.5129349293057707," - "0.0340920954604794 0.31438191683587363 0.31438191683587363 " - "0.015657244938206753 1.2823373232644266"), - oscillation_neg_str=("0. 0. 0. 0. 0.," - "0.5180684032155981 4.777392983773268 4.777392983773268 " - "0.00844206573002786 48.69888276854567," - "1.2951710080389953 11.94348245943317 11.94348245943317 " - "0.02110516432506965 121.7472069213642"), - weno_weights_pos_str=("0.9999965203327451 0.999999959029252 " - "0.999999959029252 0.9999835300215946 0.9999999975371708," - "3.2217041402391125e-6 3.793560951911702e-8 " - "3.793560951911702e-8 0.000015247816238787948 2.2803933579018906e-9," - "2.579631146567429e-7 3.0351383606886035e-9 " - "3.0351383606886035e-9 1.2221621667041045e-6 1.824357365679662e-10"), - weno_weights_neg_str=("0.999999997585736 0.9999999999716082 " - "0.9999999999716082 0.9999909282503908 0.9999999999997268," - "2.2354258683870077e-9 2.6288602366075745e-11 " - "2.6288602366075745e-11 8.39888391917283e-6 2.5299566294114733e-13," - "1.788382117901561e-10 2.1030934718853924e-12 " - "2.1030934718853924e-12 6.728656898188601e-7 2.0239658022589593e-14"), - consistent_str="-2.5 6.899999999999999 4.5 4.5 -26.75", - dissipation_pos_str=("-0.17685508040141606 0.523974175351619 " - "0.49761166908056337 0.49761166908056337 -2.495196349669178"), - dissipation_neg_str=("-1.6768551393982627 4.823974372333487 " - "3.9976117689805504 3.9976117689805504 -22.145196359962693"), - weno_flux_str=("-4.353710219799678 12.247948547685105 " - "8.995223438061114 8.995223438061114 -51.390392709631875"), - direction="y") + states_str="1 -1 -1 -1 5.5,2 -4 -4 -4 20", direction="y") single_data["Case b:z"] = FluxDataSingle( - states_str="1 -1 -1 -1 5.5,2 -4 -4 -4 20", - fluxes_str="-1 2.6 1 1 -7.1,-4 11.2 8 8 -46.4", - lam_str=("-1. -1. -1. 0.49666295470957644 -2.4966629547095764," - "-2. -2. -2. -0.5033370452904236 -3.4966629547095764"), - R_str=("1 0 0 0.45781245952886396 0.45781245952886396," - "-1.5857864376269053 0 0 -0.018886008110941373 " - "-1.4330995704840366," - "-1.5857864376269053 1.4142135623730951 0 -0.7259927892974889 " - "-0.7259927892974889," - "-1.5857864376269053 0 1.4142135623730951 -0.7259927892974889 " - "-0.7259927892974889," - "3.7720779386421466 -2.2426406871192857 -2.2426406871192857 " - "3.335959603054103 5.578600290173388"), - R_inv_str=("0.36752136386566203 -0.265894835574803 -0.265894835574803 " - "-0.265894835574803 -0.16767379847989416," - "1.1213203435596428 0 0.7071067811865475 0 0," - "1.1213203435596428 0 0 0.7071067811865475 0," - "1.8120820550093746 0.9975038969055432 0.2903971157189956 " - "0.2903971157189956 0.1831249838115456," - "-0.43055863210991147 -0.41670966546755195 0.2903971157189956 " - "0.2903971157189956 0.1831249838115456"), - wavespeeds_str="2.2 2.2 2.2 0.553670749819466 3.8463292501805344", - char_fluxes_pos_str=("0.06722315769446469 0.24852813742385726 " - "0.24852813742385726 0.37456222716537935 0.10725061063772967," - "0.16835489671908455 -0.05857864376269045 " - "-0.05857864376269045 0.30602629876675014 0.7274934638648571"), - char_fluxes_neg_str=("-0.4673767959969717 -0.6627416997969526 " - "-0.6627416997969526 -0.3125273038443238 -1.4795302623674356," - "-1.0907156303492833 1.2301515190164993 " - "1.2301515190164993 -0.23295627081394965 -7.523052586013577"), - oscillation_pos_str=("0. 0. 0. 0. 0.," - "0.01363683818419176 0.12575276673434946 0.12575276673434946 " - "0.006262897975282706 0.5129349293057707," - "0.0340920954604794 0.31438191683587363 0.31438191683587363 " - "0.015657244938206753 1.2823373232644266"), - oscillation_neg_str=("0. 0. 0. 0. 0.," - "0.5180684032155981 4.777392983773268 4.777392983773268 " - "0.00844206573002786 48.69888276854567," - "1.2951710080389953 11.94348245943317 11.94348245943317 " - "0.02110516432506965 121.7472069213642"), - weno_weights_pos_str=("0.9999965203327451 0.999999959029252 " - "0.999999959029252 0.9999835300215946 0.9999999975371708," - "3.2217041402391125e-6 3.793560951911702e-8 " - "3.793560951911702e-8 0.000015247816238787948 2.2803933579018906e-9," - "2.579631146567429e-7 3.0351383606886035e-9 " - "3.0351383606886035e-9 1.2221621667041045e-6 1.824357365679662e-10"), - weno_weights_neg_str=("0.999999997585736 0.9999999999716082 " - "0.9999999999716082 0.9999909282503908 0.9999999999997268," - "2.2354258683870077e-9 2.6288602366075745e-11 " - "2.6288602366075745e-11 8.39888391917283e-6 2.5299566294114733e-13," - "1.788382117901561e-10 2.1030934718853924e-12 " - "2.1030934718853924e-12 6.728656898188601e-7 2.0239658022589593e-14"), - consistent_str="-2.5 6.899999999999999 4.5 4.5 -26.75", - dissipation_pos_str=("-0.17685508040141606 0.523974175351619 " - "0.49761166908056337 0.49761166908056337 -2.495196349669178"), - dissipation_neg_str=("-1.6768551393982627 4.823974372333487 " - "3.9976117689805504 3.9976117689805504 -22.145196359962693"), - weno_flux_str=("-4.353710219799678 12.247948547685105 " - "8.995223438061114 8.995223438061114 -51.390392709631875"), - direction="z") - -# }}} - -# {{{ Input data: Case (c) + states_str="1 -1 -1 -1 5.5,2 -4 -4 -4 20", direction="z") single_data["Case c:x"] = FluxDataSingle( - states_str="2 4 8 12 64,1 1 2 3 11", - fluxes_str="4 11.2 16 24 134.4,1 2.6 2 3 12.6", - lam_str=("2. 2. 2. 3.4966629547095764 0.5033370452904236," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.41384589551844686 0.41384589551844686," - "1.5857864376269053 0 0 1.363377989567262 -0.05083557280583326," - "3.1715728752538106 1.4142135623730951 0 1.3125424167614286 " - "1.3125424167614286," - "4.757359312880716 0 1.4142135623730951 1.968813625142143 " - "1.968813625142143," - "17.60303038033002 4.485281374238571 6.727922061357858 " - "11.42671019719969 9.184069510080404"), - R_inv_str=("-1.4118746341171051 0.21727611674823194 0.4345522334964639 " - "0.6518283502446959 -0.13701474018997217," - "-2.2426406871192857 0 0.7071067811865475 0 0," - "-3.3639610306789285 0 0 0.7071067811865475 0," - "1.7926564050747988 0.4445982978342618 -0.5250169667045714 " - "-0.7875254500568571 0.16553835820737872," - "4.035297092194084 -0.9696152645388333 -0.5250169667045714 " - "-0.7875254500568571 0.16553835820737872"), - wavespeeds_str="2.2 2.2 2.2 3.8463292501805344 0.553670749819466", - char_fluxes_pos_str=("1.1162114029572359 2.4603030380329987 " - "3.690454557049497 7.986924884679773 0.4290108979594782," - "0.26073527447612554 -1.3254833995939053 " - "-1.9882250993908572 2.052422890589809 0.5017887559695788"), - char_fluxes_neg_str=("-0.1482823715615963 -0.1171572875253809 " - "-0.1757359312880714 -0.8893252542028551 -0.20004041758408686," - "-0.009488213714461069 0.49705627484771453 " - "0.7455844122715716 -0.4306378813126712 -0.31431832174320373"), - oscillation_pos_str=("0. 0. 0. 0. 0.,0.9757858752013722 " - "19.109571935093072 42.996536853959384 46.95775189047701 " - "0.007062155488717821,2.4394646880034303 47.77392983773268 " - "107.49134213489849 117.39437972619254 0.017655388721794552"), - oscillation_neg_str=("0. 0. 0. 0. 0.,0.025685091003327314 " - "0.5030110669373978 1.1317749006091449 0.28052547473186484 " - "0.017412585838667068,0.06421272750831829 1.2575276673434945 " - "2.8294372515228616 0.7013136868296621 0.04353146459666767"), - weno_weights_pos_str=("0.999999999319454 0.9999999999982254 " - "0.9999999999996494 0.9999999999997061 0.9999870425235151," - "6.301345524776077e-10 1.6430428067143077e-12 " - "3.245518542322869e-13 2.721049684463335e-13 0.000011996153712066484," - "5.041138413805998e-11 1.3144350707803127e-13 " - "2.5964155584975223e-14 2.1768403038595738e-14 9.613227729623656e-7"), - weno_weights_neg_str=("0.9999990185022956 0.9999999974390363 " - "0.9999999994941201 0.9999999917661908 0.9999978651320311," - "9.08762722250494e-7 2.3712585027633853e-9 " - "4.684070887233427e-10 7.62387333908512e-9 1.976628702372801e-6," - "7.27349821618269e-8 1.897052057748541e-10 " - "3.747296441221644e-11 6.099359570650648e-10 1.5823926647977797e-7"), - consistent_str="2.5 6.9 9. 13.5 73.5", - dissipation_pos_str=("1.6406634409601506 4.725635754575325 " - "7.88043892893644 11.820658393408754 68.69422377699841"), - dissipation_neg_str=("0.14066328824586258 0.4256356884430299 " - "0.8804384437989111 1.3206576666570364 7.7942206041633595"), - weno_flux_str=("4.281326729206013 12.051271443018354 " - "17.76087737273535 26.64131606006579 149.98844438116177"), - direction="x") + states_str="2 4 8 12 64,1 1 2 3 11", direction="x") single_data["Case c:y"] = FluxDataSingle( - states_str="2 8 12 4 64,1 2 3 1 11", - fluxes_str="8 35.2 48 16 268.8,2 5.6 6 2 25.2", - lam_str=("4. 4. 4. 5.496662954709576 2.5033370452904236," - "2. 2. 2. 3.4966629547095764 0.5033370452904236"), - R_str=("1 0 0 0.41384589551844686 0.41384589551844686," - "3.1715728752538106 0 0 2.019649197947976 0.605435635574881," - "4.757359312880716 1.4142135623730951 0 1.968813625142143 " - "1.968813625142143," - "1.5857864376269053 0 1.4142135623730951 0.6562712083807143 " - "0.6562712083807143," - "17.60303038033002 6.727922061357858 2.2426406871192857 " - "12.548030540759331 8.062749166520762"), - R_inv_str=("-1.4118746341171051 0.4345522334964639 0.6518283502446959 " - "0.21727611674823194 -0.13701474018997217," - "-3.3639610306789285 0 0.7071067811865475 0 0," - "-1.1213203435596428 0 0 0.7071067811865475 0," - "0.671336061515156 0.18208981448197611 -0.7875254500568571 " - "-0.2625084833522857 0.16553835820737872," - "5.156617435753728 -1.2321237478911191 -0.7875254500568571 " - "-0.2625084833522857 0.16553835820737872"), - wavespeeds_str="4.4 4.4 4.4 6.046329250180534 2.753670749819466", - char_fluxes_pos_str=("2.2324228059144673 7.380909114098994 " - "2.4603030380329987 15.885347333048884 0.9465242322295992," - "0.5214705489522515 -3.9764501987817145 " - "-1.3254833995939053 1.3413036144786457 3.767119678640133"), - char_fluxes_neg_str=("-0.2965647431231918 -0.3514718625761428 " - "-0.1171572875253809 -1.6097440213843948 -0.5689873221894901," - "-0.018976427428922138 1.4911688245431431 " - "0.49705627484771453 -0.05753157056903602 -1.432380835542713"), - oscillation_pos_str=("0. 0. 0. 0. 0.,3.9031435008054665 " - "171.98614741583754 19.109571935093072 282.0389435835765 " - "10.607678229749117,9.757858752013666 429.96536853959395 " - "47.77392983773268 705.0973589589414 26.519195574372795"), - oscillation_neg_str=("0. 0. 0. 0. 0.,0.10274036401330869 " - "4.5270996024365795 0.5030110669373978 3.21248465662163 " - "0.9939311452005626,0.25685091003327176 11.317749006091447 " - "1.2575276673434945 8.031211641554076 2.484827863001407"), - weno_weights_pos_str=("0.9999999999574652 0.999999999999978 " - "0.9999999999982254 0.9999999999999919 0.9999999999942413," - "3.9384014966385437e-11 2.0284497966079935e-14 " - "1.6430428067143077e-12 7.542808138536806e-15 5.332240836330361e-12," - "3.1507308840273685e-12 1.622759950511315e-15 " - "1.3144350707803127e-13 6.034246767570432e-16 4.265797494767529e-13"), - weno_weights_neg_str=("0.9999999386221037 0.9999999999683822 " - "0.9999999974390363 0.9999999999372101 0.9999999993440752," - "5.68308936788955e-8 2.9275831062158654e-11 " - "2.3712585027633853e-9 5.8138848037057226e-11 6.073372407373299e-10," - "4.547002513715645e-9 2.3420726930957915e-12 " - "1.897052057748541e-10 4.6511252168302e-12 4.8587565862160355e-11"), - consistent_str="5. 20.4 27. 9. 147.", - dissipation_pos_str=("3.281326602835503 16.54629350160538 " - "23.641315459112736 7.8804384863675505 137.3884413587739"), - dissipation_neg_str=("0.2813265968286516 1.7462934823903076 " - "2.641315430506613 0.8804384760489334 15.588441251607525"), - weno_flux_str=("8.562653199664155 38.69258698399568 " - "53.28263088961935 17.760876962416482 299.9768826103814"), - direction="y") + states_str="2 8 12 4 64,1 2 3 1 11", direction="y") single_data["Case c:z"] = FluxDataSingle( - states_str="2 12 4 8 64,1 3 1 2 11", - fluxes_str="12 75.2 24 48 403.2,3 10.6 3 6 37.8", - lam_str=("6. 6. 6. 7.496662954709576 4.503337045290424," - "3. 3. 3. 4.496662954709576 1.5033370452904236"), - R_str=("1 0 0 0.41384589551844686 0.41384589551844686," - "4.757359312880716 0 0 2.6759204063286903 1.2617068439555954," - "1.5857864376269053 1.4142135623730951 0 0.6562712083807143 " - "0.6562712083807143," - "3.1715728752538106 0 1.4142135623730951 1.3125424167614286 " - "1.3125424167614286," - "17.60303038033002 2.2426406871192857 4.485281374238571 " - "13.669350884318975 6.941428822961119"), - R_inv_str=("-1.4118746341171051 0.6518283502446959 " - "0.21727611674823194 0.4345522334964639 -0.13701474018997217," - "-1.1213203435596428 0 0.7071067811865475 0 0," - "-2.2426406871192857 0 0 0.7071067811865475 0," - "-0.4499842820444868 -0.08041866887030964 -0.2625084833522857 " - "-0.5250169667045714 0.16553835820737872," - "6.27793777931337 -1.4946322312434048 -0.2625084833522857 " - "-0.5250169667045714 0.16553835820737872"), - wavespeeds_str="6.6 6.6 6.6 8.246329250180533 4.953670749819467", - char_fluxes_pos_str=("3.348634208871708 3.690454557049497 " - "7.380909114098994 26.24407281945101 -0.9962654715332988," - "0.7822058234283737 -1.9882250993908581 " - "-3.9764501987817162 -0.6952990612264269 8.357934000904585"), - char_fluxes_neg_str=("-0.44484711468478866 -0.1757359312880714 " - "-0.3514718625761428 -2.447320076091316 -0.8207769392695052," - "-0.02846464114338254 0.7455844122715716 " - "1.4911688245431431 0.8126310150223119 -3.0474996241899346"), - oscillation_pos_str=("0. 0. 0. 0. 0.,8.782072876812371 " - "42.9965368539594 171.9861474158376 967.6396764339121 " - "116.6680636935429,21.955182192030932 107.49134213489847 " - "429.9653685395939 2419.099191084781 291.67015923385725"), - oscillation_neg_str=("0. 0. 0. 0. 0.,0.23116581902994632 " - "1.1317749006091449 4.5270996024365795 14.169708155270577 " - "6.6110585540523275,0.5779145475748658 2.8294372515228616 " - "11.317749006091447 35.42427038817644 16.527646385130815"), - weno_weights_pos_str=("0.999999999991598 0.9999999999996494 " - "0.999999999999978 0.9999999999999993 0.9999999999999524," - "7.779580658268568e-12 3.2455185423228674e-13 " - "2.028449796607992e-14 6.408020704124379e-16 4.408056940300416e-14," - "6.223673030753551e-13 2.596415558497523e-14 " - "1.6227599505113154e-15 5.126416626873783e-17 3.526445914956101e-15"), - weno_weights_neg_str=("0.9999999878747177 0.9999999994941201 " - "0.9999999999683822 0.9999999999967727 0.9999999999851737," - "1.1227070122726888e-8 4.684070887233427e-10 " - "2.9275831062158654e-11 2.988331869942141e-12 1.372802081812638e-11," - "8.982122341016933e-10 3.747296441221644e-11 " - "2.3420726930957915e-12 2.390667520553204e-13 1.0982436589127136e-12"), - consistent_str="7.5 42.9 13.5 27. 220.5", - dissipation_pos_str=("4.921989904281101 36.24738971766925 " - "11.82065772959958 23.641315459201046 206.08266203865145"), - dissipation_neg_str=("0.4219899024845117 3.9473897091113366 " - "1.3206577265155963 2.6413154534736667 23.382662006532225"), - weno_flux_str=("12.843979806765613 83.09477942678058 " - "26.641315456115176 53.28263091267471 449.9653240451837"), - direction="z") - -# }}} - -# {{{ Input data: Case (d) + states_str="2 12 4 8 64,1 3 1 2 11", direction="z") single_data["Case d:x"] = FluxDataSingle( - states_str="1 -1 -2 -3 11,2 -4 -8 -12 64", - fluxes_str="-1 2.6 2 3 -12.6,-4 11.2 16 24 -134.4", - lam_str=("-1. -1. -1. 0.49666295470957644 -2.4966629547095764," - "-2. -2. -2. -0.5033370452904236 -3.4966629547095764"), - R_str=("1 0 0 0.41384589551844686 0.41384589551844686," - "-1.5857864376269053 0 0 0.05083557280583326 -1.363377989567262," - "-3.1715728752538106 1.4142135623730951 0 -1.3125424167614286 " - "-1.3125424167614286," - "-4.757359312880716 0 1.4142135623730951 -1.968813625142143 " - "-1.968813625142143," - "17.60303038033002 -4.485281374238571 -6.727922061357858 " - "9.184069510080404 11.42671019719969"), - R_inv_str=("-1.4118746341171051 -0.21727611674823194 " - "-0.4345522334964639 -0.6518283502446959 -0.13701474018997217," - "2.2426406871192857 0 0.7071067811865475 0 0," - "3.3639610306789285 0 0 0.7071067811865475 0," - "4.035297092194084 0.9696152645388333 0.5250169667045714 " - "0.7875254500568571 0.16553835820737872," - "1.7926564050747988 -0.4445982978342618 0.5250169667045714 " - "0.7875254500568571 0.16553835820737872"), - wavespeeds_str="2.2 2.2 2.2 0.553670749819466 3.8463292501805344", - char_fluxes_pos_str=("0.009488213714461069 0.49705627484771453 " - "0.7455844122715716 0.31431832174320373 0.4306378813126712," - "0.1482823715615963 -0.1171572875253809 " - "-0.1757359312880714 0.20004041758408686 0.8893252542028551"), - char_fluxes_neg_str=("-0.26073527447612554 -1.3254833995939053 " - "-1.9882250993908572 -0.5017887559695788 -2.052422890589809," - "-1.1162114029572359 2.4603030380329987 " - "3.690454557049497 -0.4290108979594782 -7.986924884679773"), - oscillation_pos_str=("0. 0. 0. 0. 0.,0.025685091003327314 " - "0.5030110669373978 1.1317749006091449 0.017412585838667068 " - "0.28052547473186484,0.06421272750831829 1.2575276673434945 " - "2.8294372515228616 0.04353146459666767 0.7013136868296621"), - oscillation_neg_str=("0. 0. 0. 0. 0.,0.9757858752013722 " - "19.109571935093072 42.996536853959384 0.007062155488717821 " - "46.95775189047701,2.4394646880034303 47.77392983773268 " - "107.49134213489849 0.017655388721794552 117.39437972619254"), - weno_weights_pos_str=("0.9999990185022956 0.9999999974390363 " - "0.9999999994941201 0.9999978651320311 0.9999999917661908," - "9.08762722250494e-7 2.3712585027633853e-9 " - "4.684070887233427e-10 1.976628702372801e-6 7.62387333908512e-9," - "7.27349821618269e-8 1.897052057748541e-10 " - "3.747296441221644e-11 1.5823926647977797e-7 6.099359570650648e-10"), - weno_weights_neg_str=("0.999999999319454 0.9999999999982254 " - "0.9999999999996494 0.9999870425235151 0.9999999999997061," - "6.301345524776077e-10 1.6430428067143077e-12 " - "3.245518542322869e-13 0.000011996153712066484 2.721049684463335e-13," - "5.041138413805998e-11 1.3144350707803127e-13 " - "2.5964155584975223e-14 9.613227729623656e-7 2.1768403038595738e-14"), - consistent_str="-2.5 6.9 9. 13.5 -73.5", - dissipation_pos_str=("-0.14066328824586258 0.42563568844302985 " - "0.8804384437989112 1.3206576666570364 -7.7942206041633595"), - dissipation_neg_str=("-1.6406634409601506 4.725635754575325 " - "7.88043892893644 11.820658393408754 -68.69422377699841"), - weno_flux_str=("-4.281326729206013 12.051271443018354 " - "17.76087737273535 26.641316060065794 -149.98844438116177"), - direction="x") + states_str="1 -1 -2 -3 11,2 -4 -8 -12 64", direction="x") single_data["Case d:y"] = FluxDataSingle( - states_str="1 -2 -3 -1 11,2 -8 -12 -4 64", - fluxes_str="-2 5.6 6 2 -25.2,-8 35.2 48 16 -268.8", - lam_str=("-2. -2. -2. -0.5033370452904236 -3.4966629547095764," - "-4. -4. -4. -2.5033370452904236 -5.496662954709576"), - R_str=("1 0 0 0.41384589551844686 0.41384589551844686," - "-3.1715728752538106 0 0 -0.605435635574881 -2.019649197947976," - "-4.757359312880716 1.4142135623730951 0 -1.968813625142143 " - "-1.968813625142143," - "-1.5857864376269053 0 1.4142135623730951 -0.6562712083807143 " - "-0.6562712083807143," - "17.60303038033002 -6.727922061357858 -2.2426406871192857 " - "8.062749166520762 12.548030540759331"), - R_inv_str=("-1.4118746341171051 -0.4345522334964639 " - "-0.6518283502446959 -0.21727611674823194 -0.13701474018997217," - "3.3639610306789285 0 0.7071067811865475 0 0," - "1.1213203435596428 0 0 0.7071067811865475 0," - "5.156617435753728 1.2321237478911191 0.7875254500568571 " - "0.2625084833522857 0.16553835820737872," - "0.671336061515156 -0.18208981448197611 0.7875254500568571 " - "0.2625084833522857 0.16553835820737872"), - wavespeeds_str="4.4 4.4 4.4 2.753670749819466 6.046329250180534", - char_fluxes_pos_str=("0.018976427428922138 1.4911688245431431 " - "0.49705627484771453 1.432380835542713 0.05753157056903602," - "0.2965647431231918 -0.3514718625761428 " - "-0.1171572875253809 0.5689873221894901 1.6097440213843948"), - char_fluxes_neg_str=("-0.5214705489522515 -3.9764501987817145 " - "-1.3254833995939053 -3.767119678640133 -1.3413036144786457," - "-2.2324228059144673 7.380909114098994 " - "2.4603030380329987 -0.9465242322295992 -15.885347333048884"), - oscillation_pos_str=("0. 0. 0. 0. 0.,0.10274036401330869 " - "4.5270996024365795 0.5030110669373978 0.9939311452005626 " - "3.21248465662163,0.25685091003327176 11.317749006091447 " - "1.2575276673434945 2.484827863001407 8.031211641554076"), - oscillation_neg_str=("0. 0. 0. 0. 0.,3.9031435008054665 " - "171.98614741583754 19.109571935093072 10.607678229749117 " - "282.0389435835765,9.757858752013666 429.96536853959395 " - "47.77392983773268 26.519195574372795 705.0973589589414"), - weno_weights_pos_str=("0.9999999386221037 0.9999999999683822 " - "0.9999999974390363 0.9999999993440752 0.9999999999372101," - "5.68308936788955e-8 2.9275831062158654e-11 " - "2.3712585027633853e-9 6.073372407373299e-10 5.8138848037057226e-11," - "4.547002513715645e-9 2.3420726930957915e-12 " - "1.897052057748541e-10 4.8587565862160355e-11 4.6511252168302e-12"), - weno_weights_neg_str=("0.9999999999574652 0.999999999999978 " - "0.9999999999982254 0.9999999999942413 0.9999999999999919," - "3.9384014966385437e-11 2.0284497966079935e-14 " - "1.6430428067143077e-12 5.332240836330361e-12 7.542808138536806e-15," - "3.1507308840273685e-12 1.622759950511315e-15 " - "1.3144350707803127e-13 4.265797494767529e-13 6.034246767570432e-16"), - consistent_str="-5. 20.4 27. 9. -147.", - dissipation_pos_str=("-0.2813265968286516 1.7462934823903074 " - "2.641315430506612 0.8804384760489334 -15.588441251607525"), - dissipation_neg_str=("-3.281326602835503 16.54629350160538 " - "23.641315459112736 7.880438486367551 -137.3884413587739"), - weno_flux_str=("-8.562653199664155 38.69258698399569 " - "53.28263088961934 17.760876962416486 -299.97688261038144"), - direction="y") + states_str="1 -2 -3 -1 11,2 -8 -12 -4 64", direction="y") single_data["Case d:z"] = FluxDataSingle( - states_str="1 -3 -1 -2 11,2 -12 -4 -8 64", - fluxes_str="-3 10.6 3 6 -37.8,-12 75.2 24 48 -403.2", - lam_str=("-3. -3. -3. -1.5033370452904236 -4.496662954709576," - "-6. -6. -6. -4.503337045290424 -7.496662954709576"), - R_str=("1 0 0 0.41384589551844686 0.41384589551844686," - "-4.757359312880716 0 0 -1.2617068439555954 -2.6759204063286903," - "-1.5857864376269053 1.4142135623730951 0 -0.6562712083807143 " - "-0.6562712083807143," - "-3.1715728752538106 0 1.4142135623730951 -1.3125424167614286 " - "-1.3125424167614286," - "17.60303038033002 -2.2426406871192857 -4.485281374238571 " - "6.941428822961119 13.669350884318975"), - R_inv_str=("-1.4118746341171051 -0.6518283502446959 " - "-0.21727611674823194 -0.4345522334964639 -0.13701474018997217," - "1.1213203435596428 0 0.7071067811865475 0 0," - "2.2426406871192857 0 0 0.7071067811865475 0," - "6.27793777931337 1.4946322312434048 0.2625084833522857 " - "0.5250169667045714 0.16553835820737872," - "-0.4499842820444868 0.08041866887030964 0.2625084833522857 " - "0.5250169667045714 0.16553835820737872"), - wavespeeds_str="6.6 6.6 6.6 4.953670749819467 8.246329250180533", - char_fluxes_pos_str=("0.02846464114338254 0.7455844122715716 " - "1.4911688245431431 3.0474996241899346 -0.8126310150223119," - "0.44484711468478866 -0.1757359312880714 " - "-0.3514718625761428 0.8207769392695052 2.447320076091316"), - char_fluxes_neg_str=("-0.7822058234283737 -1.9882250993908581 " - "-3.9764501987817162 -8.357934000904585 0.6952990612264269," - "-3.348634208871708 3.690454557049497 " - "7.380909114098994 0.9962654715332988 -26.24407281945101"), - oscillation_pos_str=("0. 0. 0. 0. 0.,0.23116581902994632 " - "1.1317749006091449 4.5270996024365795 6.6110585540523275 " - "14.169708155270577,0.5779145475748658 2.8294372515228616 " - "11.317749006091447 16.527646385130815 35.42427038817644"), - oscillation_neg_str=("0. 0. 0. 0. 0.,8.782072876812371 " - "42.9965368539594 171.9861474158376 116.6680636935429 " - "967.6396764339121,21.955182192030932 107.49134213489847 " - "429.9653685395939 291.67015923385725 2419.099191084781"), - weno_weights_pos_str=("0.9999999878747177 0.9999999994941201 " - "0.9999999999683822 0.9999999999851737 0.9999999999967727," - "1.1227070122726888e-8 4.684070887233427e-10 " - "2.9275831062158654e-11 1.372802081812638e-11 2.988331869942141e-12," - "8.982122341016933e-10 3.747296441221644e-11 " - "2.3420726930957915e-12 1.0982436589127136e-12 2.390667520553204e-13"), - weno_weights_neg_str=("0.999999999991598 0.9999999999996494 " - "0.999999999999978 0.9999999999999524 0.9999999999999993," - "7.779580658268568e-12 3.2455185423228674e-13 " - "2.028449796607992e-14 4.408056940300416e-14 6.408020704124379e-16," - "6.223673030753551e-13 2.596415558497523e-14 " - "1.6227599505113154e-15 3.526445914956101e-15 5.126416626873783e-17"), - consistent_str="-7.5 42.9 13.5 27. -220.5", - dissipation_pos_str=("-0.42198990248451174 3.947389709111337 " - "1.3206577265155963 2.6413154534736667 -23.382662006532225"), - dissipation_neg_str=("-4.9219899042811 36.247389717669265 " - "11.820657729599578 23.641315459201046 -206.08266203865145"), - weno_flux_str=("-12.843979806765612 83.09477942678059 " - "26.641315456115173 53.28263091267471 -449.9653240451837"), - direction="z") - -# }}} + states_str="1 -3 -1 -2 11,2 -12 -4 -8 64", direction="z") @pytest.fixture(scope="session", params=[ -- GitLab From 6c257d3af08e5ba868303dc6869526b4c060f0d8 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 21:22:15 -0500 Subject: [PATCH 22/43] add consistent_part to reference implementation --- data_for_test.py | 5 +++-- reference_implementation.py | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index 625f6c9..4ceac1b 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -29,6 +29,8 @@ class FluxDataSingle: self.states = u.expand_to_6(self.state_pair) # FIXME: these should be generalized fluxes + # FIXME: make a clear distinction between fluxes in physical and + # generalized coordinates self.flux_pair = ref.pointwise_fluxes( self.state_pair)[:,self.direction-1,:].copy(order="F") self.fluxes = ref.pointwise_fluxes( @@ -53,8 +55,7 @@ class FluxDataSingle: self.weno_weights_neg = ref.weno_weights( self.oscillation_neg, self.combined_frozen_metrics) - self.consistent = self.swap_array( - u.array_from_string(consistent_str), self.direction) + self.consistent = ref.consistent_part(self.fluxes) self.dissipation_pos = ref.dissipation_part( self.R, self.char_fluxes_pos, self.weno_weights_pos, 1) self.dissipation_neg = ref.dissipation_part( diff --git a/reference_implementation.py b/reference_implementation.py index 289ea59..f255b0a 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -198,5 +198,10 @@ def dissipation_part(R, char_fluxes, w, sign): return -sign*R@flux_comb/60 +def consistent_part(fluxes): + w = np.array([1.0, -8.0, 37.0, 37.0, -8.0, 1.0])/60.0 + return np.dot(fluxes, w) + + def weno_flux(consistent, dissipation_pos, dissipation_neg): return consistent + dissipation_pos + dissipation_neg -- GitLab From 37800d2b563016dca997ab6e31385025c3fbf66a Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 21:37:38 -0500 Subject: [PATCH 23/43] break out ideal gas specific elements of reference implementation --- ideal_gas.py | 54 +++++++++++++++++++++++++++++++++ reference_implementation.py | 59 +++---------------------------------- 2 files changed, 58 insertions(+), 55 deletions(-) create mode 100644 ideal_gas.py diff --git a/ideal_gas.py b/ideal_gas.py new file mode 100644 index 0000000..12b8c00 --- /dev/null +++ b/ideal_gas.py @@ -0,0 +1,54 @@ +import numpy as np +import numpy.linalg as la # noqa: F401 +import pyopencl as cl # noqa: F401 +import pyopencl.array # noqa +import pyopencl.tools # noqa +import pyopencl.clrandom # noqa +import loopy as lp # noqa + + +ndim = 3 +nvars = 3 +gamma = 1.4 + + +def rho(state): + return state[0] + + +def velocity(state): + return state[1:ndim+1]/rho(state) + + +def energy(state): + return state[ndim+1] + + +def kinetic_energy(state): + vel = velocity(state) + return 0.5*rho(state)*np.dot(vel, vel) + + +def internal_energy(state): + return energy(state) - kinetic_energy(state) + + +def pressure(state): + return (gamma - 1)*internal_energy(state) + + +def sound_speed(state): + return np.sqrt(gamma*pressure(state)/rho(state)) + + +def flux(state): + vel = velocity(state) + p = pressure(state) + + result = np.outer(state, vel) + + for i in range(ndim): + result[i+1,i] += p + result[ndim+1,i] += vel[i]*p + + return result diff --git a/reference_implementation.py b/reference_implementation.py index f255b0a..b34d9fe 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -7,58 +7,7 @@ import pyopencl.clrandom # noqa import loopy as lp # noqa import utilities as u - - -# FIXME: add new file ideal_gas.py that has flux, pressure, etc. (any -# computation that depends on EOS - -def pressure(state): - # FIXME: for ideal gas stuff, make nvars, ndim, gamma, etc module level - # constants - # FIXME: also split out velocity, rho, energy into separate routines - gamma = 1.4 - ndim = state.size - 2 - - rho = state[0] - energy = state[ndim+1] - - ke = 0.0 - for i in range(ndim): - ke += (state[i+1]/rho)**2 - ke = 0.5*rho*ke - - return (gamma - 1)*(energy - ke) - - -def sound_speed(state): - gamma = 1.4 - p = pressure(state) - rho = state[0] - - return np.sqrt(gamma*p/rho) - - -def velocity(state): - rho = state[0] - return state[1:4]/rho - - -def flux(state): - nvars = state.size - ndim = nvars - 2 - result = u.empty_array(nvars, ndim) - - rho = state[0] - vel = state[1:ndim+1]/rho - energy = state[ndim+1] - p = pressure(state) - - for i in range(ndim): - result[:,i] = vel[i]*state - result[i+1,i] += p - result[ndim+1,i] += vel[i]*p - - return result +import ideal_gas def pointwise_fluxes(states): @@ -67,7 +16,7 @@ def pointwise_fluxes(states): result = u.empty_array(nvars, ndim, npoints) for k in range(npoints): - result[:,:,k] = flux(states[:,k]) + result[:,:,k] = ideal_gas.flux(states[:,k]) return result @@ -92,9 +41,9 @@ def roe_eigensystem(state_pair, frozen_metrics, direction): def lambda_pointwise(states, metrics, direction): def lam(state, metric_norm, direction): - c = sound_speed(state) + c = ideal_gas.sound_speed(state) c_norm = c*metric_norm[direction] - vel = velocity(state)[direction] + vel = ideal_gas.velocity(state)[direction] result = np.repeat(vel, state.size) result[-2] += c_norm result[-1] -= c_norm -- GitLab From 65baa9e051aff5f79d5ecb9739c5f748c4394173 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 21:49:37 -0500 Subject: [PATCH 24/43] clean up pointwise flux computation in reference implementation --- data_for_test.py | 4 ++-- reference_implementation.py | 12 +++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index 4ceac1b..4cd7ec1 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -32,9 +32,9 @@ class FluxDataSingle: # FIXME: make a clear distinction between fluxes in physical and # generalized coordinates self.flux_pair = ref.pointwise_fluxes( - self.state_pair)[:,self.direction-1,:].copy(order="F") + self.state_pair)[:,:,self.direction-1].T.copy(order="F") self.fluxes = ref.pointwise_fluxes( - self.states)[:,self.direction-1,:].copy(order="F") + self.states)[:,:,self.direction-1].T.copy(order="F") self.lam_pointwise = ref.lambda_pointwise( self.states, self.metrics, self.direction) diff --git a/reference_implementation.py b/reference_implementation.py index b34d9fe..0caabc6 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -11,14 +11,7 @@ import ideal_gas def pointwise_fluxes(states): - nvars, npoints = states.shape - ndim = 3 - result = u.empty_array(nvars, ndim, npoints) - - for k in range(npoints): - result[:,:,k] = ideal_gas.flux(states[:,k]) - - return result + return np.array([ideal_gas.flux(s) for s in states.T]) def roe_eigensystem(state_pair, frozen_metrics, direction): @@ -44,6 +37,7 @@ def lambda_pointwise(states, metrics, direction): c = ideal_gas.sound_speed(state) c_norm = c*metric_norm[direction] vel = ideal_gas.velocity(state)[direction] + result = np.repeat(vel, state.size) result[-2] += c_norm result[-1] -= c_norm @@ -72,7 +66,7 @@ def split_char_fluxes(states, wavespeeds, frozen_metrics, frozen_jacobian, R_inv for k in range(npoints): generalized_fluxes = u.zero_array(nvars) for i in range(ndim): - generalized_fluxes += frozen_metrics[i]*fluxes[:,i,k] + generalized_fluxes += frozen_metrics[i]*fluxes[k,:,i] generalized_states = states[:,k]/frozen_jacobian -- GitLab From c0485b37f7dc46277eb1ab9b78b9ce2a95c322a2 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 22:13:50 -0500 Subject: [PATCH 25/43] get rid of commented single-precision values for array comparison check --- utilities.py | 1 - 1 file changed, 1 deletion(-) diff --git a/utilities.py b/utilities.py index 2f3b949..09aca47 100644 --- a/utilities.py +++ b/utilities.py @@ -11,7 +11,6 @@ from pytest import approx # {{{ arrays def compare_arrays(a, b): - #assert a == approx(b, rel=1e-5, abs=2e-5) assert a == approx(b, rel=1e-12, abs=1e-14) -- GitLab From a37151b980f80d857f93f1c295426f2cf4a81bb4 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 22:28:15 -0500 Subject: [PATCH 26/43] some cleanup in flux splitting reference --- reference_implementation.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/reference_implementation.py b/reference_implementation.py index 0caabc6..88ccc20 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -15,6 +15,9 @@ def pointwise_fluxes(states): def roe_eigensystem(state_pair, frozen_metrics, direction): + # FIXME: startup for test suite is pretty slow due to this routine + # -- can we speed this up? + nvars = state_pair.shape[0] ndim = frozen_metrics.shape[0] @@ -64,19 +67,14 @@ def split_char_fluxes(states, wavespeeds, frozen_metrics, frozen_jacobian, R_inv char_fluxes_pos = u.empty_array(nvars, npoints) char_fluxes_neg = u.empty_array(nvars, npoints) for k in range(npoints): - generalized_fluxes = u.zero_array(nvars) - for i in range(ndim): - generalized_fluxes += frozen_metrics[i]*fluxes[k,:,i] - - generalized_states = states[:,k]/frozen_jacobian - - combination_pos = u.empty_array(nvars, nvars) - combination_neg = u.empty_array(nvars, nvars) - for i in range(nvars): - char_fluxes_pos[i,k] = 0.5*np.dot(R_inv[i,:], - (generalized_fluxes + wavespeeds[i]*generalized_states)) - char_fluxes_neg[i,k] = 0.5*np.dot(R_inv[i,:], - (generalized_fluxes - wavespeeds[i]*generalized_states)) + generalized_fluxes = np.dot(fluxes[k], frozen_metrics) + weighted_states = np.outer(wavespeeds, states[:,k]/frozen_jacobian) + + combination_pos = weighted_states + generalized_fluxes + combination_neg = -weighted_states + generalized_fluxes + + char_fluxes_pos[:,k] = 0.5*np.sum(R_inv*combination_pos, axis=1) + char_fluxes_neg[:,k] = 0.5*np.sum(R_inv*combination_neg, axis=1) return char_fluxes_pos, char_fluxes_neg -- GitLab From 9ec9e5adb8822b927e894da54d03533ebd62566d Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 22:56:45 -0500 Subject: [PATCH 27/43] more cleanup on flux splitting, add new utility to transpose and copy arrays --- reference_implementation.py | 31 ++++++++++++++----------------- utilities.py | 4 ++++ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/reference_implementation.py b/reference_implementation.py index 88ccc20..3560e55 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -36,6 +36,7 @@ def roe_eigensystem(state_pair, frozen_metrics, direction): def lambda_pointwise(states, metrics, direction): + # FIXME: lose some arguments here def lam(state, metric_norm, direction): c = ideal_gas.sound_speed(state) c_norm = c*metric_norm[direction] @@ -49,8 +50,8 @@ def lambda_pointwise(states, metrics, direction): metric_norm = np.sqrt((metrics**2).sum(axis=1)) - return np.array([lam(s, m, direction-1) - for s, m in zip(states.T, metric_norm)]).T.copy(order="F") + return u.transposed_array( + [lam(s, m, direction-1) for s, m in zip(states.T, metric_norm)]) def wavespeeds(pointwise, roe): @@ -59,24 +60,20 @@ def wavespeeds(pointwise, roe): def split_char_fluxes(states, wavespeeds, frozen_metrics, frozen_jacobian, R_inv): - nvars, npoints = states.shape - ndim = frozen_metrics.size + def split(flux, state): + generalized_fluxes = np.dot(flux, frozen_metrics) + weighted_states = np.outer(wavespeeds, state/frozen_jacobian) - fluxes = pointwise_fluxes(states) - - char_fluxes_pos = u.empty_array(nvars, npoints) - char_fluxes_neg = u.empty_array(nvars, npoints) - for k in range(npoints): - generalized_fluxes = np.dot(fluxes[k], frozen_metrics) - weighted_states = np.outer(wavespeeds, states[:,k]/frozen_jacobian) + return (0.5*np.sum(R_inv*(generalized_fluxes + weighted_states), axis=1), + 0.5*np.sum(R_inv*(generalized_fluxes - weighted_states), axis=1)) - combination_pos = weighted_states + generalized_fluxes - combination_neg = -weighted_states + generalized_fluxes + fluxes = pointwise_fluxes(states) - char_fluxes_pos[:,k] = 0.5*np.sum(R_inv*combination_pos, axis=1) - char_fluxes_neg[:,k] = 0.5*np.sum(R_inv*combination_neg, axis=1) + char_fluxes_pos, char_fluxes_neg = zip( + *[split(f, s) for f, s in zip(fluxes, states.T)]) - return char_fluxes_pos, char_fluxes_neg + return (u.transposed_array(char_fluxes_pos), + u.transposed_array(char_fluxes_neg)) def oscillation(fluxes): @@ -129,7 +126,7 @@ def combination_weighting(w): def combine_fluxes(w, f): cw = combination_weighting(w) - return np.sum(np.multiply(cw, f), axis=1) + return np.sum(cw*f, axis=1) def dissipation_part(R, char_fluxes, w, sign): diff --git a/utilities.py b/utilities.py index 09aca47..869579f 100644 --- a/utilities.py +++ b/utilities.py @@ -14,6 +14,10 @@ def compare_arrays(a, b): assert a == approx(b, rel=1e-12, abs=1e-14) +def transposed_array(a): + return np.array(a).T.copy(order="F") + + def zero_array(*shape): return np.zeros(shape, dtype=np.float64, order="F") -- GitLab From d4eec5d8b563a77cdfce9e52fcaf53481b59940a Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 23:21:44 -0500 Subject: [PATCH 28/43] cleanup oscillation indicator computation --- reference_implementation.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/reference_implementation.py b/reference_implementation.py index 3560e55..03b172c 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -77,19 +77,16 @@ def split_char_fluxes(states, wavespeeds, frozen_metrics, frozen_jacobian, R_inv def oscillation(fluxes): - sum1 = u.empty_array(fluxes.shape[0], 3) - sum2 = u.empty_array(fluxes.shape[0], 3) + coeffs1 = np.array([[1, -4, 3], [-1, 0, 1], [-3, 4, -1]]) + coeffs2 = np.array([1, -2, 1]) - sum1[:,0] = fluxes[:,0] - 4*fluxes[:,1] + 3*fluxes[:,2] - sum1[:,1] = -fluxes[:,1] + fluxes[:,3] - sum1[:,2] = -3*fluxes[:,2] + 4*fluxes[:,3] - fluxes[:,4] + indices = np.arange(3)[None,:] + np.arange(3)[:,None] - for i in range(3): - sum2[:,i] = fluxes[:,i] - 2*fluxes[:,i+1] + fluxes[:,i+2] + sum1 = u.transposed_array( + [np.dot(c, f) for c, f in zip(coeffs1, fluxes.T[indices])]) + sum2 = u.transposed_array([np.dot(coeffs2, f) for f in fluxes.T[indices]]) - result = (1.0/4)*(sum1**2) + (13.0/12)*(sum2**2) - - return result + return (1.0/4)*(sum1**2) + (13.0/12)*(sum2**2) def weno_weights(oscillation, frozen_metric): -- GitLab From e3c32d34c8cf585a4635400c00a622ec351533e3 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 23:36:34 -0500 Subject: [PATCH 29/43] more cleanup in reference implementation --- reference_implementation.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/reference_implementation.py b/reference_implementation.py index 03b172c..adaf9f4 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -93,26 +93,16 @@ def weno_weights(oscillation, frozen_metric): linear = np.array([0.1, 0.6, 0.3]) eps = 1e-6*frozen_metric - raw_weights = u.empty_array(5,3) - for i in range(5): - for j in range(3): - raw_weights[i,j] = linear[j]/(oscillation[i,j] + eps)**2 + raw_weights = linear[None,:]/(oscillation + eps)**2 - weight_sum = raw_weights.sum(axis=1) - weights = u.empty_array(5,3) - for i in range(5): - for j in range(3): - weights[i,j] = raw_weights[i,j]/weight_sum[i] + return raw_weights/raw_weights.sum(axis=1)[:,None] - return weights - -def flux_differences(f): +def flux_differences(fluxes): w = np.array([-1, 3, -3, 1]) - res = u.empty_array(5, 3) - for j in range(res.shape[1]): - res[:,j] = f[:,j:j+4]@w - return res + indices = np.arange(3)[:,None] + np.arange(4)[None,:] + + return u.transposed_array([np.dot(w, f) for f in fluxes.T[indices]]) def combination_weighting(w): -- GitLab From e3208c9ff245ab90c94fba3b893da965c33fa4ae Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 23:37:37 -0500 Subject: [PATCH 30/43] get rid of some unused utility functions --- utilities.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/utilities.py b/utilities.py index 869579f..1395001 100644 --- a/utilities.py +++ b/utilities.py @@ -18,14 +18,6 @@ def transposed_array(a): return np.array(a).T.copy(order="F") -def zero_array(*shape): - return np.zeros(shape, dtype=np.float64, order="F") - - -def empty_array(*shape): - return np.empty(shape, dtype=np.float64, order="F") - - def empty_array_on_device(queue, *shape): return cl.array.empty(queue, shape, dtype=np.float64, order="F") -- GitLab From 19aee636f0b0bff9c7673653f81318614b8535e1 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 23:44:55 -0500 Subject: [PATCH 31/43] get rid of stuff we don't need anymore, and cleanup usage of direction --- data_for_test.py | 23 +++++++---------------- reference_implementation.py | 6 ++---- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index 4cd7ec1..7468282 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -14,6 +14,7 @@ class FluxDataSingle: def __init__(self, states_str, direction): self.direction = self.dirs[direction] + self.dir_internal = self.direction-1 self.metrics = np.array([np.identity(self.ndim) for i in range(6)], dtype=np.float64, order="F") @@ -25,26 +26,26 @@ class FluxDataSingle: self.combined_frozen_metrics = 1.0 self.state_pair = self.swap_array_rows( - u.transposed_array_from_string(states_str), self.direction) + u.transposed_array_from_string(states_str), self.dir_internal) self.states = u.expand_to_6(self.state_pair) # FIXME: these should be generalized fluxes # FIXME: make a clear distinction between fluxes in physical and # generalized coordinates self.flux_pair = ref.pointwise_fluxes( - self.state_pair)[:,:,self.direction-1].T.copy(order="F") + self.state_pair)[:,:,self.dir_internal].T.copy(order="F") self.fluxes = ref.pointwise_fluxes( - self.states)[:,:,self.direction-1].T.copy(order="F") + self.states)[:,:,self.dir_internal].T.copy(order="F") self.lam_pointwise = ref.lambda_pointwise( - self.states, self.metrics, self.direction) + self.states, self.metrics, self.dir_internal) self.R, self.R_inv, self.lam_roe = ref.roe_eigensystem( self.state_pair, self.frozen_metrics, self.direction) self.wavespeeds = ref.wavespeeds(self.lam_pointwise, self.lam_roe) self.char_fluxes_pos, self.char_fluxes_neg = ref.split_char_fluxes( self.states, self.wavespeeds, - self.frozen_metrics[self.direction-1], self.frozen_jacobian, + self.frozen_metrics[self.dir_internal], self.frozen_jacobian, self.R_inv) self.oscillation_pos = ref.oscillation(self.char_fluxes_pos) @@ -64,23 +65,13 @@ class FluxDataSingle: self.weno_flux = ref.weno_flux( self.consistent, self.dissipation_pos, self.dissipation_neg) - def swap_array(self, arr, d): - p = self.permutation(d) - arr[p] = arr[[1, 2, 3]] - return arr - def swap_array_rows(self, arr, d): p = self.permutation(d) arr[p, :] = arr[[1, 2, 3], :] return arr - def swap_array_cols(self, arr, d): - p = self.permutation(d) - arr[:, p] = arr[:, [1, 2, 3]] - return arr - def permutation(self, d): - return [(d-1+i) % 3 + 1 for i in range(3)] + return [(d+i) % 3 + 1 for i in range(3)] # }}} diff --git a/reference_implementation.py b/reference_implementation.py index adaf9f4..9c4bb77 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -36,8 +36,7 @@ def roe_eigensystem(state_pair, frozen_metrics, direction): def lambda_pointwise(states, metrics, direction): - # FIXME: lose some arguments here - def lam(state, metric_norm, direction): + def lam(state, metric_norm): c = ideal_gas.sound_speed(state) c_norm = c*metric_norm[direction] vel = ideal_gas.velocity(state)[direction] @@ -50,8 +49,7 @@ def lambda_pointwise(states, metrics, direction): metric_norm = np.sqrt((metrics**2).sum(axis=1)) - return u.transposed_array( - [lam(s, m, direction-1) for s, m in zip(states.T, metric_norm)]) + return u.transposed_array([lam(s, m) for s, m in zip(states.T, metric_norm)]) def wavespeeds(pointwise, roe): -- GitLab From 9de94353861a7798675ce992760b2cadb57f9f55 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 2 Sep 2019 23:47:52 -0500 Subject: [PATCH 32/43] add an alias for ideal_gas so it's easier to use another gas in future --- reference_implementation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reference_implementation.py b/reference_implementation.py index 9c4bb77..2b18fd7 100644 --- a/reference_implementation.py +++ b/reference_implementation.py @@ -7,11 +7,11 @@ import pyopencl.clrandom # noqa import loopy as lp # noqa import utilities as u -import ideal_gas +import ideal_gas as gas def pointwise_fluxes(states): - return np.array([ideal_gas.flux(s) for s in states.T]) + return np.array([gas.flux(s) for s in states.T]) def roe_eigensystem(state_pair, frozen_metrics, direction): @@ -37,9 +37,9 @@ def roe_eigensystem(state_pair, frozen_metrics, direction): def lambda_pointwise(states, metrics, direction): def lam(state, metric_norm): - c = ideal_gas.sound_speed(state) + c = gas.sound_speed(state) c_norm = c*metric_norm[direction] - vel = ideal_gas.velocity(state)[direction] + vel = gas.velocity(state)[direction] result = np.repeat(vel, state.size) result[-2] += c_norm -- GitLab From b81b851bf9283553b9e8425b5cf050ac796b908c Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Tue, 3 Sep 2019 00:34:56 -0500 Subject: [PATCH 33/43] move test files to separate directory --- benchmark.py => tests/benchmark.py | 0 conftest.py => tests/conftest.py | 0 data_for_test.py => tests/data_for_test.py | 0 ideal_gas.py => tests/ideal_gas.py | 0 pytest.ini => tests/pytest.ini | 0 .../reference_implementation.py | 0 test.py => tests/test_all.py | 0 utilities.py => tests/utilities.py | 2 +- 8 files changed, 1 insertion(+), 1 deletion(-) rename benchmark.py => tests/benchmark.py (100%) rename conftest.py => tests/conftest.py (100%) rename data_for_test.py => tests/data_for_test.py (100%) rename ideal_gas.py => tests/ideal_gas.py (100%) rename pytest.ini => tests/pytest.ini (100%) rename reference_implementation.py => tests/reference_implementation.py (100%) rename test.py => tests/test_all.py (100%) rename utilities.py => tests/utilities.py (99%) diff --git a/benchmark.py b/tests/benchmark.py similarity index 100% rename from benchmark.py rename to tests/benchmark.py diff --git a/conftest.py b/tests/conftest.py similarity index 100% rename from conftest.py rename to tests/conftest.py diff --git a/data_for_test.py b/tests/data_for_test.py similarity index 100% rename from data_for_test.py rename to tests/data_for_test.py diff --git a/ideal_gas.py b/tests/ideal_gas.py similarity index 100% rename from ideal_gas.py rename to tests/ideal_gas.py diff --git a/pytest.ini b/tests/pytest.ini similarity index 100% rename from pytest.ini rename to tests/pytest.ini diff --git a/reference_implementation.py b/tests/reference_implementation.py similarity index 100% rename from reference_implementation.py rename to tests/reference_implementation.py diff --git a/test.py b/tests/test_all.py similarity index 100% rename from test.py rename to tests/test_all.py diff --git a/utilities.py b/tests/utilities.py similarity index 99% rename from utilities.py rename to tests/utilities.py index 1395001..70eb942 100644 --- a/utilities.py +++ b/tests/utilities.py @@ -93,7 +93,7 @@ _WENO_PRG = {} def parse_weno(): - fn = "WENO.F90" + fn = "../WENO.F90" with open(fn, "r") as infile: infile_content = infile.read() -- GitLab From 166e2d04e3b7ad2f13bd5f6c295d540203c67333 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Tue, 3 Sep 2019 00:50:30 -0500 Subject: [PATCH 34/43] split tests into separate files --- tests/test_eigensystem.py | 143 +++++++++++++++++++++++ tests/test_flux_derivatives.py | 53 +++++++++ tests/{test_all.py => test_weno_flux.py} | 142 +--------------------- 3 files changed, 197 insertions(+), 141 deletions(-) create mode 100644 tests/test_eigensystem.py create mode 100644 tests/test_flux_derivatives.py rename tests/{test_all.py => test_weno_flux.py} (51%) diff --git a/tests/test_eigensystem.py b/tests/test_eigensystem.py new file mode 100644 index 0000000..1d8dfd9 --- /dev/null +++ b/tests/test_eigensystem.py @@ -0,0 +1,143 @@ +import numpy as np +import numpy.linalg as la # noqa: F401 +import pyopencl as cl # noqa: F401 +import pyopencl.array # noqa +import pyopencl.tools # noqa +import pyopencl.clrandom # noqa +import loopy as lp # noqa + +import sys +import logging + +import pytest +from pyopencl.tools import ( # noqa + pytest_generate_tests_for_pyopencl + as pytest_generate_tests) + +import utilities as u +from data_for_test import ( # noqa: F401 + flux_test_data_fixture, + single_data as sd + ) + + +def test_flux_splitting_uniform_grid(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture + + prg = u.get_weno_program_with_root_kernel("split_characteristic_fluxes") + queue = u.get_queue(ctx_factory) + + fluxes_pos_dev = u.empty_array_on_device(queue, data.nvars, 6) + fluxes_neg_dev = u.empty_array_on_device(queue, data.nvars, 6) + + prg(queue, nvars=data.nvars, + generalized_states_frozen=data.states, + generalized_fluxes_frozen=data.fluxes, + R_inv=data.R_inv, + wavespeeds=data.wavespeeds, + characteristic_fluxes_pos=fluxes_pos_dev, + characteristic_fluxes_neg=fluxes_neg_dev) + + u.compare_arrays(fluxes_pos_dev.get(), data.char_fluxes_pos) + u.compare_arrays(fluxes_neg_dev.get(), data.char_fluxes_neg) + + +def test_pointwise_eigenvalues_ideal_gas(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture + + prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") + queue = u.get_queue(ctx_factory) + + lam_dev = u.empty_array_on_device(queue, data.nvars, 6) + + prg(queue, nvars=data.nvars, d=data.direction, + states=data.states, lambda_pointwise=lam_dev) + + u.compare_arrays(lam_dev.get(), data.lam_pointwise) + + +def test_roe_uniform_grid_ideal_gas(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture + + def identity_matrix(n): + return np.identity(n).astype(np.float64).copy(order="F") + + def check_roe_identity(states, R, R_inv): + d_state = states[:, 1] - states[:, 0] + u.compare_arrays(R@(R_inv@d_state), d_state) + + def check_roe_property(states, fluxes, R, R_inv, lam): + d_state = states[:, 1] - states[:, 0] + d_flux = fluxes[:, 1] - fluxes[:, 0] + + temp = R_inv@d_state + temp = np.multiply(lam, temp) + u.compare_arrays(R@temp, d_flux) + + prg = u.get_weno_program_with_root_kernel("roe_eigensystem") + queue = u.get_queue(ctx_factory) + + metrics_frozen = identity_matrix(data.ndim) + + R_dev = u.empty_array_on_device(queue, data.nvars, data.nvars) + R_inv_dev = u.empty_array_on_device(queue, data.nvars, data.nvars) + lam_dev = u.empty_array_on_device(queue, data.nvars) + + prg(queue, nvars=data.nvars, ndim=data.ndim, d=data.direction, + states=data.state_pair, metrics_frozen=metrics_frozen, + R=R_dev, R_inv=R_inv_dev, lambda_roe=lam_dev) + + R = R_dev.get() + R_inv = R_inv_dev.get() + lam = lam_dev.get() + + check_roe_identity(data.state_pair, R, R_inv) + check_roe_property(data.state_pair, data.flux_pair, R, R_inv, lam) + + +@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", "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): + prg = u.get_weno_program_with_root_kernel("lax_wavespeeds") + queue = u.get_queue(ctx_factory) + + nvars = 5 + + lam_pointwise = u.expand_to_6(u.transposed_array_from_string(lam_pointwise_str)) + lam_roe = u.array_from_string(lam_roe_str) + lam_dev = u.empty_array_on_device(queue, nvars) + + prg(queue, nvars=nvars, lambda_pointwise=lam_pointwise, + lambda_roe=lam_roe, wavespeeds=lam_dev) + + lam_expected = u.array_from_string(lam_expected_str) + u.compare_arrays(lam_dev.get(), lam_expected) + + +def test_matvec(ctx_factory): + prg = u.get_weno_program_with_root_kernel("mult_mat_vec") + queue = u.get_queue(ctx_factory) + + a = u.random_array_on_device(queue, 10, 10) + b = u.random_array_on_device(queue, 10) + + c = u.empty_array_on_device(queue, 10) + + prg(queue, alpha=1.0, a=a, b=b, c=c) + + u.compare_arrays(a.get()@b.get(), c.get()) + + +# This lets you run 'python test.py test_case(cl._csc)' without pytest. +if __name__ == "__main__": + if len(sys.argv) > 1: + logging.basicConfig(level="INFO") + exec(sys.argv[1]) + else: + pytest.main([__file__]) diff --git a/tests/test_flux_derivatives.py b/tests/test_flux_derivatives.py new file mode 100644 index 0000000..4fb26d4 --- /dev/null +++ b/tests/test_flux_derivatives.py @@ -0,0 +1,53 @@ +import numpy as np +import numpy.linalg as la # noqa: F401 +import pyopencl as cl # noqa: F401 +import pyopencl.array # noqa +import pyopencl.tools # noqa +import pyopencl.clrandom # noqa +import loopy as lp # noqa + +import sys +import logging + +import pytest +from pyopencl.tools import ( # noqa + pytest_generate_tests_for_pyopencl + as pytest_generate_tests) + +import utilities as u + + +@pytest.mark.slow +def test_compute_flux_derivatives(ctx_factory): + prg = u.get_weno_program() + + queue = u.get_queue(ctx_factory) + prg = prg.copy(target=lp.PyOpenCLTarget(queue.device)) + + lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=1, + parameters=dict(ndim=3, nvars=5, nx=16, ny=16, nz=16)) + + +@pytest.mark.slow +def test_compute_flux_derivatives_gpu(ctx_factory, write_code=False): + prg = u.get_weno_program() + prg = u.transform_weno_for_gpu(prg) + + queue = u.get_queue(ctx_factory) + prg = prg.copy(target=lp.PyOpenCLTarget(queue.device)) + prg = lp.set_options(prg, no_numpy=True) + + if write_code: + u.write_target_device_code(prg) + + lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=1, + parameters=dict(ndim=3, nvars=5, nx=16, ny=16, nz=16)) + + +# This lets you run 'python test.py test_case(cl._csc)' without pytest. +if __name__ == "__main__": + if len(sys.argv) > 1: + logging.basicConfig(level="INFO") + exec(sys.argv[1]) + else: + pytest.main([__file__]) diff --git a/tests/test_all.py b/tests/test_weno_flux.py similarity index 51% rename from tests/test_all.py rename to tests/test_weno_flux.py index da3abad..83efe45 100644 --- a/tests/test_all.py +++ b/tests/test_weno_flux.py @@ -17,7 +17,7 @@ from pyopencl.tools import ( # noqa import utilities as u from data_for_test import ( # noqa: F401 flux_test_data_fixture, - single_data as std # "single_test_data", sorry + single_data as sd ) @@ -157,146 +157,6 @@ def test_oscillation_neg_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(oscillation_dev.get(), data.oscillation_neg) -def test_flux_splitting_uniform_grid(ctx_factory, flux_test_data_fixture): - data = flux_test_data_fixture - - prg = u.get_weno_program_with_root_kernel("split_characteristic_fluxes") - queue = u.get_queue(ctx_factory) - - fluxes_pos_dev = u.empty_array_on_device(queue, data.nvars, 6) - fluxes_neg_dev = u.empty_array_on_device(queue, data.nvars, 6) - - prg(queue, nvars=data.nvars, - generalized_states_frozen=data.states, - generalized_fluxes_frozen=data.fluxes, - R_inv=data.R_inv, - wavespeeds=data.wavespeeds, - characteristic_fluxes_pos=fluxes_pos_dev, - characteristic_fluxes_neg=fluxes_neg_dev) - - u.compare_arrays(fluxes_pos_dev.get(), data.char_fluxes_pos) - u.compare_arrays(fluxes_neg_dev.get(), data.char_fluxes_neg) - - -def test_pointwise_eigenvalues_ideal_gas(ctx_factory, flux_test_data_fixture): - data = flux_test_data_fixture - - prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") - queue = u.get_queue(ctx_factory) - - lam_dev = u.empty_array_on_device(queue, data.nvars, 6) - - prg(queue, nvars=data.nvars, d=data.direction, - states=data.states, lambda_pointwise=lam_dev) - - u.compare_arrays(lam_dev.get(), data.lam_pointwise) - - -def test_roe_uniform_grid_ideal_gas(ctx_factory, flux_test_data_fixture): - data = flux_test_data_fixture - - def identity_matrix(n): - return np.identity(n).astype(np.float64).copy(order="F") - - def check_roe_identity(states, R, R_inv): - d_state = states[:, 1] - states[:, 0] - u.compare_arrays(R@(R_inv@d_state), d_state) - - def check_roe_property(states, fluxes, R, R_inv, lam): - d_state = states[:, 1] - states[:, 0] - d_flux = fluxes[:, 1] - fluxes[:, 0] - - temp = R_inv@d_state - temp = np.multiply(lam, temp) - u.compare_arrays(R@temp, d_flux) - - prg = u.get_weno_program_with_root_kernel("roe_eigensystem") - queue = u.get_queue(ctx_factory) - - metrics_frozen = identity_matrix(data.ndim) - - R_dev = u.empty_array_on_device(queue, data.nvars, data.nvars) - R_inv_dev = u.empty_array_on_device(queue, data.nvars, data.nvars) - lam_dev = u.empty_array_on_device(queue, data.nvars) - - prg(queue, nvars=data.nvars, ndim=data.ndim, d=data.direction, - states=data.state_pair, metrics_frozen=metrics_frozen, - R=R_dev, R_inv=R_inv_dev, lambda_roe=lam_dev) - - R = R_dev.get() - R_inv = R_inv_dev.get() - lam = lam_dev.get() - - check_roe_identity(data.state_pair, R, R_inv) - check_roe_property(data.state_pair, data.flux_pair, R, R_inv, lam) - - -@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", "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): - prg = u.get_weno_program_with_root_kernel("lax_wavespeeds") - queue = u.get_queue(ctx_factory) - - nvars = 5 - - lam_pointwise = u.expand_to_6(u.transposed_array_from_string(lam_pointwise_str)) - lam_roe = u.array_from_string(lam_roe_str) - lam_dev = u.empty_array_on_device(queue, nvars) - - prg(queue, nvars=nvars, lambda_pointwise=lam_pointwise, - lambda_roe=lam_roe, wavespeeds=lam_dev) - - lam_expected = u.array_from_string(lam_expected_str) - u.compare_arrays(lam_dev.get(), lam_expected) - - -def test_matvec(ctx_factory): - prg = u.get_weno_program_with_root_kernel("mult_mat_vec") - queue = u.get_queue(ctx_factory) - - a = u.random_array_on_device(queue, 10, 10) - b = u.random_array_on_device(queue, 10) - - c = u.empty_array_on_device(queue, 10) - - prg(queue, alpha=1.0, a=a, b=b, c=c) - - u.compare_arrays(a.get()@b.get(), c.get()) - - -@pytest.mark.slow -def test_compute_flux_derivatives(ctx_factory): - prg = u.get_weno_program() - - queue = u.get_queue(ctx_factory) - prg = prg.copy(target=lp.PyOpenCLTarget(queue.device)) - - lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=1, - parameters=dict(ndim=3, nvars=5, nx=16, ny=16, nz=16)) - - -@pytest.mark.slow -def test_compute_flux_derivatives_gpu(ctx_factory, write_code=False): - prg = u.get_weno_program() - prg = u.transform_weno_for_gpu(prg) - - queue = u.get_queue(ctx_factory) - prg = prg.copy(target=lp.PyOpenCLTarget(queue.device)) - prg = lp.set_options(prg, no_numpy=True) - - if write_code: - u.write_target_device_code(prg) - - lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=1, - parameters=dict(ndim=3, nvars=5, nx=16, ny=16, nz=16)) - - # This lets you run 'python test.py test_case(cl._csc)' without pytest. if __name__ == "__main__": if len(sys.argv) > 1: -- GitLab From 8d1e3fbaa0eb9e82fb4d9439a07909b48e958799 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Tue, 3 Sep 2019 00:54:02 -0500 Subject: [PATCH 35/43] eliminate duplicate computation of frozen metrics for Roe eigensystem test --- tests/test_eigensystem.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/test_eigensystem.py b/tests/test_eigensystem.py index 1d8dfd9..e2d095a 100644 --- a/tests/test_eigensystem.py +++ b/tests/test_eigensystem.py @@ -59,9 +59,6 @@ def test_pointwise_eigenvalues_ideal_gas(ctx_factory, flux_test_data_fixture): def test_roe_uniform_grid_ideal_gas(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture - def identity_matrix(n): - return np.identity(n).astype(np.float64).copy(order="F") - def check_roe_identity(states, R, R_inv): d_state = states[:, 1] - states[:, 0] u.compare_arrays(R@(R_inv@d_state), d_state) @@ -77,14 +74,12 @@ def test_roe_uniform_grid_ideal_gas(ctx_factory, flux_test_data_fixture): prg = u.get_weno_program_with_root_kernel("roe_eigensystem") queue = u.get_queue(ctx_factory) - metrics_frozen = identity_matrix(data.ndim) - R_dev = u.empty_array_on_device(queue, data.nvars, data.nvars) R_inv_dev = u.empty_array_on_device(queue, data.nvars, data.nvars) lam_dev = u.empty_array_on_device(queue, data.nvars) prg(queue, nvars=data.nvars, ndim=data.ndim, d=data.direction, - states=data.state_pair, metrics_frozen=metrics_frozen, + states=data.state_pair, metrics_frozen=data.frozen_metrics, R=R_dev, R_inv=R_inv_dev, lambda_roe=lam_dev) R = R_dev.get() -- GitLab From aa7c847306a0ec036a71e431a363196fe2238a16 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Tue, 3 Sep 2019 00:56:17 -0500 Subject: [PATCH 36/43] eliminate confusing name 'cfd' --- WENO.F90 | 12 ++++++------ tests/utilities.py | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/WENO.F90 b/WENO.F90 index 712b8b7..8013b2c 100644 --- a/WENO.F90 +++ b/WENO.F90 @@ -982,18 +982,18 @@ end subroutine ! prg = lp.parse_fortran(lp.c_preprocess(SOURCE), FILENAME) ! prg = lp.fix_parameters(prg, ndim=3, nvars=5, _remove=False) ! -! cfd = prg["compute_flux_derivatives"] +! knl = prg["compute_flux_derivatives"] ! -! cfd = lp.assume(cfd, "nx > 0 and ny > 0 and nz > 0") +! knl = lp.assume(knl, "nx > 0 and ny > 0 and nz > 0") ! -! cfd = lp.set_temporary_scope(cfd, "flux_derivatives_generalized", +! knl = lp.set_temporary_scope(knl, "flux_derivatives_generalized", ! lp.AddressSpace.GLOBAL) -! cfd = lp.set_temporary_scope(cfd, "generalized_fluxes", +! knl = lp.set_temporary_scope(knl, "generalized_fluxes", ! lp.AddressSpace.GLOBAL) -! cfd = lp.set_temporary_scope(cfd, "weno_flux_tmp", +! knl = lp.set_temporary_scope(knl, "weno_flux_tmp", ! lp.AddressSpace.GLOBAL) ! -! prg = prg.with_kernel(cfd) +! prg = prg.with_kernel(knl) ! ! RESULT = prg ! diff --git a/tests/utilities.py b/tests/utilities.py index 70eb942..fc1a965 100644 --- a/tests/utilities.py +++ b/tests/utilities.py @@ -133,26 +133,26 @@ def get_weno_program_with_root_kernel(knl): def transform_weno_for_gpu(prg, print_kernel=False): - cfd = prg["compute_flux_derivatives"] + knl = prg["compute_flux_derivatives"] for suffix in ["", "_1", "_2", "_3", "_4", "_5", "_6", "_7"]: - cfd = lp.split_iname(cfd, "i"+suffix, 16, + knl = lp.split_iname(knl, "i"+suffix, 16, outer_tag="g.0", inner_tag="l.0") - cfd = lp.split_iname(cfd, "j"+suffix, 16, + knl = lp.split_iname(knl, "j"+suffix, 16, outer_tag="g.1", inner_tag="l.1") for var_name in ["delta_xi", "delta_eta", "delta_zeta"]: - cfd = lp.assignment_to_subst(cfd, var_name) + knl = lp.assignment_to_subst(knl, var_name) - cfd = lp.add_barrier(cfd, "tag:to_generalized", "tag:flux_x_compute") - cfd = lp.add_barrier(cfd, "tag:flux_x_compute", "tag:flux_x_diff") - cfd = lp.add_barrier(cfd, "tag:flux_x_diff", "tag:flux_y_compute") - cfd = lp.add_barrier(cfd, "tag:flux_y_compute", "tag:flux_y_diff") - cfd = lp.add_barrier(cfd, "tag:flux_y_diff", "tag:flux_z_compute") - cfd = lp.add_barrier(cfd, "tag:flux_z_compute", "tag:flux_z_diff") - cfd = lp.add_barrier(cfd, "tag:flux_z_diff", "tag:from_generalized") + knl = lp.add_barrier(knl, "tag:to_generalized", "tag:flux_x_compute") + knl = lp.add_barrier(knl, "tag:flux_x_compute", "tag:flux_x_diff") + knl = lp.add_barrier(knl, "tag:flux_x_diff", "tag:flux_y_compute") + knl = lp.add_barrier(knl, "tag:flux_y_compute", "tag:flux_y_diff") + knl = lp.add_barrier(knl, "tag:flux_y_diff", "tag:flux_z_compute") + knl = lp.add_barrier(knl, "tag:flux_z_compute", "tag:flux_z_diff") + knl = lp.add_barrier(knl, "tag:flux_z_diff", "tag:from_generalized") - prg = prg.with_kernel(cfd) + prg = prg.with_kernel(knl) # FIXME: These should work, but don't # FIXME: Undo the hand-inlining in WENO.F90 -- GitLab From c6741d15328b6857914c53631c13a6a8efcf5308 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Tue, 3 Sep 2019 01:01:52 -0500 Subject: [PATCH 37/43] flux splitting test should really be with WENO flux tests --- tests/test_eigensystem.py | 21 --------------------- tests/test_weno_flux.py | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/test_eigensystem.py b/tests/test_eigensystem.py index e2d095a..4b0a7a6 100644 --- a/tests/test_eigensystem.py +++ b/tests/test_eigensystem.py @@ -21,27 +21,6 @@ from data_for_test import ( # noqa: F401 ) -def test_flux_splitting_uniform_grid(ctx_factory, flux_test_data_fixture): - data = flux_test_data_fixture - - prg = u.get_weno_program_with_root_kernel("split_characteristic_fluxes") - queue = u.get_queue(ctx_factory) - - fluxes_pos_dev = u.empty_array_on_device(queue, data.nvars, 6) - fluxes_neg_dev = u.empty_array_on_device(queue, data.nvars, 6) - - prg(queue, nvars=data.nvars, - generalized_states_frozen=data.states, - generalized_fluxes_frozen=data.fluxes, - R_inv=data.R_inv, - wavespeeds=data.wavespeeds, - characteristic_fluxes_pos=fluxes_pos_dev, - characteristic_fluxes_neg=fluxes_neg_dev) - - u.compare_arrays(fluxes_pos_dev.get(), data.char_fluxes_pos) - u.compare_arrays(fluxes_neg_dev.get(), data.char_fluxes_neg) - - def test_pointwise_eigenvalues_ideal_gas(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture diff --git a/tests/test_weno_flux.py b/tests/test_weno_flux.py index 83efe45..76976cd 100644 --- a/tests/test_weno_flux.py +++ b/tests/test_weno_flux.py @@ -157,6 +157,27 @@ def test_oscillation_neg_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(oscillation_dev.get(), data.oscillation_neg) +def test_flux_splitting_uniform_grid(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture + + prg = u.get_weno_program_with_root_kernel("split_characteristic_fluxes") + queue = u.get_queue(ctx_factory) + + fluxes_pos_dev = u.empty_array_on_device(queue, data.nvars, 6) + fluxes_neg_dev = u.empty_array_on_device(queue, data.nvars, 6) + + prg(queue, nvars=data.nvars, + generalized_states_frozen=data.states, + generalized_fluxes_frozen=data.fluxes, + R_inv=data.R_inv, + wavespeeds=data.wavespeeds, + characteristic_fluxes_pos=fluxes_pos_dev, + characteristic_fluxes_neg=fluxes_neg_dev) + + u.compare_arrays(fluxes_pos_dev.get(), data.char_fluxes_pos) + u.compare_arrays(fluxes_neg_dev.get(), data.char_fluxes_neg) + + # This lets you run 'python test.py test_case(cl._csc)' without pytest. if __name__ == "__main__": if len(sys.argv) > 1: -- GitLab From df3fbb76c331d4a9e4215fd46a0887c62fea1093 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Tue, 3 Sep 2019 01:04:28 -0500 Subject: [PATCH 38/43] trying to placate CI script since it doesn't like that we changed the test filename --- build-and-test-py-project.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-and-test-py-project.sh b/build-and-test-py-project.sh index 8bfbc06..5b10aed 100644 --- a/build-and-test-py-project.sh +++ b/build-and-test-py-project.sh @@ -85,6 +85,6 @@ if test -f $REQUIREMENTS_TXT; then $PIP install -r $REQUIREMENTS_TXT fi -${PY_EXE} -m pytest -rw --durations=10 --tb=native --junitxml=pytest.xml -rxsw --runslow test.py +${PY_EXE} -m pytest -rw --durations=10 --tb=native --junitxml=pytest.xml -rxsw --runslow tests # vim: foldmethod=marker -- GitLab From db1cc72fc57c4a14e0a510a3ab8876d9d0a1f77c Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Tue, 3 Sep 2019 01:21:05 -0500 Subject: [PATCH 39/43] using more robust approach to finding WENO source file --- tests/utilities.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/utilities.py b/tests/utilities.py index fc1a965..35ea205 100644 --- a/tests/utilities.py +++ b/tests/utilities.py @@ -7,6 +7,8 @@ import pyopencl.clrandom # noqa import loopy as lp # noqa from pytest import approx +import os.path + # {{{ arrays @@ -91,9 +93,11 @@ def get_queue(ctx_factory): _WENO_PRG = {} +project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + def parse_weno(): - fn = "../WENO.F90" + fn = os.path.join(project_root, "WENO.F90") with open(fn, "r") as infile: infile_content = infile.read() -- GitLab From a7d7566a5c56ad6754d9254acada7bef7c8562eb Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Tue, 3 Sep 2019 01:31:14 -0500 Subject: [PATCH 40/43] set warmup_rounds to 0 --- tests/test_flux_derivatives.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_flux_derivatives.py b/tests/test_flux_derivatives.py index 4fb26d4..aaa0e43 100644 --- a/tests/test_flux_derivatives.py +++ b/tests/test_flux_derivatives.py @@ -24,7 +24,7 @@ def test_compute_flux_derivatives(ctx_factory): queue = u.get_queue(ctx_factory) prg = prg.copy(target=lp.PyOpenCLTarget(queue.device)) - lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=1, + lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=0, parameters=dict(ndim=3, nvars=5, nx=16, ny=16, nz=16)) @@ -40,7 +40,7 @@ def test_compute_flux_derivatives_gpu(ctx_factory, write_code=False): if write_code: u.write_target_device_code(prg) - lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=1, + lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=0, parameters=dict(ndim=3, nvars=5, nx=16, ny=16, nz=16)) -- GitLab From 0beaeff1d8c9f0e3cdbd9efec9e88c9dac5ead3b Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Tue, 3 Sep 2019 10:25:06 -0500 Subject: [PATCH 41/43] rename test directory --- {tests => test}/benchmark.py | 0 {tests => test}/conftest.py | 0 {tests => test}/data_for_test.py | 0 {tests => test}/ideal_gas.py | 0 {tests => test}/pytest.ini | 0 {tests => test}/reference_implementation.py | 0 {tests => test}/test_eigensystem.py | 0 {tests => test}/test_flux_derivatives.py | 0 {tests => test}/test_weno_flux.py | 0 {tests => test}/utilities.py | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename {tests => test}/benchmark.py (100%) rename {tests => test}/conftest.py (100%) rename {tests => test}/data_for_test.py (100%) rename {tests => test}/ideal_gas.py (100%) rename {tests => test}/pytest.ini (100%) rename {tests => test}/reference_implementation.py (100%) rename {tests => test}/test_eigensystem.py (100%) rename {tests => test}/test_flux_derivatives.py (100%) rename {tests => test}/test_weno_flux.py (100%) rename {tests => test}/utilities.py (100%) diff --git a/tests/benchmark.py b/test/benchmark.py similarity index 100% rename from tests/benchmark.py rename to test/benchmark.py diff --git a/tests/conftest.py b/test/conftest.py similarity index 100% rename from tests/conftest.py rename to test/conftest.py diff --git a/tests/data_for_test.py b/test/data_for_test.py similarity index 100% rename from tests/data_for_test.py rename to test/data_for_test.py diff --git a/tests/ideal_gas.py b/test/ideal_gas.py similarity index 100% rename from tests/ideal_gas.py rename to test/ideal_gas.py diff --git a/tests/pytest.ini b/test/pytest.ini similarity index 100% rename from tests/pytest.ini rename to test/pytest.ini diff --git a/tests/reference_implementation.py b/test/reference_implementation.py similarity index 100% rename from tests/reference_implementation.py rename to test/reference_implementation.py diff --git a/tests/test_eigensystem.py b/test/test_eigensystem.py similarity index 100% rename from tests/test_eigensystem.py rename to test/test_eigensystem.py diff --git a/tests/test_flux_derivatives.py b/test/test_flux_derivatives.py similarity index 100% rename from tests/test_flux_derivatives.py rename to test/test_flux_derivatives.py diff --git a/tests/test_weno_flux.py b/test/test_weno_flux.py similarity index 100% rename from tests/test_weno_flux.py rename to test/test_weno_flux.py diff --git a/tests/utilities.py b/test/utilities.py similarity index 100% rename from tests/utilities.py rename to test/utilities.py -- GitLab From 4d64c97b3cfde4cc96073fae5d925bbd6c620a9d Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Tue, 3 Sep 2019 10:27:49 -0500 Subject: [PATCH 42/43] update CI script to reflect new test directory --- build-and-test-py-project.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-and-test-py-project.sh b/build-and-test-py-project.sh index 5b10aed..22bf669 100644 --- a/build-and-test-py-project.sh +++ b/build-and-test-py-project.sh @@ -85,6 +85,6 @@ if test -f $REQUIREMENTS_TXT; then $PIP install -r $REQUIREMENTS_TXT fi -${PY_EXE} -m pytest -rw --durations=10 --tb=native --junitxml=pytest.xml -rxsw --runslow tests +${PY_EXE} -m pytest -rw --durations=10 --tb=native --junitxml=pytest.xml -rxsw --runslow test # vim: foldmethod=marker -- GitLab From c6715caf32631b7a931e3c09fb420601403e7fe0 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Tue, 3 Sep 2019 21:35:44 -0500 Subject: [PATCH 43/43] rename WENO reference implementation module for clarity --- test/data_for_test.py | 2 +- ...rence_implementation.py => weno_reference_implementation.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename test/{reference_implementation.py => weno_reference_implementation.py} (100%) diff --git a/test/data_for_test.py b/test/data_for_test.py index 7468282..ccea4b9 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -1,7 +1,7 @@ import numpy as np import pytest import utilities as u -import reference_implementation as ref +import weno_reference_implementation as ref # {{{ FluxDataSingle diff --git a/test/reference_implementation.py b/test/weno_reference_implementation.py similarity index 100% rename from test/reference_implementation.py rename to test/weno_reference_implementation.py -- GitLab