Skip to content

Commit

Permalink
Add convenience method in stencils (#2221)
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski authored Mar 9, 2025
1 parent ba8e3ff commit e417013
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/Operators/finitedifference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3739,6 +3739,27 @@ end
right_idx(space)
end

@inline function should_call_left_boundary(idx, space, bc, loc)
(; op) = bc
return Operators.has_boundary(op, loc) &&
idx < Operators.left_interior_idx(
space,
op,
Operators.get_boundary(op, loc),
bc.args...,
)
end

@inline function should_call_right_boundary(idx, space, bc, loc)
(; op) = bc
return Operators.has_boundary(op, loc) &&
idx > Operators.right_interior_idx(
space,
bc.op,
Operators.get_boundary(bc.op, loc),
bc.args...,
)
end

Base.@propagate_inbounds function getidx(
parent_space,
Expand All @@ -3760,9 +3781,7 @@ Base.@propagate_inbounds function getidx(
)
space = reconstruct_placeholder_space(axes(bc), parent_space)
op = bc.op
if has_boundary(op, loc) &&
idx <
left_interior_idx(space, bc.op, get_boundary(bc.op, loc), bc.args...)
if should_call_left_boundary(idx, space, bc, loc)
stencil_left_boundary(
op,
get_boundary(op, loc),
Expand All @@ -3787,9 +3806,7 @@ Base.@propagate_inbounds function getidx(
)
op = bc.op
space = reconstruct_placeholder_space(axes(bc), parent_space)
if has_boundary(op, loc) &&
idx >
right_interior_idx(space, bc.op, get_boundary(bc.op, loc), bc.args...)
if should_call_right_boundary(idx, space, bc, loc)
stencil_right_boundary(
op,
get_boundary(op, loc),
Expand Down

0 comments on commit e417013

Please sign in to comment.