From 2a72555d25d8fce3e51bdc5dbf0e99facd7a6306 Mon Sep 17 00:00:00 2001 From: nicomerino Date: Wed, 19 Jun 2024 10:22:00 +0200 Subject: [PATCH] Renaming --- src/kernel/outwards.jl | 20 ++++++++++---------- test/integration.jl | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/kernel/outwards.jl b/src/kernel/outwards.jl index d19cc9f..97b5baa 100644 --- a/src/kernel/outwards.jl +++ b/src/kernel/outwards.jl @@ -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 diff --git a/test/integration.jl b/test/integration.jl index 1a8a0b3..778d72a 100644 --- a/test/integration.jl +++ b/test/integration.jl @@ -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)