From b5a7ee90bf7f42257f487f73ca6c373e49dc1c99 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Thu, 7 Nov 2019 19:41:23 -0600 Subject: [PATCH 01/23] lose folds in data_for_test for now so stuff isn't hiding --- test/data_for_test.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 3bba73d..2bfb8ba 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -26,8 +26,6 @@ import utilities as u import weno_reference_implementation as ref -# {{{ FluxDataSingle - class FluxDataSingle: # FIXME: can we set some of these constants from ref.gas? # -- if all nvars references come from there, it's relatively easy to @@ -103,10 +101,6 @@ class FluxDataSingle: def permutation(self, d): return [(d+i) % 3 + 1 for i in range(3)] -# }}} - -# {{{ FluxDataVector - # FIXME: is there a better way to divide responsibilities with these fixture classes? class FluxDataVector: nvars = 5 @@ -190,7 +184,6 @@ class FluxDataVector: def add_dimension(self, arr, n): return np.stack([arr for i in range(n)], axis=-1) -# }}} @pytest.fixture(scope="session", params=[ ("1 1 1 1 5.5,1 1 1 1 5.5", "x"), -- GitLab From 195f1fc27667a1b60bc0a7acc63e3942eec749a3 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Thu, 7 Nov 2019 19:42:32 -0600 Subject: [PATCH 02/23] rename FluxDataSingle as WindowResults --- test/data_for_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 2bfb8ba..2bc3e74 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -26,7 +26,7 @@ import utilities as u import weno_reference_implementation as ref -class FluxDataSingle: +class WindowResults: # FIXME: can we set some of these constants from ref.gas? # -- if all nvars references come from there, it's relatively easy to # introduce a new gas with more (e.g. scalar) variables @@ -48,7 +48,7 @@ class FluxDataSingle: self.frozen_jacobian = np.mean(self.jacobians[2:4], axis=0) self.combined_frozen_metrics = 1.0 - # FIXME: Move array_from_string stuff outside FluxDataSingle + # FIXME: Move array_from_string stuff outside WindowResults # -- just pass an array & have external utilities that generate # Riemann, sine wave, etc. initial conditions # FIXME: Consider handling row swapping outside as well? @@ -134,7 +134,7 @@ class FluxDataVector: state_pair = self.swap_array_rows( u.transposed_array_from_string(states_str), self.direction) - # FIXME: Move array_from_string stuff outside FluxDataSingle + # FIXME: Move array_from_string stuff outside WindowResults # -- just pass an array & have external utilities that generate # Riemann, sine wave, etc. initial conditions # FIXME: Consider handling row swapping outside as well? @@ -203,7 +203,7 @@ class FluxDataVector: ("1 -3 -1 -2 11,2 -12 -4 -8 64", "z") ]) def flux_test_data_fixture(request, queue): - return FluxDataSingle(queue, *request.param) + return WindowResults(queue, *request.param) vector_data = {} -- GitLab From aa105852f409a35d436fdde28c438c95b541fab1 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Thu, 7 Nov 2019 21:38:16 -0600 Subject: [PATCH 03/23] added a WindowData object to store data --- test/data_for_test.py | 50 +++++++++++++++++++++++----------------- test/test_eigensystem.py | 11 +++++---- test/test_weno_flux.py | 39 ++++++++++++++++--------------- 3 files changed, 55 insertions(+), 45 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 2bc3e74..924a992 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -26,7 +26,7 @@ import utilities as u import weno_reference_implementation as ref -class WindowResults: +class WindowData: # FIXME: can we set some of these constants from ref.gas? # -- if all nvars references come from there, it's relatively easy to # introduce a new gas with more (e.g. scalar) variables @@ -34,29 +34,39 @@ class WindowResults: ndim = 3 dirs = {"x": 1, "y": 2, "z": 3} - def __init__(self, queue, states_str, direction): - + def __init__(self, states_str, direction): self.direction = self.dirs[direction] self.dir_internal = self.direction-1 + # FIXME: Move array_from_string stuff outside WindowResults + # -- just pass an array & have external utilities that generate + # Riemann, sine wave, etc. initial conditions + self.state_pair = u.transposed_array_from_string(states_str) + self.states = u.expand_to_n(self.state_pair, 6) + 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) + +class WindowResults: + def __init__(self, queue, data): + self.nvars = data.nvars + self.ndim = data.ndim + self.direction = data.direction + self.dir_internal = data.dir_internal + + self.state_pair = data.state_pair + self.states = data.states + + self.metrics = data.metrics + self.jacobians = data.jacobians + # FIXME: should be computed directly from the metrics and jacobians 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 - # FIXME: Move array_from_string stuff outside WindowResults - # -- just pass an array & have external utilities that generate - # Riemann, sine wave, etc. initial conditions - # FIXME: Consider handling row swapping outside as well? - # FIXME: Do we even need to swap rows? - self.state_pair = self.swap_array_rows( - u.transposed_array_from_string(states_str), self.dir_internal) - self.states = u.expand_to_n(self.state_pair, 6) - # FIXME: these should be generalized fluxes # FIXME: make a clear distinction between fluxes in physical and # generalized coordinates @@ -93,13 +103,6 @@ class WindowResults: self.weno_flux = ref.weno_flux( self.consistent, self.dissipation_pos, self.dissipation_neg) - def swap_array_rows(self, arr, d): - p = self.permutation(d) - arr[p, :] = arr[[1, 2, 3], :] - return arr - - def permutation(self, d): - return [(d+i) % 3 + 1 for i in range(3)] # FIXME: is there a better way to divide responsibilities with these fixture classes? class FluxDataVector: @@ -202,8 +205,13 @@ class FluxDataVector: ("1 -2 -3 -1 11,2 -8 -12 -4 64", "y"), ("1 -3 -1 -2 11,2 -12 -4 -8 64", "z") ]) -def flux_test_data_fixture(request, queue): - return WindowResults(queue, *request.param) +def window_data(request): + return WindowData(*request.param) + + +@pytest.fixture(scope="session") +def window_results(queue, window_data): + return WindowResults(queue, window_data) vector_data = {} diff --git a/test/test_eigensystem.py b/test/test_eigensystem.py index bc7df0a..ce686f0 100644 --- a/test/test_eigensystem.py +++ b/test/test_eigensystem.py @@ -35,12 +35,13 @@ import pytest import utilities as u from data_for_test import ( # noqa: F401 - flux_test_data_fixture + window_data, + window_results ) -def test_pointwise_eigenvalues_ideal_gas(queue, flux_test_data_fixture): - data = flux_test_data_fixture +def test_pointwise_eigenvalues_ideal_gas(queue, window_results): + data = window_results prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") @@ -52,8 +53,8 @@ def test_pointwise_eigenvalues_ideal_gas(queue, flux_test_data_fixture): u.compare_arrays(lam_dev.get(), data.lam_pointwise) -def test_roe_uniform_grid_ideal_gas(queue, flux_test_data_fixture): - data = flux_test_data_fixture +def test_roe_uniform_grid_ideal_gas(queue, window_results): + data = window_results def check_roe_identity(states, R, R_inv): d_state = states[:, 1] - states[:, 0] diff --git a/test/test_weno_flux.py b/test/test_weno_flux.py index 40f9b2f..9170181 100644 --- a/test/test_weno_flux.py +++ b/test/test_weno_flux.py @@ -35,12 +35,13 @@ import pytest import utilities as u from data_for_test import ( # noqa: F401 - flux_test_data_fixture + window_data, + window_results ) -def test_weno_flux_uniform_grid(queue, flux_test_data_fixture): - data = flux_test_data_fixture +def test_weno_flux_uniform_grid(queue, window_results): + data = window_results prg = u.get_weno_program_with_root_kernel("weno_flux") @@ -57,8 +58,8 @@ def test_weno_flux_uniform_grid(queue, flux_test_data_fixture): u.compare_arrays(flux_dev.get(), data.weno_flux) -def test_consistent_part_uniform_grid(queue, flux_test_data_fixture): - data = flux_test_data_fixture +def test_consistent_part_uniform_grid(queue, window_results): + data = window_results prg = u.get_weno_program_with_root_kernel("consistent_part") @@ -71,8 +72,8 @@ def test_consistent_part_uniform_grid(queue, flux_test_data_fixture): u.compare_arrays(consistent_dev.get(), data.consistent) -def test_dissipation_part_pos_uniform_grid(queue, flux_test_data_fixture): - data = flux_test_data_fixture +def test_dissipation_part_pos_uniform_grid(queue, window_results): + data = window_results prg = u.get_weno_program_with_root_kernel("dissipation_part_pos") @@ -87,8 +88,8 @@ def test_dissipation_part_pos_uniform_grid(queue, flux_test_data_fixture): u.compare_arrays(dissipation_dev.get(), data.dissipation_pos) -def test_dissipation_part_neg_uniform_grid(queue, flux_test_data_fixture): - data = flux_test_data_fixture +def test_dissipation_part_neg_uniform_grid(queue, window_results): + data = window_results prg = u.get_weno_program_with_root_kernel("dissipation_part_neg") @@ -103,8 +104,8 @@ def test_dissipation_part_neg_uniform_grid(queue, flux_test_data_fixture): u.compare_arrays(dissipation_dev.get(), data.dissipation_neg) -def test_weno_weights_pos_uniform_grid(queue, flux_test_data_fixture): - data = flux_test_data_fixture +def test_weno_weights_pos_uniform_grid(queue, window_results): + data = window_results prg = u.get_weno_program_with_root_kernel("weno_weights_pos") @@ -121,8 +122,8 @@ def test_weno_weights_pos_uniform_grid(queue, flux_test_data_fixture): u.compare_arrays(weights_dev.get(), data.weno_weights_pos) -def test_weno_weights_neg_uniform_grid(queue, flux_test_data_fixture): - data = flux_test_data_fixture +def test_weno_weights_neg_uniform_grid(queue, window_results): + data = window_results prg = u.get_weno_program_with_root_kernel("weno_weights_neg") @@ -139,8 +140,8 @@ def test_weno_weights_neg_uniform_grid(queue, flux_test_data_fixture): u.compare_arrays(weights_dev.get(), data.weno_weights_neg) -def test_oscillation_pos_uniform_grid(queue, flux_test_data_fixture): - data = flux_test_data_fixture +def test_oscillation_pos_uniform_grid(queue, window_results): + data = window_results prg = u.get_weno_program_with_root_kernel("oscillation_pos") @@ -153,8 +154,8 @@ def test_oscillation_pos_uniform_grid(queue, flux_test_data_fixture): u.compare_arrays(oscillation_dev.get(), data.oscillation_pos) -def test_oscillation_neg_uniform_grid(queue, flux_test_data_fixture): - data = flux_test_data_fixture +def test_oscillation_neg_uniform_grid(queue, window_results): + data = window_results prg = u.get_weno_program_with_root_kernel("oscillation_neg") @@ -167,8 +168,8 @@ def test_oscillation_neg_uniform_grid(queue, flux_test_data_fixture): u.compare_arrays(oscillation_dev.get(), data.oscillation_neg) -def test_flux_splitting_uniform_grid(queue, flux_test_data_fixture): - data = flux_test_data_fixture +def test_flux_splitting_uniform_grid(queue, window_results): + data = window_results prg = u.get_weno_program_with_root_kernel("split_characteristic_fluxes") -- GitLab From 252544cd67b176c4bb32f562be5f3844a206e480 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Thu, 7 Nov 2019 21:41:49 -0600 Subject: [PATCH 04/23] hide some private functions in WENO reference implementation --- test/weno_reference_implementation.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/test/weno_reference_implementation.py b/test/weno_reference_implementation.py index bd4f7bc..179402a 100644 --- a/test/weno_reference_implementation.py +++ b/test/weno_reference_implementation.py @@ -124,18 +124,16 @@ def flux_differences(fluxes): return u.transposed_array([np.dot(w, f) for f in fluxes.T[indices]]) -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(cw*f, axis=1) +def dissipation_part(R, char_fluxes, w, sign): + def combine_fluxes(w, f): + def combination_weighting(w): + return np.array( + [20*w[:,0] - 1, -10*(w[:,0] + w[:,1]) + 5, np.ones(w.shape[0])] + ).T + cw = combination_weighting(w) + return np.sum(cw*f, axis=1) -def dissipation_part(R, char_fluxes, w, sign): flux_diff = flux_differences(char_fluxes)[:,::sign] flux_comb = combine_fluxes(w, flux_diff) -- GitLab From 25b9929aa71fe21a610326a1a948820fd388d388 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Thu, 7 Nov 2019 21:45:38 -0600 Subject: [PATCH 05/23] some rearrangement of test functions --- test/test_eigensystem.py | 13 ------------- test/test_weno_flux.py | 31 ++++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/test/test_eigensystem.py b/test/test_eigensystem.py index ce686f0..62ee128 100644 --- a/test/test_eigensystem.py +++ b/test/test_eigensystem.py @@ -40,19 +40,6 @@ from data_for_test import ( # noqa: F401 ) -def test_pointwise_eigenvalues_ideal_gas(queue, window_results): - data = window_results - - prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") - - 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(queue, window_results): data = window_results diff --git a/test/test_weno_flux.py b/test/test_weno_flux.py index 9170181..1f8d9d9 100644 --- a/test/test_weno_flux.py +++ b/test/test_weno_flux.py @@ -40,7 +40,7 @@ from data_for_test import ( # noqa: F401 ) -def test_weno_flux_uniform_grid(queue, window_results): +def test_weno_flux(queue, window_results): data = window_results prg = u.get_weno_program_with_root_kernel("weno_flux") @@ -58,7 +58,7 @@ def test_weno_flux_uniform_grid(queue, window_results): u.compare_arrays(flux_dev.get(), data.weno_flux) -def test_consistent_part_uniform_grid(queue, window_results): +def test_consistent_part(queue, window_results): data = window_results prg = u.get_weno_program_with_root_kernel("consistent_part") @@ -72,7 +72,7 @@ def test_consistent_part_uniform_grid(queue, window_results): u.compare_arrays(consistent_dev.get(), data.consistent) -def test_dissipation_part_pos_uniform_grid(queue, window_results): +def test_dissipation_part_pos(queue, window_results): data = window_results prg = u.get_weno_program_with_root_kernel("dissipation_part_pos") @@ -88,7 +88,7 @@ def test_dissipation_part_pos_uniform_grid(queue, window_results): u.compare_arrays(dissipation_dev.get(), data.dissipation_pos) -def test_dissipation_part_neg_uniform_grid(queue, window_results): +def test_dissipation_part_neg(queue, window_results): data = window_results prg = u.get_weno_program_with_root_kernel("dissipation_part_neg") @@ -104,7 +104,7 @@ def test_dissipation_part_neg_uniform_grid(queue, window_results): u.compare_arrays(dissipation_dev.get(), data.dissipation_neg) -def test_weno_weights_pos_uniform_grid(queue, window_results): +def test_weno_weights_pos(queue, window_results): data = window_results prg = u.get_weno_program_with_root_kernel("weno_weights_pos") @@ -122,7 +122,7 @@ def test_weno_weights_pos_uniform_grid(queue, window_results): u.compare_arrays(weights_dev.get(), data.weno_weights_pos) -def test_weno_weights_neg_uniform_grid(queue, window_results): +def test_weno_weights_neg(queue, window_results): data = window_results prg = u.get_weno_program_with_root_kernel("weno_weights_neg") @@ -140,7 +140,7 @@ def test_weno_weights_neg_uniform_grid(queue, window_results): u.compare_arrays(weights_dev.get(), data.weno_weights_neg) -def test_oscillation_pos_uniform_grid(queue, window_results): +def test_oscillation_pos(queue, window_results): data = window_results prg = u.get_weno_program_with_root_kernel("oscillation_pos") @@ -154,7 +154,7 @@ def test_oscillation_pos_uniform_grid(queue, window_results): u.compare_arrays(oscillation_dev.get(), data.oscillation_pos) -def test_oscillation_neg_uniform_grid(queue, window_results): +def test_oscillation_neg(queue, window_results): data = window_results prg = u.get_weno_program_with_root_kernel("oscillation_neg") @@ -168,7 +168,7 @@ def test_oscillation_neg_uniform_grid(queue, window_results): u.compare_arrays(oscillation_dev.get(), data.oscillation_neg) -def test_flux_splitting_uniform_grid(queue, window_results): +def test_flux_splitting(queue, window_results): data = window_results prg = u.get_weno_program_with_root_kernel("split_characteristic_fluxes") @@ -188,6 +188,19 @@ def test_flux_splitting_uniform_grid(queue, window_results): u.compare_arrays(fluxes_neg_dev.get(), data.char_fluxes_neg) +def test_pointwise_eigenvalues(queue, window_results): + data = window_results + + prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") + + 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) + + # This lets you run 'python test.py test_case(cl._csc)' without pytest. if __name__ == "__main__": if len(sys.argv) > 1: -- GitLab From 35d9c50b93a9e27be72640e30a17b6fc9b8876fb Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Thu, 7 Nov 2019 21:51:46 -0600 Subject: [PATCH 06/23] rename and reorganize test_weno_flux.py --- ...t_weno_flux.py => test_flux_window_ops.py} | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) rename test/{test_weno_flux.py => test_flux_window_ops.py} (100%) diff --git a/test/test_weno_flux.py b/test/test_flux_window_ops.py similarity index 100% rename from test/test_weno_flux.py rename to test/test_flux_window_ops.py index 1f8d9d9..b9534af 100644 --- a/test/test_weno_flux.py +++ b/test/test_flux_window_ops.py @@ -40,6 +40,39 @@ from data_for_test import ( # noqa: F401 ) +def test_pointwise_eigenvalues(queue, window_results): + data = window_results + + prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") + + 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_flux_splitting(queue, window_results): + data = window_results + + prg = u.get_weno_program_with_root_kernel("split_characteristic_fluxes") + + 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_weno_flux(queue, window_results): data = window_results @@ -168,39 +201,6 @@ def test_oscillation_neg(queue, window_results): u.compare_arrays(oscillation_dev.get(), data.oscillation_neg) -def test_flux_splitting(queue, window_results): - data = window_results - - prg = u.get_weno_program_with_root_kernel("split_characteristic_fluxes") - - 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(queue, window_results): - data = window_results - - prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") - - 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) - - # This lets you run 'python test.py test_case(cl._csc)' without pytest. if __name__ == "__main__": if len(sys.argv) > 1: -- GitLab From 0a7dfdd6c79577a6563a9d1baf93657ad1efdfd9 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Thu, 7 Nov 2019 21:53:29 -0600 Subject: [PATCH 07/23] mark some tests as slow that we want to keep, but don't need to run all the time --- test/test_flux_window_ops.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/test_flux_window_ops.py b/test/test_flux_window_ops.py index b9534af..6e9aa38 100644 --- a/test/test_flux_window_ops.py +++ b/test/test_flux_window_ops.py @@ -91,6 +91,7 @@ def test_weno_flux(queue, window_results): u.compare_arrays(flux_dev.get(), data.weno_flux) +@pytest.mark.slow def test_consistent_part(queue, window_results): data = window_results @@ -105,6 +106,7 @@ def test_consistent_part(queue, window_results): u.compare_arrays(consistent_dev.get(), data.consistent) +@pytest.mark.slow def test_dissipation_part_pos(queue, window_results): data = window_results @@ -121,6 +123,7 @@ def test_dissipation_part_pos(queue, window_results): u.compare_arrays(dissipation_dev.get(), data.dissipation_pos) +@pytest.mark.slow def test_dissipation_part_neg(queue, window_results): data = window_results @@ -137,6 +140,7 @@ def test_dissipation_part_neg(queue, window_results): u.compare_arrays(dissipation_dev.get(), data.dissipation_neg) +@pytest.mark.slow def test_weno_weights_pos(queue, window_results): data = window_results @@ -155,6 +159,7 @@ def test_weno_weights_pos(queue, window_results): u.compare_arrays(weights_dev.get(), data.weno_weights_pos) +@pytest.mark.slow def test_weno_weights_neg(queue, window_results): data = window_results @@ -173,6 +178,7 @@ def test_weno_weights_neg(queue, window_results): u.compare_arrays(weights_dev.get(), data.weno_weights_neg) +@pytest.mark.slow def test_oscillation_pos(queue, window_results): data = window_results @@ -187,6 +193,7 @@ def test_oscillation_pos(queue, window_results): u.compare_arrays(oscillation_dev.get(), data.oscillation_pos) +@pytest.mark.slow def test_oscillation_neg(queue, window_results): data = window_results -- GitLab From 492b584438cff7a599a19b80dd7015a76f73f094 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Fri, 8 Nov 2019 20:32:54 -0600 Subject: [PATCH 08/23] eigensystem now uses PairResults to get separation with weno flux tests --- test/test_eigensystem.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/test/test_eigensystem.py b/test/test_eigensystem.py index 62ee128..7ef615a 100644 --- a/test/test_eigensystem.py +++ b/test/test_eigensystem.py @@ -34,14 +34,38 @@ import logging import pytest import utilities as u +import weno_reference_implementation as ref from data_for_test import ( # noqa: F401 - window_data, - window_results + window_data ) -def test_roe_uniform_grid_ideal_gas(queue, window_results): - data = window_results +class PairResults: + def __init__(self, data): + self.nvars = data.nvars + self.ndim = data.ndim + self.direction = data.direction + self.dir_internal = data.dir_internal + + self.state_pair = data.states[:,2:4] + + # 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.dir_internal].T.copy(order="F") + + # FIXME: should be computed directly from the metrics and jacobians + self.frozen_metrics = np.mean(data.metrics[2:4], axis=0) + + +@pytest.fixture(scope="session") +def pair_results(window_data): + return PairResults(window_data) + + +def test_roe_uniform_grid_ideal_gas(queue, pair_results): + data = pair_results def check_roe_identity(states, R, R_inv): d_state = states[:, 1] - states[:, 0] -- GitLab From 3f7d000bc4cae8684d966650e06cc3f35005f257 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Fri, 8 Nov 2019 20:42:58 -0600 Subject: [PATCH 09/23] move WindowResults to window_ops test file --- test/data_for_test.py | 98 +++++++----------------------------- test/test_eigensystem.py | 4 +- test/test_flux_window_ops.py | 65 ++++++++++++++++++++++-- 3 files changed, 81 insertions(+), 86 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 924a992..7e2ae9e 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -49,59 +49,25 @@ class WindowData: self.jacobians = np.repeat(1.0, 6) -class WindowResults: - def __init__(self, queue, data): - self.nvars = data.nvars - self.ndim = data.ndim - self.direction = data.direction - self.dir_internal = data.dir_internal - - self.state_pair = data.state_pair - self.states = data.states - - self.metrics = data.metrics - self.jacobians = data.jacobians - - # FIXME: should be computed directly from the metrics and jacobians - 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 - - # 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.dir_internal].T.copy(order="F") - self.fluxes = ref.pointwise_fluxes( - self.states)[:,:,self.dir_internal].T.copy(order="F") - - self.lam_pointwise = ref.lambda_pointwise( - self.states, self.metrics, self.dir_internal) - self.R, self.R_inv, self.lam_roe = ref.roe_eigensystem( - queue, 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.dir_internal], self.frozen_jacobian, - self.R_inv) - - self.oscillation_pos = ref.oscillation(self.char_fluxes_pos) - self.oscillation_neg = ref.oscillation(self.char_fluxes_neg[:,::-1]) - - 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 = 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( - self.R, self.char_fluxes_neg, self.weno_weights_neg, -1) - - self.weno_flux = ref.weno_flux( - self.consistent, self.dissipation_pos, self.dissipation_neg) +@pytest.fixture(scope="session", params=[ + ("1 1 1 1 5.5,1 1 1 1 5.5", "x"), + ("1 1 1 1 5.5,1 1 1 1 5.5", "y"), + ("1 1 1 1 5.5,1 1 1 1 5.5", "z"), + ("2 4 4 4 20,1 1 1 1 5.5", "x"), + ("2 4 4 4 20,1 1 1 1 5.5", "y"), + ("2 4 4 4 20,1 1 1 1 5.5", "z"), + ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "x"), + ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "y"), + ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "z"), + ("2 4 8 12 64,1 1 2 3 11", "x"), + ("2 8 12 4 64,1 2 3 1 11", "y"), + ("2 12 4 8 64,1 3 1 2 11", "z"), + ("1 -1 -2 -3 11,2 -4 -8 -12 64", "x"), + ("1 -2 -3 -1 11,2 -8 -12 -4 64", "y"), + ("1 -3 -1 -2 11,2 -12 -4 -8 64", "z") + ]) +def window_data(request): + return WindowData(*request.param) # FIXME: is there a better way to divide responsibilities with these fixture classes? @@ -188,32 +154,6 @@ class FluxDataVector: return np.stack([arr for i in range(n)], axis=-1) -@pytest.fixture(scope="session", params=[ - ("1 1 1 1 5.5,1 1 1 1 5.5", "x"), - ("1 1 1 1 5.5,1 1 1 1 5.5", "y"), - ("1 1 1 1 5.5,1 1 1 1 5.5", "z"), - ("2 4 4 4 20,1 1 1 1 5.5", "x"), - ("2 4 4 4 20,1 1 1 1 5.5", "y"), - ("2 4 4 4 20,1 1 1 1 5.5", "z"), - ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "x"), - ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "y"), - ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "z"), - ("2 4 8 12 64,1 1 2 3 11", "x"), - ("2 8 12 4 64,1 2 3 1 11", "y"), - ("2 12 4 8 64,1 3 1 2 11", "z"), - ("1 -1 -2 -3 11,2 -4 -8 -12 64", "x"), - ("1 -2 -3 -1 11,2 -8 -12 -4 64", "y"), - ("1 -3 -1 -2 11,2 -12 -4 -8 64", "z") - ]) -def window_data(request): - return WindowData(*request.param) - - -@pytest.fixture(scope="session") -def window_results(queue, window_data): - return WindowResults(queue, window_data) - - vector_data = {} vector_data["Case flat:x"] = FluxDataVector( diff --git a/test/test_eigensystem.py b/test/test_eigensystem.py index 7ef615a..c8ce865 100644 --- a/test/test_eigensystem.py +++ b/test/test_eigensystem.py @@ -35,9 +35,7 @@ import pytest import utilities as u import weno_reference_implementation as ref -from data_for_test import ( # noqa: F401 - window_data - ) +from data_for_test import window_data class PairResults: diff --git a/test/test_flux_window_ops.py b/test/test_flux_window_ops.py index 6e9aa38..d467338 100644 --- a/test/test_flux_window_ops.py +++ b/test/test_flux_window_ops.py @@ -34,10 +34,67 @@ import logging import pytest import utilities as u -from data_for_test import ( # noqa: F401 - window_data, - window_results - ) +import weno_reference_implementation as ref +from data_for_test import window_data + + +class WindowResults: + def __init__(self, queue, data): + self.nvars = data.nvars + self.ndim = data.ndim + self.direction = data.direction + self.dir_internal = data.dir_internal + + self.states = data.states + # FIXME: duplicate code + self.state_pair = data.states[:,2:4] + + self.metrics = data.metrics + self.jacobians = data.jacobians + + # FIXME: should be computed directly from the metrics and jacobians + 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 + + # FIXME: these should be generalized fluxes + # FIXME: make a clear distinction between fluxes in physical and + # generalized coordinates + self.fluxes = ref.pointwise_fluxes( + self.states)[:,:,self.dir_internal].T.copy(order="F") + + self.lam_pointwise = ref.lambda_pointwise( + self.states, self.metrics, self.dir_internal) + self.R, self.R_inv, self.lam_roe = ref.roe_eigensystem( + queue, 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.dir_internal], self.frozen_jacobian, + self.R_inv) + + self.oscillation_pos = ref.oscillation(self.char_fluxes_pos) + self.oscillation_neg = ref.oscillation(self.char_fluxes_neg[:,::-1]) + + 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 = 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( + self.R, self.char_fluxes_neg, self.weno_weights_neg, -1) + + self.weno_flux = ref.weno_flux( + self.consistent, self.dissipation_pos, self.dissipation_neg) + + +@pytest.fixture(scope="session") +def window_results(queue, window_data): + return WindowResults(queue, window_data) def test_pointwise_eigenvalues(queue, window_results): -- GitLab From b0d38f9a4893663d13edf815c67a0804820383f5 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Fri, 8 Nov 2019 20:59:47 -0600 Subject: [PATCH 10/23] move flux data vector stuff to test_flux_derivatives --- test/data_for_test.py | 119 -------------------------------- test/test_flux_derivatives.py | 123 +++++++++++++++++++++++++++++++++- 2 files changed, 120 insertions(+), 122 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 7e2ae9e..30c833f 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -70,123 +70,4 @@ def window_data(request): return WindowData(*request.param) -# FIXME: is there a better way to divide responsibilities with these fixture classes? -class FluxDataVector: - nvars = 5 - ndim = 3 - dirs = {"x": 1, "y": 2, "z": 3} - halo = 3 - - def __init__(self, nx, ny, nz, states_str, direction): - self.direction = self.dirs[direction] - self.dir_internal = self.direction-1 - - self.nx = nx - self.ny = ny - self.nz = nz - - self.nxhalo = self.nx + 2*self.halo - self.nyhalo = self.ny + 2*self.halo - self.nzhalo = self.nz + 2*self.halo - - self.flux_dims = (self.nvars, self.nx, self.ny, self.nz) - - self.metrics = np.stack( - [np.stack( - [np.stack( - [np.identity(self.ndim) for i in range(self.nxhalo)], - axis=-1) for j in range(self.nyhalo)], - axis=-1) for k in range(self.nzhalo)], - axis=-1).copy(order="F") - self.jacobians = np.ones((self.nxhalo, self.nyhalo, self.nzhalo), - order="F") - - state_pair = self.swap_array_rows( - u.transposed_array_from_string(states_str), self.direction) - # FIXME: Move array_from_string stuff outside WindowResults - # -- just pass an array & have external utilities that generate - # Riemann, sine wave, etc. initial conditions - # FIXME: Consider handling row swapping outside as well? - # FIXME: Do we even need to swap rows? - self.state_pair = self.swap_array_rows( - u.transposed_array_from_string(states_str), self.dir_internal) - # NOTE: dimensions are nvars x nxhalo x nyhalo x nzhalo - self.states = self.fill_from_pair() - - # NOTE: dimensions are nvars x nxhalo x nyhalo x nzhalo - # FIXME: these should be generalized fluxes - # FIXME: make a clear distinction between fluxes in physical and - # generalized coordinates - npoints = self.nxhalo*self.nyhalo*self.nzhalo - flat_states = self.states.reshape((self.nvars, npoints)) - self.fluxes = ref.pointwise_fluxes( - flat_states)[:,:,self.dir_internal].T.reshape( - (self.nvars, self.nxhalo, self.nyhalo, self.nzhalo) - ).copy(order="F") - - # FIXME: use reference implementation - # NOTE: dimensions are nvars x nx x ny x nz - self.flux_derivatives = np.zeros((self.nvars, self.nx, self.ny, - self.nz), order="F") - - def swap_array_rows(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)] - - def fill_from_pair(self): - d = self.dir_internal - nx_arr = np.array([self.nxhalo, self.nyhalo, self.nzhalo]) - result = u.expand_to_n(self.state_pair, nx_arr[d]) - - for i in range(d): - result = self.add_dimension(result, nx_arr[i]) - result = np.swapaxes(result, -2, -1) - for i in range(d+1,self.ndim): - result = self.add_dimension(result, nx_arr[i]) - - return result.copy(order="F") - - def add_dimension(self, arr, n): - return np.stack([arr for i in range(n)], axis=-1) - - -vector_data = {} - -vector_data["Case flat:x"] = FluxDataVector( - nx=6, ny=2, nz=2, - states_str="1 1 1 1 5.5,1 1 1 1 5.5", - direction="x") -vector_data["Case flat:y"] = FluxDataVector( - nx=2, ny=6, nz=2, - states_str="1 1 1 1 5.5,1 1 1 1 5.5", - direction="y") -vector_data["Case flat:z"] = FluxDataVector( - nx=2, ny=2, nz=6, - states_str="1 1 1 1 5.5,1 1 1 1 5.5", - direction="z") - -vector_data["Case a:x"] = FluxDataVector( - nx=6, ny=2, nz=2, - states_str="2 4 4 4 20,1 1 1 1 5.5", - direction="x") -vector_data["Case a:y"] = FluxDataVector( - nx=2, ny=6, nz=2, - states_str="2 4 4 4 20,1 1 1 1 5.5", - direction="y") -vector_data["Case a:z"] = FluxDataVector( - nx=2, ny=2, nz=6, - states_str="2 4 4 4 20,1 1 1 1 5.5", - direction="z") - - -@pytest.fixture(scope="session", params=[ - "Case flat:x", "Case flat:y", "Case flat:z"]) -def cfd_test_data_fixture(request): - return vector_data[request.param] - - # vim: foldmethod=marker diff --git a/test/test_flux_derivatives.py b/test/test_flux_derivatives.py index 33b8430..2c4ec9c 100644 --- a/test/test_flux_derivatives.py +++ b/test/test_flux_derivatives.py @@ -34,9 +34,126 @@ import logging import pytest import utilities as u -from data_for_test import ( # noqa: F401 - cfd_test_data_fixture - ) +import weno_reference_implementation as ref + + +# FIXME: is there a better way to divide responsibilities with these fixture classes? +class FluxDataVector: + nvars = 5 + ndim = 3 + dirs = {"x": 1, "y": 2, "z": 3} + halo = 3 + + def __init__(self, nx, ny, nz, states_str, direction): + self.direction = self.dirs[direction] + self.dir_internal = self.direction-1 + + self.nx = nx + self.ny = ny + self.nz = nz + + self.nxhalo = self.nx + 2*self.halo + self.nyhalo = self.ny + 2*self.halo + self.nzhalo = self.nz + 2*self.halo + + self.flux_dims = (self.nvars, self.nx, self.ny, self.nz) + + self.metrics = np.stack( + [np.stack( + [np.stack( + [np.identity(self.ndim) for i in range(self.nxhalo)], + axis=-1) for j in range(self.nyhalo)], + axis=-1) for k in range(self.nzhalo)], + axis=-1).copy(order="F") + self.jacobians = np.ones((self.nxhalo, self.nyhalo, self.nzhalo), + order="F") + + state_pair = self.swap_array_rows( + u.transposed_array_from_string(states_str), self.direction) + # FIXME: Move array_from_string stuff outside WindowResults + # -- just pass an array & have external utilities that generate + # Riemann, sine wave, etc. initial conditions + # FIXME: Consider handling row swapping outside as well? + # FIXME: Do we even need to swap rows? + self.state_pair = self.swap_array_rows( + u.transposed_array_from_string(states_str), self.dir_internal) + # NOTE: dimensions are nvars x nxhalo x nyhalo x nzhalo + self.states = self.fill_from_pair() + + # NOTE: dimensions are nvars x nxhalo x nyhalo x nzhalo + # FIXME: these should be generalized fluxes + # FIXME: make a clear distinction between fluxes in physical and + # generalized coordinates + npoints = self.nxhalo*self.nyhalo*self.nzhalo + flat_states = self.states.reshape((self.nvars, npoints)) + self.fluxes = ref.pointwise_fluxes( + flat_states)[:,:,self.dir_internal].T.reshape( + (self.nvars, self.nxhalo, self.nyhalo, self.nzhalo) + ).copy(order="F") + + # FIXME: use reference implementation + # NOTE: dimensions are nvars x nx x ny x nz + self.flux_derivatives = np.zeros((self.nvars, self.nx, self.ny, + self.nz), order="F") + + def swap_array_rows(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)] + + def fill_from_pair(self): + d = self.dir_internal + nx_arr = np.array([self.nxhalo, self.nyhalo, self.nzhalo]) + result = u.expand_to_n(self.state_pair, nx_arr[d]) + + for i in range(d): + result = self.add_dimension(result, nx_arr[i]) + result = np.swapaxes(result, -2, -1) + for i in range(d+1,self.ndim): + result = self.add_dimension(result, nx_arr[i]) + + return result.copy(order="F") + + def add_dimension(self, arr, n): + return np.stack([arr for i in range(n)], axis=-1) + + +vector_data = {} + +vector_data["Case flat:x"] = FluxDataVector( + nx=6, ny=2, nz=2, + states_str="1 1 1 1 5.5,1 1 1 1 5.5", + direction="x") +vector_data["Case flat:y"] = FluxDataVector( + nx=2, ny=6, nz=2, + states_str="1 1 1 1 5.5,1 1 1 1 5.5", + direction="y") +vector_data["Case flat:z"] = FluxDataVector( + nx=2, ny=2, nz=6, + states_str="1 1 1 1 5.5,1 1 1 1 5.5", + direction="z") + +vector_data["Case a:x"] = FluxDataVector( + nx=6, ny=2, nz=2, + states_str="2 4 4 4 20,1 1 1 1 5.5", + direction="x") +vector_data["Case a:y"] = FluxDataVector( + nx=2, ny=6, nz=2, + states_str="2 4 4 4 20,1 1 1 1 5.5", + direction="y") +vector_data["Case a:z"] = FluxDataVector( + nx=2, ny=2, nz=6, + states_str="2 4 4 4 20,1 1 1 1 5.5", + direction="z") + + +@pytest.fixture(scope="session", params=[ + "Case flat:x", "Case flat:y", "Case flat:z"]) +def cfd_test_data_fixture(request): + return vector_data[request.param] def test_compute_flux_derivatives_uniform_grid(queue, cfd_test_data_fixture): -- GitLab From 9bceea8ee265fa1c3c9a7b75fb9b9b0bfb047910 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Fri, 8 Nov 2019 22:06:09 -0600 Subject: [PATCH 11/23] move fluxes to WindowData --- test/data_for_test.py | 6 ++++++ test/test_eigensystem.py | 13 ++++++------- test/test_flux_window_ops.py | 7 +------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 30c833f..47354d7 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -44,6 +44,12 @@ class WindowData: self.state_pair = u.transposed_array_from_string(states_str) self.states = u.expand_to_n(self.state_pair, 6) + # FIXME: these should be generalized fluxes + # FIXME: make a clear distinction between fluxes in physical and + # generalized coordinates + self.fluxes = ref.pointwise_fluxes( + self.states)[:,:,self.dir_internal].T.copy(order="F") + 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) diff --git a/test/test_eigensystem.py b/test/test_eigensystem.py index c8ce865..ea71046 100644 --- a/test/test_eigensystem.py +++ b/test/test_eigensystem.py @@ -38,7 +38,7 @@ import weno_reference_implementation as ref from data_for_test import window_data -class PairResults: +class PairData: def __init__(self, data): self.nvars = data.nvars self.ndim = data.ndim @@ -50,20 +50,19 @@ class PairResults: # 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.dir_internal].T.copy(order="F") + self.flux_pair = data.fluxes[:,2:4] # FIXME: should be computed directly from the metrics and jacobians self.frozen_metrics = np.mean(data.metrics[2:4], axis=0) @pytest.fixture(scope="session") -def pair_results(window_data): - return PairResults(window_data) +def pair_data(window_data): + return PairData(window_data) -def test_roe_uniform_grid_ideal_gas(queue, pair_results): - data = pair_results +def test_roe_uniform_grid_ideal_gas(queue, pair_data): + data = pair_data def check_roe_identity(states, R, R_inv): d_state = states[:, 1] - states[:, 0] diff --git a/test/test_flux_window_ops.py b/test/test_flux_window_ops.py index d467338..f699072 100644 --- a/test/test_flux_window_ops.py +++ b/test/test_flux_window_ops.py @@ -46,6 +46,7 @@ class WindowResults: self.dir_internal = data.dir_internal self.states = data.states + self.fluxes = data.fluxes # FIXME: duplicate code self.state_pair = data.states[:,2:4] @@ -57,12 +58,6 @@ class WindowResults: self.frozen_jacobian = np.mean(self.jacobians[2:4], axis=0) self.combined_frozen_metrics = 1.0 - # FIXME: these should be generalized fluxes - # FIXME: make a clear distinction between fluxes in physical and - # generalized coordinates - self.fluxes = ref.pointwise_fluxes( - self.states)[:,:,self.dir_internal].T.copy(order="F") - self.lam_pointwise = ref.lambda_pointwise( self.states, self.metrics, self.dir_internal) self.R, self.R_inv, self.lam_roe = ref.roe_eigensystem( -- GitLab From 0212894a684bc9beff1be36cf20102b3c5259434 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Fri, 8 Nov 2019 22:21:40 -0600 Subject: [PATCH 12/23] some cleanup --- test/data_for_test.py | 9 +++------ test/ideal_gas.py | 5 +++-- test/test_eigensystem.py | 2 +- test/test_flux_window_ops.py | 3 ++- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 47354d7..2f12e9c 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -27,12 +27,9 @@ import weno_reference_implementation as ref class WindowData: - # FIXME: can we set some of these constants from ref.gas? - # -- if all nvars references come from there, it's relatively easy to - # introduce a new gas with more (e.g. scalar) variables - nvars = 5 - ndim = 3 - dirs = {"x": 1, "y": 2, "z": 3} + nvars = ref.gas.nvars + ndim = ref.gas.ndim + dirs = ref.gas.dirs def __init__(self, states_str, direction): self.direction = self.dirs[direction] diff --git a/test/ideal_gas.py b/test/ideal_gas.py index a062acb..0be569f 100644 --- a/test/ideal_gas.py +++ b/test/ideal_gas.py @@ -29,8 +29,9 @@ import pyopencl.clrandom # noqa import loopy as lp # noqa -ndim = 3 -nvars = 3 +dirs = {"x": 1, "y": 2, "z": 3} +ndim = len(dirs) +nvars = ndim + 2 gamma = 1.4 diff --git a/test/test_eigensystem.py b/test/test_eigensystem.py index ea71046..e8f3a9c 100644 --- a/test/test_eigensystem.py +++ b/test/test_eigensystem.py @@ -52,7 +52,7 @@ class PairData: # generalized coordinates self.flux_pair = data.fluxes[:,2:4] - # FIXME: should be computed directly from the metrics and jacobians + # FIXME: is this the right computation? self.frozen_metrics = np.mean(data.metrics[2:4], axis=0) diff --git a/test/test_flux_window_ops.py b/test/test_flux_window_ops.py index f699072..b48e98a 100644 --- a/test/test_flux_window_ops.py +++ b/test/test_flux_window_ops.py @@ -47,13 +47,14 @@ class WindowResults: self.states = data.states self.fluxes = data.fluxes - # FIXME: duplicate code + # FIXME: duplicate of code in PairData self.state_pair = data.states[:,2:4] self.metrics = data.metrics self.jacobians = data.jacobians # FIXME: should be computed directly from the metrics and jacobians + # FIXME: partial duplicate of code in PairData 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 -- GitLab From cec0cc945f525b81bfffd7f87b8f8e7a5f54f001 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Fri, 15 Nov 2019 21:05:55 -0600 Subject: [PATCH 13/23] refactor out metric term creation into fixture --- test/data_for_test.py | 61 +++++++++++++++++++++++------------- test/test_eigensystem.py | 2 +- test/test_flux_window_ops.py | 2 +- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 2f12e9c..1b1db78 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -31,7 +31,7 @@ class WindowData: ndim = ref.gas.ndim dirs = ref.gas.dirs - def __init__(self, states_str, direction): + def __init__(self, states_str, direction, window_metrics): self.direction = self.dirs[direction] self.dir_internal = self.direction-1 @@ -47,30 +47,49 @@ class WindowData: self.fluxes = ref.pointwise_fluxes( self.states)[:,:,self.dir_internal].T.copy(order="F") - 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) + self.metrics, self.jacobians = window_metrics + + +@pytest.fixture(scope="session") +def metrics_generator(): + ndim = ref.gas.ndim + + def window_metrics(metric_str): + if (metric_str == "uniform"): + metrics = np.array([np.identity(ndim) for i in range(6)], + dtype=np.float64, + order="F") + jacobians = np.repeat(1.0, 6) + else: + raise ValueError("Metric string {} not supported".format(metric_str)) + return metrics, jacobians + + return window_metrics @pytest.fixture(scope="session", params=[ - ("1 1 1 1 5.5,1 1 1 1 5.5", "x"), - ("1 1 1 1 5.5,1 1 1 1 5.5", "y"), - ("1 1 1 1 5.5,1 1 1 1 5.5", "z"), - ("2 4 4 4 20,1 1 1 1 5.5", "x"), - ("2 4 4 4 20,1 1 1 1 5.5", "y"), - ("2 4 4 4 20,1 1 1 1 5.5", "z"), - ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "x"), - ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "y"), - ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "z"), - ("2 4 8 12 64,1 1 2 3 11", "x"), - ("2 8 12 4 64,1 2 3 1 11", "y"), - ("2 12 4 8 64,1 3 1 2 11", "z"), - ("1 -1 -2 -3 11,2 -4 -8 -12 64", "x"), - ("1 -2 -3 -1 11,2 -8 -12 -4 64", "y"), - ("1 -3 -1 -2 11,2 -12 -4 -8 64", "z") + ("1 1 1 1 5.5,1 1 1 1 5.5", "x", "uniform"), + ("1 1 1 1 5.5,1 1 1 1 5.5", "y", "uniform"), + ("1 1 1 1 5.5,1 1 1 1 5.5", "z", "uniform"), + ("2 4 4 4 20,1 1 1 1 5.5", "x", "uniform"), + ("2 4 4 4 20,1 1 1 1 5.5", "y", "uniform"), + ("2 4 4 4 20,1 1 1 1 5.5", "z", "uniform"), + ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "x", "uniform"), + ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "y", "uniform"), + ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "z", "uniform"), + ("2 4 8 12 64,1 1 2 3 11", "x", "uniform"), + ("2 8 12 4 64,1 2 3 1 11", "y", "uniform"), + ("2 12 4 8 64,1 3 1 2 11", "z", "uniform"), + ("1 -1 -2 -3 11,2 -4 -8 -12 64", "x", "uniform"), + ("1 -2 -3 -1 11,2 -8 -12 -4 64", "y", "uniform"), + ("1 -3 -1 -2 11,2 -12 -4 -8 64", "z", "uniform") ]) -def window_data(request): - return WindowData(*request.param) +def window_data(request, metrics_generator): + states_str = request.param[0] + dir_str = request.param[1] + metric_str = request.param[2] + + return WindowData(states_str, dir_str, metrics_generator(metric_str)) # vim: foldmethod=marker diff --git a/test/test_eigensystem.py b/test/test_eigensystem.py index e8f3a9c..b8b0364 100644 --- a/test/test_eigensystem.py +++ b/test/test_eigensystem.py @@ -35,7 +35,7 @@ import pytest import utilities as u import weno_reference_implementation as ref -from data_for_test import window_data +from data_for_test import window_data, metrics_generator class PairData: diff --git a/test/test_flux_window_ops.py b/test/test_flux_window_ops.py index b48e98a..a32d5bb 100644 --- a/test/test_flux_window_ops.py +++ b/test/test_flux_window_ops.py @@ -35,7 +35,7 @@ import pytest import utilities as u import weno_reference_implementation as ref -from data_for_test import window_data +from data_for_test import window_data, metrics_generator class WindowResults: -- GitLab From 1e864da060155d519b0826ec6a492e3b6e0873f9 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Fri, 15 Nov 2019 21:50:04 -0600 Subject: [PATCH 14/23] update reference implementation of frozen metric computation to match paper --- test/data_for_test.py | 25 +++++++++++++++++++++++++ test/test_eigensystem.py | 25 +------------------------ test/test_flux_window_ops.py | 29 ++++++++++++++--------------- 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 1b1db78..9e62317 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -92,4 +92,29 @@ def window_data(request, metrics_generator): return WindowData(states_str, dir_str, metrics_generator(metric_str)) +class PairData: + def __init__(self, data): + self.nvars = data.nvars + self.ndim = data.ndim + self.direction = data.direction + self.dir_internal = data.dir_internal + + self.state_pair = data.states[:,2:4] + + # FIXME: these should be generalized fluxes + # FIXME: make a clear distinction between fluxes in physical and + # generalized coordinates + self.flux_pair = data.fluxes[:,2:4] + + weighted_metric_slice = data.metrics[2:4]/data.jacobians[2:4,None,None] + self.frozen_metrics = np.mean(weighted_metric_slice, axis=0) + self.frozen_jacobian = np.mean(data.jacobians[2:4]) + self.combined_frozen_metrics = np.sum(self.frozen_metrics**2, axis=1) + + +@pytest.fixture(scope="session") +def pair_data(window_data): + return PairData(window_data) + + # vim: foldmethod=marker diff --git a/test/test_eigensystem.py b/test/test_eigensystem.py index b8b0364..c077e68 100644 --- a/test/test_eigensystem.py +++ b/test/test_eigensystem.py @@ -35,30 +35,7 @@ import pytest import utilities as u import weno_reference_implementation as ref -from data_for_test import window_data, metrics_generator - - -class PairData: - def __init__(self, data): - self.nvars = data.nvars - self.ndim = data.ndim - self.direction = data.direction - self.dir_internal = data.dir_internal - - self.state_pair = data.states[:,2:4] - - # FIXME: these should be generalized fluxes - # FIXME: make a clear distinction between fluxes in physical and - # generalized coordinates - self.flux_pair = data.fluxes[:,2:4] - - # FIXME: is this the right computation? - self.frozen_metrics = np.mean(data.metrics[2:4], axis=0) - - -@pytest.fixture(scope="session") -def pair_data(window_data): - return PairData(window_data) +from data_for_test import pair_data, window_data, metrics_generator def test_roe_uniform_grid_ideal_gas(queue, pair_data): diff --git a/test/test_flux_window_ops.py b/test/test_flux_window_ops.py index a32d5bb..8387bda 100644 --- a/test/test_flux_window_ops.py +++ b/test/test_flux_window_ops.py @@ -35,11 +35,13 @@ import pytest import utilities as u import weno_reference_implementation as ref -from data_for_test import window_data, metrics_generator +from data_for_test import PairData, window_data, metrics_generator class WindowResults: def __init__(self, queue, data): + pair = PairData(data) + self.nvars = data.nvars self.ndim = data.ndim self.direction = data.direction @@ -47,17 +49,14 @@ class WindowResults: self.states = data.states self.fluxes = data.fluxes - # FIXME: duplicate of code in PairData - self.state_pair = data.states[:,2:4] + self.state_pair = pair.state_pair self.metrics = data.metrics self.jacobians = data.jacobians - # FIXME: should be computed directly from the metrics and jacobians - # FIXME: partial duplicate of code in PairData - 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.frozen_metrics = pair.frozen_metrics + self.frozen_jacobian = pair.frozen_jacobian + self.combined_frozen_metric = pair.combined_frozen_metrics[self.dir_internal] self.lam_pointwise = ref.lambda_pointwise( self.states, self.metrics, self.dir_internal) @@ -74,9 +73,9 @@ class WindowResults: self.oscillation_neg = ref.oscillation(self.char_fluxes_neg[:,::-1]) self.weno_weights_pos = ref.weno_weights( - self.oscillation_pos, self.combined_frozen_metrics) + self.oscillation_pos, self.combined_frozen_metric) self.weno_weights_neg = ref.weno_weights( - self.oscillation_neg, self.combined_frozen_metrics) + self.oscillation_neg, self.combined_frozen_metric) self.consistent = ref.consistent_part(self.fluxes) self.dissipation_pos = ref.dissipation_part( @@ -137,7 +136,7 @@ def test_weno_flux(queue, window_results): generalized_fluxes=data.fluxes, characteristic_fluxes_pos=data.char_fluxes_pos, characteristic_fluxes_neg=data.char_fluxes_neg, - combined_frozen_metrics=data.combined_frozen_metrics, + combined_frozen_metrics=data.combined_frozen_metric, R=data.R, flux=flux_dev) @@ -169,7 +168,7 @@ def test_dissipation_part_pos(queue, window_results): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_pos, - combined_frozen_metrics=data.combined_frozen_metrics, + combined_frozen_metrics=data.combined_frozen_metric, R=data.R, dissipation_pos=dissipation_dev) @@ -186,7 +185,7 @@ def test_dissipation_part_neg(queue, window_results): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_neg, - combined_frozen_metrics=data.combined_frozen_metrics, + combined_frozen_metrics=data.combined_frozen_metric, R=data.R, dissipation_neg=dissipation_dev) @@ -203,7 +202,7 @@ def test_weno_weights_pos(queue, window_results): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_pos, - combined_frozen_metrics=data.combined_frozen_metrics, + combined_frozen_metrics=data.combined_frozen_metric, w=weights_dev) sum_weights = np.sum(weights_dev.get(), axis=1) @@ -222,7 +221,7 @@ def test_weno_weights_neg(queue, window_results): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_neg, - combined_frozen_metrics=data.combined_frozen_metrics, + combined_frozen_metrics=data.combined_frozen_metric, w=weights_dev) sum_weights = np.sum(weights_dev.get(), axis=1) -- GitLab From 84a6e5289aa4a8830d7298bd21809f9e9b5747bd Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Fri, 15 Nov 2019 21:55:40 -0600 Subject: [PATCH 15/23] add note on provenance of algorithm --- test/weno_reference_implementation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/weno_reference_implementation.py b/test/weno_reference_implementation.py index 179402a..a7b4095 100644 --- a/test/weno_reference_implementation.py +++ b/test/weno_reference_implementation.py @@ -31,6 +31,7 @@ import loopy as lp # noqa import utilities as u import ideal_gas as gas +### WENO algorithm taken from Nonomura, et al., Comput. Fluids 107 (2015) 242-255 def pointwise_fluxes(states): return np.array([gas.flux(s) for s in states.T]) -- GitLab From 91b7427684cd9826d89fe8c524f402c75673e639 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Fri, 15 Nov 2019 22:17:39 -0600 Subject: [PATCH 16/23] rename combined_frozen_metrics in some locations to reflect that there's only one --- WENO.F90 | 44 ++++++++++++++++++------------------ test/test_flux_window_ops.py | 10 ++++---- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/WENO.F90 b/WENO.F90 index d798cdb..5a7a6f4 100644 --- a/WENO.F90 +++ b/WENO.F90 @@ -509,14 +509,14 @@ subroutine split_characteristic_fluxes(nvars, & end subroutine subroutine weno_flux(nvars, generalized_fluxes, characteristic_fluxes_pos, & - characteristic_fluxes_neg, combined_frozen_metrics, R, flux) + characteristic_fluxes_neg, combined_frozen_metric, R, flux) implicit none integer, intent(in) :: nvars real*8, intent(in) :: generalized_fluxes(nvars, -2:3) real*8, intent(in) :: characteristic_fluxes_pos(nvars, -2:3) real*8, intent(in) :: characteristic_fluxes_neg(nvars, -2:3) - real*8, intent(in) :: combined_frozen_metrics + real*8, intent(in) :: combined_frozen_metric real*8, intent(in) :: R(nvars, nvars) real*8, intent(out) :: flux(nvars) @@ -527,9 +527,9 @@ subroutine weno_flux(nvars, generalized_fluxes, characteristic_fluxes_pos, & call consistent_part(nvars, generalized_fluxes, consistent) call dissipation_part_pos(nvars, characteristic_fluxes_pos, & - combined_frozen_metrics, R, dissipation_pos) + combined_frozen_metric, R, dissipation_pos) call dissipation_part_neg(nvars, characteristic_fluxes_neg, & - combined_frozen_metrics, R, dissipation_neg) + combined_frozen_metric, R, dissipation_neg) do v=1,nvars flux(v) = consistent(v) + dissipation_pos(v) + dissipation_neg(v) @@ -554,36 +554,36 @@ subroutine consistent_part(nvars, generalized_fluxes, consistent) end subroutine subroutine dissipation_part_pos(nvars, characteristic_fluxes, & - combined_frozen_metrics, R, dissipation_pos) + combined_frozen_metric, R, dissipation_pos) implicit none integer, intent(in) :: nvars real*8, intent(in) :: characteristic_fluxes(nvars, -2:3) - real*8, intent(in) :: combined_frozen_metrics + real*8, intent(in) :: combined_frozen_metric real*8, intent(in) :: R(nvars, nvars) real*8, intent(out) :: dissipation_pos(nvars) real*8 combined_fluxes(nvars) - call weno_combination_pos(nvars, characteristic_fluxes, combined_frozen_metrics, combined_fluxes) + call weno_combination_pos(nvars, characteristic_fluxes, combined_frozen_metric, combined_fluxes) call mult_mat_vec(nvars, nvars, -1.0d0/60, R, combined_fluxes, dissipation_pos) end subroutine subroutine weno_combination_pos(nvars, characteristic_fluxes, & - combined_frozen_metrics, combined_fluxes) + combined_frozen_metric, combined_fluxes) implicit none integer, intent(in) :: nvars real*8, intent(in) :: characteristic_fluxes(nvars, -2:3) - real*8, intent(in) :: combined_frozen_metrics + real*8, intent(in) :: combined_frozen_metric real*8, intent(out) :: combined_fluxes(nvars) real*8 w(nvars, 3) real*8 flux_differences(nvars, 3) integer v - call weno_weights_pos(nvars, characteristic_fluxes, combined_frozen_metrics, w) + call weno_weights_pos(nvars, characteristic_fluxes, combined_frozen_metric, w) call flux_differences_pos(nvars, characteristic_fluxes, flux_differences) do v=1,nvars @@ -593,12 +593,12 @@ subroutine weno_combination_pos(nvars, characteristic_fluxes, & end do end subroutine -subroutine weno_weights_pos(nvars, characteristic_fluxes, combined_frozen_metrics, w) +subroutine weno_weights_pos(nvars, characteristic_fluxes, combined_frozen_metric, w) implicit none integer, intent(in) :: nvars real*8, intent(in) :: characteristic_fluxes(nvars, -2:3) - real*8, intent(in) :: combined_frozen_metrics + real*8, intent(in) :: combined_frozen_metric real*8, intent(out) :: w(nvars, 3) real*8 :: C(3) = (/0.1d0, 0.6d0, 0.3d0/) @@ -607,7 +607,7 @@ subroutine weno_weights_pos(nvars, characteristic_fluxes, combined_frozen_metric integer p, i, j real*8 sum_alpha(1) - eps = 1.0d-6!*combined_frozen_metrics + eps = 1.0d-6!*combined_frozen_metric p = 2 call oscillation_pos(nvars, characteristic_fluxes, IS) @@ -671,36 +671,36 @@ subroutine flux_differences_pos(nvars, characteristic_fluxes, flux_differences) end subroutine subroutine dissipation_part_neg(nvars, characteristic_fluxes, & - combined_frozen_metrics, R, dissipation_neg) + combined_frozen_metric, R, dissipation_neg) implicit none integer, intent(in) :: nvars real*8, intent(in) :: characteristic_fluxes(nvars, -2:3) - real*8, intent(in) :: combined_frozen_metrics + real*8, intent(in) :: combined_frozen_metric real*8, intent(in) :: R(nvars, nvars) real*8, intent(out) :: dissipation_neg(nvars) real*8 combined_fluxes(nvars) - call weno_combination_neg(nvars, characteristic_fluxes, combined_frozen_metrics, combined_fluxes) + call weno_combination_neg(nvars, characteristic_fluxes, combined_frozen_metric, combined_fluxes) call mult_mat_vec(nvars, nvars, 1.0d0/60, R, combined_fluxes, dissipation_neg) end subroutine subroutine weno_combination_neg(nvars, characteristic_fluxes, & - combined_frozen_metrics, combined_fluxes) + combined_frozen_metric, combined_fluxes) implicit none integer, intent(in) :: nvars real*8, intent(in) :: characteristic_fluxes(nvars, -2:3) - real*8, intent(in) :: combined_frozen_metrics + real*8, intent(in) :: combined_frozen_metric real*8, intent(out) :: combined_fluxes(nvars) real*8 w(nvars, 3) real*8 flux_differences(nvars, 3) integer v - call weno_weights_neg(nvars, characteristic_fluxes, combined_frozen_metrics, w) + call weno_weights_neg(nvars, characteristic_fluxes, combined_frozen_metric, w) call flux_differences_neg(nvars, characteristic_fluxes, flux_differences) do v=1,nvars @@ -710,12 +710,12 @@ subroutine weno_combination_neg(nvars, characteristic_fluxes, & end do end subroutine -subroutine weno_weights_neg(nvars, characteristic_fluxes, combined_frozen_metrics, w) +subroutine weno_weights_neg(nvars, characteristic_fluxes, combined_frozen_metric, w) implicit none integer, intent(in) :: nvars real*8, intent(in) :: characteristic_fluxes(nvars, -2:3) - real*8, intent(in) :: combined_frozen_metrics + real*8, intent(in) :: combined_frozen_metric real*8, intent(out) :: w(nvars, 3) real*8 :: C(3) = (/0.1d0, 0.6d0, 0.3d0/) @@ -724,7 +724,7 @@ subroutine weno_weights_neg(nvars, characteristic_fluxes, combined_frozen_metric integer p, i, j real*8 sum_alpha(1) - eps = 1.0d-6!*combined_frozen_metrics + eps = 1.0d-6!*combined_frozen_metric p = 2 call oscillation_neg(nvars, characteristic_fluxes, IS) diff --git a/test/test_flux_window_ops.py b/test/test_flux_window_ops.py index 8387bda..0f4742a 100644 --- a/test/test_flux_window_ops.py +++ b/test/test_flux_window_ops.py @@ -136,7 +136,7 @@ def test_weno_flux(queue, window_results): generalized_fluxes=data.fluxes, characteristic_fluxes_pos=data.char_fluxes_pos, characteristic_fluxes_neg=data.char_fluxes_neg, - combined_frozen_metrics=data.combined_frozen_metric, + combined_frozen_metric=data.combined_frozen_metric, R=data.R, flux=flux_dev) @@ -168,7 +168,7 @@ def test_dissipation_part_pos(queue, window_results): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_pos, - combined_frozen_metrics=data.combined_frozen_metric, + combined_frozen_metric=data.combined_frozen_metric, R=data.R, dissipation_pos=dissipation_dev) @@ -185,7 +185,7 @@ def test_dissipation_part_neg(queue, window_results): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_neg, - combined_frozen_metrics=data.combined_frozen_metric, + combined_frozen_metric=data.combined_frozen_metric, R=data.R, dissipation_neg=dissipation_dev) @@ -202,7 +202,7 @@ def test_weno_weights_pos(queue, window_results): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_pos, - combined_frozen_metrics=data.combined_frozen_metric, + combined_frozen_metric=data.combined_frozen_metric, w=weights_dev) sum_weights = np.sum(weights_dev.get(), axis=1) @@ -221,7 +221,7 @@ def test_weno_weights_neg(queue, window_results): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_neg, - combined_frozen_metrics=data.combined_frozen_metric, + combined_frozen_metric=data.combined_frozen_metric, w=weights_dev) sum_weights = np.sum(weights_dev.get(), axis=1) -- GitLab From 00413a56aaddf02b7fec7db8e386e160ddd935e7 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Fri, 15 Nov 2019 22:39:20 -0600 Subject: [PATCH 17/23] update test suite to clarify when generalized fluxes are being used --- test/data_for_test.py | 12 +++--------- test/test_eigensystem.py | 1 + test/test_flux_window_ops.py | 10 +++++----- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 9e62317..817fe52 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -41,13 +41,11 @@ class WindowData: self.state_pair = u.transposed_array_from_string(states_str) self.states = u.expand_to_n(self.state_pair, 6) - # FIXME: these should be generalized fluxes - # FIXME: make a clear distinction between fluxes in physical and - # generalized coordinates + self.metrics, self.jacobians = window_metrics + self.fluxes = ref.pointwise_fluxes( self.states)[:,:,self.dir_internal].T.copy(order="F") - - self.metrics, self.jacobians = window_metrics + self.generalized_fluxes = self.fluxes # FIXME: wrong @pytest.fixture(scope="session") @@ -100,10 +98,6 @@ class PairData: self.dir_internal = data.dir_internal self.state_pair = data.states[:,2:4] - - # FIXME: these should be generalized fluxes - # FIXME: make a clear distinction between fluxes in physical and - # generalized coordinates self.flux_pair = data.fluxes[:,2:4] weighted_metric_slice = data.metrics[2:4]/data.jacobians[2:4,None,None] diff --git a/test/test_eigensystem.py b/test/test_eigensystem.py index c077e68..de1e110 100644 --- a/test/test_eigensystem.py +++ b/test/test_eigensystem.py @@ -67,6 +67,7 @@ def test_roe_uniform_grid_ideal_gas(queue, pair_data): R_inv = R_inv_dev.get() lam = lam_dev.get() + # FIXME: what are Roe identity/property when metric terms are involved? check_roe_identity(data.state_pair, R, R_inv) check_roe_property(data.state_pair, data.flux_pair, R, R_inv, lam) diff --git a/test/test_flux_window_ops.py b/test/test_flux_window_ops.py index 0f4742a..a3e163d 100644 --- a/test/test_flux_window_ops.py +++ b/test/test_flux_window_ops.py @@ -48,7 +48,7 @@ class WindowResults: self.dir_internal = data.dir_internal self.states = data.states - self.fluxes = data.fluxes + self.generalized_fluxes = data.generalized_fluxes self.state_pair = pair.state_pair self.metrics = data.metrics @@ -77,7 +77,7 @@ class WindowResults: self.weno_weights_neg = ref.weno_weights( self.oscillation_neg, self.combined_frozen_metric) - self.consistent = ref.consistent_part(self.fluxes) + self.consistent = ref.consistent_part(self.generalized_fluxes) self.dissipation_pos = ref.dissipation_part( self.R, self.char_fluxes_pos, self.weno_weights_pos, 1) self.dissipation_neg = ref.dissipation_part( @@ -115,7 +115,7 @@ def test_flux_splitting(queue, window_results): prg(queue, nvars=data.nvars, generalized_states_frozen=data.states, - generalized_fluxes_frozen=data.fluxes, + generalized_fluxes_frozen=data.generalized_fluxes, R_inv=data.R_inv, wavespeeds=data.wavespeeds, characteristic_fluxes_pos=fluxes_pos_dev, @@ -133,7 +133,7 @@ def test_weno_flux(queue, window_results): flux_dev = u.empty_array_on_device(queue, data.nvars) prg(queue, nvars=data.nvars, - generalized_fluxes=data.fluxes, + generalized_fluxes=data.generalized_fluxes, characteristic_fluxes_pos=data.char_fluxes_pos, characteristic_fluxes_neg=data.char_fluxes_neg, combined_frozen_metric=data.combined_frozen_metric, @@ -152,7 +152,7 @@ def test_consistent_part(queue, window_results): consistent_dev = u.empty_array_on_device(queue, data.nvars) prg(queue, nvars=data.nvars, - generalized_fluxes=data.fluxes, + generalized_fluxes=data.generalized_fluxes, consistent=consistent_dev) u.compare_arrays(consistent_dev.get(), data.consistent) -- GitLab From ac0b617a62b3b146d2b94e0dacfec367241820ba Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Fri, 15 Nov 2019 22:46:57 -0600 Subject: [PATCH 18/23] need to keep track that we compute the generalized fluxes in two different ways --- test/test_flux_window_ops.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_flux_window_ops.py b/test/test_flux_window_ops.py index a3e163d..06a000b 100644 --- a/test/test_flux_window_ops.py +++ b/test/test_flux_window_ops.py @@ -48,9 +48,11 @@ class WindowResults: self.dir_internal = data.dir_internal self.states = data.states - self.generalized_fluxes = data.generalized_fluxes self.state_pair = pair.state_pair + self.generalized_fluxes = data.generalized_fluxes + self.generalized_fluxes_frozen = data.generalized_fluxes # FIXME: wrong + self.metrics = data.metrics self.jacobians = data.jacobians @@ -115,7 +117,7 @@ def test_flux_splitting(queue, window_results): prg(queue, nvars=data.nvars, generalized_states_frozen=data.states, - generalized_fluxes_frozen=data.generalized_fluxes, + generalized_fluxes_frozen=data.generalized_fluxes_frozen, R_inv=data.R_inv, wavespeeds=data.wavespeeds, characteristic_fluxes_pos=fluxes_pos_dev, -- GitLab From feb94554b12399f5232cee7212cdf20796621d44 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Sat, 16 Nov 2019 23:55:01 -0600 Subject: [PATCH 19/23] some refactoring to use generalized fluxes for Roe property testing --- test/data_for_test.py | 6 +++--- test/test_eigensystem.py | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 817fe52..957fadd 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -43,9 +43,9 @@ class WindowData: self.metrics, self.jacobians = window_metrics - self.fluxes = ref.pointwise_fluxes( + # FIXME: wrong + self.generalized_fluxes = ref.pointwise_fluxes( self.states)[:,:,self.dir_internal].T.copy(order="F") - self.generalized_fluxes = self.fluxes # FIXME: wrong @pytest.fixture(scope="session") @@ -98,7 +98,7 @@ class PairData: self.dir_internal = data.dir_internal self.state_pair = data.states[:,2:4] - self.flux_pair = data.fluxes[:,2:4] + self.generalized_flux_pair = data.generalized_fluxes[:,2:4] weighted_metric_slice = data.metrics[2:4]/data.jacobians[2:4,None,None] self.frozen_metrics = np.mean(weighted_metric_slice, axis=0) diff --git a/test/test_eigensystem.py b/test/test_eigensystem.py index de1e110..e7b64f1 100644 --- a/test/test_eigensystem.py +++ b/test/test_eigensystem.py @@ -67,9 +67,8 @@ def test_roe_uniform_grid_ideal_gas(queue, pair_data): R_inv = R_inv_dev.get() lam = lam_dev.get() - # FIXME: what are Roe identity/property when metric terms are involved? check_roe_identity(data.state_pair, R, R_inv) - check_roe_property(data.state_pair, data.flux_pair, R, R_inv, lam) + check_roe_property(data.state_pair, data.generalized_flux_pair, R, R_inv, lam) @pytest.mark.parametrize("lam_pointwise_str,lam_roe_str,lam_expected_str", [ -- GitLab From 0a67b7f41d17da3d6b425f01ea1b3939388601be Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Sun, 17 Nov 2019 00:09:03 -0600 Subject: [PATCH 20/23] fix incorrect setup for generalized fluxes --- test/data_for_test.py | 8 +++++--- test/test_flux_window_ops.py | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 957fadd..28b1a9a 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -43,9 +43,11 @@ class WindowData: self.metrics, self.jacobians = window_metrics - # FIXME: wrong - self.generalized_fluxes = ref.pointwise_fluxes( - self.states)[:,:,self.dir_internal].T.copy(order="F") + self.fluxes = ref.pointwise_fluxes(self.states) + self.generalized_fluxes = np.array([np.dot(flux, metrics/jacobian) + for flux, metrics, jacobian + in zip(self.fluxes, self.metrics, self.jacobians)] + )[:,:,self.dir_internal].T.copy(order="F") @pytest.fixture(scope="session") diff --git a/test/test_flux_window_ops.py b/test/test_flux_window_ops.py index 06a000b..e6f0667 100644 --- a/test/test_flux_window_ops.py +++ b/test/test_flux_window_ops.py @@ -50,9 +50,6 @@ class WindowResults: self.states = data.states self.state_pair = pair.state_pair - self.generalized_fluxes = data.generalized_fluxes - self.generalized_fluxes_frozen = data.generalized_fluxes # FIXME: wrong - self.metrics = data.metrics self.jacobians = data.jacobians @@ -60,6 +57,10 @@ class WindowResults: self.frozen_jacobian = pair.frozen_jacobian self.combined_frozen_metric = pair.combined_frozen_metrics[self.dir_internal] + self.generalized_fluxes = data.generalized_fluxes + self.generalized_fluxes_frozen = np.array([np.dot(flux, self.frozen_metrics) + for flux in data.fluxes])[:,:,self.dir_internal].T.copy(order="F") + self.lam_pointwise = ref.lambda_pointwise( self.states, self.metrics, self.dir_internal) self.R, self.R_inv, self.lam_roe = ref.roe_eigensystem( -- GitLab From 17c02e6279c6e1461220d943afb5947f9151c035 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Sun, 17 Nov 2019 00:21:44 -0600 Subject: [PATCH 21/23] refactor out state setup from WindowData --- test/data_for_test.py | 24 +++++++++++++++--------- test/test_eigensystem.py | 3 ++- test/test_flux_window_ops.py | 3 ++- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 28b1a9a..255932e 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -31,16 +31,11 @@ class WindowData: ndim = ref.gas.ndim dirs = ref.gas.dirs - def __init__(self, states_str, direction, window_metrics): + def __init__(self, states, direction, window_metrics): self.direction = self.dirs[direction] self.dir_internal = self.direction-1 - # FIXME: Move array_from_string stuff outside WindowResults - # -- just pass an array & have external utilities that generate - # Riemann, sine wave, etc. initial conditions - self.state_pair = u.transposed_array_from_string(states_str) - self.states = u.expand_to_n(self.state_pair, 6) - + self.states = states self.metrics, self.jacobians = window_metrics self.fluxes = ref.pointwise_fluxes(self.states) @@ -50,6 +45,15 @@ class WindowData: )[:,:,self.dir_internal].T.copy(order="F") +@pytest.fixture(scope="session") +def states_generator(): + def states(states_str): + state_pair = u.transposed_array_from_string(states_str) + return u.expand_to_n(state_pair, 6) + + return states + + @pytest.fixture(scope="session") def metrics_generator(): ndim = ref.gas.ndim @@ -84,12 +88,14 @@ def metrics_generator(): ("1 -2 -3 -1 11,2 -8 -12 -4 64", "y", "uniform"), ("1 -3 -1 -2 11,2 -12 -4 -8 64", "z", "uniform") ]) -def window_data(request, metrics_generator): +def window_data(request, states_generator, metrics_generator): states_str = request.param[0] dir_str = request.param[1] metric_str = request.param[2] - return WindowData(states_str, dir_str, metrics_generator(metric_str)) + return WindowData(states_generator(states_str), + dir_str, + metrics_generator(metric_str)) class PairData: diff --git a/test/test_eigensystem.py b/test/test_eigensystem.py index e7b64f1..8c1ba93 100644 --- a/test/test_eigensystem.py +++ b/test/test_eigensystem.py @@ -35,7 +35,8 @@ import pytest import utilities as u import weno_reference_implementation as ref -from data_for_test import pair_data, window_data, metrics_generator +from data_for_test import ( + pair_data, window_data, states_generator, metrics_generator) def test_roe_uniform_grid_ideal_gas(queue, pair_data): diff --git a/test/test_flux_window_ops.py b/test/test_flux_window_ops.py index e6f0667..4bdb27e 100644 --- a/test/test_flux_window_ops.py +++ b/test/test_flux_window_ops.py @@ -35,7 +35,8 @@ import pytest import utilities as u import weno_reference_implementation as ref -from data_for_test import PairData, window_data, metrics_generator +from data_for_test import ( + PairData, window_data, states_generator, metrics_generator) class WindowResults: -- GitLab From 7cd6188141457dc3b1d490bc7e71c9d2846cfaa5 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Sun, 17 Nov 2019 00:56:29 -0600 Subject: [PATCH 22/23] refactor ideal_gas and add function to compute conserved variables --- test/ideal_gas.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/ideal_gas.py b/test/ideal_gas.py index 0be569f..85aa4b7 100644 --- a/test/ideal_gas.py +++ b/test/ideal_gas.py @@ -47,13 +47,12 @@ def energy(state): return state[ndim+1] -def kinetic_energy(state): - vel = velocity(state) - return 0.5*rho(state)*np.dot(vel, vel) +def kinetic_energy(rho, vel): + return 0.5*rho*np.dot(vel, vel) def internal_energy(state): - return energy(state) - kinetic_energy(state) + return energy(state) - kinetic_energy(rho(state), velocity(state)) def pressure(state): @@ -75,3 +74,14 @@ def flux(state): result[ndim+1,i] += vel[i]*p return result + + +def conserved(rho, vel, p): + def energy(rho, vel, p): + return p/(gamma - 1) + kinetic_energy(rho, vel) + + state = np.empty(nvars) + state[0] = rho + state[1:nvars-1] = rho*vel + state[nvars-1] = energy(rho, vel, p) + return state -- GitLab From a5b1d36f1c7a912da01e0fd64aa2e5772b8bd1b5 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" <2timothy18@gmail.com> Date: Sun, 17 Nov 2019 00:56:48 -0600 Subject: [PATCH 23/23] add a sine wave test --- test/data_for_test.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/data_for_test.py b/test/data_for_test.py index 255932e..483d50b 100644 --- a/test/data_for_test.py +++ b/test/data_for_test.py @@ -48,8 +48,16 @@ class WindowData: @pytest.fixture(scope="session") def states_generator(): def states(states_str): - state_pair = u.transposed_array_from_string(states_str) - return u.expand_to_n(state_pair, 6) + if states_str == "sine": + rho = np.sin(0.01*np.arange(6)+1.55) + vel = np.repeat(np.array([1.0, 2.0, 3.0])[None,:], 6, axis=0) + pressure = np.repeat(3.2, 6) + return u.transposed_array([ref.gas.conserved(r, v, p) + for r, v, p + in zip(rho, vel, pressure)]) + else: + state_pair = u.transposed_array_from_string(states_str) + return u.expand_to_n(state_pair, 6) return states @@ -72,6 +80,9 @@ def metrics_generator(): @pytest.fixture(scope="session", params=[ + ("sine", "x", "uniform"), + ("sine", "y", "uniform"), + ("sine", "z", "uniform"), ("1 1 1 1 5.5,1 1 1 1 5.5", "x", "uniform"), ("1 1 1 1 5.5,1 1 1 1 5.5", "y", "uniform"), ("1 1 1 1 5.5,1 1 1 1 5.5", "z", "uniform"), -- GitLab