fdtdx.UniformGrid#
- class fdtdx.UniformGrid(*, spacing=null, center=(0, 0, 0))[source]#
Bases:
TreeClassUnresolved policy for a uniform rectilinear grid.
UniformGridis user intent, not the solver mesh itself. It records the physical cell spacing while the final simulation shape may still be unknown. Object placement resolves this policy to a concreteRectilinearGridonce the volume shape is known.Keeping uniform spacing here avoids a second scalar discretization source on
SimulationConfig. Uniform grids and explicitly non-uniform grids both enter the solver through the same realizedRectilinearGridstructure.The grid origin is at the center of the simulation domain. Edge arrays therefore span
[-N/2 * spacing, +N/2 * spacing]along each axis, giving the domain symmetric negative and positive coordinates.centershifts this physical center away from the geometric origin when non-zero.
Quick Reference#
Attributes
Methods
Attributes#
-
UniformGrid.center:
tuple[float,float,float]# Physical coordinate of the domain center in metres. Defaults to (0, 0, 0).
- UniformGrid.is_uniform#
Uniform policies always represent equal cell widths.
- UniformGrid.min_spacing#
Smallest cell width implied by this policy.
-
UniformGrid.spacing:
float# Physical cell spacing in metres. Must be positive.
- UniformGrid.uniform_spacing#
Scalar cell width in metres.
Methods#
- UniformGrid.anchor_coordinate(axis, bounds, position)[source]#
Return a physical anchor coordinate inside a uniform interval.
- Return type:
float
- UniformGrid.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
- UniformGrid.axis_extent(axis, bounds)[source]#
Physical length covered by an index interval on one axis.
- Return type:
float
- UniformGrid.bounds_for_anchor(axis, size, anchor, position)[source]#
Choose a uniform-grid interval from an object anchor.
- Return type:
tuple[int,int]
- UniformGrid.bounds_for_center(axis, center, size)[source]#
Convert a physical center and grid size to edge bounds.
- Return type:
tuple[int,int]
- UniformGrid.cell_volume(slice_tuple)[source]#
Return per-cell volumes for a slice on this uniform policy.
- Return type:
Array
- UniformGrid.coord_to_index(axis, coord, snap='nearest')[source]#
Map a physical coordinate to a uniform-grid edge index.
Because unresolved policies do not yet know
shape, this helper uses a center-relative basis:coordis interpreted relative toself.center[axis]and the returned index is a center-relative edge offset. UseRectilinearGrid.coord_to_index()on the resolved grid when you need absolute edge indices.- Return type:
int
- UniformGrid.face_area(axis, slice_tuple)[source]#
Return per-face areas for a slice on this uniform policy.
- Return type:
Array
- UniformGrid.get_class_fields()#
- Return type:
list[TreeClassField]
- UniformGrid.get_public_fields()#
- Return type:
list[TreeClassField]
- UniformGrid.length_to_cell_count(axis, length, snap='nearest')[source]#
Convert a physical length to a uniform-grid cell count.
- Return type:
int
- UniformGrid.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!