Grid
#
homemade_conslaws.Grid
— Type.
Grid
A type representing a grid. Contains the cell averages and determines how to loop over the grid.
Dispatch functions
An implementation of Grid
should provide the following functions:
#
homemade_conslaws.cell_centers
— Function.
cell_centers(::Grid)
Returns the cell centers of the grid.
#
homemade_conslaws.cells
— Function.
cells(::Grid)
Returns the cell averages of the grid.
#
homemade_conslaws.for_each_boundary_cell
— Function.
for_each_boundary_cell(f, ::Grid, cells)
for_each_boundary_cell(f, ::Grid, left_reconstruction, right_reconstruction)
Calls f
on the the stencils centered at the boundary cells and their indices.
Example
Compute the forward difference reconstruction of the boundary cells
left_reconstruction, right_reconstruction = ... # Preallocated buffers
for_each_boundary_cell(grid, cells(grid)) do (left, center, right), idx
left_reconstruction[idx] = center - 0.5 * (right - center)
right_reconstruction[idx] = center + 0.5 * (right - center)
end
Compute the temporal derivative of the cell averages at the boundary cells.
out = ... # Preallocated buffer
for_each_boundary_cell(grid, left_reconstruction, right_reconstruction) do (lleft, lcenter, lright), (rleft, rcenter, rright), idx
left_flux = F(rcenter, lright, dx, dt)
right_flux = F(rleft, lcenter, dx, dt)
out[idx] = (left_flux - right_flux) / dx
end
#
homemade_conslaws.for_each_interior_cell
— Function.
for_each_interior_cell(f, ::Grid; p=1, q=p)
Calls f
on the cells and the index of every interior cell its p
and q
left and right neighbours, specified by the stencil size of the numerical flux.
Example
Compute the forward difference reconstruction of the interior cells:
left_reconstruction, right_reconstruction = ... # Preallocated buffers
for_each_interior_cell(grid; p=1, q=1) do cells, (left_idx, center_idx, right_idx)
left, center, right = cells[left_idx], cells[center_idx], cells[right_idx]
left_reconstruction[idx] = center - 0.5 * (right - center)
right_reconstruction[idx] = center + 0.5 * (right - center)
end
#
homemade_conslaws.for_each_cell
— Function.
for_each_cell(f, ::Grid)
Calls f
on the cells of the grid and each cell index.
Example
# Set all cells to zero
for_each_cell(grid) do cells, idx
cells[idx] = zero(eltype(cells))
end
#
homemade_conslaws.create_buffer
— Function.
create_buffer(::Grid)
Preallocates a buffer of the same shape as the cells of the grid.
Implementations
#
homemade_conslaws.UniformGrid1D
— Type.
UniformGrid1D{BC <: BoundaryCondition, Float <: AbstractFloat, Cell} <: Grid1D{BC}
#
homemade_conslaws.UniformGrid1DWalls
— Type.
UniformGrid1DWalls{Float <: AbstractFloat, CellFloat <: Number, Index <: Integer} <: Grid1D{WallsBC{Float}}
A uniform grid in 1D with walls starting and stopping at cell interfaces, specified by the WallsBC
boundary condition.