Constraint Utilities¶
Index Generation¶
fdtdx.constraints.utils.compute_allowed_indices(num_layers, indices, fill_holes_with_index, single_polymer_columns=False)
¶
Compute allowed index combinations for multi-layer structures.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_layers
|
int
|
Number of vertical layers in the structure. |
required |
indices
|
Sequence[int]
|
Sequence of allowed material indices. |
required |
fill_holes_with_index
|
Sequence[int]
|
Indices that can be used to fill holes/gaps. |
required |
single_polymer_columns
|
bool
|
If True, restrict to single polymer columns. |
False
|
Returns:
Type | Description |
---|---|
Array
|
jax.Array: Array of allowed index combinations, shape (n_combinations, num_layers). |
Source code in src/fdtdx/constraints/utils.py
fdtdx.constraints.utils.compute_allowed_indices_without_holes(num_layers, indices, fill_holes_with_index)
¶
Compute allowed indices for multi-layer structures without holes.
Generates valid index combinations ensuring no trapped air holes by filling gaps with specified indices. Shows progress with a tqdm progress bar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_layers
|
int
|
Number of vertical layers in the structure. |
required |
indices
|
Sequence[int]
|
Sequence of allowed material indices. |
required |
fill_holes_with_index
|
Sequence[int]
|
Indices that can be used to fill holes/gaps. |
required |
Returns:
Type | Description |
---|---|
Array
|
jax.Array: Array of valid index combinations, shape (n_combinations, num_layers). |
Source code in src/fdtdx/constraints/utils.py
fdtdx.constraints.utils.compute_allowed_indices_without_holes_single_polymer_columns(num_layers, indices, fill_holes_with_index)
¶
Compute allowed indices for single polymer column structures without holes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_layers
|
int
|
Number of vertical layers in the structure. |
required |
indices
|
Sequence[int]
|
Sequence of allowed material indices. |
required |
fill_holes_with_index
|
Sequence[int]
|
Indices that can be used to fill holes/gaps. |
required |
Returns:
Type | Description |
---|---|
Array
|
jax.Array: Array of valid index combinations, shape (n_combinations, num_layers). |
Source code in src/fdtdx/constraints/utils.py
Value Matching¶
fdtdx.constraints.utils.nearest_index(values, allowed_values, axis=None, allowed_indices=None, return_distances=False, distance_metric='permittivity_differences_plus_average_permittivity')
¶
Find nearest allowed indices for given values based on distance metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values
|
Array
|
Input array of values to match. |
required |
allowed_values
|
Array
|
Array of allowed values to match against. |
required |
axis
|
int | None
|
Axis along which to compute distances. Required if using allowed_indices. |
None
|
allowed_indices
|
Array | None
|
Optional array of allowed indices per position. |
None
|
return_distances
|
bool
|
If True, return both indices and distances. |
False
|
distance_metric
|
Literal['euclidean', 'permittivity_differences_plus_average_permittivity']
|
Method to compute distances between values: - "euclidean": Standard Euclidean distance - "permittivity_differences_plus_average_permittivity": Special metric for permittivity optimization combining differences and averages. |
'permittivity_differences_plus_average_permittivity'
|
Returns:
Type | Description |
---|---|
Array | tuple[Array, Array]
|
If return_distances is False: jax.Array: Array of indices of nearest allowed values. |
Array | tuple[Array, Array]
|
If return_distances is True: Tuple[jax.Array, jax.Array]: (indices, distances) |
Raises:
Type | Description |
---|---|
Exception
|
If axis not provided when using allowed_indices option. |
Exception
|
If values array is not 3D when using allowed_indices. |
Exception
|
If invalid axis specified. |
ValueError
|
If unknown distance metric specified. |
Source code in src/fdtdx/constraints/utils.py
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 |
|