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

Commit 6319af2

Browse files
committed
all nonuniform complete differences
1 parent 5fb77ac commit 6319af2

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

src/derivative_operators/derivative_operator.jl

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,12 @@ function CompleteHalfCenteredDifference(derivative_order::Int,
293293
end
294294

295295
function CompleteHalfCenteredDifference(derivative_order::Int,
296-
approximation_order::Int, dx::T) where {T<:Real,N}
296+
approximation_order::Int, dx::T) where {T<:AbstractVector{<:Real},N}
297297
@assert approximation_order > 1 "approximation_order must be greater than 1."
298298
centered_stencil_length = approximation_order + 2 * Int(floor(derivative_order / 2)) + (approximation_order % 2)
299299
boundary_stencil_length = derivative_order + approximation_order
300300
endpoint = div(centered_stencil_length, 2)
301301
x = [0.0, cumsum(dx)...]
302-
#TODO Improve interpolation
303302
hx = [(x[i] + x[i+1]) / 2 for i in 1:length(x)-1]
304303

305304

@@ -315,7 +314,7 @@ function CompleteHalfCenteredDifference(derivative_order::Int,
315314

316315
R_boundary_deriv_spots = hx[length(hx):-1:length(hx)-div(centered_stencil_length, 2)+1]
317316

318-
stencil_coefs = [convert(SVector{centered_stencil_length,T}, calculate_weights(derivative_order, hx[i], x[i-endpoint+1:i+endpoint])) for i in endpoint+1:length(hx)-endpoint, 2)]
317+
stencil_coefs = [convert(SVector{centered_stencil_length,T}, calculate_weights(derivative_order, hx[i], x[i-endpoint+1:i+endpoint])) for i in endpoint+1:length(hx)-endpoint]
319318
# For each boundary point, for each tappoint in the half offset central difference stencil, we need to calculate the coefficients for the stencil.
320319

321320

@@ -510,6 +509,57 @@ function CompleteUpwindDifference(derivative_order::Int,
510509
)
511510
end
512511

512+
# TODO implement the non-uniform grid
513+
function CompleteUpwindDifference{N}(derivative_order::Int,
514+
approximation_order::Int, dx::AbstractVector{T},
515+
len::Int, coeff_func=1; offside::Int=0) where {T<:Real,N}
516+
517+
@assert offside > -1 "Number of offside points should be non-negative"
518+
@assert offside <= div(derivative_order + approximation_order - 1, 2) "Number of offside points should not exceed the primary wind points"
519+
520+
stencil_length = derivative_order + approximation_order
521+
boundary_stencil_length = derivative_order + approximation_order
522+
boundary_point_count = boundary_stencil_length - 1 - offside
523+
524+
endpoint = div(centered_stencil_length, 2)
525+
526+
x = [0.0, cumsum(dx)...]
527+
hx = [(x[i] + x[i+1]) / 2 for i in 1:length(x)-1]
528+
529+
530+
low_boundary_x = @view(x[1:boundary_stencil_length])
531+
high_boundary_x = @view(x[end-boundary_stencil_length+1:end])
532+
533+
L_boundary_deriv_spots = x[1:boundary_stencil_length-1-offside]
534+
# 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.
535+
#deriv_spots = (-div(stencil_length,2)+1) : -1 # unused
536+
537+
R_boundary_deriv_spots = x[end-boundary_stencil_length+1:end]
538+
539+
stencil_coefs = [convert(SVector{centered_stencil_length,T}, calculate_weights(derivative_order, x[i], x[i-offside:i+stencil_length-1-offside])) for i in boundary_stencil_length-offside:length(x)-boundary_stencil_length]
540+
# For each boundary point, for each tappoint in the half offset central difference stencil, we need to calculate the coefficients for the stencil.
541+
542+
543+
_low_boundary_coefs = [convert(SVector{boundary_stencil_length,T}, calculate_weights(derivative_order, offset, low_boundary_x)) for offset in L_boundary_deriv_spots]
544+
low_boundary_coefs = convert(SVector{boundary_point_count}, _low_boundary_coefs)
545+
546+
_high_boundary_coefs = [convert(SVector{boundary_stencil_length,T}, calculate_weights(derivative_order, offset, high_boundary_x)) for offset in R_boundary_deriv_spots]
547+
high_boundary_coefs = convert(SVector{boundary_point_count}, _high_boundary_coefs)
548+
# _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]
549+
550+
offside = 0
551+
coefficients = nothing
552+
553+
DerivativeOperator{T,Nothing,false,T,typeof(stencil_coefs),
554+
typeof(low_boundary_coefs),typeof(high_boundary_coefs),typeof(coefficients),Nothing}(
555+
derivative_order, approximation_order, dx, 1, centered_stencil_length,
556+
stencil_coefs,
557+
boundary_stencil_length,
558+
boundary_point_count,
559+
low_boundary_coefs,
560+
high_boundary_coefs, offside, coefficients, nothing
561+
)
562+
end
513563

514564
CenteredDifference(args...) = CenteredDifference{1}(args...)
515565
UpwindDifference(args...;kwargs...) = UpwindDifference{1}(args...;kwargs...)

0 commit comments

Comments
 (0)