Skip to content

Commit

Permalink
init xindices in Euler1DSolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Gene Lin authored and Gene Lin committed Sep 25, 2024
1 parent ff4fac0 commit bf9976e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
13 changes: 7 additions & 6 deletions modmesh/app/euler1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,29 +743,30 @@ def update_lines(self):
:return: None
"""
if self.use_grid_layout:
_s = self.st.svr.xindices
self.density.update(
adata=self.st.density_field,
ndata=self.st.svr.density[self.st.svr.xindices]
ndata=self.st.svr.density[_s]
)
self.pressure.update(
adata=self.st.pressure_field,
ndata=self.st.svr.pressure[self.st.svr.xindices]
ndata=self.st.svr.pressure[_s]
)
self.velocity.update(
adata=self.st.velocity_field,
ndata=self.st.svr.velocity[self.st.svr.xindices]
ndata=self.st.svr.velocity[_s]
)
self.temperature.update(
adata=self.st.temperature_field,
ndata=self.st.svr.temperature[self.st.svr.xindices]
ndata=self.st.svr.temperature[_s]
)
self.internal_energy.update(
adata=(self.st.internal_energy_field),
ndata=(self.st.svr.internal_energy[self.st.svr.xindices])
ndata=(self.st.svr.internal_energy[_s])
)
self.entropy.update(
adata=self.st.entropy_field,
ndata=self.st.svr.entropy[self.st.svr.xindices]
ndata=self.st.svr.entropy[_s]
)
else:
for name, is_selected, *_ in self.plot_config.state:
Expand Down
26 changes: 13 additions & 13 deletions modmesh/onedim/euler1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ class Euler1DSolver:
method.
"""

def __init__(self, xmin, xmax, ncoord, time_increment=0.05):
def __init__(self, xmin, xmax, ncoord, time_increment=0.05, keep_edge=False):
self._core = self.init_solver(xmin, xmax, ncoord, time_increment,
gamma=1.4)
# gamma is 1.4 for air.
_ = self.ncoord - 1
start = 0 if keep_edge else 2
stop = _ if keep_edge else (_ - 2)
num = (stop - start) // 2 + 1
self.xindices = np.linspace(start, stop, num, dtype='int32')

def __getattr__(self, name):
return getattr(self._core, name)
Expand Down Expand Up @@ -310,18 +315,13 @@ def build_field(self, t, coord=None, keep_edge=False):
:param coord: If None, take the coordinate from the numerical solver.
:return: None
"""

if None is coord:
_ = self.svr.ncoord
if keep_edge:
self.svr.xindices = np.linspace(
0, (_ - 1), num=((_ + 1) // 2), dtype=int
)
else:
self.svr.xindices = np.linspace(
2, (_ - 3), num=((_ - 3) // 2), dtype=int
)
# Use the numerical solver.
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
3 changes: 0 additions & 3 deletions startup.py

This file was deleted.

0 comments on commit bf9976e

Please sign in to comment.