Skip to content

Grid

# homemade_conslaws.GridType.

Grid

A type representing a grid. Contains the cell averages and determines how to loop over the grid.

source

Dispatch functions

An implementation of Grid should provide the following functions:

# homemade_conslaws.cell_centersFunction.

cell_centers(::Grid)

Returns the cell centers of the grid.

source


# homemade_conslaws.cellsFunction.

cells(::Grid)

Returns the cell averages of the grid.

source


# homemade_conslaws.for_each_boundary_cellFunction.

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

source


# homemade_conslaws.for_each_interior_cellFunction.

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

source


# homemade_conslaws.for_each_cellFunction.

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

source


# homemade_conslaws.create_bufferFunction.

create_buffer(::Grid)

Preallocates a buffer of the same shape as the cells of the grid.

source

Implementations

# homemade_conslaws.UniformGrid1DType.

UniformGrid1D{BC <: BoundaryCondition, Float <: AbstractFloat, Cell} <: Grid1D{BC}

source


# homemade_conslaws.UniformGrid1DWallsType.

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.

source