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

Commit c52e4c1

Browse files
Merge pull request #137 from JuliaDiffEq/stencil_scaling
Stencil scaling for regular grids.
2 parents 53d234b + b5ffb97 commit c52e4c1

File tree

5 files changed

+9
-11
lines changed

5 files changed

+9
-11
lines changed

src/derivative_operators/concretization.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function LinearAlgebra.Array(A::DerivativeOperator{T}, N::Int=A.len) where T
2121
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(A.high_boundary_coefs[i-N+bl]) : A.high_boundary_coefs[i-N+bl]
2222
L[i,N-bstl+3:N+2] = cur_coeff * cur_stencil
2323
end
24-
return L / A.dx^A.derivative_order
24+
return L
2525
end
2626

2727
function SparseArrays.SparseMatrixCSC(A::DerivativeOperator{T}, N::Int=A.len) where T
@@ -47,7 +47,7 @@ function SparseArrays.SparseMatrixCSC(A::DerivativeOperator{T}, N::Int=A.len) wh
4747
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(A.high_boundary_coefs[i-N+bl]) : A.high_boundary_coefs[i-N+bl]
4848
L[i,N-bstl+3:N+2] = cur_coeff * cur_stencil
4949
end
50-
return L / A.dx^A.derivative_order
50+
return L
5151
end
5252

5353
function SparseArrays.sparse(A::AbstractDerivativeOperator{T}, N::Int=A.len) where T
@@ -77,7 +77,7 @@ function BandedMatrices.BandedMatrix(A::DerivativeOperator{T}, N::Int=A.len) whe
7777
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(A.high_boundary_coefs[i-N+bl]) : A.high_boundary_coefs[i-N+bl]
7878
L[i,N-bstl+3:N+2] = cur_coeff * cur_stencil
7979
end
80-
return L / A.dx^A.derivative_order
80+
return L
8181
end
8282

8383
function Base.convert(::Type{Array},A::DerivativeOperator{T}) where T

src/derivative_operators/convolutions.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ function LinearAlgebra.mul!(x_temp::AbstractVector{T}, A::DerivativeOperator, x:
33
convolve_BC_left!(x_temp, x, A)
44
convolve_interior!(x_temp, x, A)
55
convolve_BC_right!(x_temp, x, A)
6-
rmul!(x_temp, @.(1/(A.dx^A.derivative_order)))
76
end
87

98
################################################

src/derivative_operators/derivative_operator.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ function CenteredDifference{N}(derivative_order::Int,
3030
deriv_spots = (-div(stencil_length,2)+1) : -1
3131
boundary_deriv_spots = boundary_x[2:div(stencil_length,2)]
3232

33-
stencil_coefs = convert(SVector{stencil_length, T}, calculate_weights(derivative_order, zero(T), dummy_x))
34-
_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]
33+
stencil_coefs = convert(SVector{stencil_length, T}, (1/dx^derivative_order) * calculate_weights(derivative_order, zero(T), dummy_x))
34+
_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, boundary_x)) for x0 in boundary_deriv_spots]
3535
low_boundary_coefs = convert(SVector{boundary_point_count},_low_boundary_coefs)
3636
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]))
3737

src/derivative_operators/derivative_operator_functions.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ for MT in [2,3]
8080
convolve_BC_right!(view(x_temp, idx...), view(M, idx...), A)
8181
end
8282
end
83-
mul!(x_temp,x_temp,1/A.dx^A.derivative_order)
8483
end
8584
end
8685
end

test/bc_coeff_compositions.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,19 @@ end
197197
@testset "Test Left Division L4 (fourth order)" begin
198198

199199
# Test \ homogenous and inhomogenous BC
200-
dx = 0.00001
201-
x = 0.0001:dx:0.01
200+
dx = 0.01
201+
x = 0.01:dx:0.2
202202
N = length(x)
203203
u = sin.(x)
204204

205205
L = CenteredDifference(4, 4, dx, N)
206-
Q = RobinBC(1.0, 0.0, sin(0), dx, 1.0, 0.0, sin(0.01+dx), dx)
206+
Q = RobinBC(1.0, 0.0, sin(0.0), dx, 1.0, 0.0, sin(0.2+dx), dx)
207207
A = L*Q
208208

209209
analytic_L = fourth_deriv_approx_stencil(N) ./ dx^4
210210
analytic_QL = [transpose(zeros(N)); Diagonal(ones(N)); transpose(zeros(N))]
211211
analytic_AL = analytic_L*analytic_QL
212-
analytic_Qb = [zeros(N+1); sin(0.01+dx)]
212+
analytic_Qb = [zeros(N+1); sin(0.2+dx)]
213213
analytic_Ab = analytic_L*analytic_Qb
214214

215215
analytic_u = analytic_AL \ (u - analytic_Ab)

0 commit comments

Comments
 (0)