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

Commit 5e24ee3

Browse files
committed
fixes
1 parent e456af3 commit 5e24ee3

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/derivative_operators/derivative_operator.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -477,21 +477,21 @@ function CompleteUpwindDifference(derivative_order::Int,
477477

478478
stencil_length = derivative_order + approximation_order
479479
boundary_stencil_length = derivative_order + approximation_order
480-
boundary_point_count = boundary_stencil_length - 1 - offside
480+
low_boundary_point_count = offside
481+
high_boundary_point_count = stencil_length - 1 - offside
481482

482483
# TODO: Clean up the implementation here so that it is more readable and easier to extend in the future
483484
dummy_x = (0.0 - offside) : stencil_length - 1.0 - offside
484485
stencil_coefs = convert(SVector{stencil_length, T}, (1/dx^derivative_order) * calculate_weights(derivative_order, 0.0, dummy_x))
485-
486486
low_boundary_x = 0.0:(boundary_stencil_length-1)
487-
L_boundary_deriv_spots = 0.0:boundary_stencil_length - 2.0 - offside
487+
L_boundary_deriv_spots = 0.0:low_boundary_point_count-1
488488
_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, low_boundary_x)) for x0 in L_boundary_deriv_spots]
489-
low_boundary_coefs = convert(SVector{boundary_point_count},_low_boundary_coefs)
489+
low_boundary_coefs = convert(SVector{low_boundary_point_count},_low_boundary_coefs)
490490

491491
high_boundary_x = 0.0:-1.0:-(boundary_stencil_length-1.0)
492-
R_boundary_deriv_spots = 0.0:-1.0:-(boundary_stencil_length-2.0)
492+
R_boundary_deriv_spots = 0.0:-1.0:-(high_boundary_point_count-1.0)
493493
_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, high_boundary_x)) for x0 in R_boundary_deriv_spots]
494-
high_boundary_coefs = convert(SVector{boundary_point_count + offside},reverse(_high_boundary_coefs))
494+
high_boundary_coefs = convert(SVector{high_boundary_point_count},reverse(_high_boundary_coefs))
495495

496496
coefficients = nothing
497497

@@ -502,7 +502,7 @@ function CompleteUpwindDifference(derivative_order::Int,
502502
derivative_order, approximation_order, dx, 1, stencil_length,
503503
stencil_coefs,
504504
boundary_stencil_length,
505-
boundary_point_count,
505+
high_boundary_point_count,
506506
low_boundary_coefs,
507507
high_boundary_coefs,offside,coefficients,nothing
508508
)
@@ -515,21 +515,23 @@ function CompleteUpwindDifference(derivative_order::Int,
515515
@assert offside > -1 "Number of offside points should be non-negative"
516516

517517
stencil_length = derivative_order + approximation_order
518+
@assert offside <= stencil_length - 1 "Number of offside points should be less than or equal to the stencil length"
518519
boundary_stencil_length = derivative_order + approximation_order
519-
boundary_point_count = boundary_stencil_length - 1 - offside
520+
low_boundary_point_count = offside
521+
high_boundary_point_count = stencil_length - 1 - offside
520522

521523
dx = [x[i+1] - x[i] for i in 1:length(x)-1]
522524

523525
low_boundary_x = @view(x[1:boundary_stencil_length])
524526
high_boundary_x = @view(x[end-boundary_stencil_length+1:end])
525527

526-
L_boundary_deriv_spots = x[1:boundary_stencil_length-1-offside]
528+
L_boundary_deriv_spots = x[1:low_boundary_point_count]
527529
# 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.
528530
#deriv_spots = (-div(stencil_length,2)+1) : -1 # unused
529531

530-
R_boundary_deriv_spots = x[end-boundary_stencil_length+1:end]
532+
R_boundary_deriv_spots = x[end-high_boundary_point_count+1:end]
531533

532-
stencil_coefs = [convert(SVector{stencil_length,eltype(x)}, calculate_weights(derivative_order, x[i], @view(x[i-offside:i+stencil_length-1-offside]))) for i in boundary_stencil_length-offside:length(x)-boundary_stencil_length]
534+
stencil_coefs = [convert(SVector{stencil_length,eltype(x)}, calculate_weights(derivative_order, x[i], @view(x[i-offside:i+stencil_length-1-offside]))) for i in low_boundary_point_count+1:length(x)-high_boundary_point_count]
533535
# For each boundary point, for each tappoint in the half offset central difference stencil, we need to calculate the coefficients for the stencil.
534536

535537

@@ -548,7 +550,7 @@ function CompleteUpwindDifference(derivative_order::Int,
548550
derivative_order, approximation_order, dx, 1, stencil_length,
549551
stencil_coefs,
550552
boundary_stencil_length,
551-
boundary_point_count,
553+
high_boundary_point_count,
552554
low_boundary_coefs,
553555
high_boundary_coefs, offside, coefficients, nothing
554556
)

0 commit comments

Comments
 (0)