Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,12 @@ See also: [`set!`](@ref), [`compatible`](@ref).
function op!(f::F, ϕ::Field, ϕs::Field...; check::Bool=true) where {F}
check && check_compatible(ϕ, ϕs...)
g = getgrid(ϕ)
idxs = CartesianIndices(g)
idxs = interior(g) # padded indices of the interior cells, for `cell_center`
ϕint = interior(ϕ)
ϕsint = map(interior, ϕs)
AK.foreachindex(ϕint; backend=AK.get_backend(g)) do j
idx = idxs[j]
x = cell_center(g, idx)
ϕint[j] = f(x, ϕint[idx], map(φ -> φ[idx], ϕsint)...)
x = cell_center(g, idxs[j])
ϕint[j] = f(x, ϕint[j], map(φ -> φ[j], ϕsint)...)
end
return ϕ
end
Expand Down
9 changes: 9 additions & 0 deletions test/fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
@test eltype(u32) === Float32
end

@testset "op! sees the same cell as set!" begin
# Non-square 2D grid: a padded/interior index mix-up shifts or scrambles cells.
g = CartesianGrid(((0.0, 1.0), (0.0, 2.0)), (3, 5))
f(x) = x[1] + 10 * x[2]
u = set!(f, scalar_field(g))
op!((x, a) -> a - f(x), u)
@test maximum(abs, collect(interior(u))) < 1e-12
end

@testset "component extraction" begin
g = CartesianGrid(((0.0, 1.0), (0.0, 1.0)), (3, 3))
v = set!(x -> SVector(x[1], -x[2]), vector_field(g))
Expand Down
Loading