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

Commit 87d90ef

Browse files
committed
Improved error rates further on error_benchmark.jl
1 parent 229a8dd commit 87d90ef

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

src/derivative_operators/convolutions.jl

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::D
3737
coeff = A.coefficients
3838

3939
_bpc = A.boundary_point_count
40-
40+
flag = false
4141
if stencil == []
4242
_bpc = A.boundary_point_count + 1
43+
flag = true
4344
end
4445

4546
for i in 1 : _bpc
46-
if _bpc == 1
47+
if flag == true
4748
cur_stencil = A.stencil_coefs
4849
slen = length(A.stencil_coefs)
4950
else
@@ -68,31 +69,34 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::
6869
L = A.boundary_stencil_length
6970

7071
_bpc = A.boundary_point_count
72+
flag = false
7173

7274
if stencil == []
7375
_bpc = 1
76+
flag = true
7477
end
7578

7679
for i in 1 : _bpc
77-
if _bpc == 1
80+
# @show _bpc
81+
if flag == true
7882
cur_stencil = A.stencil_coefs
7983
slen = length(A.stencil_coefs)
8084
L = A.stencil_length
8185
else
82-
cur_stencil = stencil[i]
86+
cur_stencil = stencil[end-i+1]
8387
slen = length(cur_stencil)
8488
end
8589

8690
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
8791
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
88-
# cs = cur_stencil*(A.dx^A.derivative_order)
92+
cs = cur_stencil*(A.dx^A.derivative_order)
8993
xtempi = zero(T)
9094
for idx in 1:slen
9195
# @show idx, N-L+idx, cs[idx], x[N-L+idx]
9296
xtempi += cur_coeff * cur_stencil[idx] * x[N-L+idx]
9397
end
9498
# @show xtempi*(1/(A.dx^A.derivative_order))
95-
x_temp[end-_bpc+i] = xtempi
99+
x_temp[end-i+1] = xtempi
96100
end
97101
end
98102

@@ -130,13 +134,15 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
130134
coeff = A.coefficients
131135

132136
_bpc = A.boundary_point_count
137+
flag = false
133138

134139
if stencil == []
135140
_bpc = 1
141+
flag = true
136142
end
137143

138144
for i in 1 : _bpc
139-
if _bpc == 1
145+
if flag == true
140146
cur_stencil = A.stencil_coefs
141147
slen = length(A.stencil_coefs)
142148
else
@@ -185,20 +191,22 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
185191

186192

187193
_bpc = A.boundary_point_count
194+
flag = false
188195

189196
if stencil == []
190197
_bpc = 1
191198
L = A.stencil_length
199+
flag = true
192200
end
193201

194202
bc_start = N - _bpc + 1
195203

196204
for i in 1 : _bpc
197-
if _bpc == 1
205+
if flag == true
198206
cur_stencil = A.stencil_coefs
199207
slen = length(A.stencil_coefs)
200208
else
201-
cur_stencil = stencil[i]
209+
cur_stencil = stencil[end-i+1]
202210
slen = length(cur_stencil)
203211
end
204212

@@ -214,6 +222,6 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
214222
# xtempi += cur_coeff * cur_stencil[idx] * _x.u[end-L+idx+1]
215223
# end
216224

217-
x_temp[bc_start + i - 1] = xtempi
225+
x_temp[N-i+1] = xtempi
218226
end
219227
end

test/bc_coeff_compositions.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ function fourth_deriv_approx_stencil(N)
66
A[1,1:8] = [3.5 -56/3 42.5 -54.0 251/6 -20.0 5.5 -2/3]
77
A[2,1:8] = [2/3 -11/6 0.0 31/6 -22/3 4.5 -4/3 1/6]
88

9-
A[N-1,N-5:end] = reverse([3.5 -56/3 42.5 -54.0 251/6 -20.0 5.5 -2/3], dims=2)
10-
A[N,N-5:end] = reverse([2/3 -11/6 0.0 31/6 -22/3 4.5 -4/3 1/6], dims=2)
9+
A[N-1,N-5:end] = reverse([2/3 -11/6 0.0 31/6 -22/3 4.5 -4/3 1/6], dims=2)
10+
A[N,N-5:end] = reverse([3.5 -56/3 42.5 -54.0 251/6 -20.0 5.5 -2/3], dims=2)
1111

1212
for i in 3:N-2
1313
A[i,i-2:i+4] = [-1/6 2.0 -13/2 28/3 -13/2 2.0 -1/6]

test/derivative_operators_interface.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
using SparseArrays, DiffEqOperators, LinearAlgebra, Random,
22
Test, BandedMatrices, FillArrays
33

4-
function second_derivative_stencil(N)
5-
A = zeros(N,N+2)
6-
for i in 1:N, j in 1:N+2
7-
(j-i==0 || j-i==2) && (A[i,j]=1)
8-
j-i==1 && (A[i,j]=-2)
9-
end
10-
A
11-
end
124

135
# Analytic solutions to higher order operators.
146
# Do not modify unless you are completely certain of the changes.
@@ -39,7 +31,16 @@ function second_deriv_fourth_approx_stencil(N)
3931
return A
4032
end
4133

34+
function second_derivative_stencil(N)
35+
A = zeros(N,N+2)
36+
for i in 1:N, j in 1:N+2
37+
(j-i==0 || j-i==2) && (A[i,j]=1)
38+
j-i==1 && (A[i,j]=-2)
39+
end
40+
A
41+
end
4242

43+
# Broken?
4344
function convert_by_multiplication(::Type{Array}, A::AbstractDerivativeOperator{T}, N::Int=A.dimension) where T
4445
@assert N >= A.stencil_length # stencil must be able to fit in the matrix
4546
mat = zeros(T, (N, N+2))

test/differentiation_dimension.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ function fourth_deriv_approx_stencil(N)
44
A = zeros(N,N+2)
55
A[1,1:8] = [3.5 -56/3 42.5 -54.0 251/6 -20.0 5.5 -2/3]
66
A[2,1:8] = [2/3 -11/6 0.0 31/6 -22/3 4.5 -4/3 1/6]
7-
A[N-1,N-5:end] = reverse([2/3 -11/6 0.0 31/6 -22/3 4.5 -4/3 1/6], dims=2)
8-
A[N,N-5:end] = reverse([3.5 -56/3 42.5 -54.0 251/6 -20.0 5.5 -2/3], dims=2)
7+
A[N-1,N-5:end] = reverse([3.5 -56/3 42.5 -54.0 251/6 -20.0 5.5 -2/3], dims=2)
8+
A[N,N-5:end] = reverse([2/3 -11/6 0.0 31/6 -22/3 4.5 -4/3 1/6], dims=2)
99
for i in 3:N-2
1010
A[i,i-2:i+4] = [-1/6 2.0 -13/2 28/3 -13/2 2.0 -1/6]
1111
end

0 commit comments

Comments
 (0)