diff --git a/src/BoundaryConditions/field_boundary_conditions.jl b/src/BoundaryConditions/field_boundary_conditions.jl index a42cebc3..2ffa9ded 100644 --- a/src/BoundaryConditions/field_boundary_conditions.jl +++ b/src/BoundaryConditions/field_boundary_conditions.jl @@ -30,7 +30,7 @@ end function _validate_boundary_conditions(bc::FieldBoundaryConditions, dim, side) for f in bc.fields - if halo(f, dim, side) < 1 + if (location(f, Val(dim)) == Center()) && (halo(f, dim, side) < 1) error("to apply boundary conditions, halo width must be at least 1") end end diff --git a/src/FastIce.jl b/src/FastIce.jl index 6070362c..63fa6cde 100644 --- a/src/FastIce.jl +++ b/src/FastIce.jl @@ -4,8 +4,8 @@ module FastIce include("Grids/Grids.jl") include("GridOperators.jl") include("Logging.jl") -include("Fields.jl") include("Architectures.jl") +include("Fields.jl") include("Utils/Utils.jl") include("BoundaryConditions/BoundaryConditions.jl") include("KernelLaunch.jl") diff --git a/src/Fields.jl b/src/Fields.jl index d34f4a20..c2e86e5a 100644 --- a/src/Fields.jl +++ b/src/Fields.jl @@ -8,7 +8,9 @@ using Adapt using OffsetArrays using KernelAbstractions -import FastIce.Grids: Location, CartesianGrid, coord +using FastIce.Grids +using FastIce.GridOperators +using FastIce.Architectures abstract type AbstractField{T,N,L} <: AbstractArray{T,N} end @@ -44,6 +46,8 @@ function Field(backend::Backend, grid::CartesianGrid, T::DataType, loc::L, halo: return Field{L}(data, halo, indices) end +Field(arch::Architecture, args...; kwargs...) = Field(backend(arch), args...; kwargs...) + expand_axis_halo(::Nothing) = (0, 0) expand_axis_halo(halo::Integer) = (halo, halo) expand_axis_halo(halo::Tuple) = (something(halo[1], 0), something(halo[2], 0)) @@ -124,4 +128,9 @@ function set!(f::Field{T,N}, grid::CartesianGrid{N}, fun::F; discrete=false, par return end +# grid operators +Base.@propagate_inbounds ∂(f::AbstractField, I, dim) = ∂(f, I, dim, location(f, dim)) +Base.@propagate_inbounds ∂(f::AbstractField, I, dim, ::Vertex) = ∂ᶜ(f, I, dim) +Base.@propagate_inbounds ∂(f::AbstractField, I, dim, ::Center) = ∂ᵛ(f, I, dim) + end