From c98054b6d66ec7708ff10a1de4080fe434f3c53e Mon Sep 17 00:00:00 2001 From: Gene Lin Date: Sun, 30 Jun 2024 23:04:55 +0800 Subject: [PATCH 1/3] vars_problem --- cpp/modmesh/onedim/Euler1DCore.cpp | 1 + cpp/modmesh/onedim/Euler1DCore.hpp | 4 ++++ modmesh/app/euler1d.py | 18 +++++++++--------- modmesh/onedim/euler1d.py | 3 ++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cpp/modmesh/onedim/Euler1DCore.cpp b/cpp/modmesh/onedim/Euler1DCore.cpp index 8065d791f..be0b7d938 100644 --- a/cpp/modmesh/onedim/Euler1DCore.cpp +++ b/cpp/modmesh/onedim/Euler1DCore.cpp @@ -49,6 +49,7 @@ void Euler1DCore::initialize_data(size_t ncoord) { throw std::invalid_argument("ncoord cannot be even"); } + m_pt_plot = SimpleArray(/*length*/ ((ncoord - 3) / 2)); m_coord = SimpleArray(/*length*/ ncoord); m_cfl = SimpleArray(/*length*/ ncoord); m_so0 = SimpleArray(/*shape*/ small_vector{ncoord, NVAR}); diff --git a/cpp/modmesh/onedim/Euler1DCore.hpp b/cpp/modmesh/onedim/Euler1DCore.hpp index 6b419559a..3b8faccf8 100644 --- a/cpp/modmesh/onedim/Euler1DCore.hpp +++ b/cpp/modmesh/onedim/Euler1DCore.hpp @@ -92,6 +92,9 @@ class Euler1DCore double time_increment() const { return m_time_increment; } + SimpleArray const & pt_plot() const { return m_pt_plot; } + SimpleArray & pt_plot() { return m_pt_plot; } + size_t ncoord() const { return m_coord.size(); } SimpleArray const & coord() const { return m_coord; } SimpleArray & coord() { return m_coord; } @@ -139,6 +142,7 @@ class Euler1DCore private: real_type m_time_increment = 0; + SimpleArray m_pt_plot; SimpleArray m_coord; SimpleArray m_cfl; SimpleArray m_so0; diff --git a/modmesh/app/euler1d.py b/modmesh/app/euler1d.py index f1f79598e..3c829c0cb 100644 --- a/modmesh/app/euler1d.py +++ b/modmesh/app/euler1d.py @@ -530,7 +530,7 @@ def build_grid_figure(self): :return: FigureCanvas """ - x = self.st.svr.coord[::2] + x = self.st.svr.coord[self.st.svr.pt_plot] fig = Figure() canvas = FigureCanvas(fig) ax = canvas.figure.subplots(3, 2) @@ -574,7 +574,7 @@ def build_single_figure(self): :return: FigureCanvas """ - x = self.st.svr.coord[::2] + x = self.st.svr.coord[self.st.svr.pt_plot] fig = Figure() canvas = FigureCanvas(fig) ax = canvas.figure.subplots() @@ -744,23 +744,23 @@ def update_lines(self): """ if self.use_grid_layout: self.density.update(adata=self.st.density_field, - ndata=self.st.svr.density[::2]) + ndata=self.st.svr.density[self.st.svr.pt_plot]) self.pressure.update(adata=self.st.pressure_field, - ndata=self.st.svr.pressure[::2]) + ndata=self.st.svr.pressure[self.st.svr.pt_plot]) self.velocity.update(adata=self.st.velocity_field, - ndata=self.st.svr.velocity[::2]) + ndata=self.st.svr.velocity[self.st.svr.pt_plot]) self.temperature.update(adata=self.st.temperature_field, - ndata=self.st.svr.temperature[::2]) + ndata=self.st.svr.temperature[self.st.svr.pt_plot]) self.internal_energy.update(adata=(self.st.internal_energy_field), ndata=(self.st.svr. - internal_energy[::2])) + internal_energy[self.st.svr.pt_plot])) self.entropy.update(adata=self.st.entropy_field, - ndata=self.st.svr.entropy[::2]) + ndata=self.st.svr.entropy[self.st.svr.pt_plot]) else: for name, is_selected, *_ in self.plot_config.state: if is_selected: eval(f'(self.{name}.update(adata=self.st.{name}_field,' - f' ndata=self.st.svr.{name}[::2]))') + f' ndata=self.st.svr.{name}[self.st.svr.pt_plot]))') class PlotArea(PuiInQt): diff --git a/modmesh/onedim/euler1d.py b/modmesh/onedim/euler1d.py index 90297d8a8..9262387e3 100644 --- a/modmesh/onedim/euler1d.py +++ b/modmesh/onedim/euler1d.py @@ -38,6 +38,7 @@ def init_solver(xmin, xmax, ncoord, time_increment, gamma): svr = _impl.Euler1DCore(ncoord=ncoord, time_increment=time_increment) # Initialize spatial grid. + svr.pt_plot[...] = np.linspace(2, (ncoord - 3), num=((ncoord - 3) // 2), dtype=int) svr.coord[...] = np.linspace(xmin, xmax, num=ncoord) # Initialize field. @@ -311,7 +312,7 @@ def build_field(self, t, coord=None): :return: None """ if None is coord: - coord = self.svr.coord[::2] # Use the numerical solver. + coord = self.svr.coord[self.svr.pt_plot] # Use the numerical solver. self.coord = coord.copy() # Make a copy; no write back to argument. # Determine the zone location and the Boolean selection arrays. From 7c918dff232dac29282d35dd909a943b9f86b4e2 Mon Sep 17 00:00:00 2001 From: Gene Lin Date: Tue, 2 Jul 2024 16:59:24 +0800 Subject: [PATCH 2/3] add_startup.py --- startup.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 startup.py diff --git a/startup.py b/startup.py new file mode 100644 index 000000000..d5f49ed7b --- /dev/null +++ b/startup.py @@ -0,0 +1,3 @@ +import modmesh.view as mv + +mv.launch() \ No newline at end of file From ea93b68d7bf501a8c8c7178a69ae3c2ba67fb803 Mon Sep 17 00:00:00 2001 From: Gene Lin Date: Sat, 6 Jul 2024 14:13:45 +0800 Subject: [PATCH 3/3] add pt_plot to wrap_onedim --- cpp/modmesh/onedim/pymod/wrap_onedim.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cpp/modmesh/onedim/pymod/wrap_onedim.cpp b/cpp/modmesh/onedim/pymod/wrap_onedim.cpp index 30d493bc7..ec1786ef8 100644 --- a/cpp/modmesh/onedim/pymod/wrap_onedim.cpp +++ b/cpp/modmesh/onedim/pymod/wrap_onedim.cpp @@ -109,6 +109,10 @@ class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapEuler1DCore { return to_ndarray(self.gamma()); }); (*this) + .def_property_readonly( + "pt_plot", + [](wrapped_type & self) + { return to_ndarray(self.pt_plot()); }) .def_property_readonly( "coord", [](wrapped_type & self)