solver.py¶
LevelSetSolver
dataclass
¶
LevelSetSolver(
Δx: float,
Δt: float = 0,
n_total: int | None = None,
i_step: int | None = None,
t_total: float = 0,
Δt_reinitialize: float = 0.1,
κ_boost: float = 1,
n_slabfailure: int | None = None,
n_pad_pixels: int | None = None,
band_width: float | None = None,
fm_order: int | None = None,
n_pixels_xz0: tuple[int, int] | None = None,
n_pixels_xz: tuple[int, int] | None = None,
do_extend_line: bool = True,
do_φ_everywhere: bool | None = None,
domain: Domain | None = None,
raw_domain: Domain | None = None,
surface: (
StraightLineSurface
| ErrorFunctionSurface
| SemiCircularArcSurface
| QuarterCircularArcSurface
| None
) = None,
substrate: (
OneLayerSubstrate | TwoLayerSubstrate | MultiLayerSubstrate | None
) = None,
model: Isotropic | Step | ExponentialActivation | None = None,
gma: GeometricMechanicsAnalysis | None = None,
)
flowchart TD
erosionfront.levelset.solver.LevelSetSolver[LevelSetSolver]
erosionfront.levelset.base.LevelSetSolverBase[LevelSetSolverBase]
erosionfront.levelset.speed.LevelSetSpeedMethods[LevelSetSpeedMethods]
erosionfront.levelset.grid.LevelSetGridMethods[LevelSetGridMethods]
erosionfront.levelset.elementary.LevelSetElementaryMethods[LevelSetElementaryMethods]
erosionfront.levelset.data.LevelSetData[LevelSetData]
erosionfront.levelset.gradient.GradientMixin[GradientMixin]
erosionfront.levelset.shock.ShocksMixin[ShocksMixin]
erosionfront.levelset.export.ExportMixin[ExportMixin]
erosionfront.levelset.base.LevelSetSolverBase --> erosionfront.levelset.solver.LevelSetSolver
erosionfront.levelset.speed.LevelSetSpeedMethods --> erosionfront.levelset.base.LevelSetSolverBase
erosionfront.levelset.grid.LevelSetGridMethods --> erosionfront.levelset.speed.LevelSetSpeedMethods
erosionfront.levelset.elementary.LevelSetElementaryMethods --> erosionfront.levelset.grid.LevelSetGridMethods
erosionfront.levelset.data.LevelSetData --> erosionfront.levelset.elementary.LevelSetElementaryMethods
erosionfront.levelset.gradient.GradientMixin --> erosionfront.levelset.solver.LevelSetSolver
erosionfront.levelset.shock.ShocksMixin --> erosionfront.levelset.solver.LevelSetSolver
erosionfront.levelset.export.ExportMixin --> erosionfront.levelset.solver.LevelSetSolver
click erosionfront.levelset.solver.LevelSetSolver href "" "erosionfront.levelset.solver.LevelSetSolver"
click erosionfront.levelset.base.LevelSetSolverBase href "" "erosionfront.levelset.base.LevelSetSolverBase"
click erosionfront.levelset.speed.LevelSetSpeedMethods href "" "erosionfront.levelset.speed.LevelSetSpeedMethods"
click erosionfront.levelset.grid.LevelSetGridMethods href "" "erosionfront.levelset.grid.LevelSetGridMethods"
click erosionfront.levelset.elementary.LevelSetElementaryMethods href "" "erosionfront.levelset.elementary.LevelSetElementaryMethods"
click erosionfront.levelset.data.LevelSetData href "" "erosionfront.levelset.data.LevelSetData"
click erosionfront.levelset.gradient.GradientMixin href "" "erosionfront.levelset.gradient.GradientMixin"
click erosionfront.levelset.shock.ShocksMixin href "" "erosionfront.levelset.shock.ShocksMixin"
click erosionfront.levelset.export.ExportMixin href "" "erosionfront.levelset.export.ExportMixin"
Solver implementing level-set solution of geomorphic Hamilton-Jacobi eqn.
Subclasses LevelSetSolverBase and uses GradientMixin, ShocksMixin,
ExportMixin.
Parameters¶
See LevelSetSolverBase and its antecedents.
Attributes¶
φ: MaskedArray Signed-distance function φ grid, masked to narrow band across surface. Δφ_x: MaskedArray Finite-difference approx of ∂φ/∂x. Δφ_z: MaskedArray Finite-difference approx of ∂φ/∂z. Δ2φ_x2: MaskedArray Finite-difference approx of ∂2φ/∂x2. Δ2φ_z2: MaskedArray Finite-difference approx of ∂2φ/∂z2. β: MaskedArray Surface tilt angle grid. ξ_fn_β: Callable Surface-normal erosion speed model function ξ(β). ξ_model: MaskedArray Grid of model erosion speed ξ_model for narrow-band across the surface. ξ0: MaskedArray Grid of reference erosion speed ξ_0 for narrow-band across the surface. ξ: MaskedArray Grid of actual erosion speed ξ for narrow-band across the surface, computed as ξ = ξ_0 * ξ_model H_ls: MaskedArray Level-set numerical Hamiltonian (not to be confused with the geomorphic Hamiltonian) used in the HJE solution of erosion-front motion. Again computed for a narrow-band across the surface. dHlsdφx: MaskedArray Finite-difference approximation of the derivative of the level-set Hamiltonian wrt ∂φ/∂x. This term is used to compute a numerical viscosity such that we obtain a 'viscosity solution' of the HJE. Again computed for a narrow-band across the surface. dHlsdφz: MaskedArray Finite-difference approximation of the derivative of the level-set Hamiltonian wrt ∂φ/∂z. This term is used to compute a numerical viscosity such that we obtain a 'viscosity solution' of the HJE. Again computed for a narrow-band across the surface. κx: float Numerical viscosity in the x direction. Again computed for a narrow-band across the surface. κz: float Numerical viscosity in the x direction. Again computed for a narrow-band across the surface. dφdt: MaskedArray Rate of change of signed-distance function φ wrt time. Obtained from the (level-set) Hamilton-Jacobi equation. Again computed for a narrow-band across the surface. φ_next: MaskedArray | None Signed-distance function φ grid for the next time step. Again computed for a narrow-band across the surface. φ_everywhere: NDArray Signed-distance function φ computed across the whole grid. This field is not extrapolated by rather simply extended from the narrow band by filling the remaining grid cells with max/min values. φ_aux: NDArray | None An auxiliary grid used to compute which pixels are subject to 'slab failure'.
- Python package visualization
Methods:
-
__post_init__–Complete instantiation by computing domain, pixel size, offset.
-
above_or_below_ji–Test whether pixel i,j lies above or below surface.
-
above_or_below_xz–Test whether point x,z lies above or below surface.
-
compute_contour–Generate a continuous (for now) contour of grid function f.
-
compute_domain–(Re)build domain after resizing.
-
compute_line_pixel_offsets–Measure signed offsets between rasterized line pixels and line curve.
-
compute_pixel_dimensions–Calculate numbers of pixels spanning the grid.
-
compute_pixel_origin–Calculate pixel offset of domain x,z position (0,0).
-
evolve–Iteratively propagate the erosion front surface.
-
export_data–Tool to export time T slice data to HDF5 file.
-
export_metadata–Tool to simulation metadata to JSON file.
-
find_shock–Locate main break-in-slope by smoothing & changepoint detection.
-
find_shocks–Find breaks-in-slope in the set of T-sliced surfaces.
-
first_update–Set up time-stepping solution with requisite initializations.
-
fm_distance–Use fast marching to compute signed distance from a ref grid (zeroset).
-
fm_distance_everywhere–FM compute a narrowband signed distance and then extend everywhere.
-
fwd_back_differences–Compute forward, backward, mean & double finite differences.
-
get_extent–Get domain (x,z) extent.
-
get_front_points–Fetch points along erosion front surface aka zeroset of f.
-
get_line_points–Convert Shapely geometry Line into (x,z) points.
-
get_points_xz–Get surface (x,z) coordinates.
-
get_substrate_ξ0–Generate relative η grid (effective speed ξ0).
-
get_x_limits–Get domain x min, max.
-
get_z_limits–Get domain z min, max.
-
get_φ_next–Return next signed-distance grid φ_next or just φ if not available.
-
ij_to_xz–Convert pixel indices [i,j] into pixel center coords (x,z).
-
initialize–Initialize level-set solver.
-
ji_to_xz–Convert reversed pixel indices [j,i] into pixel center coords (x,z).
-
make_line–Convert surface (x,z) coordinates into a Shapely Line geometry.
-
make_polygon–Create a 'bounding' polygon from surface x,z points.
-
measure_normal_distance–Compute distance between line and point using Shapely.
-
measure_φ_ji–Compute signed distance between line and i,j pixel using Shapely.
-
measure_φ_xz–Compute signed distance between line and xz point using Shapely.
-
pad_domain–Expand the domain vertically by pixel width amounts.
-
pad_grid–Pad grid with specified number of pixels below and above.
-
rasterize_T_slices–Rasterize time T slices onto grids.
-
rasterize_line–Rasterize surface line as x,z points into grid pixels using Rasterio.
-
record_T_slice–Record selected sim data for a single time step.
-
redo_φ_everywhere–Reassign signed distance values to pixels beyond the narrow band.
-
update–Update grids for one time step of duration Δt.
-
xz_to_ij–Convert pixel center coords (x,z) into pixel indices [i,j].
__post_init__
¶
Complete instantiation by computing domain, pixel size, offset.
Attributes¶
raw_domain: Domain Model domain instance. n_pixels_xz: tuple[int, int]: Grid pixel size. n_pixels_xz0: tuple[int, int]: Origin location in pixels.
Source code in erosionfront/levelset/elementary.py
above_or_below_ji
¶
Test whether pixel i,j lies above or below surface.
Uses "in_rock_polygon" to test if pixel is within the bedrock or in the air. In other words, it tests which side of the surface zeroset the pixel lies.
The pixel center is used in this computation.
Parameters¶
ji: tuple[float,float] | NDArray Test pixel with reversed indexes. in_rock_polygon: Polygon Shapely polygon defining "below ground".
Atrributes¶
Uses ji_to_xz method.
Returns¶
-1 if "in the air" and +1 if "in the rock".
Source code in erosionfront/levelset/grid.py
above_or_below_xz
staticmethod
¶
Test whether point x,z lies above or below surface.
Uses "in_rock_polygon" to test if point is within the bedrock or in the air. In other words, it tests which side of the surface zeroset the point lies.
Parameters¶
xz: tuple[float,float] | NDArray Test point. in_rock_polygon: Polygon Shapely polygon defining "below ground".
Returns¶
-1 if "in the air" and +1 if "in the rock".
Source code in erosionfront/levelset/grid.py
compute_contour
¶
compute_contour(f: NDArray | MaskedArray, level: float = 0) -> NDArray
Generate a continuous (for now) contour of grid function f.
BUG: the contouring function actually returns a set of disjoint contour segments, often with more than one segment. Here it's incorrectly assumed these segments are contiguous and can simply be concatenated. This is not true! But to do better downstream use of this method needs to handle the segment set properly, which is going to be inconvenient.
Parameters¶
f: NDArray | MaskedArray Smooth grid (e.g., signed distance) on which to compute contour. level: float=0 Chosen contour level.
Attributes¶
Uses ij_to_xz method.
Returns¶
NDArray Single sequence of x,z contour coordinates as (2,N) array.
Source code in erosionfront/levelset/grid.py
compute_domain
staticmethod
¶
(Re)build domain after resizing.
Parameters¶
x: tuple | NDArray Vectors of x coordinates for which a domain geometry needs to be measured. z: tuple | NDArray Vectors of z coordinates for which a domain geometry needs to be measured. resolution: float Grid pixel size.
Returns¶
Domain Domain geometry class instance.
Source code in erosionfront/levelset/elementary.py
compute_line_pixel_offsets
¶
compute_line_pixel_offsets(
line: LineString, ρ: NDArray, do_φ_everywhere: bool | None = False
) -> NDArray
Measure signed offsets between rasterized line pixels and line curve.
Spatial aliasing during rasterization means each line pixel is likely offset a bit from the line curve, so this function computes these offsets.
Parameters¶
line: LineString ρ: NDArray
bool
Compute distances for all grid pixels, not just those not masked.
Attributes¶
Uses measure_φ_ji and above_or_below_ji methods.
Returns¶
NDArray Grid with signed-distance normal offsets from the line curve at each rasterized line pixel.
Source code in erosionfront/levelset/grid.py
compute_pixel_dimensions
staticmethod
¶
Calculate numbers of pixels spanning the grid.
Parameters¶
domain: Domain Grid domain geometry. resolution: float Grid pixel size.
Returns¶
tuple[int, int] Width and height of grid in pixel numbers.
Source code in erosionfront/levelset/elementary.py
compute_pixel_origin
staticmethod
¶
Calculate pixel offset of domain x,z position (0,0).
Parameters¶
domain: Domain Grid domain geometry. resolution: float Grid pixel size.
Returns¶
tuple[int, int] Pixel indexes of bottom-left origin of grid.
Source code in erosionfront/levelset/elementary.py
evolve
¶
evolve(
Δt: float = 0,
t_span: float | None = None,
n_steps: int | None = None,
Δt_reinitialize: float | None = None,
κ_boost: float = 1,
report_pc: int = 5,
n_record_steps: int = 5,
do_initial: bool = False,
do_timing: bool = False,
) -> None
Iteratively propagate the erosion front surface.
Parameters¶
Δt: float=0
Simulation time step.
t_span: float | None = None
Duration of simulation.
n_steps: int | None = None
Number of time steps to take in the simulation.
If neither t_span nor n_steps is specified,
If neither are, a single step is assumed.
Δt_reinitialize: float | None = None
Period of reinitialization of φ signed-distance function grid.
κ_boost: float = 1
Scale factor for boosting numerical viscosity.
report_pc: int = 5
Reporting interval as percentage of runtime.
n_record_steps: int = 5
Number of steps between T slicings.
do_initial: bool=False
Specify if this is the first update, and act accordingly.
do_timing: bool=False
Choose whether to perform timings of sim stages.
Attributes
Most of the sim grids are modified.
Source code in erosionfront/levelset/base.py
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 | |
export_data
¶
Tool to export time T slice data to HDF5 file.
Parameters¶
dir: str Path to directory to write HDF5 file into. filename: str="T_slices" Name of HDF file.
Source code in erosionfront/levelset/export.py
export_metadata
¶
Tool to simulation metadata to JSON file.
Parameters¶
dir: str Path to directory to write JSON file into. filename: str="metadata" Name of JSON file.
Source code in erosionfront/levelset/export.py
find_shock
¶
find_shock(
i_step: int,
method: ChangepointMethods = BINSEG,
i_max: int = 300,
n_filterwidth: int = 50,
which_changepoint: int = 1,
do_plot: bool = False,
) -> tuple[float, float]
Locate main break-in-slope by smoothing & changepoint detection.
Parameters¶
i_step: int
method: ChangepointMethods=ChangepointMethods.BINSEG
i_max: int=300
n_filterwidth: int=50
which_changepoint: int=1
do_plot: bool=False
Returns¶
tuple[float, float]: x, z coordinate of break-in-slope shock changepoint.
Source code in erosionfront/levelset/shock.py
find_shocks
¶
find_shocks(
method: ChangepointMethods = BINSEG,
subset: slice = s_[100:1000:50],
i_max: int = 1000,
n_filterwidth: int = 50,
which_changepoint=0,
i_plot: int = 200,
i_plot_offset: int = 50,
) -> None
Find breaks-in-slope in the set of T-sliced surfaces.
Parameters¶
method: ChangepointMethods=ChangepointMethods.BINSEG
subset: slice=np.s_[100:1000:50]
i_max: int=1000
n_filterwidth: int=50
which_changepoint=0,
i_plot: int=200
i_plot_offset: int=50
Attributes¶
Modifies shocks_xz with estimated locations of breaks-in-slope.
Source code in erosionfront/levelset/shock.py
first_update
¶
Set up time-stepping solution with requisite initializations.
Source code in erosionfront/levelset/solver.py
fm_distance
staticmethod
¶
fm_distance(
f: NDArray, band_width: float | None, resolution: float, order: int | None
) -> MaskedArray
Use fast marching to compute signed distance from a ref grid (zeroset).
The reference grid (typically travel time, but may be rasterized line offsets) provides a zero contour from which the signed distance is computed by fast marching.
Parameters¶
f: NDArray Reference grid to provide a zero contour. band_width: float | None, Width of the narrow band. resolution: float Grid pixel width (and height). order: int Fast-marching order of computational stencil (1 or 2).
Returns¶
MaskedArray Signed distance grid.
Source code in erosionfront/levelset/grid.py
fm_distance_everywhere
¶
fm_distance_everywhere(
φ: MaskedArray, φ_everywhere: NDArray, resolution: float, order: int | None
) -> NDArray
FM compute a narrowband signed distance and then extend everywhere.
The previous 'everywhere' grid of signed distance is used to supply values beyond the narrowband.
Parameters¶
φ: MaskedArray Reference grid to provide a zero contour. φ_everywhere: NDArray Previous grid of signed distance everywhere. resolution: float Grid pixel width (and height). order: int Fast-marching order of computational stencil (1 or [2]).
Attributes¶
Uses the fm_distance method.
Returns¶
MaskedArray Grid with signed distance values everywhere, not just on the nb.
Source code in erosionfront/levelset/grid.py
fwd_back_differences
staticmethod
¶
fwd_back_differences(
φ: MaskedArray, Δx: float
) -> tuple[MaskedArray, MaskedArray, MaskedArray, MaskedArray]
Compute forward, backward, mean & double finite differences.
Could perhaps use np.roll to make this process more efficient?
Parameters¶
φ: MaskedArray Signed distance grid. Δx: float Grid spacing in both x and z directions (assumed equal).
Returns¶
(Δφ_x, Δφ_z, Δ2φ_x2, Δ2φ_z2,): tuple[MaskedArray, MaskedArray, MaskedArray, MaskedArray] 1st-order (center-weighted) and 2nd-order φ finite differences.
Source code in erosionfront/levelset/gradient.py
get_extent
¶
Get domain (x,z) extent.
Returns¶
NDArray: Domain bounds as [x_min, x_max, z_max, z_min].
Source code in erosionfront/levelset/elementary.py
get_front_points
¶
Fetch points along erosion front surface aka zeroset of f.
Parameters¶
f: NDArray | MaskedArray Presumably a signed distance grid (but not necessarily).
Attributes¶
Uses compute_contour method.
Returns¶
NDArray Coordinate sequence (x,z)*N along surface as (2,N) array.
Source code in erosionfront/levelset/grid.py
get_line_points
¶
get_points_xz
¶
get_substrate_ξ0
¶
Generate relative η grid (effective speed ξ0).
Parameters¶
φ: MaskedArray Any grid of the size being used in the sim.
Attributes¶
substrate: OneLayerSubstrate | TwoLayerSubstrate | MultiLayerSubstrate Instance of class containing substrate info. surface.height: float Top height of surface above z=0 base. η_upperlayer: float Relative erodiblity of strong layer (weak layer assumed = 1). do_hardtop: bool Whether to fake a highly resistant, very thin, upper "caprock". do_hardbase: bool Whether to fake a highly resistant, very thin, lower "bedrock". η_hardtopbase: float Relative erodiblity of base/top layers (weak layer assumed = 1).
Returns¶
MaskedArray Modulated erodbility (ref speed) grid ξ0 across the narrow band.
Source code in erosionfront/levelset/speed.py
get_x_limits
¶
get_x_limits() -> tuple
Get domain x min, max.
Returns¶
tuple: x_min, x_max pair.
Source code in erosionfront/levelset/elementary.py
get_z_limits
¶
get_z_limits() -> tuple
Get domain z min, max.
Returns¶
tuple: z_min, z_max pair.
Source code in erosionfront/levelset/elementary.py
get_φ_next
¶
Return next signed-distance grid φ_next or just φ if not available.
Returns¶
MaskedArray: Next signed-distance φ grid or just current φ if next unavailable.
Source code in erosionfront/levelset/speed.py
ij_to_xz
¶
ij_to_xz(ij: NDArray | tuple) -> NDArray
Convert pixel indices [i,j] into pixel center coords (x,z).
Parameters¶
ij: NDArray | tuple Pixel index pairs [i,j] as numpy array or tuple.
Returns¶
NDArray: Pixel (x,z) coordinate pairs as float64 numpy array.
Source code in erosionfront/levelset/elementary.py
initialize
¶
initialize(do_timing: bool = False) -> None
Initialize level-set solver.
Parameters¶
do_timing: bool=False Perform timing estimates for each computational stage.
Attributes¶
Many class attributes are modified.
Source code in erosionfront/levelset/base.py
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 | |
ji_to_xz
¶
ji_to_xz(ji: NDArray | tuple) -> NDArray
Convert reversed pixel indices [j,i] into pixel center coords (x,z).
Parameters¶
ji: NDArray | tuple Pixel (reversed) index pairs [j,i] as numpy array or tuple.
Returns¶
NDArray: Pixel (x,z) coordinate pairs as float64 numpy array.
Source code in erosionfront/levelset/elementary.py
make_line
staticmethod
¶
Convert surface (x,z) coordinates into a Shapely Line geometry.
Parameters¶
points_xz: NDArray Stacked vectors of x and z surface point coordinates.
Returns¶
LineString: Shapely LineString geometry of surface line.
Source code in erosionfront/levelset/elementary.py
make_polygon
staticmethod
¶
Create a 'bounding' polygon from surface x,z points.
This polygon is used to decide whether a point lies within the bedrock or outside it.
BUG: Crudely done. Should be much tighter geometry close to domain.
Parameters¶
points_xz: NDArray Surface coordinates n_pixels_xz: tuple | NDArray Grid dimensions resolution: float Grid pixel size.
Returns¶
Polygon Shapely geometry of bounding polygon.
Source code in erosionfront/levelset/elementary.py
measure_normal_distance
staticmethod
¶
measure_normal_distance(
line: tuple | NDArray | LineString, point: tuple | NDArray | Point
) -> float
Compute distance between line and point using Shapely.
Parameters¶
line: tuple | NDArray | LineString Line represented by various possible types. point: tuple | NDArray | Point Coordinate (x,z) represented by various possible types.
Returns¶
float Perpendicular distance from line curve to point.
Source code in erosionfront/levelset/grid.py
measure_φ_ji
¶
Compute signed distance between line and i,j pixel using Shapely.
The sign is -1 for "in the air" and +1 for "in the rock".
Parameters¶
line: LineString Surface line. ji: tuple[int,int] | NDArray Pixel indexes in reversed format.
Attributes¶
Uses measure_φ_xz method to test which side of the surface the pixel lies.
Returns¶
float Signed perpendicular distance from the line to the pixel.
Source code in erosionfront/levelset/grid.py
measure_φ_xz
¶
Compute signed distance between line and xz point using Shapely.
The sign is -1 for "in the air" and +1 for "in the rock".
Parameters¶
line: LineString Surface line. xz: tuple[float,float] | NDArray Point coordinates.
Attributes¶
Uses above_or_below_xz method to test which side of the surface the point lies.
Returns¶
float Signed perpendicular distance from the line to the point.
Source code in erosionfront/levelset/grid.py
pad_domain
staticmethod
¶
Expand the domain vertically by pixel width amounts.
Parameters¶
domain: Domain (Initial) domain to be padded. resolution: float Grid pixel size. n_pad_pixels: int Number of pixel widths to pad by below the current domain.
Returns¶
New domain instance padded vertically.
Source code in erosionfront/levelset/elementary.py
pad_grid
staticmethod
¶
pad_grid(grid: NDArray, n_pad_pixels: int) -> NDArray
Pad grid with specified number of pixels below and above.
Parameters¶
grid: NDArray Grid to be padded. n_pad_pixels: int Number of pixels to pad below.
Returns¶
NDArray Padded grid.
Source code in erosionfront/levelset/elementary.py
rasterize_T_slices
¶
rasterize_T_slices(n_subset: int = 1) -> None
Rasterize time T slices onto grids.
Parameters¶
n_subset: int=1 Rate of subsetting of T slices (n=1 means all of them).
Source code in erosionfront/levelset/base.py
rasterize_line
¶
rasterize_line(points_xz: NDArray, do_extend_line: bool = True) -> NDArray
Rasterize surface line as x,z points into grid pixels using Rasterio.
The x,z bounds of the raster grid are precisely set by the bounding box of the line.
Parameters¶
points_xz: NDArray Surface line as a series of x,z points. do_extend_line: bool=True Artificially extend the surface line so it reaches the boundary.
Attributes¶
Uses n_pixels_xz and xz_to_ij methods.
Returns¶
NDArray Grid of rasterized line.
Source code in erosionfront/levelset/grid.py
record_T_slice
¶
Record selected sim data for a single time step.
Recorded data are placed in a 'T_slice' dictionary.
Parameters¶
step: int Simulation step number. t_total: float Total time in simulation so far.
Attributes¶
Data for this sim time step are appended to the time-slicing dict.
Source code in erosionfront/levelset/base.py
redo_φ_everywhere
staticmethod
¶
Reassign signed distance values to pixels beyond the narrow band.
Assumes that pixels beyond the narrow band have signed-distance signs that are currently correct: given these signs, each beyond-nb pixel is assigned either the min or max value of the nb signed-distance values.
Parameters¶
φ_everywhere: NDArray Beyond narrow-band signed-distance grid to be recomputed. φ: MaskedArray Narrow-band signed-distance grid.
Returns¶
NDArray Recomputed signed-distances beyond narrow band.
Source code in erosionfront/levelset/grid.py
update
¶
update(
Δt: float,
Δt_reinitialize: float | None = None,
do_finalize: bool = False,
do_timing: bool = False,
) -> None
Update grids for one time step of duration Δt.
The basic cycle needs to be:
set t=0, set up grids
- loop while t<=T_limit
- sometimes reinitialize signed distance φ(t) by fast marching
- back & forward gradients (Δφ_xp, Δφ_xm), (Δφ_zp, Δφ_zm)
- mean grad Δφ_x, Δφ_z = (Δφ_xp+Δφ_xm)/2, (Δφ_zp+Δφ_zm)/2
- dbl-diff Δ2φ_x2, Δ2φ_z2 = (Δφ_xp-Δφ_xm)/2, (Δφ_zp-Δφ_zm)/2
- slope angle from mean grad β = arctan2(Δφ_z, Δφ_x)
- front-normal speed from slope angle ξ(β)
- level-set Hamiltonian lsH(Δφ_x,Δφ_z) = ξ(β).|(Δφ_x, Δφ_z)|
- Hamiltonian derivatives lsH_{∂φ/∂x}, lsH_{∂φ/∂z} wrt ∂φ/∂x, ∂φ/∂z
- numerical viscosities κx, κz = max(lsH_{∂φ/∂x}), max(lsH_{∂φ/∂z})
- update rate dφ/dt = - lsH(Δφ_x, Δφ_z) - κx.Δ2φ_x2 - κz.Δ2φ_z2
- signed distance change Δφ = (∂φ/∂t).Δt
- signed distance update φ(t+Δt) = φ(t) + Δφ
- front T(x,z) from zero level-set {x,z} | φ(t)=0
- update time t -> t+Δt
- repeat
Parameters¶
Δt: float Time step. Δt_reinitialize: float | None=None Periodicity of reinitialization of φ signed-distance grid. do_finalize: bool=False Just finish up, don't do another loop of computation. do_timing: bool=False Measure and report compute times taken at steps during the loop.
Attributes¶
Most of the sim grids are modified.
Source code in erosionfront/levelset/solver.py
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 | |
xz_to_ij
¶
xz_to_ij(xz: NDArray | tuple) -> NDArray
Convert pixel center coords (x,z) into pixel indices [i,j].
Parameters¶
xz: NDArray | tuple Pixel (x,z) coordinate pairs as numpy array or tuple.
Returns¶
NDArray: Pixel index pairs [i,j] as int64 numpy array