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 1/3] 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 2/3] 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 3/3] 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