fdtdx.BoundaryConfig

Bases: TreeClass

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:
  • 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.

from_uniform_bound classmethod

from_uniform_bound(
    thickness: int = 10,
    boundary_type: str = "pml",
    kappa_start: float = 1,
    kappa_end: float = 1.5,
) -> BoundaryConfig

Creates a BoundaryConfig with uniform parameters for all boundaries.

Parameters:
  • thickness (int, default: 10 ) –

    Grid thickness to use for all PML boundaries. Defaults to 10.

  • boundary_type (str, default: 'pml' ) –

    Type of boundary to use ("pml" or "periodic"). Defaults to "pml".

  • kappa_start (float, default: 1 ) –

    Initial kappa value for all boundaries. Defaults to 1.0.

  • kappa_end (float, default: 1.5 ) –

    Final kappa value for all boundaries. Defaults to 1.5.

Returns:
  • BoundaryConfig( BoundaryConfig ) –

    New config object with uniform parameters

Source code in src/fdtdx/objects/boundaries/initialization.py
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
@classmethod
def from_uniform_bound(
    cls,
    thickness: int = 10,
    boundary_type: str = "pml",
    kappa_start: float = 1,
    kappa_end: float = 1.5,
) -> "BoundaryConfig":
    """Creates a BoundaryConfig with uniform parameters for all boundaries.

    Args:
        thickness (int, optional): Grid thickness to use for all PML boundaries. Defaults to 10.
        boundary_type (str, optional): Type of boundary to use ("pml" or "periodic"). Defaults to "pml".
        kappa_start (float, optional): Initial kappa value for all boundaries. Defaults to 1.0.
        kappa_end (float, optional): Final kappa value for all boundaries. Defaults to 1.5.

    Returns:
        BoundaryConfig: New config object with uniform parameters
    """
    return cls(
        boundary_type_minx=boundary_type,
        boundary_type_maxx=boundary_type,
        boundary_type_miny=boundary_type,
        boundary_type_maxy=boundary_type,
        boundary_type_minz=boundary_type,
        boundary_type_maxz=boundary_type,
        thickness_grid_minx=thickness,
        thickness_grid_maxx=thickness,
        thickness_grid_miny=thickness,
        thickness_grid_maxy=thickness,
        thickness_grid_minz=thickness,
        thickness_grid_maxz=thickness,
        kappa_start_minx=kappa_start,
        kappa_end_minx=kappa_end,
        kappa_start_maxx=kappa_start,
        kappa_end_maxx=kappa_end,
        kappa_start_miny=kappa_start,
        kappa_end_miny=kappa_end,
        kappa_start_maxy=kappa_start,
        kappa_end_maxy=kappa_end,
        kappa_start_minz=kappa_start,
        kappa_end_minz=kappa_end,
        kappa_start_maxz=kappa_start,
        kappa_end_maxz=kappa_end,
    )

get_dict

get_dict() -> dict[str, int]

Gets a dictionary mapping boundary names to their grid thicknesses.

Returns:
  • 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def get_dict(self) -> dict[str, int]:
    """Gets a dictionary mapping boundary names to their grid thicknesses.

    Returns:
        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.
    """
    return {
        "min_x": self.thickness_grid_minx,
        "max_x": self.thickness_grid_maxx,
        "min_y": self.thickness_grid_miny,
        "max_y": self.thickness_grid_maxy,
        "min_z": self.thickness_grid_minz,
        "max_z": self.thickness_grid_maxz,
    }

get_inside_boundary_slice

get_inside_boundary_slice() -> tuple[slice, slice, slice]

Gets slice objects for the non-PML interior region of the simulation volume.

Returns:
  • 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
def get_inside_boundary_slice(self) -> tuple[slice, slice, slice]:
    """Gets slice objects for the non-PML interior region of the simulation volume.

    Returns:
        tuple[slice, slice, slice]: Three slice objects for indexing the x, y, z dimensions
            respectively, excluding the PML boundary regions.
    """
    return (
        slice(
            self.thickness_grid_minx + 1 if self.boundary_type_minx == "pml" else 0,
            -self.thickness_grid_maxx - 1 if self.boundary_type_maxx == "pml" else None,
        ),
        slice(
            self.thickness_grid_miny + 1 if self.boundary_type_miny == "pml" else 0,
            -self.thickness_grid_maxy - 1 if self.boundary_type_maxy == "pml" else None,
        ),
        slice(
            self.thickness_grid_minz + 1 if self.boundary_type_minz == "pml" else 0,
            -self.thickness_grid_maxz - 1 if self.boundary_type_maxz == "pml" else None,
        ),
    )

get_kappa_dict

get_kappa_dict(
    prop: Literal["kappa_start", "kappa_end"],
) -> dict[str, float]

Gets a dictionary mapping boundary names to their kappa values.

Parameters:
  • prop (Literal['kappa_start', 'kappa_end']) –

    Which kappa property to get, either "kappa_start" or "kappa_end".

Returns:
  • 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:
  • Exception

    If prop is not "kappa_start" or "kappa_end"

Source code in src/fdtdx/objects/boundaries/initialization.py
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
def get_kappa_dict(
    self,
    prop: Literal["kappa_start", "kappa_end"],
) -> dict[str, float]:
    """Gets a dictionary mapping boundary names to their kappa values.

    Args:
        prop (Literal["kappa_start", "kappa_end"]): Which kappa property to get,
            either "kappa_start" or "kappa_end".

    Returns:
        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:
        Exception: If prop is not "kappa_start" or "kappa_end"
    """
    if prop == "kappa_start":
        return {
            "min_x": self.kappa_start_minx,
            "max_x": self.kappa_start_maxx,
            "min_y": self.kappa_start_miny,
            "max_y": self.kappa_start_maxy,
            "min_z": self.kappa_start_minz,
            "max_z": self.kappa_start_maxz,
        }
    elif prop == "kappa_end":
        return {
            "min_x": self.kappa_end_minx,
            "max_x": self.kappa_end_maxx,
            "min_y": self.kappa_end_miny,
            "max_y": self.kappa_end_maxy,
            "min_z": self.kappa_end_minz,
            "max_z": self.kappa_end_maxz,
        }
    else:
        raise Exception(f"Unknown: {prop=}")

get_type_dict

get_type_dict() -> dict[str, str]

Gets a dictionary mapping boundary names to their boundary types.

Returns:
  • 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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def get_type_dict(self) -> dict[str, str]:
    """Gets a dictionary mapping boundary names to their boundary types.

    Returns:
        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").
    """
    return {
        "min_x": self.boundary_type_minx,
        "max_x": self.boundary_type_maxx,
        "min_y": self.boundary_type_miny,
        "max_y": self.boundary_type_maxy,
        "min_z": self.boundary_type_minz,
        "max_z": self.boundary_type_maxz,
    }