From 0936eb946f6ef750d194119026e12c8a96e3ea98 Mon Sep 17 00:00:00 2001 From: Gene Lin Date: Sat, 5 Oct 2024 15:19:08 +0800 Subject: [PATCH] refactor xindices --- modmesh/app/euler1d.py | 37 +++++++++++++------------------------ modmesh/onedim/euler1d.py | 12 ++++-------- tests/test_onedim_euler.py | 4 ++-- 3 files changed, 19 insertions(+), 34 deletions(-) diff --git a/modmesh/app/euler1d.py b/modmesh/app/euler1d.py index a798373e..3cc65b26 100644 --- a/modmesh/app/euler1d.py +++ b/modmesh/app/euler1d.py @@ -744,30 +744,19 @@ def update_lines(self): """ if self.use_grid_layout: _s = self.st.svr.xindices - self.density.update( - adata=self.st.density_field, - ndata=self.st.svr.density[_s] - ) - self.pressure.update( - adata=self.st.pressure_field, - ndata=self.st.svr.pressure[_s] - ) - self.velocity.update( - adata=self.st.velocity_field, - ndata=self.st.svr.velocity[_s] - ) - self.temperature.update( - adata=self.st.temperature_field, - ndata=self.st.svr.temperature[_s] - ) - self.internal_energy.update( - adata=(self.st.internal_energy_field), - ndata=(self.st.svr.internal_energy[_s]) - ) - self.entropy.update( - adata=self.st.entropy_field, - ndata=self.st.svr.entropy[_s] - ) + self.density.update(adata=self.st.density_field, + ndata=self.st.svr.density[_s]) + self.pressure.update(adata=self.st.pressure_field, + ndata=self.st.svr.pressure[_s]) + self.velocity.update(adata=self.st.velocity_field, + ndata=self.st.svr.velocity[_s]) + self.temperature.update(adata=self.st.temperature_field, + ndata=self.st.svr.temperature[_s]) + self.internal_energy.update(adata=(self.st.internal_energy_field), + ndata=(self.st.svr. + internal_energy[_s])) + self.entropy.update(adata=self.st.entropy_field, + ndata=self.st.svr.entropy[_s]) else: for name, is_selected, *_ in self.plot_config.state: if is_selected: diff --git a/modmesh/onedim/euler1d.py b/modmesh/onedim/euler1d.py index e23617a5..201deaf4 100644 --- a/modmesh/onedim/euler1d.py +++ b/modmesh/onedim/euler1d.py @@ -122,7 +122,7 @@ def __init__(self): self.svr = None def build_numerical(self, xmin, xmax, ncoord, time_increment=0.05, - xdiaphragm=0.0): + xdiaphragm=0.0, keep_edge=False): """ After :py:meth:`build_constant` is done, optionally build the numerical solver :py:attr:`svr`. @@ -139,7 +139,8 @@ def build_numerical(self, xmin, xmax, ncoord, time_increment=0.05, # Initialize the numerical solver. self.svr = Euler1DSolver(xmin, xmax, ncoord, - time_increment=time_increment) + time_increment=time_increment, + keep_edge=keep_edge) # Fill gamma. self.svr.gamma.fill(self.gamma) @@ -308,7 +309,7 @@ def calc_internal_energy(self, pressure, density): def calc_entropy(self, pressure, density): return pressure / (density ** self.gamma) - def build_field(self, t, coord=None, keep_edge=False): + def build_field(self, t, coord=None): """ Populate the field data using the analytical solution. @@ -317,11 +318,6 @@ def build_field(self, t, coord=None, keep_edge=False): :return: None """ if coord is None: - _ = self.svr.ncoord - 1 - start = 0 if keep_edge else 2 - stop = _ if keep_edge else (_ - 2) - num = (stop - start) // 2 + 1 - self.svr.xindices = np.linspace(start, stop, num, dtype='int32') # set the x-coordinate for numerical solver. coord = self.svr.coord[self.svr.xindices] self.coord = coord.copy() # Make a copy; no write back to argument. diff --git a/tests/test_onedim_euler.py b/tests/test_onedim_euler.py index 98bb7fed..312598eb 100644 --- a/tests/test_onedim_euler.py +++ b/tests/test_onedim_euler.py @@ -104,8 +104,8 @@ def test_field_without_numerical(self): def test_field_with_numerical(self): self.st.build_numerical(xmin=-1, xmax=1, ncoord=21, - time_increment=0.05) - self.st.build_field(t=0.0, keep_edge=True) + time_increment=0.05, keep_edge=True) + self.st.build_field(t=0.0) self.assertIsInstance(self.st.svr, euler1d.Euler1DSolver) self.assertEqual(len(self.st.coord), 11) self._check_field_value_at_t0()