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

Commit 5d917e1

Browse files
committed
[WIP]: Making bc_coeff_compositions tests pass
1 parent 2e3cb96 commit 5d917e1

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

src/derivative_operators/convolutions.jl

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,18 @@ end
3535
function convolve_BC_left!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::DerivativeOperator) where {T<:Real}
3636
stencil = A.low_boundary_coefs
3737
coeff = A.coefficients
38-
for i in 1 : A.boundary_point_count
39-
cur_stencil = stencil[i]
4038

41-
if cur_stencil == []
39+
_bpc = A.boundary_point_count
40+
41+
if cur_stencil == []
42+
_bpc = A.boundary_point_count + 1
43+
end
44+
45+
for i in 1 : _bpc
46+
if _bpc == 1
4247
cur_stencil = A.stencil_coefs
48+
else
49+
cur_stencil = stencil[i]
4350
end
4451

4552
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
@@ -57,11 +64,18 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::
5764
coeff = A.coefficients
5865
N = length(x)
5966
L = A.boundary_stencil_length
60-
for i in 1 : A.boundary_point_count
61-
cur_stencil = stencil[i]
6267

63-
if cur_stencil == []
68+
_bpc = A.boundary_point_count
69+
70+
if cur_stencil == []
71+
_bpc = 1
72+
end
73+
74+
for i in 1 : _bpc
75+
if _bpc == 1
6476
cur_stencil = A.stencil_coefs
77+
else
78+
cur_stencil = stencil[i]
6579
end
6680

6781
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
@@ -109,11 +123,18 @@ end
109123
function convolve_BC_left!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector, A::DerivativeOperator) where {T<:Real}
110124
stencil = A.low_boundary_coefs
111125
coeff = A.coefficients
112-
for i in 1 : A.boundary_point_count
113-
cur_stencil = stencil[i]
114126

115-
if cur_stencil == []
127+
_bpc = A.boundary_point_count
128+
129+
if cur_stencil == []
130+
_bpc = 1
131+
end
132+
133+
for i in 1 : _bpc
134+
if _bpc == 1
116135
cur_stencil = A.stencil_coefs
136+
else
137+
cur_stencil = stencil[i]
117138
end
118139

119140
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
@@ -156,8 +177,20 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
156177
L = A.boundary_stencil_length
157178

158179
bc_start = N - bpc + 1
159-
for i in 1 : A.boundary_point_count
160-
cur_stencil = stencil[i]
180+
181+
_bpc = A.boundary_point_count
182+
183+
if cur_stencil == []
184+
_bpc = 1
185+
end
186+
187+
for i in 1 : _bpc
188+
if _bpc == 1
189+
cur_stencil = A.stencil_coefs
190+
else
191+
cur_stencil = stencil[i]
192+
end
193+
161194
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[bc_start + i] : coeff isa Number ? coeff : true
162195
xtempi = cur_coeff*cur_stencil[end]*_x.r
163196
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil

src/derivative_operators/derivative_operator.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function CenteredDifference{N}(derivative_order::Int,
2727
left_boundary_x = 0:(boundary_stencil_length-1)
2828
right_boundary_x = reverse(-boundary_stencil_length+1:0)
2929

30-
boundary_point_count = max(1, div(stencil_length,2) - 1) # -1 due to the ghost point
30+
boundary_point_count = div(stencil_length,2) - 1 # -1 due to the ghost point
3131
# 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.
3232
deriv_spots = (-div(stencil_length,2)+1) : -1
3333
L_boundary_deriv_spots = left_boundary_x[2:div(stencil_length,2)]
@@ -60,7 +60,7 @@ function CenteredDifference{N}(derivative_order::Int,
6060
stencil_length = derivative_order + approximation_order - 1 + (derivative_order+approximation_order)%2
6161
boundary_stencil_length = derivative_order + approximation_order
6262
stencil_x = zeros(T, stencil_length)
63-
boundary_point_count = max(1, div(stencil_length,2) - 1) # -1 due to the ghost point
63+
boundary_point_count = div(stencil_length,2) - 1# -1 due to the ghost point
6464

6565
interior_x = boundary_point_count+2:len+1-boundary_point_count
6666
dummy_x = -div(stencil_length,2) : div(stencil_length,2)-1
@@ -112,7 +112,7 @@ function UpwindDifference{N}(derivative_order::Int,
112112
boundary_stencil_length = derivative_order + approximation_order
113113
dummy_x = -div(stencil_length,2) : div(stencil_length,2)
114114
boundary_x = -boundary_stencil_length+1:0
115-
boundary_point_count = max(1, div(stencil_length,2) - 1) # -1 due to the ghost point
115+
boundary_point_count = div(stencil_length,2) - 1 # -1 due to the ghost point
116116
# 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.
117117
deriv_spots = (-div(stencil_length,2)+1) : -1
118118
boundary_deriv_spots = boundary_x[2:div(stencil_length,2)]
@@ -144,7 +144,7 @@ function UpwindDifference{N}(derivative_order::Int,
144144
boundary_stencil_length = derivative_order + approximation_order
145145
dummy_x = -div(stencil_length,2) : div(stencil_length,2)
146146
boundary_x = -boundary_stencil_length+1:0
147-
boundary_point_count = max(div(stencil_length,2) - 1) # -1 due to the ghost point
147+
boundary_point_count = div(stencil_length,2) - 1 # -1 due to the ghost point
148148
# 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.
149149
deriv_spots = (-div(stencil_length,2)+1) : -1
150150
boundary_deriv_spots = boundary_x[2:div(stencil_length,2)]

test/bc_coeff_compositions.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function second_derivative_stencil(N)
3434
A
3535
end
3636

37+
3738
@testset "Test Constructor, Multiplication, and Concretization" begin
3839
# Generate random parameters
3940
al = rand()

0 commit comments

Comments
 (0)