Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to create variables in euler1d.py #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/modmesh/onedim/Euler1DCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void Euler1DCore::initialize_data(size_t ncoord)
{
throw std::invalid_argument("ncoord cannot be even");
}
m_pt_plot = SimpleArray<int>(/*length*/ ((ncoord - 3) / 2));
m_coord = SimpleArray<double>(/*length*/ ncoord);
m_cfl = SimpleArray<double>(/*length*/ ncoord);
m_so0 = SimpleArray<double>(/*shape*/ small_vector<size_t>{ncoord, NVAR});
Expand Down
4 changes: 4 additions & 0 deletions cpp/modmesh/onedim/Euler1DCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class Euler1DCore

double time_increment() const { return m_time_increment; }

SimpleArray<int> const & pt_plot() const { return m_pt_plot; }
SimpleArray<int> & pt_plot() { return m_pt_plot; }

size_t ncoord() const { return m_coord.size(); }
SimpleArray<double> const & coord() const { return m_coord; }
SimpleArray<double> & coord() { return m_coord; }
Expand Down Expand Up @@ -139,6 +142,7 @@ class Euler1DCore
private:

real_type m_time_increment = 0;
SimpleArray<int> m_pt_plot;
SimpleArray<double> m_coord;
SimpleArray<double> m_cfl;
SimpleArray<double> m_so0;
Expand Down
4 changes: 4 additions & 0 deletions cpp/modmesh/onedim/pymod/wrap_onedim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapEuler1DCore
{ return to_ndarray(self.gamma()); });

(*this)
.def_property_readonly(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An inline annotation can be added like this.

"pt_plot",
[](wrapped_type & self)
{ return to_ndarray(self.pt_plot()); })
.def_property_readonly(
"coord",
[](wrapped_type & self)
Expand Down
18 changes: 9 additions & 9 deletions modmesh/app/euler1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion modmesh/onedim/euler1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions startup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import modmesh.view as mv
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not necessary to use a file to run code like this. A one-liner python3 -c 'import modmesh.view as v ; v.launch()' would do it.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I'm not sure which file is appropriate to add this code. Is there anything wrong to add the startup.py in modmesh?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need to add the code in a file. That is a one-liner you type in command line.


mv.launch()
Loading