Skip to content

Unstructured mesh refinement regions #2306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a74d302
Adding the refinement region for the mesh
vasilyzabelin Mar 11, 2025
9e7560d
Adding the refinement regions for the mesh
vasilyzabelin Mar 11, 2025
ac12e01
Adding the refinement liness for the mesh
vasilyzabelin Mar 11, 2025
a3b0885
fix[autograd]: add validation for missing frequency-domain monitors
yaugenst-flex Mar 6, 2025
e980185
Fix corner filtering in LayerRefinementSpec
weiliangjin2021 Mar 10, 2025
0c6bc76
Fix for numpy deprecating cross product in 2D
lucas-flexcompute Mar 14, 2025
121d41c
fix[web]: fix task querying
yaugenst-flex Mar 14, 2025
9c77d53
fix: automatically create batch output directories
yaugenst-flex Mar 13, 2025
d24b81b
chore: add dependency groups for `design` plugin as well as heat &
yaugenst-flex Mar 18, 2025
0d935b2
fix[adjoint]: fix tuple handling in autograd gradient calculations
yaugenst-flex Mar 14, 2025
92fd6e3
:package: Limit xarray version for 3.9 compatibility
daquinteroflex Mar 20, 2025
e80d9a1
fix: erroneous results in field projection monitors with many samplin…
dmarek-flex Mar 20, 2025
53ff93c
Improve accuracy of normal E-field computation in mode solver
weiliangjin2021 Mar 20, 2025
3f9f2a7
Raise an error if far_field_approx=False enabled for 2D simulations.
QimingFlex Mar 4, 2025
8bc76f9
Add metal surface roughness models
weiliangjin2021 Mar 18, 2025
94510bc
fix: deletion of tasks using `web.delete(task_id)`
yaugenst-flex Mar 20, 2025
7336df3
final changes for 2.8.1
momchil-flex Mar 20, 2025
8d0366f
Merge branch 'develop' into vasily/refinement_region
vasilyzabelin Apr 3, 2025
3876500
Update refinement regions and refinement lines
vasilyzabelin Apr 15, 2025
7a8b3f7
Convenience class to generate charge perturbations following model by…
marc-flex Mar 12, 2025
0c35d7d
fix[adjoint]: Pass correct frequency for epsilon calculation in adjoi…
yaugenst-flex Apr 2, 2025
3ba6774
fix[testing]: fixed test_geometry bounds checking tests
Mar 31, 2025
752b78b
fix[adjoint]: correct scaling for adjoint sources created from field …
Mar 21, 2025
4aec1bc
feat[viz] Add option to plot specific permittivity component of aniso…
bzhangflex Feb 4, 2025
29a6321
Fix heat conductivity plot
marc-flex Apr 3, 2025
2bfb7d4
Warn when mode solver pml covers a significant portion of the mode plane
caseyflex Mar 14, 2025
bfb193f
Add aux field monitors
caseyflex Mar 5, 2025
22b3cb1
Better validation of TFSF sources, and enabling broadband
momchil-flex Apr 4, 2025
7a80353
Set angle_phi to multiple of np.pi / 2 if angle_rotation is used
momchil-flex Apr 7, 2025
960aa6d
added ability to define a wave port using only a single voltage or cu…
dmarek-flex Mar 27, 2025
eb292f6
Change doping ramp-up default
marc-flex Apr 9, 2025
32e9457
Notebooks, changelog, schema, version bump for 2.8.2
momchil-flex Apr 7, 2025
45e41bf
chore: add dependency groups for `design` plugin as well as heat &
yaugenst-flex Mar 18, 2025
ea5b0a1
:package: Limit xarray version for 3.9 compatibility
daquinteroflex Mar 20, 2025
804fe6c
final changes for 2.8.1
momchil-flex Mar 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.8.1] - 2025-03-20
## [2.8.2] - 2025-04-09

### Added
- `fill` and `fill_structures` argument in `td.Simulation.plot_structures()` and `td.Simulation.plot()` respectively to disable fill and plot outlines of structures only.
- New subpixel averaging option `ContourPathAveraging` applied to dielectric material boundaries.
- A property `interior_angle` in `PolySlab` that stores angles formed inside polygon by two adjacent edges.
- `eps_component` argument in `td.Simulation.plot_eps()` to optionally select a specific permittivity component to plot (eg. `"xx"`).
- Monitor `AuxFieldTimeMonitor` for aux fields like the free carrier density in `TwoPhotonAbsorption`.
- Broadband handling (`num_freqs` argument) to the TFSF source.
- Ability to define a `WavePort` using only a voltage or current path integral, with the missing quantity inferred via power conservation.

### Fixed
- Compatibility with `xarray>=2025.03`.
- Inaccurate gradient when auto-grabbing permittivities for structures using `td.PolySlab` when using dispersive material models.
- Fixed scaling for adjoint sources when differentiating with respect to `FieldData` to account for the mesh size of the monitor and thus the created source. This aligns adjoint gradient magnitudes with numerical finite difference gradients for field data.
- Warn when mode solver pml covers a significant portion of the mode plane.
- TFSF server errors related to the auxiliary plane wave source that would previously happen on the server are now caught upon simulation creation.

### Changed
- `num_freqs` in Gaussian beam type sources limited to 20, which should besufficient for all cases.
- The `angle_phi` parameter of `ModeSpec` is only limited to multiples of `np.pi / 2` if `angle_rotation` is set to `True`, as other values would currently not work correctly.
- The `ramp_up_iters` parameter of the `ChargeSolver` was changed back to 1 for efficiency. It can be increased in cases with e.g. high doping when convergence is more difficult.

## [2.8.1] - 2025-03-20

Expand All @@ -22,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Validation step that raises a `ValueError` when no frequency-domain monitors are present, preventing invalid adjoint runs.
- Metal surface roughness models: modified Hammerstad, Huray Snowball, and Cannonball-Huray.
- Support for Fermi-Dirac statistics in Charge solver. This option can be activated when defining the analysis type `IsothermalSteadyChargeDCAnalysis` with `fermi_dirac=True`. This option will provide more accurate results in simulations where very high doping may lead the pseudo-Fermi energy levels to approach either the conduction or the valence energy levels.
- Unstructured grid now supports 2D/3D box-shaped refinement regions and 1D refinement lines of arbitrary direction.

### Changed

Expand Down Expand Up @@ -1555,8 +1572,11 @@ which fields are to be projected is now determined automatically based on the me
- Job and Batch classes for better simulation handling (eventually to fully replace webapi functions).
- A large number of small improvements and bug fixes.

[Unreleased]: https://github.com/flexcompute/tidy3d/compare/v2.8.1...develop
[Unreleased]: https://github.com/flexcompute/tidy3d/compare/v2.8.2...develop
[2.8.2]: https://github.com/flexcompute/tidy3d/compare/v2.8.1...v2.8.2
[2.8.1]: https://github.com/flexcompute/tidy3d/compare/v2.8.0...v2.8.1
[Unreleased]: https://github.com/flexcompute/tidy3d/compare/v2.8.1...develop
[2.8.0]: https://github.com/flexcompute/tidy3d/compare/v2.8.0...v2.8.1
[2.8.0]: https://github.com/flexcompute/tidy3d/compare/v2.7.9...v2.8.0
[2.7.9]: https://github.com/flexcompute/tidy3d/compare/v2.7.8...v2.7.9
[2.7.8]: https://github.com/flexcompute/tidy3d/compare/v2.7.7...v2.7.8
Expand Down
2 changes: 1 addition & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Tidy3D also offers plugins that require additional dependencies:

- ``design``: Design space exploration and optimization.
- ``pytorch``: A PyTorch wrapper for objective functions defined using autograd.
- ``adjoint``: Adjoint optimization using JAX (deprecated in favor of native autograd support in Tidy3D)
- ``adjoint``: Adjoint optimization using JAX (deprecated in favor of native autorad support in Tidy3D)

For example, to install the design plugin dependencies:

Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks
142 changes: 62 additions & 80 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ documentation = "https://docs.flexcompute.com/projects/tidy3d/en/latest/"
[tool.poetry.dependencies]
python = ">=3.9,<3.14"
pyroots = ">=0.5.0"
xarray = ">=2023.08"
xarray = ">=2023.08.0,<2025.03.0"
importlib-metadata = ">=6.0.0"
h5netcdf = "1.0.2"
h5py = "^3.0.0"
Expand Down Expand Up @@ -275,7 +275,10 @@ ignore = [

[tool.pytest.ini_options]
# TODO: remove --assert=plain when https://github.com/scipy/scipy/issues/22236 is resolved
addopts = "--cov=tidy3d --doctest-modules -n auto --dist worksteal --assert=plain"
addopts = "--cov=tidy3d --doctest-modules -n auto --dist worksteal --assert=plain -m 'not numerical' "
markers = [
"numerical: marks numerical tests for adjoint gradients that require running simulations (deselect with '-m \"not numerical\"')",
]
env = ["MPLBACKEND=Agg", "OMP_NUM_THREADS=1"]
doctest_optionflags = "NORMALIZE_WHITESPACE ELLIPSIS"
norecursedirs = [
Expand Down
32 changes: 32 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
from pathlib import Path

import autograd
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import psutil
Expand Down Expand Up @@ -68,3 +70,33 @@ def pytest_xdist_auto_num_workers(config):
if os.getenv("GITHUB_ACTIONS"):
return cores
return max(1, cores - 1)


@pytest.fixture
def mpl_config_noninteractive():
"""Configure matplotlib non-interactive backend for all tests in this module."""
original_backend = mpl.get_backend()
mpl.use("Agg")
yield
plt.close("all")
mpl.use(original_backend)


@pytest.fixture
def mpl_config_interactive():
"""Configure matplotlib interactive backend for all tests in this module."""
original_backend = mpl.get_backend()
mpl.use("TkAgg")
yield
mpl.use(original_backend)


@pytest.fixture
def dir_name(request):
return request.param


@pytest.fixture
def create_directory(dir_name):
if dir_name is not None:
directory = Path(dir_name).mkdir(parents=True, exist_ok=True)
Binary file modified tests/sims/simulation_sample.h5
Binary file not shown.
96 changes: 95 additions & 1 deletion tests/sims/simulation_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,72 @@
}
}
},
{
"attrs": {},
"geometry": {
"attrs": {},
"type": "Box",
"center": [
-1.0,
0.0,
0.0
],
"size": [
1.0,
1.0,
1.0
]
},
"name": "fully_anisotropic_box",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"modulation_spec": null,
"viz_spec": null,
"heat_spec": null,
"type": "FullyAnisotropicMedium",
"permittivity": [
[
6.0,
2.0,
3.0
],
[
2.0,
7.0,
4.0
],
[
3.0,
4.0,
9.0
]
],
"conductivity": [
[
0.0,
0.0,
0.0
],
[
0.0,
0.0,
0.0
],
[
0.0,
0.0,
0.0
]
]
}
},
{
"attrs": {},
"geometry": {
Expand Down Expand Up @@ -2015,6 +2081,7 @@
"offset": 5.0,
"remove_dc_component": true
},
"num_freqs": 3,
"direction": "+",
"angle_theta": 0.5235987755982988,
"angle_phi": 0.6283185307179586,
Expand Down Expand Up @@ -2192,6 +2259,33 @@
"Hz"
]
},
{
"attrs": {},
"type": "AuxFieldTimeMonitor",
"center": [
0.0,
0.0,
0.0
],
"size": [
0.0,
0.0,
0.0
],
"name": "aux_field_time",
"interval_space": [
1,
1,
1
],
"colocate": true,
"start": 0.0,
"stop": null,
"interval": 100,
"fields": [
"Nfx"
]
},
{
"attrs": {},
"type": "FluxMonitor",
Expand Down Expand Up @@ -3107,7 +3201,7 @@
"layer_refinement_specs": [],
"type": "GridSpec"
},
"version": "2.8.0",
"version": "2.8.1",
"plot_length_units": "\u03bcm",
"lumped_elements": [
{
Expand Down
33 changes: 33 additions & 0 deletions tests/test_components/test_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,17 @@ def make_structures(params: anp.ndarray) -> dict[str, td.Structure]:
medium=med,
)

polyslab_dispersive = td.Structure(
geometry=td.PolySlab(
vertices=vertices,
slab_bounds=slab_bounds,
axis=POLYSLAB_AXIS,
sidewall_angle=0.00,
dilation=0.00,
),
medium=td.material_library["Si3N4"]["Philipp1973Sellmeier"],
)

# geometry group
geo_group = td.Structure(
geometry=td.GeometryGroup(
Expand Down Expand Up @@ -469,6 +480,7 @@ def make_structures(params: anp.ndarray) -> dict[str, td.Structure]:
custom_med=custom_med,
custom_med_vec=custom_med_vec,
polyslab=polyslab,
polyslab_dispersive=polyslab_dispersive,
geo_group=geo_group,
complex_polyslab=complex_polyslab_geo_group,
pole_res=pole_res,
Expand Down Expand Up @@ -2117,3 +2129,24 @@ def objective(params):

grad_no_flux_monitors = ag.grad(objective_with_monitors(monitors_just_field))(params0)
grad_with_flux_monitors = ag.grad(objective_with_monitors(monitors_with_flux))(params0)


def test_dispersive_no_inf(use_emulated_run):
"""Test that automatic permittivity grabbing uses the correct freq_adj to
retrieve permittivity in dispersive material models.
"""

fn_dict = get_functions(args[0][0], args[0][1])
make_sim = fn_dict["sim"]
postprocess = fn_dict["postprocess"]

def objective(args):
structure_traced = make_structures(args)["polyslab_dispersive"]
sim = make_sim(args).updated_copy(structures=[structure_traced])
sim_data = run(sim, task_name="adjoint_test", verbose=False)
return postprocess(sim_data)

# the following will raise a warning (and fail) if the dispersive material
# model is called without a frequency
with AssertLogLevel("INFO"):
grad = ag.grad(objective)(params0)
Loading