Skip to content

Commit 15b3f7c

Browse files
committed
grab inside pixel at index=3 or 1 depending on cells
1 parent c8f2386 commit 15b3f7c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Fixed
1414
- Ensure same `Grid` is generated in forward and adjoint simulations by setting `GridSpec.wavelength` manually in adjoint.
15-
15+
- Proper handling of `JaxBox` derivatives both for multi-cell and single cell thickness.
1616

1717
## [2.4.1] - 2023-9-20
1818

tidy3d/plugins/adjoint/components/geometry.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,20 @@ def store_vjp(
237237
eps_data = grad_data_eps.field_components[eps_field_name].isel(f=0)
238238

239239
# get the permittivity values just inside and outside the edge
240-
n_cells_in = 2
240+
241+
num_cells_normal_dim = len(eps_data.coords[dim_normal])
242+
243+
# if the eps_data is <=3 grid cells thick, pick the middle cell
244+
if num_cells_normal_dim <= 3:
245+
isel_ins = num_cells_normal_dim // 2
246+
247+
# otherwise, pick the cell 4 pixels from outside cell
248+
else:
249+
n_cells_in = 3
250+
isel_ins = n_cells_in if min_max_index == 0 else -n_cells_in - 1
251+
241252
isel_out = 0 if min_max_index == 0 else -1
242-
isel_ins = n_cells_in if min_max_index == 0 else -n_cells_in - 1
253+
243254
eps2 = eps_data.isel(**{dim_normal: isel_out})
244255
eps1 = eps_data.isel(**{dim_normal: isel_ins})
245256

0 commit comments

Comments
 (0)