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