Skip to content

Commit 11b59e7

Browse files
dbochkov-flexcomputemomchil-flex
authored andcommitted
PR comments
1 parent 76a4ac1 commit 11b59e7

File tree

4 files changed

+250
-67
lines changed

4 files changed

+250
-67
lines changed

tests/test_components/test_scene.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
def test_scene_init():
1717
"""make sure a scene can be initialized"""
1818

19-
sim = td.Scene(
19+
scene = td.Scene(
2020
structures=[
2121
td.Structure(
2222
geometry=td.Box(size=(1, 1, 1), center=(-1, 0, 0)),
@@ -37,9 +37,9 @@ def test_scene_init():
3737
medium=td.Medium(permittivity=3.0),
3838
)
3939

40-
_ = sim.mediums
41-
_ = sim.medium_map
42-
_ = sim.background_structure
40+
_ = scene.mediums
41+
_ = scene.medium_map
42+
_ = scene.background_structure
4343

4444

4545
def test_validate_components_none():

tests/test_components/test_simulation.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,15 @@ def test_sim_init():
7979
_ = sim.dt
8080
_ = sim.tmesh
8181
sim.validate_pre_upload()
82+
m = sim.get_monitor_by_name("point")
83+
# will not work in 3.0
8284
_ = sim.mediums
8385
_ = sim.medium_map
84-
m = sim.get_monitor_by_name("point")
8586
_ = sim.background_structure
87+
# will continue working in 3.0
88+
_ = sim.scene.mediums
89+
_ = sim.scene.medium_map
90+
_ = sim.scene.background_structure
8691
# sim.plot(x=0)
8792
# plt.close()
8893
# sim.plot_eps(x=0)
@@ -915,11 +920,18 @@ def test_sim_monitor_homogeneous():
915920
boundary_spec=td.BoundarySpec.all_sides(boundary=td.Periodic()),
916921
)
917922

923+
# will be removed in 3.0
918924
mediums = td.Simulation.intersecting_media(monitor_n2f_vol, [box])
919925
assert len(mediums) == 1
920926
mediums = td.Simulation.intersecting_media(monitor_n2f_vol, [box_transparent])
921927
assert len(mediums) == 1
922928

929+
# continue in 3.0
930+
mediums = td.Scene.intersecting_media(monitor_n2f_vol, [box])
931+
assert len(mediums) == 1
932+
mediums = td.Scene.intersecting_media(monitor_n2f_vol, [box_transparent])
933+
assert len(mediums) == 1
934+
923935
# when another medium intersects an excluded surface, no errors should be raised
924936
monitor_n2f_vol_exclude = td.FieldProjectionAngleMonitor(
925937
center=(0.2, 0, 0.2),

tidy3d/components/base_sim/simulation.py

Lines changed: 173 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def simulation_geometry(self) -> Box:
165165
@cached_property
166166
def simulation_structure(self) -> Structure:
167167
"""Returns structure representing the domain of the simulation. This differs from
168-
``Simulation.background_structure`` in that it has finite extent."""
168+
``Simulation.scene.background_structure`` in that it has finite extent."""
169169
return Structure(geometry=self.simulation_geometry, medium=self.medium)
170170

171171
@equal_aspect
@@ -416,6 +416,178 @@ def plot_boundaries(
416416
The supplied or created matplotlib axes.
417417
"""
418418

419+
@equal_aspect
420+
@add_ax_if_none
421+
def plot_structures(
422+
self,
423+
x: float = None,
424+
y: float = None,
425+
z: float = None,
426+
ax: Ax = None,
427+
hlim: Tuple[float, float] = None,
428+
vlim: Tuple[float, float] = None,
429+
) -> Ax:
430+
"""Plot each of simulation's structures on a plane defined by one nonzero x,y,z coordinate.
431+
432+
Parameters
433+
----------
434+
x : float = None
435+
position of plane in x direction, only one of x, y, z must be specified to define plane.
436+
y : float = None
437+
position of plane in y direction, only one of x, y, z must be specified to define plane.
438+
z : float = None
439+
position of plane in z direction, only one of x, y, z must be specified to define plane.
440+
ax : matplotlib.axes._subplots.Axes = None
441+
Matplotlib axes to plot on, if not specified, one is created.
442+
hlim : Tuple[float, float] = None
443+
The x range if plotting on xy or xz planes, y range if plotting on yz plane.
444+
vlim : Tuple[float, float] = None
445+
The z range if plotting on xz or yz planes, y plane if plotting on xy plane.
446+
447+
Returns
448+
-------
449+
matplotlib.axes._subplots.Axes
450+
The supplied or created matplotlib axes.
451+
"""
452+
453+
hlim_new, vlim_new = Scene._get_plot_lims(
454+
bounds=self.simulation_bounds, x=x, y=y, z=z, hlim=hlim, vlim=vlim
455+
)
456+
457+
return self.scene.plot_structures(x=x, y=y, z=z, ax=ax, hlim=hlim_new, vlim=vlim_new)
458+
459+
@equal_aspect
460+
@add_ax_if_none
461+
def plot_structures_eps(
462+
self,
463+
x: float = None,
464+
y: float = None,
465+
z: float = None,
466+
freq: float = None,
467+
alpha: float = None,
468+
cbar: bool = True,
469+
reverse: bool = False,
470+
ax: Ax = None,
471+
hlim: Tuple[float, float] = None,
472+
vlim: Tuple[float, float] = None,
473+
) -> Ax:
474+
"""Plot each of simulation's structures on a plane defined by one nonzero x,y,z coordinate.
475+
The permittivity is plotted in grayscale based on its value at the specified frequency.
476+
477+
Parameters
478+
----------
479+
x : float = None
480+
position of plane in x direction, only one of x, y, z must be specified to define plane.
481+
y : float = None
482+
position of plane in y direction, only one of x, y, z must be specified to define plane.
483+
z : float = None
484+
position of plane in z direction, only one of x, y, z must be specified to define plane.
485+
freq : float = None
486+
Frequency to evaluate the relative permittivity of all mediums.
487+
If not specified, evaluates at infinite frequency.
488+
reverse : bool = False
489+
If ``False``, the highest permittivity is plotted in black.
490+
If ``True``, it is plotteed in white (suitable for black backgrounds).
491+
cbar : bool = True
492+
Whether to plot a colorbar for the relative permittivity.
493+
alpha : float = None
494+
Opacity of the structures being plotted.
495+
Defaults to the structure default alpha.
496+
ax : matplotlib.axes._subplots.Axes = None
497+
Matplotlib axes to plot on, if not specified, one is created.
498+
hlim : Tuple[float, float] = None
499+
The x range if plotting on xy or xz planes, y range if plotting on yz plane.
500+
vlim : Tuple[float, float] = None
501+
The z range if plotting on xz or yz planes, y plane if plotting on xy plane.
502+
503+
Returns
504+
-------
505+
matplotlib.axes._subplots.Axes
506+
The supplied or created matplotlib axes.
507+
"""
508+
509+
hlim, vlim = Scene._get_plot_lims(
510+
bounds=self.simulation_bounds, x=x, y=y, z=z, hlim=hlim, vlim=vlim
511+
)
512+
513+
return self.scene.plot_structures_eps(
514+
freq=freq,
515+
cbar=cbar,
516+
alpha=alpha,
517+
ax=ax,
518+
x=x,
519+
y=y,
520+
z=z,
521+
hlim=hlim,
522+
vlim=vlim,
523+
reverse=reverse,
524+
)
525+
526+
@equal_aspect
527+
@add_ax_if_none
528+
def plot_structures_heat_conductivity(
529+
self,
530+
x: float = None,
531+
y: float = None,
532+
z: float = None,
533+
alpha: float = None,
534+
cbar: bool = True,
535+
reverse: bool = False,
536+
ax: Ax = None,
537+
hlim: Tuple[float, float] = None,
538+
vlim: Tuple[float, float] = None,
539+
) -> Ax:
540+
"""Plot each of simulation's structures on a plane defined by one nonzero x,y,z coordinate.
541+
The permittivity is plotted in grayscale based on its value at the specified frequency.
542+
543+
Parameters
544+
----------
545+
x : float = None
546+
position of plane in x direction, only one of x, y, z must be specified to define plane.
547+
y : float = None
548+
position of plane in y direction, only one of x, y, z must be specified to define plane.
549+
z : float = None
550+
position of plane in z direction, only one of x, y, z must be specified to define plane.
551+
freq : float = None
552+
Frequency to evaluate the relative permittivity of all mediums.
553+
If not specified, evaluates at infinite frequency.
554+
reverse : bool = False
555+
If ``False``, the highest permittivity is plotted in black.
556+
If ``True``, it is plotteed in white (suitable for black backgrounds).
557+
cbar : bool = True
558+
Whether to plot a colorbar for the relative permittivity.
559+
alpha : float = None
560+
Opacity of the structures being plotted.
561+
Defaults to the structure default alpha.
562+
ax : matplotlib.axes._subplots.Axes = None
563+
Matplotlib axes to plot on, if not specified, one is created.
564+
hlim : Tuple[float, float] = None
565+
The x range if plotting on xy or xz planes, y range if plotting on yz plane.
566+
vlim : Tuple[float, float] = None
567+
The z range if plotting on xz or yz planes, y plane if plotting on xy plane.
568+
569+
Returns
570+
-------
571+
matplotlib.axes._subplots.Axes
572+
The supplied or created matplotlib axes.
573+
"""
574+
575+
hlim, vlim = Scene._get_plot_lims(
576+
bounds=self.simulation_bounds, x=x, y=y, z=z, hlim=hlim, vlim=vlim
577+
)
578+
579+
return self.scene.plot_structures_heat_conductivity(
580+
cbar=cbar,
581+
alpha=alpha,
582+
ax=ax,
583+
x=x,
584+
y=y,
585+
z=z,
586+
hlim=hlim,
587+
vlim=vlim,
588+
reverse=reverse,
589+
)
590+
419591
@classmethod
420592
def from_scene(cls, scene: Scene, **kwargs) -> AbstractSimulation:
421593
"""Create a simulation from a :class:.`Scene` instance. Must provide additional parameters

0 commit comments

Comments
 (0)