11# mul! done by convolutions
2- function LinearAlgebra. mul! (x_temp:: AbstractVector{T} , A:: DerivativeOperator , x:: AbstractVector{T} ) where T<: Real
3- convolve_BC_left! (x_temp, x, A)
4- convolve_interior! (x_temp, x, A)
5- convolve_BC_right! (x_temp, x, A)
2+ function LinearAlgebra. mul! (x_temp:: AbstractVector{T} , A:: DerivativeOperator , x:: AbstractVector{T} ; overwrite = true ) where T<: Real
3+ convolve_BC_left! (x_temp, x, A, overwrite = overwrite )
4+ convolve_interior! (x_temp, x, A, overwrite = overwrite )
5+ convolve_BC_right! (x_temp, x, A, overwrite = overwrite )
66end
77
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 ) where {T<: Real }
11+ function convolve_interior! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator ; overwrite = true ) where {T<: Real }
1212 @assert length (x_temp)+ 2 == length (x)
1313 stencil = A. stencil_coefs
1414 coeff = A. coefficients
@@ -21,11 +21,11 @@ function convolve_interior!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::
2121 for idx in 1 : A. stencil_length
2222 xtempi += cur_coeff * cur_stencil[idx] * x[i - mid + idx]
2323 end
24- x_temp[i] = xtempi
24+ x_temp[i] = xtempi + ! overwrite * x_temp[i]
2525 end
2626end
2727
28- function convolve_BC_left! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator ) where {T<: Real }
28+ function convolve_BC_left! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator ; overwrite = true ) where {T<: Real }
2929 stencil = A. low_boundary_coefs
3030 coeff = A. coefficients
3131 for i in 1 : A. boundary_point_count
@@ -36,11 +36,11 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::D
3636 for idx in 2 : A. boundary_stencil_length
3737 xtempi += cur_coeff * cur_stencil[idx] * x[idx]
3838 end
39- x_temp[i] = xtempi
39+ x_temp[i] = xtempi + ! overwrite * x_temp[i]
4040 end
4141end
4242
43- function convolve_BC_right! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator ) where {T<: Real }
43+ function convolve_BC_right! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator ; overwrite = true ) where {T<: Real }
4444 stencil = A. high_boundary_coefs
4545 coeff = A. coefficients
4646 for i in 1 : A. boundary_point_count
@@ -51,14 +51,14 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::
5151 for idx in (A. boundary_stencil_length- 1 ): - 1 : 1
5252 xtempi += cur_coeff * cur_stencil[end - idx] * x[end - idx]
5353 end
54- x_temp[end - A. boundary_point_count+ i] = xtempi
54+ x_temp[end - A. boundary_point_count+ i] = xtempi + ! overwrite * x_temp[ end - A . boundary_point_count + i]
5555 end
5656end
5757
5858# ##########################################
5959
6060# Against A BC-padded vector, specialize the computation to explicitly use the left, right, and middle parts
61- function convolve_interior! (x_temp:: AbstractVector{T} , _x:: BoundaryPaddedVector , A:: DerivativeOperator ) where {T<: Real }
61+ function convolve_interior! (x_temp:: AbstractVector{T} , _x:: BoundaryPaddedVector , A:: DerivativeOperator ; overwrite = true ) where {T<: Real }
6262 stencil = A. stencil_coefs
6363 coeff = A. coefficients
6464 x = _x. u
@@ -72,11 +72,11 @@ function convolve_interior!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
7272 @inbounds for idx in 1 : A. stencil_length
7373 xtempi += cur_coeff * cur_stencil[idx] * x[(i- 1 ) - (mid- idx) + 1 ]
7474 end
75- x_temp[i] = xtempi
75+ x_temp[i] = xtempi + ! overwrite * x_temp[i]
7676 end
7777end
7878
79- function convolve_BC_left! (x_temp:: AbstractVector{T} , _x:: BoundaryPaddedVector , A:: DerivativeOperator ) where {T<: Real }
79+ function convolve_BC_left! (x_temp:: AbstractVector{T} , _x:: BoundaryPaddedVector , A:: DerivativeOperator ; overwrite = true ) where {T<: Real }
8080 stencil = A. low_boundary_coefs
8181 coeff = A. coefficients
8282 for i in 1 : A. boundary_point_count
@@ -87,7 +87,7 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
8787 @inbounds for idx in 2 : A. boundary_stencil_length
8888 xtempi += cur_coeff * cur_stencil[idx] * _x. u[idx- 1 ]
8989 end
90- x_temp[i] = xtempi
90+ x_temp[i] = xtempi + ! overwrite * x_temp[i]
9191 end
9292 # need to account for x.l in first interior
9393 mid = div (A. stencil_length,2 ) + 1
@@ -101,10 +101,10 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
101101 @inbounds for idx in 2 : A. stencil_length
102102 xtempi += cur_coeff * cur_stencil[idx] * x[(i- 1 ) - (mid- idx) + 1 ]
103103 end
104- x_temp[i] = xtempi
104+ x_temp[i] = xtempi + ! overwrite * x_temp[i]
105105end
106106
107- function convolve_BC_right! (x_temp:: AbstractVector{T} , _x:: BoundaryPaddedVector , A:: DerivativeOperator ) where {T<: Real }
107+ function convolve_BC_right! (x_temp:: AbstractVector{T} , _x:: BoundaryPaddedVector , A:: DerivativeOperator ; overwrite = true ) where {T<: Real }
108108 stencil = A. high_boundary_coefs
109109 coeff = A. coefficients
110110 bc_start = length (_x. u) - A. boundary_point_count
@@ -120,7 +120,7 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
120120 @inbounds for idx in 1 : A. stencil_length- 1
121121 xtempi += cur_coeff * cur_stencil[idx] * x[(i- 1 ) - (mid- idx) + 1 ]
122122 end
123- x_temp[i] = xtempi
123+ x_temp[i] = xtempi + ! overwrite * x_temp[i]
124124 for i in 1 : A. boundary_point_count
125125 cur_stencil = stencil[i]
126126 cur_coeff = typeof (coeff) <: AbstractVector ? coeff[bc_start + i] : coeff isa Number ? coeff : true
@@ -129,6 +129,25 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
129129 @inbounds for idx in A. stencil_length: - 1 : 1
130130 xtempi += cur_coeff * cur_stencil[end - idx] * _x. u[end - idx+ 1 ]
131131 end
132- x_temp[bc_start + i] = xtempi
132+ x_temp[bc_start + i] = xtempi + ! overwrite* x_temp[bc_start + i]
133+ end
134+ end
135+
136+ # ##########################################
137+
138+ function convolve_interior_add_range! (x_temp:: AbstractVector{T} , x:: AbstractVector{T} , A:: DerivativeOperator , offset:: Int ) where {T<: Real }
139+ @assert length (x_temp)+ 2 == length (x)
140+ stencil = A. stencil_coefs
141+ coeff = A. coefficients
142+ mid = div (A. stencil_length,2 )
143+ for i in [(1 + A. boundary_point_count): (A. boundary_point_count+ offset); (length (x_temp)- A. boundary_point_count- offset+ 1 ): (length (x_temp)- A. boundary_point_count)]
144+ xtempi = zero (T)
145+ cur_stencil = eltype (stencil) <: AbstractVector ? stencil[i] : stencil
146+ cur_coeff = typeof (coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
147+ cur_stencil = use_winding (A) && cur_coeff < 0 ? reverse (cur_stencil) : cur_stencil
148+ for idx in 1 : A. stencil_length
149+ xtempi += cur_coeff * cur_stencil[idx] * x[i - mid + idx]
150+ end
151+ x_temp[i] += xtempi
133152 end
134153end
0 commit comments