¶
Initialization of Boundaries¶
Currently, the simulation boundary can either be a Perfectly Matched Layer for absorbing all incoming light, or a periodic boundary which wraps around to the other side of the simulation.
fdtdx.objects.boundaries.BoundaryConfig
¶
Bases: ExtendedTreeClass
Configuration class for boundary conditions.
This class stores parameters for boundary conditions in all six directions (min/max x/y/z). Supports both PML and periodic boundaries. For PML, the parameters control the absorption properties and physical size of the PML regions.
Attributes:
Name | Type | Description |
---|---|---|
boundary_type_minx |
str
|
Boundary type at minimum x ("pml" or "periodic"). Default "pml". |
boundary_type_maxx |
str
|
Boundary type at maximum x ("pml" or "periodic"). Default "pml". |
boundary_type_miny |
str
|
Boundary type at minimum y ("pml" or "periodic"). Default "pml". |
boundary_type_maxy |
str
|
Boundary type at maximum y ("pml" or "periodic"). Default "pml". |
boundary_type_minz |
str
|
Boundary type at minimum z ("pml" or "periodic"). Default "pml". |
boundary_type_maxz |
str
|
Boundary type at maximum z ("pml" or "periodic"). Default "pml". |
thickness_grid_minx |
int
|
Number of grid cells for PML at minimum x boundary. Default 10. |
thickness_grid_maxx |
int
|
Number of grid cells for PML at maximum x boundary. Default 10. |
thickness_grid_miny |
int
|
Number of grid cells for PML at minimum y boundary. Default 10. |
thickness_grid_maxy |
int
|
Number of grid cells for PML at maximum y boundary. Default 10. |
thickness_grid_minz |
int
|
Number of grid cells for PML at minimum z boundary. Default 10. |
thickness_grid_maxz |
int
|
Number of grid cells for PML at maximum z boundary. Default 10. |
kappa_start_minx |
float
|
Initial kappa value at min x boundary. Default 1.0. |
kappa_end_minx |
float
|
Final kappa value at min x boundary. Default 1.5. |
kappa_start_maxx |
float
|
Initial kappa value at max x boundary. Default 1.0. |
kappa_end_maxx |
float
|
Final kappa value at max x boundary. Default 1.5. |
kappa_start_miny |
float
|
Initial kappa value at min y boundary. Default 1.0. |
kappa_end_miny |
float
|
Final kappa value at min y boundary. Default 1.5. |
kappa_start_maxy |
float
|
Initial kappa value at max y boundary. Default 1.0. |
kappa_end_maxy |
float
|
Final kappa value at max y boundary. Default 1.5. |
kappa_start_minz |
float
|
Initial kappa value at min z boundary. Default 1.0. |
kappa_end_minz |
float
|
Final kappa value at min z boundary. Default 1.5. |
kappa_start_maxz |
float
|
Initial kappa value at max z boundary. Default 1.0. |
kappa_end_maxz |
float
|
Final kappa value at max z boundary. Default 1.5. |
Source code in src/fdtdx/objects/boundaries/initialization.py
11 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 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 |
|
from_uniform_bound(thickness=10, boundary_type='pml', kappa_start=1, kappa_end=1.5)
classmethod
¶
Creates a BoundaryConfig with uniform parameters for all boundaries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thickness
|
int
|
Grid thickness to use for all PML boundaries |
10
|
boundary_type
|
str
|
Type of boundary to use ("pml" or "periodic"). Defaults to "pml". |
'pml'
|
kappa_start
|
float
|
Initial kappa value for all boundaries. Defaults to 1.0. |
1
|
kappa_end
|
float
|
Final kappa value for all boundaries. Defaults to 1.5. |
1.5
|
Returns:
Name | Type | Description |
---|---|---|
BoundaryConfig |
BoundaryConfig
|
New config object with uniform parameters |
Source code in src/fdtdx/objects/boundaries/initialization.py
get_dict()
¶
Gets a dictionary mapping boundary names to their grid thicknesses.
Returns:
Type | Description |
---|---|
dict[str, int]
|
dict[str, int]: Dictionary with keys 'min_x', 'max_x', 'min_y', 'max_y', 'min_z', 'max_z' mapping to their respective grid thickness values. |
Source code in src/fdtdx/objects/boundaries/initialization.py
get_inside_boundary_slice()
¶
Gets slice objects for the non-PML interior region of the simulation volume.
Returns:
Type | Description |
---|---|
tuple[slice, slice, slice]
|
tuple[slice, slice, slice]: Three slice objects for indexing the x, y, z dimensions respectively, excluding the PML boundary regions. |
Source code in src/fdtdx/objects/boundaries/initialization.py
get_kappa_dict(prop)
¶
Gets a dictionary mapping boundary names to their kappa values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prop
|
Literal['kappa_start', 'kappa_end']
|
Which kappa property to get, either "kappa_start" or "kappa_end" |
required |
Returns:
Type | Description |
---|---|
dict[str, float]
|
dict[str, float]: Dictionary with keys 'min_x', 'max_x', 'min_y', 'max_y', 'min_z', 'max_z' mapping to their respective kappa values. |
Raises:
Type | Description |
---|---|
Exception
|
If prop is not "kappa_start" or "kappa_end" |
Source code in src/fdtdx/objects/boundaries/initialization.py
get_type_dict()
¶
Gets a dictionary mapping boundary names to their boundary types.
Returns:
Type | Description |
---|---|
dict[str, str]
|
dict[str, str]: Dictionary with keys 'min_x', 'max_x', 'min_y', 'max_y', 'min_z', 'max_z' mapping to their respective boundary types ("pml" or "periodic"). |
Source code in src/fdtdx/objects/boundaries/initialization.py
Configuration object for specifying at which side of the simulation wich type of boundary should be used. Also allows specification of the PML thickness and other parameters if used.
fdtdx.objects.boundaries.boundary_objects_from_config(config, volume)
¶
Creates boundary objects from a boundary configuration.
Creates PerfectlyMatchedLayer or PeriodicBoundary objects for all six boundaries (min/max x/y/z) based on the provided configuration. Also generates position constraints to properly place the boundary objects relative to the simulation volume.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
BoundaryConfig
|
Configuration object containing boundary parameters |
required |
volume
|
SimulationObject
|
The main simulation volume object that the boundaries will surround |
required |
Returns:
Type | Description |
---|---|
tuple[dict[str, Union[PerfectlyMatchedLayer, PeriodicBoundary]], list[PositionConstraint]]
|
tuple containing: - dict mapping boundary names ('min_x', 'max_x', etc) to boundary objects - list of PositionConstraint objects for placing the boundaries |
Source code in src/fdtdx/objects/boundaries/initialization.py
Initializes the corresponding boundary objects based on the config object.
Boundary Objects¶
fdtdx.objects.boundaries.PerfectlyMatchedLayer
¶
Bases: BaseBoundary
Implements a Convolutional Perfectly Matched Layer (CPML) boundary condition.
The CPML absorbs outgoing electromagnetic waves with minimal reflection by using a complex coordinate stretching approach. This implementation supports arbitrary axis orientation and both positive/negative directions.
Attributes:
Name | Type | Description |
---|---|---|
axis |
int
|
Principal axis for PML (0=x, 1=y, 2=z) |
direction |
Literal['+', '-']
|
Direction along axis ("+" or "-") |
alpha |
float
|
Loss parameter for complex frequency shifting |
kappa_start |
float
|
Initial kappa stretching coefficient |
kappa_end |
float
|
Final kappa stretching coefficient |
color |
tuple[float, float, float]
|
RGB color tuple for visualization |
Source code in src/fdtdx/objects/boundaries/perfectly_matched_layer.py
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 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 |
|
descriptive_name: str
property
¶
Gets a human-readable name describing this PML boundary's location.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Description like "min_x" or "max_z" indicating position |
thickness: int
property
¶
Gets the thickness of the PML layer in grid points.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of grid points in the PML along its axis |
fdtdx.objects.boundaries.PeriodicBoundary
¶
Bases: BaseBoundary
Implements periodic boundary conditions.
The periodic boundary connects opposite sides of the simulation domain, making waves that exit one side reenter from the opposite side.
Attributes:
Name | Type | Description |
---|---|---|
axis |
int
|
Principal axis for periodicity (0=x, 1=y, 2=z) |
direction |
Literal['+', '-']
|
Direction along axis ("+" or "-") |
color |
tuple[float, float, float]
|
RGB color tuple for visualization |
Source code in src/fdtdx/objects/boundaries/periodic.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 |
|
descriptive_name: str
property
¶
Gets a human-readable name describing this periodic boundary's location.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Description like "min_x" or "max_z" indicating position |
thickness: int
property
¶
Gets the thickness of the periodic boundary layer in grid points.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of grid points in the boundary layer (always 1 for periodic) |