diff --git a/test/data_for_test.py b/test/data_for_test.py index 2bc3e74e560560f31fd83cea779d5a359cdbb18c..924a99234b9e1e7300d40b316d9e73fdda257011 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 bc7df0a0e44a89b1cf3451576be91ed1c4ecf23a..ce686f09925ab7fac9f8ebb5e61b357bd4cfb1d0 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 40f9b2f5636e0ba833b7c257a4bcf7f84b6b3cb4..917018181b7582ab94851da3ff2dc8bfc107f5bf 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")