bf.grids¶
grids ¶
Cell edges for non-uniform rectilinear grids.
:func:graded_edges places the cell edges of one axis: cells no larger than a spacing, finer in given
regions, growing by at most a fixed ratio from one cell to the next, with given coordinates (layer
interfaces, for example) exactly on edges. :meth:bifrost.StackDevice.rectilinear_grid turns such edges
into the fdtdx grid of a device's box.
The smallest cell sets the time step of the whole simulation, so refining saves cells and memory, not time steps.
graded_edges ¶
graded_edges(lo: float, hi: float, spacing: float, fine: Sequence[tuple[float, float, float]] = (), growth: float = 1.25, snap: Sequence[float] = (), uniform_ends: tuple[int, int] = (0, 0)) -> np.ndarray
Cell edges from lo to hi: at most spacing wide, finer where asked, smoothly graded.
The cell size at x is min(spacing, d_i + (growth - 1) dist(x, [a_i, b_i])) over the fine
regions (a_i, b_i, d_i): d_i inside a region, growing by about growth per cell away
from it. Between consecutive snap coordinates (and the ends) the edges spread that size
evenly, so every snap coordinate is an edge. A snap coordinate closer than half the local cell
size to another one (or to an end) is dropped, with a warning, rather than making a sliver of a
cell, which would shorten the time step of the whole simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lo
|
float
|
first edge. |
required |
hi
|
float
|
last edge. |
required |
spacing
|
float
|
largest cell. |
required |
fine
|
Sequence[tuple[float, float, float]]
|
(a, b, d) regions [a, b] with cells of at most d. |
()
|
growth
|
float
|
largest ratio of neighbouring cells away from a fine region (> 1). |
1.25
|
snap
|
Sequence[float]
|
coordinates that become edges (e.g. layer interfaces). |
()
|
uniform_ends
|
tuple[int, int]
|
the first and last this many cells are exactly |
(0, 0)
|
Returns:
| Type | Description |
|---|---|
ndarray
|
(n + 1,) strictly increasing edges, the first |
Raises:
| Type | Description |
|---|---|
ValueError
|
on an empty range, a nonpositive spacing or fine size, |
Source code in bifrost/grids.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 | |