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

Commit f42cc79

Browse files
committed
calculate correct boundary stencils for irregular grid
1 parent e6f468d commit f42cc79

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/derivative_operators/derivative_operator.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,18 @@ function CenteredDifference{N}(derivative_order::Int,
9090

9191
interior_x = boundary_point_count+2:len+1-boundary_point_count
9292
dummy_x = -div(stencil_length,2) : div(stencil_length,2)-1
93-
boundary_x = -boundary_stencil_length+1:0
94-
93+
low_boundary_x = [zero(T); cumsum(dx[1:boundary_stencil_length-1])]
94+
high_boundary_x = cumsum(dx[end-boundary_stencil_length+1:end])
9595
# 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.
9696
deriv_spots = (-div(stencil_length,2)+1) : -1
97-
boundary_deriv_spots = boundary_x[2:div(stencil_length,2)]
9897

9998
stencil_coefs = [convert(SVector{stencil_length, T}, calculate_weights(derivative_order, zero(T), generate_coordinates(i, stencil_x, dummy_x, dx))) for i in interior_x]
100-
_low_boundary_coefs = SVector{boundary_stencil_length, T}[convert(SVector{boundary_stencil_length, T}, calculate_weights(derivative_order, oneunit(T)*x0, boundary_x)) for x0 in boundary_deriv_spots]
99+
_low_boundary_coefs = SVector{boundary_stencil_length, T}[convert(SVector{boundary_stencil_length, T},
100+
calculate_weights(derivative_order, low_boundary_x[i+1], low_boundary_x)) for i in 1:boundary_point_count]
101101
low_boundary_coefs = convert(SVector{boundary_point_count},_low_boundary_coefs)
102-
high_boundary_coefs = convert(SVector{boundary_point_count},reverse(SVector{boundary_stencil_length, T}[reverse(low_boundary_coefs[i]) for i in 1:boundary_point_count]))
102+
_high_boundary_coefs = SVector{boundary_stencil_length, T}[convert(SVector{boundary_stencil_length, T},
103+
calculate_weights(derivative_order, high_boundary_x[end-i], high_boundary_x)) for i in boundary_point_count:-1:1]
104+
high_boundary_coefs = convert(SVector{boundary_point_count},_high_boundary_coefs)
103105

104106
coefficients = coeff_func isa Nothing ? nothing : Vector{T}(undef,len)
105107

0 commit comments

Comments
 (0)