Skip to content

Commit

Permalink
refactor xindices
Browse files Browse the repository at this point in the history
  • Loading branch information
Gene Lin authored and Gene Lin committed Oct 5, 2024
1 parent e2de8d0 commit 0936eb9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
37 changes: 13 additions & 24 deletions modmesh/app/euler1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 4 additions & 8 deletions modmesh/onedim/euler1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_onedim_euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0936eb9

Please sign in to comment.