Discrete Constraints¶
Material Connectivity¶
fdtdx.constraints.discrete.RemoveFloatingMaterial
¶
Bases: ConstraintModule
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/constraints/discrete.py
input_interface(output_interface)
¶
Validates and processes the input interface specification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_interface
|
ConstraintInterface
|
Interface specification from the next module in the chain. |
required |
Returns:
Type | Description |
---|---|
ConstraintInterface
|
The validated interface specification. |
Raises:
Type | Description |
---|---|
Exception
|
If output interface has multiple shapes or wrong type. |
NotImplementedError
|
If more than 2 permittivities are specified. |
Source code in src/fdtdx/constraints/discrete.py
transform(input_params)
¶
Transforms input parameters by removing floating material regions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_params
|
dict[str, Array]
|
Dictionary mapping parameter names to their values as JAX arrays. Expected to contain a single array with material indices. |
required |
Returns:
Type | Description |
---|---|
dict[str, Array]
|
Dictionary with same structure as input but with floating material regions |
dict[str, Array]
|
converted to air index. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If more than 2 permittivities are specified. |
Exception
|
If input contains more than one array. |
Source code in src/fdtdx/constraints/discrete.py
fdtdx.constraints.discrete.ConnectHolesAndStructures
¶
Bases: ConstraintModule
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/constraints/discrete.py
Feature Size Control¶
fdtdx.constraints.discrete.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/constraints/discrete.py
fdtdx.constraints.discrete.BrushConstraint2D
¶
Bases: ConstraintModule
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/constraints/discrete.py
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 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 287 288 289 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 |
|
Smoothing and Filtering¶
fdtdx.constraints.discrete.BinaryMedianFilterModule
¶
Bases: ConstraintModule
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/constraints/discrete.py
fdtdx.constraints.discrete.BOTTOM_Z_PADDING_CONFIG = PaddingConfig(modes=('constant', 'constant', 'constant', 'constant', 'constant', 'constant'), widths=(10), values=(1, 0, 1, 1, 1, 0))
module-attribute
¶
fdtdx.constraints.discrete.BOTTOM_Z_PADDING_CONFIG_REPEAT = PaddingConfig(modes=('edge', 'edge', 'edge', 'edge', 'constant', 'edge'), widths=(20), values=(1))
module-attribute
¶
Pillar Constraints¶
fdtdx.constraints.pillars.PillarMapping
¶
Bases: ConstraintModule
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 |
_allowed_indices |
Array
|
Private array of allowed index combinations. |
Source code in src/fdtdx/constraints/pillars.py
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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
init_module(config, permittivity_config, output_interface)
¶
Initialize the pillar mapping module.
Sets up allowed index combinations based on material constraints and geometry requirements. Computes valid pillar configurations that satisfy fabrication rules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
SimulationConfig
|
Global simulation configuration. |
required |
permittivity_config
|
dict[str, float]
|
Material permittivity configurations. |
required |
output_interface
|
ConstraintInterface
|
Interface specification from previous module. |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
Initialized module instance. |
Source code in src/fdtdx/constraints/pillars.py
input_interface(output_interface)
¶
Define input interface requirements for this constraint module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_interface
|
ConstraintInterface
|
Interface specification from previous module. |
required |
Returns:
Name | Type | Description |
---|---|---|
ConstraintInterface |
ConstraintInterface
|
Required input interface specification. |
Raises:
Type | Description |
---|---|
Exception
|
If output interface type is not inverse permittivity. |
Exception
|
If output interface has multiple shapes. |
Source code in src/fdtdx/constraints/pillars.py
transform(input_params)
¶
Transform input parameters to satisfy pillar constraints.
Maps arbitrary material distributions to nearest allowed pillar configurations using straight-through estimation for gradient computation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_params
|
dict[str, Array]
|
Dictionary of input parameter arrays. |
required |
Returns:
Type | Description |
---|---|
dict[str, Array]
|
dict[str, jax.Array]: Transformed parameter arrays satisfying constraints. |
Raises:
Type | Description |
---|---|
Exception
|
If invalid axis specified. |