Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4932,6 +4932,13 @@ def plot3D(
scale_factor: float, camera zoom factor
azimuth: float, azimuthal angle in degrees
elevation: float, elevation angle in degrees
eps_parameters: Parameters to plot epsilon:
frequency: for materials with a [frequency-dependent
permittivity](Materials.md#material-dispersion) $\\varepsilon(f)$, specifies the
frequency $f$ (in Meep units) of the real part of the permittivity to use in the
plot. Defaults to 0.
resolution: the resolution of the $\\varepsilon$ grid. Defaults to the
Comment thread
stevengj marked this conversation as resolved.
Outdated
`resolution` of the `Simulation` object.
"""
import meep.visualization as vis

Expand Down
18 changes: 13 additions & 5 deletions python/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ def plot2D(
CELL_EDGE_COLOR_3D: tuple[float, float, float, float] = (0.75, 0.75, 0.75, 1) # gray


def plot3D(sim, save_to_image: bool = False, image_name: str = "sim.png", **kwargs):
def plot3D(sim: mp.Simulation, save_to_image: bool = False, image_name: str = "sim.png", **kwargs):
from vispy.scene.visuals import Box, Mesh
from vispy.scene import SceneCanvas, transforms

Expand All @@ -1112,7 +1112,14 @@ def plot3D(sim, save_to_image: bool = False, image_name: str = "sim.png", **kwar
sim_center, sim_size, sim.is_cylindrical
)

grid_resolution = sim.resolution
# Get eps parameters or use default
eps_parameters = kwargs.get("eps_parameters")
if eps_parameters:
grid_resolution = eps_parameters.get("resolution", sim.resolution)
frequency = eps_parameters.get("frequency", 0)
else:
grid_resolution = sim.resolution
frequency = 0

Nx = int((xmax - xmin) * grid_resolution + 1)
Ny = int((ymax - ymin) * grid_resolution + 1)
Expand All @@ -1123,12 +1130,13 @@ def plot3D(sim, save_to_image: bool = False, image_name: str = "sim.png", **kwar
ztics = np.linspace(zmin, zmax, Nz)

# Get eps for geometry
eps_data = np.round(np.real(sim.get_epsilon_grid(xtics, ytics, ztics)), 2)

unique = np.unique(np.abs(eps_data)).tolist()
eps_data = np.round(np.real(sim.get_epsilon_grid(xtics, ytics, ztics, frequency)), 2)

unique = np.unique((eps_data)).tolist()
Comment thread
drinwater marked this conversation as resolved.
Outdated

# Remove background material
unique.remove(np.round(np.abs(np.asarray(sim.default_material.epsilon_diag)), 2)[0])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@smartalecH, do you remember why round was being used here?

unique.remove(np.round((np.asarray(sim.default_material.epsilon_diag)), 2)[0])
Comment thread
stevengj marked this conversation as resolved.
Outdated

mesh_midpoint = (sim_size[0] / 2, sim_size[1] / 2, sim_size[2] / 2)

Expand Down
Loading