Skip to content

Commit

Permalink
- added lumped ports in the component modeler and lumped resistors to…
Browse files Browse the repository at this point in the history
… simulation

- added lumped ports to component modeler

- added automatic mesh refinement option to lumped ports; tested on 2D materials

- added lumped resistor functionality to frontend with plotting; tested

- added lumped resistors to backend

- fix solver version bug for batches

- allow picking solver version in component modeler

- adding lumped resistors as 2d materials

- mesh override above and below lumped ports

- modified init to include all components for ports

- make source confinement to bounds optional

- 2d materials modified how homogeneity of above and below media is detected

- added frontend tests

- fix estimate cost bug when solver version is provided in jobs or batches

- fix an issue related to early exit in volumetric grid checks

- fixed frontend tests, added plot_eps, forced lumped ports to snap to the grid in order to track position of the lumped resistor

- reorganization of smatrix modules

- added tests and exposed a method for automatically generating MeshOverrides for a simulation

- update docstrings and comments, modify validator

- moving methods into lumpedports

- remove refine_mesh member, num_grid_cells controls all auto mesh refinement
  • Loading branch information
shashwat-sh authored and dmarek-flex committed Mar 1, 2024
1 parent e9db741 commit e5c1439
Show file tree
Hide file tree
Showing 27 changed files with 1,656 additions and 227 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,4 @@ htmlcov/

# Specific file and folder exclusions
.idea
.vscode
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- `Simulation` now accepts `LumpedElementType`, which currently only supports the `LumpedResistor` type. `LumpedPort` together with `LumpedResistor` make up the new `TerminalComponentModeler` in the `smatrix` plugin.
- Uniaxial medium Lithium niobate to material library.
- Added support for conformal mesh methods near PEC structures that can be specified through the field `pec_conformal_mesh_spec` in the `Simulation` class.

Expand Down
1 change: 1 addition & 0 deletions docs/api/abstract_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ These are some classes that are used to organize the tidy3d components, but aren
tidy3d.components.monitor.AbstractFluxMonitor
tidy3d.components.monitor.PlanarMonitor
tidy3d.components.monitor.AbstractFieldProjectionMonitor
tidy3d.components.lumped_element.LumpedElement
tidy3d.components.grid.grid_spec.GridSpec1d
tidy3d.components.data.data_array.DataArray
tidy3d.components.data.monitor_data.MonitorData
Expand Down
2 changes: 2 additions & 0 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ API |:computer:|
sources
monitors
mode
lumped_elements
discretization
output_data
scene
Expand All @@ -34,6 +35,7 @@ API |:computer:|
.. include:: /api/sources.rst
.. include:: /api/monitors.rst
.. include:: /api/mode.rst
.. include:: /api/lumped_elements.rst
.. include:: /api/discretization.rst
.. include:: /api/output_data.rst
.. include:: /api/scene.rst
Expand Down
12 changes: 12 additions & 0 deletions docs/api/lumped_elements.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.. currentmodule:: tidy3d

Lumped elements
===============

Passive elements
----------------
.. autosummary::
:toctree: _autosummary/
:template: module.rst

tidy3d.LumpedResistor
25 changes: 15 additions & 10 deletions tests/sims/simulation_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -1015,14 +1015,14 @@
},
"transform": [
[
0.9659258262890683,
-0.25881904510252074,
0.9659258262890684,
-0.2588190451025208,
0.0,
0.0
],
[
0.25881904510252074,
0.9659258262890683,
0.2588190451025208,
0.9659258262890684,
0.0,
0.0
],
Expand Down Expand Up @@ -1084,6 +1084,7 @@
"remove_dc_component": true
},
"interpolate": true,
"confine_to_bounds": false,
"polarization": "Hx"
},
{
Expand All @@ -1109,6 +1110,7 @@
"remove_dc_component": true
},
"interpolate": true,
"confine_to_bounds": false,
"polarization": "Ex"
},
{
Expand Down Expand Up @@ -1302,6 +1304,7 @@
"remove_dc_component": true
},
"interpolate": true,
"confine_to_bounds": false,
"current_dataset": {
"type": "FieldDataset",
"Ex": "ScalarFieldDataArray",
Expand Down Expand Up @@ -1366,6 +1369,7 @@
}
},
"interpolate": true,
"confine_to_bounds": false,
"polarization": "Hx"
}
],
Expand Down Expand Up @@ -1510,7 +1514,7 @@
1,
1
],
"colocate": true,
"colocate": 1,
"freqs": [
200000000000000.0,
250000000000000.0
Expand Down Expand Up @@ -1542,7 +1546,7 @@
1,
1
],
"colocate": true,
"colocate": 1,
"start": 0.0,
"stop": null,
"interval": 1,
Expand Down Expand Up @@ -1644,7 +1648,7 @@
1,
1
],
"colocate": true,
"colocate": 1,
"freqs": [
250000000000000.0,
300000000000000.0
Expand Down Expand Up @@ -1794,7 +1798,7 @@
1,
1
],
"colocate": true,
"colocate": 1,
"freqs": [
250000000000000.0,
300000000000000.0
Expand Down Expand Up @@ -1851,7 +1855,7 @@
1,
1
],
"colocate": true,
"colocate": 1,
"freqs": [
250000000000000.0,
300000000000000.0
Expand Down Expand Up @@ -1905,7 +1909,7 @@
1,
1
],
"colocate": true,
"colocate": 1,
"freqs": [
250000000000000.0,
300000000000000.0
Expand Down Expand Up @@ -2225,6 +2229,7 @@
"version": "2.6.0",
"courant": 0.8,
"normalize_index": 0,
"lumped_elements": [],
"shutoff": 0.0001,
"subpixel": false,
"run_time": 1e-12
Expand Down
41 changes: 41 additions & 0 deletions tests/test_components/test_medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,3 +739,44 @@ def test_nonlinear_medium(log_capture):
medium2d = td.Medium2D(ss=medium, tt=medium)
with pytest.raises(ValidationError):
medium2d = td.Medium2D(ss=modulated, tt=modulated)


def test_lumped_resistor():
resistor = td.LumpedResistor(
resistance=50.0,
center=[0, 0, 0],
size=[2, 0, 3],
voltage_axis=0,
name="R",
)
_ = resistor.sheet_conductance
normal_axis = resistor.normal_axis
assert normal_axis == 1

# error if voltage axis is not in plane with the resistor
with pytest.raises(pydantic.ValidationError):
_ = td.LumpedResistor(
resistance=50.0,
center=[0, 0, 0],
size=[2, 0, 3],
voltage_axis=1,
name="R",
)

# error if not planar
with pytest.raises(pydantic.ValidationError):
_ = td.LumpedResistor(
resistance=50.0,
center=[0, 0, 0],
size=[0, 0, 3],
voltage_axis=2,
name="R",
)
with pytest.raises(pydantic.ValidationError):
_ = td.LumpedResistor(
resistance=50.0,
center=[0, 0, 0],
size=[2, 1, 3],
voltage_axis=2,
name="R",
)
79 changes: 79 additions & 0 deletions tests/test_components/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2623,3 +2623,82 @@ def test_advanced_material_intersection():
)
# it's ok if these are both present as long as they don't intersect
sim = sim.updated_copy(structures=[struct1, struct2])


def test_num_lumped_elements():
"""Make sure we error if too many lumped elements supplied."""

resistor = td.LumpedResistor(
size=(0, 1, 2), center=(0, 0, 0), name="R1", voltage_axis=2, resistance=75
)
grid_spec = td.GridSpec.auto(wavelength=1.0)

_ = td.Simulation(
size=(5, 5, 5),
grid_spec=grid_spec,
structures=[],
lumped_elements=[resistor] * MAX_NUM_MEDIUMS,
run_time=1e-12,
)
with pytest.raises(pydantic.ValidationError):
_ = td.Simulation(
size=(5, 5, 5),
grid_spec=grid_spec,
structures=[],
lumped_elements=[resistor] * (MAX_NUM_MEDIUMS + 1),
run_time=1e-12,
)


def test_validate_lumped_elements():
resistor = td.LumpedResistor(
size=(0, 1, 2), center=(0, 0, 0), name="R1", voltage_axis=2, resistance=75
)

_ = td.Simulation(
size=(1, 2, 3),
run_time=1e-12,
grid_spec=td.GridSpec.uniform(dl=0.1),
lumped_elements=[resistor],
)
# error for 1D/2D simulation with lumped elements
with pytest.raises(pydantic.ValidationError):
td.Simulation(
size=(1, 0, 3),
run_time=1e-12,
grid_spec=td.GridSpec.uniform(dl=0.1),
lumped_elements=[resistor],
)

with pytest.raises(pydantic.ValidationError):
td.Simulation(
size=(1, 0, 0),
run_time=1e-12,
grid_spec=td.GridSpec.uniform(dl=0.1),
lumped_elements=[resistor],
)


def test_suggested_mesh_overrides():
resistor = td.LumpedResistor(
size=(0, 1, 2), center=(0, 0, 0), name="R1", voltage_axis=2, resistance=75
)
sim = td.Simulation(
size=(1, 2, 3),
run_time=1e-12,
grid_spec=td.GridSpec.uniform(dl=0.1),
lumped_elements=[resistor],
)

suggested_mesh_overrides = sim.suggest_mesh_overrides()
assert len(suggested_mesh_overrides) == 2
grid_spec = sim.grid_spec.copy(
update={
"override_structures": list(sim.grid_spec.override_structures)
+ suggested_mesh_overrides,
}
)

_ = sim.updated_copy(
grid_spec=grid_spec,
)
Loading

0 comments on commit e5c1439

Please sign in to comment.