Skip to content

Commit bf9976e

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

3 files changed

Lines changed: 20 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: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ 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, keep_edge=False):
2828
self._core = self.init_solver(xmin, xmax, ncoord, time_increment,
2929
gamma=1.4)
3030
# gamma is 1.4 for air.
31+
_ = self.ncoord - 1
32+
start = 0 if keep_edge else 2
33+
stop = _ if keep_edge else (_ - 2)
34+
num = (stop - start) // 2 + 1
35+
self.xindices = np.linspace(start, stop, num, dtype='int32')
3136

3237
def __getattr__(self, name):
3338
return getattr(self._core, name)
@@ -310,18 +315,13 @@ def build_field(self, t, coord=None, keep_edge=False):
310315
:param coord: If None, take the coordinate from the numerical solver.
311316
:return: None
312317
"""
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.
318+
if coord is None:
319+
_ = self.svr.ncoord - 1
320+
start = 0 if keep_edge else 2
321+
stop = _ if keep_edge else (_ - 2)
322+
num = (stop - start) // 2 + 1
323+
self.svr.xindices = np.linspace(start, stop, num, dtype='int32')
324+
# set the x-coordinate for numerical solver.
325325
coord = self.svr.coord[self.svr.xindices]
326326
self.coord = coord.copy() # Make a copy; no write back to argument.
327327

startup.py

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

0 commit comments

Comments
 (0)