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

Commit 776dd31

Browse files
committed
rm stencil_coefs SVector, move generate_coordinates out of constructor
1 parent a5bb1df commit 776dd31

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

src/derivative_operators/derivative_operator.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ function CenteredDifference{N}(derivative_order::Int,
6767
)
6868
end
6969

70+
function generate_coordinates(i::Int, stencil_x, dummy_x, dx::AbstractVector{T}) where T <: Real
71+
len = length(stencil_x)
72+
stencil_x .= stencil_x.*zero(T)
73+
for idx in 1:div(len,2)
74+
shifted_idx1 = index(idx, len)
75+
shifted_idx2 = index(-idx, len)
76+
stencil_x[shifted_idx1] = stencil_x[shifted_idx1-1] + dx[i+idx-1]
77+
stencil_x[shifted_idx2] = stencil_x[shifted_idx2+1] - dx[i-idx]
78+
end
79+
return stencil_x
80+
end
81+
7082
function CenteredDifference{N}(derivative_order::Int,
7183
approximation_order::Int, dx::AbstractVector{T},
7284
len::Int, coeff_func=nothing) where {T<:Real,N}
@@ -84,19 +96,7 @@ function CenteredDifference{N}(derivative_order::Int,
8496
deriv_spots = (-div(stencil_length,2)+1) : -1
8597
boundary_deriv_spots = boundary_x[2:div(stencil_length,2)]
8698

87-
function generate_coordinates(i, stencil_x, dummy_x, dx)
88-
len = length(stencil_x)
89-
stencil_x .= stencil_x.*zero(T)
90-
for idx in 1:div(len,2)
91-
shifted_idx1 = index(idx, len)
92-
shifted_idx2 = index(-idx, len)
93-
stencil_x[shifted_idx1] = stencil_x[shifted_idx1-1] + dx[i+idx-1]
94-
stencil_x[shifted_idx2] = stencil_x[shifted_idx2+1] - dx[i-idx]
95-
end
96-
return stencil_x
97-
end
98-
99-
stencil_coefs = convert(SVector{length(interior_x)}, [convert(SVector{stencil_length, T}, calculate_weights(derivative_order, zero(T), generate_coordinates(i, stencil_x, dummy_x, dx))) for i in interior_x])
99+
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]
100100
_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]
101101
low_boundary_coefs = convert(SVector{boundary_point_count},_low_boundary_coefs)
102102
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]))

0 commit comments

Comments
 (0)