Skip to content

Commit

Permalink
Update fields
Browse files Browse the repository at this point in the history
  • Loading branch information
utkinis committed Oct 17, 2023
1 parent 2c59a56 commit 237ce07
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/BoundaryConditions/field_boundary_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/FastIce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 10 additions & 1 deletion src/Fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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

0 comments on commit 237ce07

Please sign in to comment.