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

Commit 797b394

Browse files
authored
Merge pull request #17 from JuliaDiffEq/master
merge changes in to master
2 parents be10288 + cd3dcda commit 797b394

File tree

6 files changed

+914
-25
lines changed

6 files changed

+914
-25
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name = "DiffEqOperators"
22
uuid = "9fdde737-9c7f-55bf-ade8-46b3f136cc48"
33
authors = ["Chris Rackauckas <accounts@chrisrackauckas.com>"]
4-
version = "4.0.0"
4+
version = "4.1.0"
55

66
[deps]
77
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
88
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
9+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
910
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1011
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
1112
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
@@ -18,11 +19,10 @@ julia = "1"
1819

1920
[extras]
2021
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
21-
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
2222
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
2323
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
2424
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2525
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2626

2727
[targets]
28-
test = ["FillArrays", "ForwardDiff", "OrdinaryDiffEq", "SafeTestsets", "SpecialFunctions", "Test"]
28+
test = ["FillArrays", "OrdinaryDiffEq", "SafeTestsets", "SpecialFunctions", "Test"]

src/derivative_operators/convolutions.jl

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# mul! done by convolutions
2-
function LinearAlgebra.mul!(x_temp::AbstractVector{T}, A::DerivativeOperator, x::AbstractVector{T}) where T<:Real
3-
convolve_BC_left!(x_temp, x, A)
4-
convolve_interior!(x_temp, x, A)
5-
convolve_BC_right!(x_temp, x, A)
2+
function LinearAlgebra.mul!(x_temp::AbstractVector{T}, A::DerivativeOperator, x::AbstractVector{T}; overwrite = true) where T<:Real
3+
convolve_BC_left!(x_temp, x, A, overwrite = overwrite)
4+
convolve_interior!(x_temp, x, A, overwrite = overwrite)
5+
convolve_BC_right!(x_temp, x, A, overwrite = overwrite)
66
end
77

88
################################################
99

1010
# Against a standard vector, assume already padded and just apply the stencil
11-
function convolve_interior!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::DerivativeOperator) where {T<:Real}
11+
function convolve_interior!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::DerivativeOperator; overwrite = true) where {T<:Real}
1212
@assert length(x_temp)+2 == length(x)
1313
stencil = A.stencil_coefs
1414
coeff = A.coefficients
@@ -21,11 +21,11 @@ function convolve_interior!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::
2121
for idx in 1:A.stencil_length
2222
xtempi += cur_coeff * cur_stencil[idx] * x[i - mid + idx]
2323
end
24-
x_temp[i] = xtempi
24+
x_temp[i] = xtempi + !overwrite*x_temp[i]
2525
end
2626
end
2727

28-
function convolve_BC_left!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::DerivativeOperator) where {T<:Real}
28+
function convolve_BC_left!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::DerivativeOperator; overwrite = true) where {T<:Real}
2929
stencil = A.low_boundary_coefs
3030
coeff = A.coefficients
3131
for i in 1 : A.boundary_point_count
@@ -36,11 +36,11 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::D
3636
for idx in 2:A.boundary_stencil_length
3737
xtempi += cur_coeff * cur_stencil[idx] * x[idx]
3838
end
39-
x_temp[i] = xtempi
39+
x_temp[i] = xtempi + !overwrite*x_temp[i]
4040
end
4141
end
4242

43-
function convolve_BC_right!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::DerivativeOperator) where {T<:Real}
43+
function convolve_BC_right!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::DerivativeOperator; overwrite = true) where {T<:Real}
4444
stencil = A.high_boundary_coefs
4545
coeff = A.coefficients
4646
for i in 1 : A.boundary_point_count
@@ -51,14 +51,14 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::
5151
for idx in (A.boundary_stencil_length-1):-1:1
5252
xtempi += cur_coeff * cur_stencil[end-idx] * x[end-idx]
5353
end
54-
x_temp[end-A.boundary_point_count+i] = xtempi
54+
x_temp[end-A.boundary_point_count+i] = xtempi + !overwrite*x_temp[end-A.boundary_point_count+i]
5555
end
5656
end
5757

5858
###########################################
5959

6060
# Against A BC-padded vector, specialize the computation to explicitly use the left, right, and middle parts
61-
function convolve_interior!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector, A::DerivativeOperator) where {T<:Real}
61+
function convolve_interior!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector, A::DerivativeOperator; overwrite = true) where {T<:Real}
6262
stencil = A.stencil_coefs
6363
coeff = A.coefficients
6464
x = _x.u
@@ -72,11 +72,11 @@ function convolve_interior!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
7272
@inbounds for idx in 1:A.stencil_length
7373
xtempi += cur_coeff * cur_stencil[idx] * x[(i-1) - (mid-idx) + 1]
7474
end
75-
x_temp[i] = xtempi
75+
x_temp[i] = xtempi + !overwrite*x_temp[i]
7676
end
7777
end
7878

79-
function convolve_BC_left!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector, A::DerivativeOperator) where {T<:Real}
79+
function convolve_BC_left!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector, A::DerivativeOperator; overwrite = true) where {T<:Real}
8080
stencil = A.low_boundary_coefs
8181
coeff = A.coefficients
8282
for i in 1 : A.boundary_point_count
@@ -87,7 +87,7 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
8787
@inbounds for idx in 2:A.boundary_stencil_length
8888
xtempi += cur_coeff * cur_stencil[idx] * _x.u[idx-1]
8989
end
90-
x_temp[i] = xtempi
90+
x_temp[i] = xtempi + !overwrite*x_temp[i]
9191
end
9292
# need to account for x.l in first interior
9393
mid = div(A.stencil_length,2) + 1
@@ -101,10 +101,10 @@ function convolve_BC_left!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
101101
@inbounds for idx in 2:A.stencil_length
102102
xtempi += cur_coeff * cur_stencil[idx] * x[(i-1) - (mid-idx) + 1]
103103
end
104-
x_temp[i] = xtempi
104+
x_temp[i] = xtempi + !overwrite*x_temp[i]
105105
end
106106

107-
function convolve_BC_right!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector, A::DerivativeOperator) where {T<:Real}
107+
function convolve_BC_right!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector, A::DerivativeOperator; overwrite = true) where {T<:Real}
108108
stencil = A.high_boundary_coefs
109109
coeff = A.coefficients
110110
bc_start = length(_x.u) - A.boundary_point_count
@@ -120,7 +120,7 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
120120
@inbounds for idx in 1:A.stencil_length-1
121121
xtempi += cur_coeff * cur_stencil[idx] * x[(i-1) - (mid-idx) + 1]
122122
end
123-
x_temp[i] = xtempi
123+
x_temp[i] = xtempi + !overwrite*x_temp[i]
124124
for i in 1 : A.boundary_point_count
125125
cur_stencil = stencil[i]
126126
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[bc_start + i] : coeff isa Number ? coeff : true
@@ -129,6 +129,25 @@ function convolve_BC_right!(x_temp::AbstractVector{T}, _x::BoundaryPaddedVector,
129129
@inbounds for idx in A.stencil_length:-1:1
130130
xtempi += cur_coeff * cur_stencil[end-idx] * _x.u[end-idx+1]
131131
end
132-
x_temp[bc_start + i] = xtempi
132+
x_temp[bc_start + i] = xtempi + !overwrite*x_temp[bc_start + i]
133+
end
134+
end
135+
136+
###########################################
137+
138+
function convolve_interior_add_range!(x_temp::AbstractVector{T}, x::AbstractVector{T}, A::DerivativeOperator, offset::Int) where {T<:Real}
139+
@assert length(x_temp)+2 == length(x)
140+
stencil = A.stencil_coefs
141+
coeff = A.coefficients
142+
mid = div(A.stencil_length,2)
143+
for i in [(1+A.boundary_point_count):(A.boundary_point_count+offset); (length(x_temp)-A.boundary_point_count-offset+1):(length(x_temp)-A.boundary_point_count)]
144+
xtempi = zero(T)
145+
cur_stencil = eltype(stencil) <: AbstractVector ? stencil[i] : stencil
146+
cur_coeff = typeof(coeff) <: AbstractVector ? coeff[i] : coeff isa Number ? coeff : true
147+
cur_stencil = use_winding(A) && cur_coeff < 0 ? reverse(cur_stencil) : cur_stencil
148+
for idx in 1:A.stencil_length
149+
xtempi += cur_coeff * cur_stencil[idx] * x[i - mid + idx]
150+
end
151+
x_temp[i] += xtempi
133152
end
134153
end

src/derivative_operators/derivative_operator.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,4 @@ end
166166
CenteredDifference(args...) = CenteredDifference{1}(args...)
167167
UpwindDifference(args...) = UpwindDifference{1}(args...)
168168
use_winding(A::DerivativeOperator{T,N,Wind}) where {T,N,Wind} = Wind
169+
diff_axis(A::DerivativeOperator{T,N}) where {T,N} = N

0 commit comments

Comments
 (0)