comparison src/SbpOperators/stencil.jl @ 1594:d68d02dd882f feature/boundary_conditions

Merge with default
author Vidar Stiernström <vidar.stiernstrom@gmail.com>
date Sat, 25 May 2024 16:07:10 -0700
parents 8b9cdadb845a
children d8fabe814d06 dfb43fdac9fc
comparison
equal deleted inserted replaced
1591:615eeb6e662e 1594:d68d02dd882f
67 end 67 end
68 return s.weights[1 + i - s.range[1]] 68 return s.weights[1 + i - s.range[1]]
69 end 69 end
70 70
71 Base.@propagate_inbounds @inline function apply_stencil(s::Stencil, v::AbstractVector, i::Int) 71 Base.@propagate_inbounds @inline function apply_stencil(s::Stencil, v::AbstractVector, i::Int)
72 w = zero(promote_type(eltype(s),eltype(v))) 72 return sum(enumerate(s.weights)) do (k,w) #TBD: Which optimizations are needed here?
73 @simd for k ∈ 1:length(s) 73 w*v[i + @inbounds s.range[k]]
74 w += s.weights[k]*v[i + s.range[k]]
75 end 74 end
76
77 return w
78 end 75 end
79 76
80 Base.@propagate_inbounds @inline function apply_stencil_backwards(s::Stencil, v::AbstractVector, i::Int) 77 Base.@propagate_inbounds @inline function apply_stencil_backwards(s::Stencil, v::AbstractVector, i::Int)
81 w = zero(promote_type(eltype(s),eltype(v))) 78 return sum(enumerate(s.weights)) do (k,w) #TBD: Which optimizations are needed here?
82 @simd for k ∈ length(s):-1:1 79 w*v[i - @inbounds s.range[k]]
83 w += s.weights[k]*v[i - s.range[k]]
84 end 80 end
85 return w
86 end 81 end
82
83 # There are many options for the implementation of `apply_stencil` and
84 # `apply_stencil_backwards`. Some alternatives were tried on the branch
85 # bugfix/sbp_operators/stencil_return_type and can be found at the following
86 # revision:
87 #
88 # * 237b980ffb91 (baseline)
89 # * a72bab15228e (mapreduce)
90 # * ffd735354d54 (multiplication)
91 # * b5abd5191f2c (promote_op)
92 # * 8d56846185fc (return_type)
93 #
87 94
88 function left_pad(s::Stencil, N) 95 function left_pad(s::Stencil, N)
89 weights = LazyTensors.left_pad_tuple(s.weights, zero(eltype(s)), N) 96 weights = LazyTensors.left_pad_tuple(s.weights, zero(eltype(s)), N)
90 range = (first(s.range) - (N - length(s.weights))):last(s.range) 97 range = (first(s.range) - (N - length(s.weights))):last(s.range)
91 98