Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit e602ab3

Browse files
Merge pull request #167 from shivin9/Clean_Upwind
Removing unnecessary use_winding() calls
2 parents 1be5258 + 27c2e96 commit e602ab3

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

src/derivative_operators/convolutions.jl

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ function convolve_interior!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::
1818
xtempi = zero(T)
1919
cur_stencil = eltype(stencil) <: AbstractVector ? stencil[i-A.boundary_point_count] : stencil
2020
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
21-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
2221
for idx in 1:A.stencil_length
2322
xtempi += cur_coeff * cur_stencil[idx] * x[i - mid + idx]
2423
end
@@ -29,7 +28,6 @@ function convolve_interior!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::
2928
xtempi = zero(T)
3029
cur_stencil = eltype(stencil) <: AbstractVector ? stencil[i-A.boundary_point_count] : stencil
3130
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
32-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
3331
for idx in 1:A.stencil_length
3432
xtempi += cur_coeff * cur_stencil[idx] * x[i - mid + idx]
3533
end
@@ -44,7 +42,6 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::D
4442
for i in 1 : A.boundary_point_count
4543
cur_stencil = stencil[i]
4644
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
47-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
4845
xtempi = cur_coeff*stencil[i][1]*x[1]
4946
for idx in 2:A.boundary_stencil_length
5047
xtempi += cur_coeff * cur_stencil[idx] * x[idx]
@@ -59,7 +56,6 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::
5956
for i in 1 : A.boundary_point_count
6057
cur_stencil = stencil[i]
6158
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
62-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
6359
xtempi = cur_coeff*stencil[i][end]*x[end]
6460
for idx in (A.boundary_stencil_length-1):-1:1
6561
xtempi += cur_coeff * cur_stencil[end-idx] * x[end-idx]
@@ -75,11 +71,7 @@ function convolve_interior!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::
7571
coeff = A.coefficients
7672

7773
# Upwind operators have a non-centred stencil
78-
if use_winding(A)
79-
mid = 1 + A.stencil_length%2
80-
else
81-
mid = div(A.stencil_length,2)
82-
end
74+
mid = 1 + A.stencil_length%2
8375

8476
for i in (1+A.boundary_point_count) : (length(x_temp)-A.boundary_point_count)
8577
xtempi = zero(T)
@@ -115,7 +107,7 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::D
115107
end
116108

117109
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
118-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
110+
cur_stencil = cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
119111
xtempi = cur_coeff*cur_stencil[1]*x[1]
120112
for idx in 2:slen
121113
xtempi += cur_coeff * cur_stencil[idx] * x[idx]
@@ -149,7 +141,7 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::
149141
end
150142

151143
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
152-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
144+
cur_stencil = cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
153145
xtempi = zero(T)
154146
for idx in 1:slen
155147
xtempi += cur_coeff * cur_stencil[idx] * x[x_len-L+idx]
@@ -172,7 +164,6 @@ function convolve_interior!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
172164
xtempi = zero(T)
173165
cur_stencil = eltype(stencil) <: AbstractVector ? stencil[i-A.boundary_point_count] : stencil
174166
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i-A.boundary_point_count] : coeff isa Number ? coeff : true
175-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
176167
@inbounds for idx in 1:A.stencil_length
177168
xtempi += cur_coeff * cur_stencil[idx] * x[(i-1) - (mid-idx) + 1]
178169
end
@@ -187,7 +178,6 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
187178
cur_stencil = stencil[i]
188179
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
189180
xtempi = cur_coeff*cur_stencil[1]*_x.l
190-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
191181
@inbounds for idx in 2:A.boundary_stencil_length
192182
xtempi += cur_coeff * cur_stencil[idx] * _x.u[idx-1]
193183
end
@@ -200,7 +190,6 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
200190
xtempi = zero(T)
201191
cur_stencil = eltype(A.stencil_coefs) <: AbstractVector ? A.stencil_coefs[i-A.boundary_point_count] : A.stencil_coefs
202192
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i-A.boundary_point_count] : coeff isa Number ? coeff : true
203-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
204193
xtempi = cur_coeff*cur_stencil[1]*_x.l
205194
@inbounds for idx in 2:A.stencil_length
206195
xtempi += cur_coeff * cur_stencil[idx] * x[(i-1) - (mid-idx) + 1]
@@ -219,7 +208,6 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
219208
xtempi = zero(T)
220209
cur_stencil = eltype(A.stencil_coefs) <: AbstractVector ? A.stencil_coefs[i-A.boundary_point_count] : A.stencil_coefs
221210
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i-A.boundary_point_count] : coeff isa Number ? coeff : true
222-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
223211
xtempi = cur_coeff*cur_stencil[end]*_x.r
224212
@inbounds for idx in 1:A.stencil_length-1
225213
xtempi += cur_coeff * cur_stencil[idx] * x[(i-1) - (mid-idx) + 1]
@@ -229,7 +217,6 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
229217
cur_stencil = stencil[i]
230218
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[bc_start + i] : coeff isa Number ? coeff : true
231219
xtempi = cur_coeff*cur_stencil[end]*_x.r
232-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
233220
@inbounds for idx in A.stencil_length:-1:1
234221
xtempi += cur_coeff * cur_stencil[end-idx] * _x.u[end-idx+1]
235222
end
@@ -252,14 +239,14 @@ function convolve_interior!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
252239
xtempi = zero(T)
253240
cur_stencil = eltype(stencil) <: AbstractVector ? stencil[i-A.boundary_point_count] : stencil
254241
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i-A.boundary_point_count] : coeff isa Number ? coeff : true
255-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
242+
cur_stencil = cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
256243
@inbounds for idx in 1:A.stencil_length
257244
if i-mid+idx == 1
258245
x_idx = _x.l
259246
elseif i-mid+idx == x_len
260247
x_idx = _x.r
261248
else
262-
x_idx = use_winding(A) && cur_coeff < 0 ? x[i + mid - idx - 1] : x[i - mid + idx - 1]
249+
x_idx = cur_coeff < 0 ? x[i + mid - idx - 1] : x[i - mid + idx - 1]
263250
end
264251
xtempi += cur_coeff * cur_stencil[idx] * x_idx
265252
end
@@ -290,7 +277,7 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
290277
end
291278

292279
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
293-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
280+
cur_stencil = cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
294281

295282
# need to account for x.l in first interior
296283
xtempi = cur_coeff*cur_stencil[1]*_x.l
@@ -308,7 +295,6 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
308295
bpc = A.boundary_point_count
309296

310297
# need to account for _x.r in last interior convolution
311-
mid = div(A.stencil_length,2) + 1
312298
x = _x.u
313299
i = length(x_temp)-A.boundary_point_count
314300
L = A.boundary_stencil_length
@@ -333,7 +319,7 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
333319

334320
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[end-_bpc+i] : coeff isa Number ? coeff : true
335321
xtempi = cur_coeff*cur_stencil[end]*_x.r
336-
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
322+
cur_stencil = cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
337323

338324
@inbounds for idx in slen-1:-1:1
339325
xtempi += cur_coeff * cur_stencil[end-idx] * _x.u[end-idx+1]

0 commit comments

Comments
 (0)