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

Commit 5f0325d

Browse files
Merge pull request #159 from shivin9/New_Upwind_Operators
New upwind operators
2 parents 806acc1 + b11988c commit 5f0325d

File tree

9 files changed

+533
-48
lines changed

9 files changed

+533
-48
lines changed

src/derivative_operators/abstract_operator_functions.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ checkbounds(A::AbstractDerivativeOperator, k::Integer, j::Colon) =
1919

2020
@inline function getindex(A::AbstractDerivativeOperator, i::Int, j::Int)
2121
@boundscheck checkbounds(A, i, j)
22+
# TODO: Implement the lazy version
23+
if use_winding(A)
24+
return Array(A)[i,j]
25+
end
26+
2227
bpc = A.boundary_point_count
2328
N = A.len
2429
bsl = A.boundary_stencil_length
@@ -70,7 +75,11 @@ end
7075
elseif bpc > 0 && (N-bpc)<i<=N
7176
v[1:bsl] .= A.high_boundary_coefs[i-(N-1)]
7277
else
73-
v[i-bpc:i-bpc+slen-1] .= A.stencil_coefs
78+
if use_winding(A)
79+
v[i-bpc+slen:i-bpc+2*slen-1] .= A.stencil_coefs
80+
else
81+
v[i-bpc:i-bpc+slen-1] .= A.stencil_coefs
82+
end
7483
end
7584
return v
7685
end

src/derivative_operators/concretization.jl

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
function LinearAlgebra.Array(A::DerivativeOperator{T}, N::Int=A.len) where T
22
L = zeros(T, N, N+2)
33
bl = A.boundary_point_count
4-
stl = A.stencil_length
4+
stencil_length = A.stencil_length
55
bstl = A.boundary_stencil_length
66
coeff = A.coefficients
7-
stl_2 = div(stl,2)
8-
for i in 1:A.boundary_point_count
7+
8+
if use_winding(A)
9+
stencil_pivot = 1 + A.stencil_length%2
10+
else
11+
stencil_pivot = div(stencil_length,2)
12+
end
13+
14+
for i in 1:bl
915
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
1016
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(A.low_boundary_coefs[i]) : A.low_boundary_coefs[i]
1117
L[i,1:bstl] = cur_coeff * cur_stencil
1218
end
19+
1320
for i in bl+1:N-bl
1421
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
1522
stencil = eltype(A.stencil_coefs) <: AbstractVector ? A.stencil_coefs[i] : A.stencil_coefs
1623
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(stencil) : stencil
17-
L[i,i+1-stl_2:i+1+stl_2] = cur_coeff * cur_stencil
24+
L[i,i+1-stencil_pivot:i-stencil_pivot+stencil_length] = cur_coeff * cur_stencil
1825
end
26+
1927
for i in N-bl+1:N
2028
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
2129
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(A.high_boundary_coefs[i-N+bl]) : A.high_boundary_coefs[i-N+bl]
@@ -27,21 +35,30 @@ end
2735
function SparseArrays.SparseMatrixCSC(A::DerivativeOperator{T}, N::Int=A.len) where T
2836
L = spzeros(T, N, N+2)
2937
bl = A.boundary_point_count
30-
stl = A.stencil_length
31-
stl_2 = div(stl,2)
38+
stencil_length = A.stencil_length
39+
stencil_pivot = div(stencil_length,2)
3240
bstl = A.boundary_stencil_length
3341
coeff = A.coefficients
42+
43+
if use_winding(A)
44+
stencil_pivot = 1 + A.stencil_length%2
45+
else
46+
stencil_pivot = div(stencil_length,2)
47+
end
48+
3449
for i in 1:A.boundary_point_count
3550
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
3651
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(A.low_boundary_coefs[i]) : A.low_boundary_coefs[i]
3752
L[i,1:bstl] = cur_coeff * cur_stencil
3853
end
54+
3955
for i in bl+1:N-bl
4056
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
4157
stencil = eltype(A.stencil_coefs) <: AbstractVector ? A.stencil_coefs[i] : A.stencil_coefs
4258
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(stencil) : stencil
43-
L[i,i+1-stl_2:i+1+stl_2] = cur_coeff * cur_stencil
59+
L[i,i+1-stencil_pivot:i-stencil_pivot+stencil_length] = cur_coeff * cur_stencil
4460
end
61+
4562
for i in N-bl+1:N
4663
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
4764
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(A.high_boundary_coefs[i-N+bl]) : A.high_boundary_coefs[i-N+bl]
@@ -56,11 +73,16 @@ end
5673

5774
function BandedMatrices.BandedMatrix(A::DerivativeOperator{T}, N::Int=A.len) where T
5875
bl = A.boundary_point_count
59-
stl = A.stencil_length
76+
stencil_length = A.stencil_length
6077
bstl = A.boundary_stencil_length
6178
coeff = A.coefficients
62-
stl_2 = div(stl,2)
63-
L = BandedMatrix{T}(Zeros(N, N+2), (max(stl-3,0,bstl),max(stl-1,0,bstl)))
79+
if use_winding(A)
80+
stencil_pivot = 1 + A.stencil_length%2
81+
else
82+
stencil_pivot = div(stencil_length,2)
83+
end
84+
L = BandedMatrix{T}(Zeros(N, N+2), (max(stencil_length-3,0,bstl),max(stencil_length-1,0,bstl)))
85+
6486
for i in 1:A.boundary_point_count
6587
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
6688
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(A.low_boundary_coefs[i]) : A.low_boundary_coefs[i]
@@ -70,7 +92,7 @@ function BandedMatrices.BandedMatrix(A::DerivativeOperator{T}, N::Int=A.len) whe
7092
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
7193
stencil = eltype(A.stencil_coefs) <: AbstractVector ? A.stencil_coefs[i] : A.stencil_coefs
7294
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(stencil) : stencil
73-
L[i,i+1-stl_2:i+1+stl_2] = cur_coeff * cur_stencil
95+
L[i,i+1-stencil_pivot:i-stencil_pivot+stencil_length] = cur_coeff * cur_stencil
7496
end
7597
for i in N-bl+1:N
7698
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
@@ -361,4 +383,4 @@ function BlockBandedMatrices.BandedBlockBandedMatrix(A::DerivativeOperator{T,N},
361383
B = Kron(BandedMatrix(Eye(n)), BandedMatrix(A))
362384
end
363385
return BandedBlockBandedMatrix(B)
364-
end
386+
end

0 commit comments

Comments
 (0)