Skip to content

Commit e2de8d0

Browse files
Gene LinGene Lin
authored andcommitted
init xindices in Euler1DSolver
1 parent ff4fac0 commit e2de8d0

3 files changed

Lines changed: 21 additions & 22 deletions

File tree

modmesh/app/euler1d.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -743,29 +743,30 @@ def update_lines(self):
743743
:return: None
744744
"""
745745
if self.use_grid_layout:
746+
_s = self.st.svr.xindices
746747
self.density.update(
747748
adata=self.st.density_field,
748-
ndata=self.st.svr.density[self.st.svr.xindices]
749+
ndata=self.st.svr.density[_s]
749750
)
750751
self.pressure.update(
751752
adata=self.st.pressure_field,
752-
ndata=self.st.svr.pressure[self.st.svr.xindices]
753+
ndata=self.st.svr.pressure[_s]
753754
)
754755
self.velocity.update(
755756
adata=self.st.velocity_field,
756-
ndata=self.st.svr.velocity[self.st.svr.xindices]
757+
ndata=self.st.svr.velocity[_s]
757758
)
758759
self.temperature.update(
759760
adata=self.st.temperature_field,
760-
ndata=self.st.svr.temperature[self.st.svr.xindices]
761+
ndata=self.st.svr.temperature[_s]
761762
)
762763
self.internal_energy.update(
763764
adata=(self.st.internal_energy_field),
764-
ndata=(self.st.svr.internal_energy[self.st.svr.xindices])
765+
ndata=(self.st.svr.internal_energy[_s])
765766
)
766767
self.entropy.update(
767768
adata=self.st.entropy_field,
768-
ndata=self.st.svr.entropy[self.st.svr.xindices]
769+
ndata=self.st.svr.entropy[_s]
769770
)
770771
else:
771772
for name, is_selected, *_ in self.plot_config.state:

modmesh/onedim/euler1d.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ class Euler1DSolver:
2424
method.
2525
"""
2626

27-
def __init__(self, xmin, xmax, ncoord, time_increment=0.05):
27+
def __init__(self, xmin, xmax, ncoord, time_increment=0.05,
28+
keep_edge=False):
2829
self._core = self.init_solver(xmin, xmax, ncoord, time_increment,
2930
gamma=1.4)
3031
# gamma is 1.4 for air.
32+
_ = self.ncoord - 1
33+
start = 0 if keep_edge else 2
34+
stop = _ if keep_edge else (_ - 2)
35+
num = (stop - start) // 2 + 1
36+
self.xindices = np.linspace(start, stop, num, dtype='int32')
3137

3238
def __getattr__(self, name):
3339
return getattr(self._core, name)
@@ -310,18 +316,13 @@ def build_field(self, t, coord=None, keep_edge=False):
310316
:param coord: If None, take the coordinate from the numerical solver.
311317
:return: None
312318
"""
313-
314-
if None is coord:
315-
_ = self.svr.ncoord
316-
if keep_edge:
317-
self.svr.xindices = np.linspace(
318-
0, (_ - 1), num=((_ + 1) // 2), dtype=int
319-
)
320-
else:
321-
self.svr.xindices = np.linspace(
322-
2, (_ - 3), num=((_ - 3) // 2), dtype=int
323-
)
324-
# Use the numerical solver.
319+
if coord is None:
320+
_ = self.svr.ncoord - 1
321+
start = 0 if keep_edge else 2
322+
stop = _ if keep_edge else (_ - 2)
323+
num = (stop - start) // 2 + 1
324+
self.svr.xindices = np.linspace(start, stop, num, dtype='int32')
325+
# set the x-coordinate for numerical solver.
325326
coord = self.svr.coord[self.svr.xindices]
326327
self.coord = coord.copy() # Make a copy; no write back to argument.
327328

startup.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)