fdtdx.QuasiUniformGrid#
- class fdtdx.QuasiUniformGrid(*, dx=null, dy=null, dz=null, center=(0, 0, 0))[source]#
Bases:
TreeClassUnresolved policy for a rectilinear grid with independent per-axis spacings.
QuasiUniformGridgeneralisesUniformGridto allow different cell widths along x, y, and z while keeping each axis internally uniform. This is sometimes called a quasi-uniform or anisotropic-uniform mesh: the grid is rectilinear and axis-aligned, but the aspect ratio is not 1 : 1 : 1.Like
UniformGrid, this is user intent rather than the solver mesh. Callingresolve()converts the policy to a concreteRectilinearGridonce the simulation shape is known. The resulting grid is centered atcenterso that coordinates span symmetrically into both negative and positive values along every axis.Example:
grid = QuasiUniformGrid(dx=10e-9, dy=10e-9, dz=20e-9) resolved = grid.resolve(shape=(100, 100, 50)) # x, y edges span [-500 nm, +500 nm]; z edges span [-500 nm, +500 nm]
Quick Reference#
Attributes
Methods
Attributes#
-
QuasiUniformGrid.center:
tuple[float,float,float]# Physical coordinate of the domain center in metres. Defaults to (0, 0, 0).
-
QuasiUniformGrid.dx:
float# Cell width along x in metres. Must be positive.
-
QuasiUniformGrid.dy:
float# Cell width along y in metres. Must be positive.
-
QuasiUniformGrid.dz:
float# Cell width along z in metres. Must be positive.
- QuasiUniformGrid.is_uniform#
True only when all three spacings are equal.
- QuasiUniformGrid.min_spacing#
Smallest cell width across all three axes in metres.
Methods#
- QuasiUniformGrid.aset(attr_name, val, create_new_ok=False)#
Sets an attribute of this class. In contrast to the classical .at[].set(), this method updates the class attribute directly and does not only operate on jax pytree leaf nodes. Instead, replaces the full attribute with the new value.
The attribute can either be the attribute name of this class, or for nested classes it can also be the attribute name of a class, which itself is an attribute of this class. The syntax for this operation could look like this: “a->b->[0]->[‘name’]”. Here, the current class has an attribute a, which has an attribute b, which is a list, which we index at index 0, which is an element of type dictionary, which we index using the dictionary key ‘name’.
Note that dictionary keys cannot contain square brackets or single quotes (even if they are escaped).
- Parameters:
attr_name (str) – Name of attribute to set
val (Any) – Value to set the attribute to
create_new_ok (bool, optional) – If false (default), throw an error if the attribute does not exist. If true, creates a new attribute if the attribute name does not exist yet.
- Returns:
Updated instance with new attribute value
- Return type:
Self
- QuasiUniformGrid.axis_extent(axis, bounds)[source]#
Physical length covered by an index interval on one axis.
- Return type:
float
- QuasiUniformGrid.axis_spacing(axis)[source]#
Return the cell width for a single axis.
- Return type:
float
- QuasiUniformGrid.cell_volume(slice_tuple)[source]#
Return per-cell volume weights broadcast to a 3D slice shape.
- Return type:
Array
- QuasiUniformGrid.coord_to_index(axis, coord, snap='nearest')[source]#
Map a physical coordinate to a grid edge index along
axis.Coordinates are measured from
self.center[axis].- Return type:
int
- QuasiUniformGrid.face_area(axis, slice_tuple)[source]#
Return per-face area weights for a detector plane normal to
axis.- Return type:
Array
- QuasiUniformGrid.get_class_fields()#
- Return type:
list[TreeClassField]
- QuasiUniformGrid.get_public_fields()#
- Return type:
list[TreeClassField]
- QuasiUniformGrid.length_to_cell_count(axis, length, snap='nearest')[source]#
Convert a physical length to a cell count along
axis.- Return type:
int
- QuasiUniformGrid.resolve(shape)[source]#
Return a concrete
RectilinearGridforshape.Edge arrays are built independently for each axis using the per-axis spacing and the requested number of cells. The domain is centered at
self.center.- Parameters:
shape (
tuple[int,int,int]) – Number of cells in(x, y, z).- Return type:
- Returns:
A
RectilinearGridwhose edge arrays are piecewise-uniform (one constant spacing per axis) and span symmetrically aroundself.center.- Raises:
ValueError – If any axis has an odd cell count. The center-origin convention requires even cell counts on every axis so the domain center always lands on a cell edge. An odd count silently shifts which Yee component sits at object boundaries, changing the effective simulated length by one cell.
- QuasiUniformGrid.slice_extent(slice_tuple)[source]#
Physical side lengths covered by a 3D grid slice.
- Return type:
tuple[float,float,float]
If you find any errors in the documentation, please report them in the Github Issues!