Skip to content

Commit

Permalink
modified voltage computation to avoid interpolation at conductor inte…
Browse files Browse the repository at this point in the history
…rface
  • Loading branch information
dmarek-flex committed Mar 6, 2024
1 parent e5c1439 commit a26fbe7
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions tidy3d/plugins/smatrix/component_modelers/terminal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tool for generating an S matrix automatically from a Tidy3d simulation and lumped port definitions."""

from __future__ import annotations

from typing import Tuple, Dict
Expand Down Expand Up @@ -193,16 +194,25 @@ def port_voltage(port: LumpedPort, sim_data: SimulationData) -> xr.DataArray:
e_component = "xyz"[port.voltage_axis]
field_data = sim_data[f"{port.name}_E{e_component}"]
e_field = field_data.field_components[f"E{e_component}"]

# Remove E field outside the port region
e_field = e_field.sel(
{
e_component: slice(
port.bounds[0][port.voltage_axis], port.bounds[1][port.voltage_axis]
)
}
)
e_coords = [e_field.x, e_field.y, e_field.z]
# interpolate E locations to coincide with port bounds along the integration path
e_coords_interp = {
e_component: np.linspace(
port.bounds[0][port.voltage_axis],
port.bounds[1][port.voltage_axis],
len(e_coords[port.voltage_axis]),
)
}
e_field = e_field.interp(**e_coords_interp)
# Integration is along the original coordinates plus two additional endpoints corresponding to the precise bounds of the port
e_coords_interp = np.array([port.bounds[0][port.voltage_axis]])
e_coords_interp = np.concatenate((e_coords_interp, e_coords[port.voltage_axis].values))
e_coords_interp = np.concatenate((e_coords_interp, [port.bounds[1][port.voltage_axis]]))
e_coords_interp = {e_component: e_coords_interp}
# Use extrapolation for the 2 additional endpoints
e_field = e_field.interp(
**e_coords_interp, method="linear", kwargs={"fill_value": "extrapolate"}
)
voltage = -e_field.integrate(coord=e_component).squeeze(drop=True)
# Return data array of voltage with coordinates of frequency
return voltage
Expand Down Expand Up @@ -271,13 +281,17 @@ def port_current(port: LumpedPort, sim_data: SimulationData) -> xr.DataArray:
h_max_bound = hcap_plus.coords[h_component].values
h_coords_interp = {
h_component: np.linspace(
# port.bounds[0][port.current_axis],
# port.bounds[1][port.current_axis],
h_min_bound,
h_max_bound,
len(h_coords[port.current_axis] + 2),
)
}
# Integration that corresponds to the tangent H field
h_field = h_field.interp(**h_coords_interp)
# h_field = h_field.sel({h_component: slice(port.bounds[0][port.current_axis], port.bounds[1][port.current_axis])})
# h_field = h_field.interp(**h_coords_interp, kwargs={"fill_value": "extrapolate"})
current = h_field.integrate(coord=h_component).squeeze(drop=True)

# Integration that corresponds with the contribution to current from cap contours
Expand Down

0 comments on commit a26fbe7

Please sign in to comment.