-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d6a8e2
commit af968e4
Showing
1 changed file
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import pytest | ||
|
||
|
||
import tidy3d as td | ||
from tidy3d.plugins.microwave import VoltageIntegralAA, CurrentIntegralAA | ||
|
||
from tidy3d.exceptions import DataError | ||
from ..utils import run_emulated | ||
|
||
|
||
def makesim(): | ||
sim = td.Simulation( | ||
size=(1, 1, 1), | ||
grid_spec=td.GridSpec.auto(wavelength=1.0), | ||
monitors=[ | ||
td.FieldMonitor(center=(0, 0, 0), size=(1, 1, 1), freqs=[2e14], name="field"), | ||
td.FieldMonitor( | ||
center=(0, 0, 0), size=(1, 1, 1), freqs=[2e14], fields=["Ex", "Hx"], name="ExHx" | ||
), | ||
td.ModeMonitor( | ||
center=(0, 0, 0), size=(1, 1, 0), freqs=[2e14], mode_spec=td.ModeSpec(), name="mode" | ||
), | ||
], | ||
sources=[ | ||
td.PointDipole( | ||
center=(0, 0, 0), | ||
polarization="Ex", | ||
source_time=td.GaussianPulse(freq0=2e14, fwidth=1e13), | ||
) | ||
], | ||
run_time=2e-12, | ||
) | ||
return sim | ||
|
||
|
||
@pytest.mark.parametrize("axis", [0, 1, 2]) | ||
def test_voltage_integral_axes(axis): | ||
length = 0.5 | ||
size = [0, 0, 0] | ||
size[axis] = length | ||
center = [0, 0, 0] | ||
voltage_integral = VoltageIntegralAA( | ||
center=center, | ||
size=size, | ||
) | ||
sim = makesim() | ||
sim_data = run_emulated(sim) | ||
_ = voltage_integral.compute_voltage(sim_data["field"].field_components) | ||
|
||
|
||
@pytest.mark.parametrize("axis", [0, 1, 2]) | ||
def test_current_integral_axes(axis): | ||
length = 0.5 | ||
size = [length, length, length] | ||
size[axis] = 0.0 | ||
center = [0, 0, 0] | ||
current_integral = CurrentIntegralAA( | ||
center=center, | ||
size=size, | ||
) | ||
sim = makesim() | ||
sim_data = run_emulated(sim) | ||
_ = current_integral.compute_current(sim_data["field"].field_components) | ||
|
||
|
||
def test_voltage_integral_toggles(): | ||
length = 0.5 | ||
size = [0, 0, 0] | ||
size[0] = length | ||
center = [0, 0, 0] | ||
voltage_integral = VoltageIntegralAA( | ||
center=center, | ||
size=size, | ||
extrapolate_to_endpoints=True, | ||
snap_path_to_grid=True, | ||
sign="-", | ||
) | ||
sim = makesim() | ||
sim_data = run_emulated(sim) | ||
_ = voltage_integral.compute_voltage(sim_data["field"].field_components) | ||
|
||
|
||
def test_current_integral_toggles(): | ||
length = 0.5 | ||
size = [length, length, length] | ||
size[0] = 0.0 | ||
center = [0, 0, 0] | ||
current_integral = CurrentIntegralAA( | ||
center=center, | ||
size=size, | ||
extrapolate_to_endpoints=True, | ||
snap_contour_to_grid=True, | ||
sign="-", | ||
) | ||
sim = makesim() | ||
sim_data = run_emulated(sim) | ||
_ = current_integral.compute_current(sim_data["field"].field_components) | ||
|
||
|
||
def test_voltage_missing_fields(): | ||
length = 0.5 | ||
size = [0, 0, 0] | ||
size[1] = length | ||
center = [0, 0, 0] | ||
voltage_integral = VoltageIntegralAA( | ||
center=center, | ||
size=size, | ||
) | ||
sim = makesim() | ||
sim_data = run_emulated(sim) | ||
with pytest.raises(DataError): | ||
_ = voltage_integral.compute_voltage(sim_data["ExHx"].field_components) | ||
|
||
|
||
def test_current_missing_fields(): | ||
length = 0.5 | ||
size = [length, length, length] | ||
size[0] = 0.0 | ||
center = [0, 0, 0] | ||
current_integral = CurrentIntegralAA( | ||
center=center, | ||
size=size, | ||
) | ||
sim = makesim() | ||
sim_data = run_emulated(sim) | ||
with pytest.raises(DataError): | ||
_ = current_integral.compute_current(sim_data["ExHx"].field_components) | ||
|
||
|
||
def test_tiny_voltage_path(): | ||
length = 0.05 | ||
size = [0, 0, 0] | ||
size[1] = length | ||
center = [0, -0.05, 0] | ||
voltage_integral = VoltageIntegralAA(center=center, size=size, extrapolate_to_endpoints=True) | ||
sim = makesim() | ||
sim_data = run_emulated(sim) | ||
_ = voltage_integral.compute_voltage(sim_data["field"].field_components) |