Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasmerino41 authored and rafaqz committed Jul 9, 2024
1 parent 5fd32c7 commit 2a72555
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/kernel/outwards.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,37 @@ is occupied.
Default is 1.0.
- `distancemethod`: [`DistanceMethod`](@ref) object for calculating distance between cells.
The default is [`CentroidToCentroid`](@ref).
- `mask_flag`: The default setting is `NoMask()`. Use `Mask()` to indicate that the grid is
- `maskbehavior`: The default setting is `IgnoreMaskEdges()`. Use `CheckMaskEdges()` to indicate that the grid is
masked, enabling the rule to perform boundary checking at mask edges. Not using
`Mask()` on a masked grid may result in the loss of individuals at the edges, but it comes
`CheckMaskEdges()` on a masked grid may result in the loss of individuals at the edges, but it comes
at a performance cost.
Pass grid name `Symbol`s to `R` and `W` type parameters to use specific grids.
"""

struct Mask end
struct NoMask end
struct CheckMaskEdges end
struct IgnoreMaskEdges end

struct OutwardsDispersal{R,W,S<:Stencils.AbstractKernelStencil, M} <: SetNeighborhoodRule{R,W}
stencil::S
mask_flag::M
maskbehavior::M
end

# Constructors for OutwardsDispersal
function OutwardsDispersal{R,W}(stencil::S; mask_flag::Union{Mask, NoMask}=NoMask()) where {R,W,S<:Stencils.AbstractKernelStencil}
OutwardsDispersal{R,W,S,typeof(mask_flag)}(stencil, mask_flag)
function OutwardsDispersal{R,W}(stencil::S; maskbehavior::Union{CheckMaskEdges, IgnoreMaskEdges}=IgnoreMaskEdges()) where {R,W,S<:Stencils.AbstractKernelStencil}
OutwardsDispersal{R,W,S,typeof(maskbehavior)}(stencil, maskbehavior)
end

function OutwardsDispersal{R,W}(; mask_flag::Union{Mask, NoMask}=NoMask(), kw...) where {R,W}
function OutwardsDispersal{R,W}(; maskbehavior::Union{CheckMaskEdges, IgnoreMaskEdges}=IgnoreMaskEdges(), kw...) where {R,W}
stencil = DispersalKernel(; kw...)
OutwardsDispersal{R,W,typeof(stencil),typeof(mask_flag)}(stencil, mask_flag)
OutwardsDispersal{R,W,typeof(stencil),typeof(maskbehavior)}(stencil, maskbehavior)
end

@inline function applyrule!(data, rule::OutwardsDispersal{R,W}, N, I) where {R,W}
N == zero(N) && return nothing

# Check if the current cell is masked, skip if it is
mask_data = if rule.mask_flag === NoMask() nothing else DynamicGrids.mask(data) end
mask_data = if rule.maskbehavior === IgnoreMaskEdges() nothing else DynamicGrids.mask(data) end
if !isnothing(mask_data) && !mask_data[I...]
return nothing
end
Expand Down
4 changes: 2 additions & 2 deletions test/integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ end
output_with_mask = ArrayOutput(init; tspan=1:1000, mask=mask_data)
a = sim!(output_with_mask, rule_with_mask)

@test sum(a[1]) sum(a[1000]) # Floating error should be smaller than 1.0
@test sum(a[1]) sum(a[1000]) # Floating error should be close to zero

# Run the simulation without a mask to check default works fine
output_without_mask = ArrayOutput(init; tspan=1:1000)
b = sim!(output_without_mask, rule_without_mask)

@test sum(b[1]) sum(b[1000]) # Floating error should be smaller than 1.0
@test sum(b[1]) sum(b[1000]) # Floating error should be close to zero

# Run the simulation with a mask but outdisp_without_mask
output_without_mask = ArrayOutput(init; tspan=1:1000, mask=mask_data)
Expand Down

0 comments on commit 2a72555

Please sign in to comment.