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

Commit 47b7868

Browse files
committed
merged dirichlet and neumann in to robin
1 parent 021c60d commit 47b7868

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

src/derivative_operators/BC_operators.jl

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,6 @@ abstract type AbstractBC{T} end
33
# robin, general, and in general neumann BCs are all affine opeartors, meaning that they take the form Qx = Qax + Qb. neumann0 is not however; is a specialization needed?
44
abstract type AffineBC{T,V} <: AbstractBC{T} end
55

6-
struct DirichletBC{T} <: AbstractBC{T}
7-
l::T
8-
r::T
9-
end
10-
11-
struct NeumannBC{T, V<:AbstractArray{T}} <: AffineBC{T,V}
12-
a_l::V
13-
b_l::T
14-
a_r::V
15-
b_r::T
16-
function NeumannBC(l::T, r::T, dx::AbstractArray{T}, order::T = one(T)) where {T,V}
17-
s = calculate_weights(1, zero(T), zero(T):order) #generate derivative coefficients about the boundary of required approximation order
18-
19-
a_l = -dx_l.*s[2:end]./s[1]
20-
a_r = -dx_r.*s[end:-1:2]./s[1]
21-
22-
b_l = dx_l.*l./s[1]
23-
b_r = dx_r.*l./s[1]
24-
25-
return new{T, typeof(a_l)}(a_l, b_l, a_r, b_r)
26-
end
27-
end
28-
296
struct PeriodicBC{T} <: AbstractBC{T}
307

318
end
@@ -42,8 +19,6 @@ end
4219
The non identity part of Qa is qa:= -b`₁/b0 = -β.*s[2:end]/(α+β*s[1]/Δx). The constant part is Qb = γ/(α+β*s[1]/Δx)
4320
do the same at the other boundary (amounts to a flip of s[2:end], with the other set of boundary coeffs)
4421
"""
45-
46-
# For condition, the variables correspond to al*u(0) + bl*u'(0) = cl
4722
struct RobinBC{T, V<:AbstractVector{T}} <: AffineBC{T,V}
4823
a_l::V
4924
b_l::T
@@ -75,7 +50,6 @@ This time there are multiple stencils for multiple derivative orders - these can
7550
All components that multiply u(0) are factored out, turns out to only involve the first colum of S, s̄0. The rest of S is denoted S`. the coeff of u(0) is s̄0⋅ᾱ[3:end] + α[2].
7651
the remaining components turn out to be ᾱ[3:end]⋅(S`ū`) or equivalantly (transpose(ᾱ[3:end])*S`)⋅ū`. Rearranging, a stencil q_a to be dotted with ū` upon extension can readily be found, along with a constant component q_b
7752
"""
78-
#If you know a more correct name for this kind of BC, please post an issue/PR
7953
struct GeneralBC{T, V<:AbstractVector{T}} <:AffineBC{T,V}
8054
a_l::V
8155
b_l::T
@@ -109,22 +83,25 @@ struct GeneralBC{T, V<:AbstractVector{T}} <:AffineBC{T,V}
10983
end
11084
end
11185

86+
NeumannBC([l::T, r::T], [dx_l,dx_r], order) where T = RobinBC([zero(T), one(T), l], [zero(T), one(T), r], [dx_l,dx_r], order)
87+
NeumannBC([l::T, r::T], [dx_l,dx_r]) where T = RobinBC([zero(T), one(T), l], [zero(T), one(T), r], [dx_l,dx_r])
88+
89+
DirichletBC([l::T, r::T], [dx_l,dx_r], order) where T = RobinBC([one(T), zero(T), l], [one(T), zero(T), r], [dx_l,dx_r], order)
90+
DirichletBC([l::T, r::T], [dx_l,dx_r]) where T = RobinBC([one(T), zero(T), l], [one(T), zero(T), r], [dx_l,dx_r])
91+
92+
93+
11294
# other acceptable argument signatures
11395
RobinBC(al::T, bl::T, cl::T, dx_l::T, ar::T, br::T, cr::T, dx_r::T) where T = RobinBC([al,bl,cl], [ar, br, cr], [dx_l, dx_r])
11496
RobinBC(al::T, bl::T, cl::T, dx_l::T, ar::T, br::T, cr::T, dx_r::T, order::T) where T = RobinBC([al,bl,cl], [ar, br, cr], [dx_l, dx_r], order)
11597

116-
NeumannBC(l::T, dx_l::T, r::T, dx_r::T) where T = NeumannBC(l, r, [dx_l,dx_r])
117-
NeumannBC(l::T, dx_l::T, r::T, dx_r::T, order::T) where T = NeumannBC(l, r, [dx_l,dx_r], order)
118-
11998
# this is 'boundary padded vector' as opposed to 'boundary padded array' to distinguish it from the n dimensional implementation that will eventually be neeeded
12099
struct BoundaryPaddedVector{T,T2 <: AbstractVector{T}}
121100
l::T
122101
r::T
123102
u::T2
124103
end
125104

126-
Base.:*(Q::DirichletBC, u) = BoundaryPaddedVector(Q.l,Q.r,u)
127-
Base.:*(Q::PeriodicBC, u) = BoundaryPaddedVector(u[end], u[1], u)
128105
Base.:*(Q::AffineBC, u) = BoundaryPaddedVector(Q.a_l u[1:length(Q.a_l)] + Q.b_l, Q.a_r u[(end-length(Q.a_r)+1):end] + Q.b_r, u)
129106

130107
Base.size(Q::AbstractBC) = (Inf, Inf) #Is this nessecary?

0 commit comments

Comments
 (0)