88# ###############################################
99
1010# Against a standard vector, assume already padded and just apply the stencil
11- function convolve_interior! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator ; overwrite = true ) where {T<: Real , N}
11+ function convolve_interior! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator{T,N,false} ; overwrite = true ) where {T<: Real , N}
1212 @assert length (x_temp)+ 2 == length (x)
1313 stencil = A. stencil_coefs
1414 coeff = A. coefficients
@@ -25,7 +25,7 @@ function convolve_interior!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::
2525 end
2626end
2727
28- function convolve_BC_left! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator ; overwrite = true ) where {T<: Real , N}
28+ function convolve_BC_left! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator{T,N,false} ; overwrite = true ) where {T<: Real , N}
2929 stencil = A. low_boundary_coefs
3030 coeff = A. coefficients
3131 for i in 1 : A. boundary_point_count
@@ -40,7 +40,7 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::D
4040 end
4141end
4242
43- function convolve_BC_right! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator ; overwrite = true ) where {T<: Real , N}
43+ function convolve_BC_right! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator{T,N,false} ; overwrite = true ) where {T<: Real , N}
4444 stencil = A. high_boundary_coefs
4545 coeff = A. coefficients
4646 for i in 1 : A. boundary_point_count
@@ -55,6 +55,97 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::
5555 end
5656end
5757
58+ # Against a standard vector, assume already padded and just apply the stencil
59+ function convolve_interior! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator{T,N,true} ; overwrite = true ) where {T<: Real , N}
60+ @assert length (x_temp)+ 2 == length (x)
61+ stencil = A. stencil_coefs
62+ coeff = A. coefficients
63+
64+ # Upwind operators have a non-centred stencil
65+ if use_winding (A)
66+ mid = 1 + A. stencil_length% 2
67+ else
68+ mid = div (A. stencil_length,2 )
69+ end
70+
71+ for i in (1 + A. boundary_point_count) : (length (x_temp)- A. boundary_point_count)
72+ xtempi = zero (T)
73+ cur_stencil = eltype (stencil) <: AbstractVector ? stencil[i- A. boundary_point_count] : stencil
74+ cur_coeff = typeof (coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
75+ cur_stencil = use_winding (A) && cur_coeff < 0 ? reverse (cur_stencil) : cur_stencil
76+ for idx in 1 : A. stencil_length
77+ x_idx = use_winding (A) && cur_coeff < 0 ? x[i + mid - idx] : x[i - mid + idx]
78+ xtempi += cur_coeff * cur_stencil[idx] * x_idx
79+ end
80+ x_temp[i] = xtempi + ! overwrite* x_temp[i]
81+ end
82+ end
83+
84+ function convolve_BC_left! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator{T,N,true} ; overwrite = true ) where {T<: Real , N}
85+ stencil = A. low_boundary_coefs
86+ coeff = A. coefficients
87+
88+ _bpc = A. boundary_point_count
89+ use_interior_stencil = false
90+ if isempty (stencil)
91+ _bpc = A. boundary_point_count + 1
92+ use_interior_stencil = true
93+ end
94+
95+ for i in 1 : _bpc
96+ if use_interior_stencil == true
97+ cur_stencil = A. stencil_coefs
98+ slen = length (A. stencil_coefs)
99+ else
100+ cur_stencil = stencil[i]
101+ slen = length (cur_stencil)
102+ end
103+
104+ cur_coeff = typeof (coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
105+ cur_stencil = use_winding (A) && cur_coeff < 0 ? reverse (cur_stencil) : cur_stencil
106+ xtempi = cur_coeff* cur_stencil[1 ]* x[1 ]
107+ for idx in 2 : slen
108+ xtempi += cur_coeff * cur_stencil[idx] * x[idx]
109+ end
110+ x_temp[i] = xtempi + ! overwrite* x_temp[i]
111+ end
112+ end
113+
114+ function convolve_BC_right! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator{T,N,true} ; overwrite = true ) where {T<: Real , N}
115+ stencil = A. high_boundary_coefs
116+ coeff = A. coefficients
117+ x_len = length (x)
118+ L = A. boundary_stencil_length
119+
120+ _bpc = A. boundary_point_count
121+ use_interior_stencil = false
122+
123+ if isempty (stencil)
124+ _bpc = 1
125+ use_interior_stencil = true
126+ end
127+
128+ for i in 1 : _bpc
129+ if use_interior_stencil == true
130+ cur_stencil = A. stencil_coefs
131+ slen = length (A. stencil_coefs)
132+ L = A. stencil_length
133+ else
134+ cur_stencil = stencil[i]
135+ slen = length (cur_stencil)
136+ end
137+
138+ cur_coeff = typeof (coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
139+ cur_stencil = use_winding (A) && cur_coeff < 0 ? reverse (cur_stencil) : cur_stencil
140+ xtempi = zero (T)
141+ for idx in 1 : slen
142+ xtempi += cur_coeff * cur_stencil[idx] * x[x_len- L+ idx]
143+ end
144+ x_temp[end - _bpc+ i] = xtempi + ! overwrite* x_temp[end - _bpc+ i]
145+ end
146+ end
147+
148+
58149# ##########################################
59150
60151# Against A BC-padded vector, specialize the computation to explicitly use the left, right, and middle parts
0 commit comments