¶
Devices¶
In FDTDX, devices are objects whose shape can be optimized. A device has a corresponding set of latent parameters, which are mapped to produce the current shape of the device.
fdtdx.Device
¶
Bases: OrderableObject
, ABC
Abstract base class for devices with optimizable permittivity distributions.
This class defines the common interface and functionality for both discrete and continuous devices that can be optimized through gradient-based methods.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Optional name identifier for the device |
dtype |
str
|
Data type for device parameters, defaults to float32 |
color |
tuple[float, float, float] | None
|
RGB color tuple for visualization, defaults to pink |
Source code in src/fdtdx/objects/device/device.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
matrix_voxel_grid_shape
property
¶
Calculate the shape of the voxel matrix in grid coordinates.
Returns:
Type | Description |
---|---|
GridShape3D
|
Tuple of (x,y,z) dimensions representing how many voxels fit in each direction |
GridShape3D
|
of the grid shape when divided by the single voxel shape. |
single_voxel_grid_shape
property
¶
Get the shape of a single voxel in grid coordinates.
Returns:
Type | Description |
---|---|
GridShape3D
|
Tuple of (x,y,z) dimensions for one voxel. |
Raises:
Type | Description |
---|---|
Exception
|
If the object has not been initialized yet. |
single_voxel_real_shape
property
¶
Calculate the shape of a single voxel in real (physical) coordinates.
Returns:
Type | Description |
---|---|
RealShape3D
|
Tuple of (x,y,z) dimensions in real units, computed by multiplying |
RealShape3D
|
the grid shape by the simulation resolution. |
Parameter Mapping¶
fdtdx.ParameterTransformation
¶
Bases: ExtendedTreeClass
, ABC
Source code in src/fdtdx/objects/device/parameters/transform.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
Projections¶
fdtdx.TanhProjection
¶
Bases: SameShapeTypeParameterTransform
Tanh projection filter.
This needs the steepness parameter \(eta\) as a keyword-argument in apply_params
Ref: F. Wang, B. S. Lazarov, & O. Sigmund, On projection methods, convergence and robust formulations in topology optimization. Structural and Multidisciplinary Optimization, 43(6), pp. 767-784 (2011).
Source code in src/fdtdx/objects/device/parameters/projection.py
fdtdx.SubpixelSmoothedProjection
¶
Bases: SameShapeTypeParameterTransform
This function is adapted from the Meep repository: https://github.com/NanoComp/meep/blob/master/python/adjoint/filters.py
The details of this projection are described in the paper by Alec Hammond: https://arxiv.org/pdf/2503.20189
Project using subpixel smoothing, which allows for β→∞. This technique integrates out the discontinuity within the projection function, allowing the user to smoothly increase β from 0 to ∞ without losing the gradient. Effectively, a level set is created, and from this level set, first-order subpixel smoothing is applied to the interfaces (if any are present).
In order for this to work, the input array must already be smooth (e.g. by filtering).
While the original approach involves numerical quadrature, this approach performs a "trick" by assuming that the user is always infinitely projecting (β=∞). In this case, the expensive quadrature simplifies to an analytic fill-factor expression. When to use this fill factor requires some careful logic.
For one, we want to make sure that the user can indeed project at any level (not just infinity). So in these cases, we simply check if in interface is within the pixel. If not, we revert to the standard filter plus project technique.
If there is an interface, we want to make sure the derivative remains continuous both as the interface leaves the cell, and as it crosses the center. To ensure this, we need to account for the different possibilities.
Source code in src/fdtdx/objects/device/parameters/projection.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
|
Tranformation of latent parameters¶
fdtdx.StandardToPlusOneMinusOneRange
¶
Bases: StandardToCustomRange
Maps standard [0,1] range to [-1,1] range.
Special case of StandardToCustomRange that maps to [-1,1] range. Used for symmetric value ranges around zero.
Attributes:
Name | Type | Description |
---|---|---|
min_value |
float
|
Fixed to -1 |
max_value |
float
|
Fixed to 1 |
Source code in src/fdtdx/objects/device/parameters/continuous.py
fdtdx.StandardToCustomRange
¶
Bases: SameShapeTypeParameterTransform
Maps standard [0,1] range to custom range [min_value, max_value].
Linearly maps values from [0,1] to a custom range specified by min_value and max_value parameters.
Attributes:
Name | Type | Description |
---|---|---|
min_value |
float
|
Minimum value of target range |
max_value |
float
|
Maximum value of target range |
Source code in src/fdtdx/objects/device/parameters/continuous.py
fdtdx.GaussianSmoothing2D
¶
Bases: SameShapeTypeParameterTransform
Applies Gaussian smoothing to 2D parameter arrays.
This transform convolves the input with a 2D Gaussian kernel, which helps reduce noise and smooth the data.
Attributes:
Name | Type | Description |
---|---|---|
std_discrete |
int
|
Integer specifying the standard deviation of the Gaussian kernel in discrete units. |
Source code in src/fdtdx/objects/device/parameters/continuous.py
Discretizations¶
fdtdx.ClosestIndex
¶
Bases: ParameterTransformation
Maps continuous latent values to nearest allowed material indices.
For each input value, finds the index of the closest allowed inverse permittivity value. Uses straight-through gradient estimation to maintain differentiability. If mapping_from_inverse_permittivities is set to False (default), then the transform only quantizes the latent parameters to the closest integer value.
Source code in src/fdtdx/objects/device/parameters/discretization.py
fdtdx.PillarDiscretization
¶
Bases: ParameterTransformation
Constraint module for mapping pillar structures to allowed configurations.
Maps arbitrary pillar structures to the nearest allowed configurations based on material constraints and geometry requirements. Ensures structures meet fabrication rules like single polymer columns and no trapped air holes.
Attributes:
Name | Type | Description |
---|---|---|
axis |
int
|
Axis along which to enforce pillar constraints (0=x, 1=y, 2=z). |
single_polymer_columns |
bool
|
If True, restrict to single polymer columns. |
distance_metric |
Literal['euclidean', 'permittivity_differences_plus_average_permittivity']
|
Method to compute distances between material distributions: - "euclidean": Standard Euclidean distance between permittivity values - "permittivity_differences_plus_average_permittivity": Weighted combination of permittivity differences and average permittivity values, optimized for material distribution comparisons |
Source code in src/fdtdx/objects/device/parameters/discretization.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
|
fdtdx.BrushConstraint2D
¶
Bases: ParameterTransformation
Applies 2D brush-based constraints to ensure minimum feature sizes.
Implements the brush-based constraint method described in: https://pubs.acs.org/doi/10.1021/acsphotonics.2c00313
This ensures minimum feature sizes and connectivity in 2D designs by using morphological operations with a brush kernel.
Attributes:
Name | Type | Description |
---|---|---|
brush |
Array
|
JAX array defining the brush kernel for morphological operations. |
axis |
int
|
Axis along which to apply the 2D constraint (perpendicular plane). |
Source code in src/fdtdx/objects/device/parameters/discretization.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
fdtdx.circular_brush(diameter, size=None)
¶
Creates a circular binary mask/brush for morphological operations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
diameter
|
float
|
Diameter of the circle in grid units. |
required |
size
|
int | None
|
Optional size of the output array. If None, uses ceil(diameter) rounded up to next odd number. |
None
|
Returns:
Type | Description |
---|---|
Array
|
Binary JAX array containing a circular mask where True indicates points |
Array
|
within the circle diameter. |
Source code in src/fdtdx/objects/device/parameters/discretization.py
Discrete PostProcessing¶
fdtdx.BinaryMedianFilterModule
¶
Bases: SameShapeTypeParameterTransform
Performs 3D binary median filtering on the design.
Applies a 3D median filter to smooth and clean up binary material distributions. This helps remove small features and noise while preserving larger structures.
Attributes:
Name | Type | Description |
---|---|---|
padding_cfg |
PaddingConfig
|
Configuration for padding behavior at boundaries. |
kernel_sizes |
tuple[int, int, int]
|
3-tuple of kernel sizes for each dimension. |
num_repeats |
int
|
Number of times to apply the filter consecutively. |
Source code in src/fdtdx/objects/device/parameters/discrete.py
fdtdx.ConnectHolesAndStructures
¶
Bases: SameShapeTypeParameterTransform
Connects floating polymer regions and ensures air holes connect to outside.
This constraint module ensures physical realizability of designs by: 1. Either connecting floating polymer regions to the substrate or removing them 2. Ensuring all air holes are connected to the outside (no trapped air)
The bottom (lower z) is treated as the substrate reference.
Attributes:
Name | Type | Description |
---|---|---|
fill_material |
str | None
|
Name of material to use for filling gaps when connecting regions. Required when working with more than 2 materials. |
Source code in src/fdtdx/objects/device/parameters/discrete.py
fdtdx.RemoveFloatingMaterial
¶
Bases: SameShapeTypeParameterTransform
Finds all material that floats in the air and sets their permittivity to air.
This constraint module identifies regions of material that are not connected to any substrate or boundary and converts them to air. This helps ensure physically realizable designs by eliminating floating/disconnected material regions.
The module only works with binary material systems (2 permittivities) where one material represents air.
Source code in src/fdtdx/objects/device/parameters/discrete.py
fdtdx.BinaryMedianFilterModule
¶
Bases: SameShapeTypeParameterTransform
Performs 3D binary median filtering on the design.
Applies a 3D median filter to smooth and clean up binary material distributions. This helps remove small features and noise while preserving larger structures.
Attributes:
Name | Type | Description |
---|---|---|
padding_cfg |
PaddingConfig
|
Configuration for padding behavior at boundaries. |
kernel_sizes |
tuple[int, int, int]
|
3-tuple of kernel sizes for each dimension. |
num_repeats |
int
|
Number of times to apply the filter consecutively. |
Source code in src/fdtdx/objects/device/parameters/discrete.py
Symmetries¶
fdtdx.DiagonalSymmetry2D
¶
Bases: SameShapeTypeParameterTransform
Enforce symmetries by effectively havling the parameter space. The symmetry is transposing by rotating the image and taking the mean of original and transpose. Attributes: min_min_to_max_max: if true, the symmetry axes is from (x_min, y_min) to (x_max, y_max). If false, the other diagonal is used.