Skip to content

Commit bef8d70

Browse files
committed
ikugh
1 parent 6d9a618 commit bef8d70

File tree

3 files changed

+29
-57
lines changed

3 files changed

+29
-57
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
### Added
11-
- Added `HeatChargeSimulation.plot()` method that provides a unified plotting interface. When `property` is `None`, it plots the scene structures using the parent class's plot method. When `property` is specified (e.g., `"heat_conductivity"`, `"electric_conductivity"`, `"source"`), it delegates to `plot_property()`. For CHARGE simulations, electric boundary conditions are automatically added to the plot.
1211

1312
### Changed
13+
- For `HeatChargeSimulation` objects, the `plot` function now adds the simulation boundary conditions.
1414

1515
### Fixed
1616

tests/test_components/test_heat_charge.py

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,7 @@ def test_heat_only_simulation_with_semiconductor():
26002600

26012601

26022602
def test_heat_charge_simulation_plot():
2603-
"""Test the HeatChargeSimulation.plot() method with different property values."""
2603+
"""Test the HeatChargeSimulation.plot() method adds BCs based on simulation type."""
26042604

26052605
# Create mediums
26062606
solid_medium = td.MultiPhysicsMedium(
@@ -2635,7 +2635,7 @@ def test_heat_charge_simulation_plot():
26352635
name="temp_mnt",
26362636
)
26372637

2638-
# Create a heat simulation
2638+
# Create a HEAT simulation
26392639
heat_sim = td.HeatChargeSimulation(
26402640
medium=fluid_medium,
26412641
structures=[solid_structure],
@@ -2647,33 +2647,25 @@ def test_heat_charge_simulation_plot():
26472647
monitors=[temp_monitor],
26482648
)
26492649

2650-
# Test plot with property=None (should use parent's plot)
2651-
_, ax = plt.subplots()
2652-
heat_sim.plot(z=0, ax=ax)
2653-
plt.close()
2654-
2655-
# Test that plot(property="heat_conductivity") produces the same result as
2656-
# plot_property(property="heat_conductivity")
2657-
_, ax1 = plt.subplots()
2658-
heat_sim.plot(z=0, property="heat_conductivity", ax=ax1)
2659-
num_children_plot = len(ax1.get_children())
2650+
# Test plot for HEAT simulation - should add heat BCs
2651+
_, ax_scene_only = plt.subplots()
2652+
heat_sim.scene.plot(z=0, ax=ax_scene_only)
2653+
num_children_scene_only = len(ax_scene_only.get_children())
26602654
plt.close()
26612655

2662-
_, ax2 = plt.subplots()
2663-
heat_sim.plot_property(z=0, property="heat_conductivity", ax=ax2)
2664-
num_children_plot_property = len(ax2.get_children())
2656+
_, ax_with_bc = plt.subplots()
2657+
heat_sim.plot(z=0, ax=ax_with_bc)
2658+
num_children_with_bc = len(ax_with_bc.get_children())
26652659
plt.close()
26662660

2667-
assert num_children_plot == num_children_plot_property, (
2668-
"plot(property='heat_conductivity') should produce the same result as "
2669-
"plot_property(property='heat_conductivity')"
2661+
# heat_sim.plot() should have more visual elements than scene.plot()
2662+
# because it adds monitors and heat boundaries for HEAT simulations
2663+
assert num_children_with_bc - num_children_scene_only >= 2, (
2664+
"heat_sim.plot() should add at least monitors and heat boundaries "
2665+
"for HEAT simulations, resulting in at least 2 more visual elements "
2666+
"than heat_sim.scene.plot()"
26702667
)
26712668

2672-
# Test plot with property="source"
2673-
_, ax = plt.subplots()
2674-
heat_sim.plot(z=0, property="source", ax=ax)
2675-
plt.close()
2676-
26772669
# Now test with a CHARGE simulation
26782670
semicon = td.material_library["cSi"].variants["Si_MultiPhysics"].medium.charge
26792671
Si_n = semicon.updated_copy(N_d=[td.ConstantDoping(concentration=1e16)], name="Si_n")
@@ -2717,13 +2709,7 @@ def test_heat_charge_simulation_plot():
27172709
analysis_spec=td.IsothermalSteadyChargeDCAnalysis(temperature=300),
27182710
)
27192711

2720-
# Test plot with property="electric_conductivity"
2721-
_, ax_elec_prop = plt.subplots()
2722-
charge_sim.plot(z=0, property="electric_conductivity", ax=ax_elec_prop)
2723-
plt.close()
2724-
2725-
# Verify that electric BCs are added when property=None for CHARGE simulations
2726-
# by comparing charge_sim.plot() against charge_sim.scene.plot()
2712+
# Test plot for CHARGE simulation - should add electric BCs
27272713
_, ax_scene_only = plt.subplots()
27282714
charge_sim.scene.plot(z=0, ax=ax_scene_only)
27292715
num_children_scene_only = len(ax_scene_only.get_children())

tidy3d/components/tcad/simulation/heat_charge.py

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,9 +1172,9 @@ def plot(
11721172
ax: Ax = None,
11731173
source_alpha: Optional[float] = None,
11741174
monitor_alpha: Optional[float] = None,
1175-
property: Optional[Literal["heat_conductivity", "electric_conductivity", "source"]] = None,
11761175
hlim: Optional[tuple[float, float]] = None,
11771176
vlim: Optional[tuple[float, float]] = None,
1177+
fill_structures: bool = True,
11781178
) -> Ax:
11791179
"""Plot each of simulation's components on a plane defined by one nonzero x,y,z coordinate.
11801180
@@ -1188,44 +1188,24 @@ def plot(
11881188
position of plane in z direction, only one of x, y, z must be specified to define plane.
11891189
ax : matplotlib.axes._subplots.Axes = None
11901190
Matplotlib axes to plot on, if not specified, one is created.
1191-
alpha : float = None
1192-
Opacity of the structures being plotted.
1193-
Defaults to the structure default alpha.
11941191
source_alpha : float = None
11951192
Opacity of the sources. If ``None``, uses Tidy3d default.
11961193
monitor_alpha : float = None
11971194
Opacity of the monitors. If ``None``, uses Tidy3d default.
1198-
property : Optional[Literal["heat_conductivity", "electric_conductivity", "source"]] = None
1199-
Specifies the type of simulation for which the plot will be tailored.
1200-
Options are ["heat_conductivity", "electric_conductivity", "source"]. If ``None``,
1201-
plots the scene structures and for CHARGE simulations also adds boundary conditions.
12021195
hlim : Tuple[float, float] = None
12031196
The x range if plotting on xy or xz planes, y range if plotting on yz plane.
12041197
vlim : Tuple[float, float] = None
12051198
The z range if plotting on xz or yz planes, y plane if plotting on xy plane.
1199+
fill_structures : bool = True
1200+
Whether to fill structures with color or just draw outlines.
12061201
12071202
Returns
12081203
-------
12091204
matplotlib.axes._subplots.Axes
12101205
The supplied or created matplotlib axes.
12111206
"""
12121207

1213-
# If property is defined, delegate to plot_property
1214-
if property is not None:
1215-
return self.plot_property(
1216-
x=x,
1217-
y=y,
1218-
z=z,
1219-
ax=ax,
1220-
alpha=alpha,
1221-
source_alpha=source_alpha,
1222-
monitor_alpha=monitor_alpha,
1223-
property=property,
1224-
hlim=hlim,
1225-
vlim=vlim,
1226-
)
1227-
1228-
# If property is None, call the parent's plot method
1208+
# Call the parent's plot method
12291209
ax = super().plot(
12301210
x=x,
12311211
y=y,
@@ -1235,11 +1215,17 @@ def plot(
12351215
monitor_alpha=monitor_alpha,
12361216
hlim=hlim,
12371217
vlim=vlim,
1218+
fill_structures=fill_structures,
12381219
)
12391220

1240-
# For CHARGE simulations, also add electric boundaries
1221+
# Add boundaries based on simulation type
12411222
simulation_types = self._get_simulation_types()
1242-
if TCADAnalysisTypes.CHARGE in simulation_types:
1223+
if TCADAnalysisTypes.HEAT in simulation_types:
1224+
ax = self.plot_boundaries(ax=ax, x=x, y=y, z=z, property="heat_conductivity")
1225+
if (
1226+
TCADAnalysisTypes.CHARGE in simulation_types
1227+
or TCADAnalysisTypes.CONDUCTION in simulation_types
1228+
):
12431229
ax = self.plot_boundaries(ax=ax, x=x, y=y, z=z, property="electric_conductivity")
12441230

12451231
return ax

0 commit comments

Comments
 (0)