Skip to content

Add plot1D function for visualizing layout of 1D simulation - #3271

Open
oskooi wants to merge 2 commits into
NanoComp:masterfrom
oskooi:plot1D
Open

Add plot1D function for visualizing layout of 1D simulation#3271
oskooi wants to merge 2 commits into
NanoComp:masterfrom
oskooi:plot1D

Conversation

@oskooi

@oskooi oskooi commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Adds a plot1D function for visualizing the layout of 1D simulation. This mirrors the existing plot2D.

PEC detection. A wall is PEC when the cell boundary is metallic — i.e. no k_point was given (Meep's default) or set_boundary(..., mp.Metallic) was called. Since fields.boundaries is only exposed to Python as an opaque SWIG pointer, Simulation.set_boundary now records what it set in self._boundary_conditions (cleared by reset_meep), which plot1D consults. This makes the tutorial setup in antenna_pec_ground_plane_1D.py (Bloch k_point + explicit metallic walls) plot correctly.

Everything is customizable through the same *_parameters dict / show_* flag convention as plot2D (index_parameters, pml_parameters, pec_parameters, source_parameters, monitor_parameters, legend_parameters), and the dispersive-permittivity frequency defaults to the first source's frequency (that lookup is now the shared get_default_frequency helper, also used by plot_eps).

An example of the output (involving a dielectric slab above a PEC ground plane) produced by plot1D is shown below.

layout_1D_plot1D

Files changed

  • python/visualization.pyplot1D and its plot_1d_* helpers, 1D default-parameter dicts
  • python/simulation.pySimulation.plot1D with full docstring; boundary-condition tracking
  • python/meep.i — export plot1D from the package
  • python/tests/test_visualization.pytest_plot1D covering legend contents, artist counts, PEC vs. Bloch-periodic, Absorber, set_boundary override, customization, and the non-1D ValueError
  • doc/docs/Python_User_Interface.md{, .in} — API docs (inserted exactly the block generate_py_api.py emits)

Verification

  • python/tests/test_visualization.py: 3 tests pass, serially and under mpirun -np 2
  • Checked against variants: PML both/one side, Absorber, Bloch-periodic, explicit metallic wall, extended sources, dispersive material (Si reads 3.478 at 1.55 μm), nonzero geometry_center, dimensions=1 and unset-dimensions 1D cells

@stevengj

stevengj commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Rather than add a Python mirror of the boundary information, I'd rather just add a method to fields:: that exposes this information, e.g. a fields::get_boundary function (mirroring fields::set_boundary) or something like that.

@oskooi

oskooi commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator Author

Rather than add a Python mirror of the boundary information, I'd rather just add a method to fields:: that exposes this information, e.g. a fields::get_boundary function (mirroring fields::set_boundary) or something like that.

The Python Simulation._boundary_condition object is removed. The boundary condition is now read from C++ using a newly added fields::get_boundary.

Two things worth flagging:

  1. Fixed a deadlock. get_boundary can call init_sim(), which is collective. The original plot_1d_pec had an early if not mp.am_master(): return ax before the query, so under mpirun -np 2 only rank 0 entered init_sim and the run hung. The query now happens on all ranks before the master-only drawing, with a comment saying why.
  2. The plot got more accurate. Querying C++ revealed that the original Python mirror was wrong for the case of set_boundary(mp.Low, mp.Z, mp.Metallic) on a Bloch-periodic cell which makes both walls metallic, because fields::set_boundary forces the opposite side to match when it was Periodic. The old code drew PEC only on the low side. The updated schematic below confirms this behavior.
layout_1D_plot1D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants