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