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

Commit 53ffe77

Browse files
committed
Finished up half offset weight generation
1 parent aaa0645 commit 53ffe77

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/derivative_operators/derivative_operator.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ function CompleteCenteredDifference{N}(derivative_order::Int,
182182
# Because it's a N x (N+2) operator, the last stencil on the sides are the [b,0,x,x,x,x] stencils, not the [0,x,x,x,x,x] stencils, since we're never solving for the derivative at the boundary point.
183183
#deriv_spots = (-div(stencil_length,2)+1) : -1 # unused
184184
L_boundary_deriv_spots = left_boundary_x[1:div(stencil_length,2)]
185-
R_boundary_deriv_spots = right_boundary_x[1:div(stencil_length,2)]
186185

187186
stencil_coefs = convert(SVector{stencil_length, T}, (1/dx^derivative_order) * calculate_weights(derivative_order, zero(T), dummy_x))
188187
_low_boundary_coefs = SVector{boundary_stencil_length, T}[convert(SVector{boundary_stencil_length, T}, (1/dx^derivative_order) * calculate_weights(derivative_order, oneunit(T)*x0, left_boundary_x)) for x0 in L_boundary_deriv_spots]
@@ -217,28 +216,30 @@ function CompleteHalfCenteredDifference(derivative_order::Int,
217216
len::Int, isforward=false) where {T<:Real,N}
218217
@assert approximation_order>1 "approximation_order must be greater than 1."
219218
stencil_length = approximation_order + 2*floor(derivative_order/2) + 2*(approximation_order%2)
219+
centered_stencil_length = derivative_order + approximation_order - 1 + (derivative_order+approximation_order)%2
220220
boundary_stencil_length = derivative_order + approximation_order
221221
endpoint = (stencil_length-1)/2
222222
dummy_x = -endpoint : endpoint
223-
left_boundary_x = -1:(boundary_stencil_length-1)
224-
right_boundary_x = reverse(-boundary_stencil_length+1:1)
223+
left_boundary_x = 0:(boundary_stencil_length-1)
224+
right_boundary_x = reverse(-boundary_stencil_length+1:0)
225225

226226
# ? Is fornberg valid when taking an x0 outside of the stencil i.e at the boundary?
227-
xoffset = isforward ? convert(T, 0.5) : convert(T, -0.5)
227+
xoffset = convert(T, 0.5).*(-div(centered_stencil_length,2) : div(centered_stencil_length,2))
228228

229229

230230
boundary_point_count = div(stencil_length,2) # -1 due to the ghost point
231231
# Because it's a N x (N+2) operator, the last stencil on the sides are the [b,0,x,x,x,x] stencils, not the [0,x,x,x,x,x] stencils, since we're never solving for the derivative at the boundary point.
232232
#deriv_spots = (-div(stencil_length,2)+1) : -1 # unused
233233
L_boundary_deriv_spots = left_boundary_x[1:div(stencil_length,2)]
234-
R_boundary_deriv_spots = right_boundary_x[1:div(stencil_length,2)]
235234

236235
stencil_coefs = convert(SVector{stencil_length, T}, (1/dx^derivative_order) * calculate_weights(derivative_order, zero(T), dummy_x))
237-
_low_boundary_coefs = SVector{boundary_stencil_length, T}[convert(SVector{boundary_stencil_length, T}, (1/dx^derivative_order) * calculate_weights(derivative_order, oneunit(T)*x0+xoffset, left_boundary_x)) for x0 in L_boundary_deriv_spots]
236+
# For each boundary point, for each tappoint in the half offset central difference stencil, we need to calculate the coefficients for the stencil.
237+
_low_boundary_coefs = [convert(SVector{centered_stencil_length}, SVector{boundary_stencil_length, T}[convert(SVector{boundary_stencil_length, T}, (1/dx^derivative_order) * calculate_weights(derivative_order, oneunit(T)*x0+offset, left_boundary_x)) for offset in xoffset]) for x0 in L_boundary_deriv_spots]
238238
low_boundary_coefs = convert(SVector{boundary_point_count},vcat(_low_boundary_coefs))
239239

240240
# _high_boundary_coefs = SVector{boundary_stencil_length, T}[convert(SVector{boundary_stencil_length, T}, (1/dx^derivative_order) * calculate_weights(derivative_order, oneunit(T)*x0, reverse(right_boundary_x))) for x0 in R_boundary_deriv_spots]
241-
high_boundary_coefs = convert(SVector{boundary_point_count},reverse(map(reverse, _low_boundary_coefs*(-1)^derivative_order)))
241+
inner_reverse(v::AbstractVector) = reverse(map.((x->reverse(x*(-1)^derivative_order),), v)) # reverse 3 ayers deep to get the high boundary cooeffs, but don't reverse in terms of the offset
242+
high_boundary_coefs = convert(SVector{boundary_point_count}, inner_reverse(_low_boundary_coefs))
242243

243244
offside = 0
244245

0 commit comments

Comments
 (0)