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

Commit fa0c34e

Browse files
committed
offside changed to kwargs
1 parent ffe0f4d commit fa0c34e

10 files changed

Lines changed: 51 additions & 51 deletions

src/derivative_operators/derivative_operator.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ julia> Array(L2 * Q)[1]
187187
"""
188188
function UpwindDifference{N}(derivative_order::Int,
189189
approximation_order::Int, dx::T,
190-
len::Int, offside::Int, coeff_func=nothing) where {T<:Real,N}
190+
len::Int, coeff_func=nothing; offside::Int=0) where {T<:Real,N}
191191

192192
@assert offside > -1 "Number of offside points should be non-negative"
193193
@assert offside <= div(derivative_order + approximation_order - 1,2) "Number of offside points should not exceed the primary wind points"
@@ -230,7 +230,7 @@ end
230230
# TODO implement the non-uniform grid
231231
function UpwindDifference{N}(derivative_order::Int,
232232
approximation_order::Int, dx::AbstractVector{T},
233-
len::Int, offside::Int, coeff_func=nothing) where {T<:Real,N}
233+
len::Int, coeff_func=nothing; offside::Int=0) where {T<:Real,N}
234234

235235
@assert offside > -1 "Number of offside points should be non-negative"
236236
@assert offside <= div(derivative_order + approximation_order - 1,2) "Number of offside points should not exceed the primary wind points"
@@ -287,7 +287,7 @@ function UpwindDifference{N}(derivative_order::Int,
287287
end
288288

289289
CenteredDifference(args...) = CenteredDifference{1}(args...)
290-
UpwindDifference(args...) = UpwindDifference{1}(args...)
290+
UpwindDifference(args...;kwargs...) = UpwindDifference{1}(args...;kwargs...)
291291
nonlinear_diffusion(args...) = nonlinear_diffusion{1}(args...)
292292
nonlinear_diffusion!(args...) = nonlinear_diffusion!{1}(args...)
293293
use_winding(A::DerivativeOperator{T,N,Wind}) where {T,N,Wind} = Wind

test/BasicSDOExamples.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ function DEO_negative_drift(pi_profit, params)
3232
dx = params.x[2] - params.x[1]
3333
# discretize L = ρ - μ D_x - σ^2 / 2 D_xx
3434
# subject to reflecting barriers at 0 and 1
35-
L1 = UpwindDifference(1,1,dx,params.M,0,1.)
35+
L1 = UpwindDifference(1,1,dx,params.M,1.)
3636
L2 = CenteredDifference(2,2,dx,params.M)
3737
Q = Neumann0BC(dx, 1)
38-
L₁₋bc = -1. .* Array(UpwindDifference(1,1,dx,params.M,0,-1.) * Q)[1]
38+
L₁₋bc = -1. .* Array(UpwindDifference(1,1,dx,params.M,-1.) * Q)[1]
3939
# Here Array(A::GhostDerivativeOperator) will return a tuple of the linear part
4040
# and the affine part of the operator A, hence we index Array(µ*L1*Q).
4141
# The operators in this example are purely linear, so we don't worry about Array(µ*L1*Q)[2]
@@ -72,7 +72,7 @@ function DEO_positive_drift(pi_profit, params)
7272
dx = params.x[2] - params.x[1]
7373
# discretize L = ρ - μ D_x - σ^2 / 2 D_xx
7474
# subject to reflecting barriers at 0 and 1
75-
L1 = UpwindDifference(1,1,dx,params.M,0,1.0)
75+
L1 = UpwindDifference(1,1,dx,params.M,1.0)
7676
L2 = CenteredDifference(2,2,dx,params.M)
7777
Q = Neumann0BC(dx, 1)
7878
# Here Array(A::GhostDerivativeOperator) will return a tuple of the linear part
@@ -114,7 +114,7 @@ function DEO_state_dependent_drift(pi_profit, μ, params)
114114
# discretize L = ρ - μ D_x - σ^2 / 2 D_xx
115115
# subject to reflecting barriers at 0 and 1
116116
drift = μ.(params.x)
117-
L1 = UpwindDifference(1,1,dx,params.M,0,drift)
117+
L1 = UpwindDifference(1,1,dx,params.M,drift)
118118
L2 = CenteredDifference(2,2,dx,params.M)
119119
Q = Neumann0BC(dx, 1)
120120
# Here Array(A::GhostDerivativeOperator) will return a tuple of the linear part
@@ -166,7 +166,7 @@ end=#
166166
function DEO_absorbing_bc(pi_profit, params)
167167
dx = params.x[2] - params.x[1]
168168

169-
L1 = UpwindDifference(1,1,dx,params.M,0,params.μ)
169+
L1 = UpwindDifference(1,1,dx,params.M,params.μ)
170170
L2 = CenteredDifference(2,2,dx,params.M)
171171
# RobinBC(l::NTuple{3,T}, r::NTuple{3,T}, dx::T, order = 1)
172172
# The variables in l are [αl, βl, γl], and correspond to a BC of the form αl*u(0) + βl*u'(0) = γl
@@ -235,7 +235,7 @@ end=#
235235
function DEO_Solve_KFE(params)
236236
dx = params.x[2] - params.x[1]
237237

238-
L1 = UpwindDifference(1,1,dx,params.M,0,-params.μ)
238+
L1 = UpwindDifference(1,1,dx,params.M,-params.μ)
239239
# L2l = UpwindDifference(2,2,dx,params.M,
240240
# vcat(-1.,zeros(params.M-1)))
241241
# L2r = UpwindDifference(2,2,dx,params.M,

test/KdV.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using DiffEqOperators, OrdinaryDiffEq, LinearAlgebra
1919
# const temp = zeros(size(x));
2020

2121
# A = CenteredDifference(1,2,Δx,length(x),:Dirichlet0,:Dirichlet0);
22-
A = UpwindDifference{Float64}(1,3,Δx,length(x),0,-1);
22+
A = UpwindDifference{Float64}(1,3,Δx,length(x),-1);
2323
# C = CenteredDifference(3,2,Δx,length(x),:Dirichlet0,:Dirichlet0);
2424
#C = UpwindDifference{Float64}(3,3,Δx,length(x),-1);
2525

test/bc_coeff_compositions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ end
5050
N = 20
5151
L = CenteredDifference(4, 4, dx, N)
5252
L2 = CenteredDifference(2,4, dx, N)
53-
L1 = UpwindDifference(1, 1, dx, N, 0, 1.)
53+
L1 = UpwindDifference(1, 1, dx, N, 1.)
5454

5555
function coeff_func(du,u,p,t)
5656
du .= u
@@ -111,7 +111,7 @@ end
111111
# Test for consistency of c*GhostDerivativeOperator*u when c is a vector
112112
c = rand(N)
113113
L = CenteredDifference(4, 4, dx, N)
114-
L1 = UpwindDifference(1, 1, 1., N, 0, 1.)
114+
L1 = UpwindDifference(1, 1, 1., N, 1.)
115115
A1 = L1 * Q
116116
cA = c * A
117117
cL = c * L
@@ -182,7 +182,7 @@ end
182182
dx = rand(N + 2)
183183

184184
Q = RobinBC((al, bl, cl), (ar, br, cr), dx)
185-
L = UpwindDifference(1, 1, dx, N + 1, 0, 1.)
185+
L = UpwindDifference(1, 1, dx, N + 1, 1.)
186186
L2 = CenteredDifference(2, 2, dx, N)
187187
L4 = CenteredDifference(4, 4, dx, N - 2)
188188

test/coefficient_functions.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ end
4646
# Set up operators to test construction with different coeff_func
4747
vec_op = Vector{DerivativeOperator}(undef,0)
4848
dxv = [1.4, 1.1, 2.3, 3.6, 1.5]
49-
push!(vec_op, UpwindDifference(1, 1, 1., 3, 0, 1.))
50-
push!(vec_op, UpwindDifference(1, 1, 1., 3, 0, [1., 2.25, 3.5]))
51-
push!(vec_op, UpwindDifference(1, 1, 1., 3, 0, cos))
52-
push!(vec_op, UpwindDifference(1, 1, dxv, 3, 0, 1.))
53-
push!(vec_op, UpwindDifference(1, 1, dxv, 3, 0, [1., 2.25, 3.5]))
54-
push!(vec_op, UpwindDifference(1, 1, dxv, 3, 0, cos))
49+
push!(vec_op, UpwindDifference(1, 1, 1., 3, 1.))
50+
push!(vec_op, UpwindDifference(1, 1, 1., 3, [1., 2.25, 3.5]))
51+
push!(vec_op, UpwindDifference(1, 1, 1., 3, cos))
52+
push!(vec_op, UpwindDifference(1, 1, dxv, 3, 1.))
53+
push!(vec_op, UpwindDifference(1, 1, dxv, 3, [1., 2.25, 3.5]))
54+
push!(vec_op, UpwindDifference(1, 1, dxv, 3, cos))
5555

5656

5757
vec_op_ans = Vector{Any}(undef,0)
@@ -63,7 +63,7 @@ end
6363
push!(vec_op_ans, ones(3))
6464

6565
# Check constructors
66-
@test UpwindDifference(1, 1, 1., 3,0).coefficients + ones(3) - ones(3) zeros(3)
66+
@test UpwindDifference(1, 1, 1., 3).coefficients + ones(3) - ones(3) zeros(3)
6767
@test CenteredDifference(2, 2, 1., 3, 0.).coefficients + ones(3) - ones(3) zeros(3)
6868
for (L, op_ans) in zip(vec_op, vec_op_ans)
6969
@test L.coefficients op_ans

test/derivative_operators_interface.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ end
329329

330330
@testset "Left-multiplying operators with a vector of coefficients" begin
331331
A = CenteredDifference(2, 2, 1., 3)
332-
B = UpwindDifference(1, 1, 1., 3, 0, 1.)
333-
C = UpwindDifference(1, 1, 1., 3, 0, [2., 3., 4.])
332+
B = UpwindDifference(1, 1, 1., 3, 1.)
333+
C = UpwindDifference(1, 1, 1., 3, [2., 3., 4.])
334334
c = [1., 1., 3.]
335335
cA = c * A
336336
cB = c * B

test/heat_eqn.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ using OrdinaryDiffEq
1717
end
1818

1919
# UpwindDifference with equal no. of primay wind and offside points should behave like a CenteredDifference
20-
A2 = UpwindDifference(2,1,2π/511,512,1,1);
20+
A2 = UpwindDifference(2,1,2π/511,512,1,offside=1);
2121
step(u,p,t) = A2*bc*u
2222
heat_eqn = ODEProblem(step, u0, (0.,10.))
2323
soln = solve(heat_eqn,Tsit5(),dense=false,tstops=0:0.01:10)
@@ -52,7 +52,7 @@ end
5252
end
5353

5454
# UpwindDifference with equal no. of primay wind and offside points should behave like a CenteredDifference
55-
A2 = UpwindDifference(2,1,dx,N,1,1)
55+
A2 = UpwindDifference(2,1,dx,N,1,offside=1)
5656
step(u,p,t) = A2*bc*u
5757
heat_eqn = ODEProblem(step, u0, (0.,10.))
5858
soln = solve(heat_eqn,Tsit5(),dense=false,tstops=0:0.01:10)
@@ -92,7 +92,7 @@ end
9292
end
9393

9494
# UpwindDifference with equal no. of primay wind and offside points should behave like a CenteredDifference
95-
A2 = UpwindDifference(2,1,dx,N,1,1);
95+
A2 = UpwindDifference(2,1,dx,N,1,offside=1);
9696
step(u,p,t) = A2*bc*u
9797
heat_eqn = ODEProblem(step, u0, (0.,10.));
9898
soln = solve(heat_eqn,Tsit5(),dense=false,tstops=0:0.01:10);

test/lcp.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function LCP_objects(sp)
3131
# construct operator and non-operator LCP objects
3232
BC1 = RobinBC((0., 1., 0.), (0., 1., 0.), grid[2] - grid[1], 1) # for first-derivative
3333
BC2 = RobinBC((0., 1., 0.), (0., 1., 0.), grid[2] - grid[1], 1) # for second-derivative
34-
L1 = UpwindDifference(1, 1, grid[2] - grid[1], M, 0, μ) * BC1
34+
L1 = UpwindDifference(1, 1, grid[2] - grid[1], M, μ) * BC1
3535
L2 = σ^2/2 * CenteredDifference(2, 2, grid[2] - grid[1], M) * BC2
3636
S_vec = S.(grid)
3737
u_vec = u.(grid)

test/lcp_split.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function LCP_split(S_)
1919

2020
# construct operator and non-operator LCP objects
2121
BC = RobinBC((0., 1., 0.), (0., 1., 0.), x[2] - x[1], 1)
22-
L1 = UpwindDifference(1, 1, x[2] - x[1], M, 0, map(t -> μ1(t), x)) * BC
22+
L1 = UpwindDifference(1, 1, x[2] - x[1], M, map(t -> μ1(t), x)) * BC
2323
L2 = σ^2 / 2 * CenteredDifference(2, 2, x[2] - x[1], M) * BC
2424
u_vec = u1.(x)
2525

0 commit comments

Comments
 (0)