This repository was archived by the owner on Jul 19, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 73
[WIP] (issue #237) Allow distinct type for grid vs. function value in BC constructor #260
Open
AndiMD
wants to merge
11
commits into
SciML:master
Choose a base branch
from
AndiMD:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0db40b7
Add distinct type for grid vs. function value
b6b39f6
Test Robin BC with complex function values
0d3d564
duplicate comment
0f63558
Add new test to runtests
e8a2d96
Restrict types to avoid ambiguity
b558da8
More tests, type restrictions
6106632
Fix Dirichlet / Neumann
d477f23
Add tests for Neuman/Dirichlet w. Complex numbers
83a9b6c
Add distinct type for grid vs. function value
AndiMD c6f45a5
Merge remote-tracking branch 'AndiMD/master'
197c9f2
Express unconjugated dot product by sum(a.*b)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,28 +22,28 @@ struct RobinBC{T, V<:AbstractVector{T}} <: AffineBC{T} | |
b_l::T | ||
a_r::V | ||
b_r::T | ||
function RobinBC(l::NTuple{3,T}, r::NTuple{3,T}, dx::T, order = 1) where {T} | ||
function RobinBC(l::NTuple{3,T}, r::NTuple{3,T}, dx::U, order = 1) where {T<:Number,U<:Real} | ||
αl, βl, γl = l | ||
αr, βr, γr = r | ||
|
||
s = calculate_weights(1, one(T), Array(one(T):convert(T,order+1))) #generate derivative coefficients about the boundary of required approximation order | ||
s = calculate_weights(1, one(U), Array(one(U):convert(U,order+1))) #generate derivative coefficients about the boundary of required approximation order | ||
|
||
a_l = -s[2:end]./(αl*dx/βl + s[1]) | ||
a_r = s[end:-1:2]./(αr*dx/βr - s[1]) # for other boundary stencil is flippedlr with *opposite sign* | ||
a_l = -βl*s[2:end]./(αl*dx + βl*s[1]) | ||
a_r = βr*s[end:-1:2]./(αr*dx - βr*s[1]) # for other boundary stencil is flippedlr with *opposite sign* | ||
|
||
b_l = γl/(αl+βl*s[1]/dx) | ||
b_r = γr/(αr-βr*s[1]/dx) | ||
|
||
return new{T, typeof(a_l)}(a_l, b_l, a_r, b_r) | ||
end | ||
function RobinBC(l::Union{NTuple{3,T},AbstractVector{T}}, r::Union{NTuple{3,T},AbstractVector{T}}, dx::AbstractVector{T}, order = 1) where {T} | ||
function RobinBC(l::Union{NTuple{3,T},AbstractVector{T}}, r::Union{NTuple{3,T},AbstractVector{T}}, dx::AbstractVector{U}, order = 1) where {T<:Number,U<:Real} | ||
αl, βl, γl = l | ||
αr, βr, γr = r | ||
|
||
s_index = Array(one(T):convert(T,order+1)) | ||
s_index = Array(one(U):convert(U,order+1)) | ||
dx_l, dx_r = dx[1:length(s_index)], dx[(end-length(s_index)+1):end] | ||
|
||
s = calculate_weights(1, one(T), s_index) #generate derivative coefficients about the boundary of required approximation order | ||
s = calculate_weights(1, one(U), s_index) #generate derivative coefficients about the boundary of required approximation order | ||
denom_l = αl+βl*s[1]/dx_l[1] | ||
denom_r = αr-βr*s[1]/dx_r[end] | ||
|
||
|
@@ -76,24 +76,24 @@ struct GeneralBC{T, L<:AbstractVector{T}, R<:AbstractVector{T}} <:AffineBC{T} | |
b_l::T | ||
a_r::R | ||
b_r::T | ||
function GeneralBC(αl::AbstractVector{T}, αr::AbstractVector{T}, dx::T, order = 1) where {T} | ||
function GeneralBC(αl::AbstractVector{T}, αr::AbstractVector{T}, dx::U, order = 1) where {T<:Number,U<:Real} | ||
nl = length(αl) | ||
nr = length(αr) | ||
S_l = zeros(T, (nl-2, order+nl-2)) | ||
S_r = zeros(T, (nr-2, order+nr-2)) | ||
|
||
for i in 1:(nl-2) | ||
S_l[i,:] = [transpose(calculate_weights(i, one(T), Array(one(T):convert(T, order+i)))) transpose(zeros(T, Int(nl-2-i)))]./(dx^i) #am unsure if the length of the dummy_x is correct here | ||
S_l[i,:] = [transpose(calculate_weights(i, one(U), Array(one(U):convert(U, order+i)))) transpose(zeros(U, Int(nl-2-i)))]./(dx^i) #am unsure if the length of the dummy_x is correct here | ||
end | ||
|
||
for i in 1:(nr-2) | ||
S_r[i,:] = [transpose(calculate_weights(i, convert(T, order+i), Array(one(T):convert(T, order+i)))) transpose(zeros(T, Int(nr-2-i)))]./(dx^i) | ||
S_r[i,:] = [transpose(calculate_weights(i, convert(U, order+i), Array(one(U):convert(U, order+i)))) transpose(zeros(U, Int(nr-2-i)))]./(dx^i) | ||
end | ||
s0_l = S_l[:,1] ; Sl = S_l[:,2:end] | ||
s0_r = S_r[:,end] ; Sr = S_r[:,(end-1):-1:1] | ||
|
||
denoml = αl[2] .+ αl[3:end] ⋅ s0_l | ||
denomr = αr[2] .+ αr[3:end] ⋅ s0_r | ||
denoml = αl[2] .+ αl[3:end]' ⋅ s0_l | ||
denomr = αr[2] .+ αr[3:end]' ⋅ s0_r | ||
|
||
a_l = -transpose(transpose(αl[3:end]) * Sl) ./denoml | ||
a_r = reverse(-transpose(transpose(αr[3:end]) * Sr) ./denomr) | ||
|
@@ -103,7 +103,7 @@ struct GeneralBC{T, L<:AbstractVector{T}, R<:AbstractVector{T}} <:AffineBC{T} | |
new{T, typeof(a_l), typeof(a_r)}(a_l,b_l,a_r,b_r) | ||
end | ||
|
||
function GeneralBC(αl::AbstractVector{T}, αr::AbstractVector{T}, dx::AbstractVector{T}, order = 1) where {T} | ||
function GeneralBC(αl::AbstractVector{T}, αr::AbstractVector{T}, dx::AbstractVector{U}, order = 1) where {T<:Number,U<:Real} | ||
|
||
nl = length(αl) | ||
nr = length(αr) | ||
|
@@ -112,17 +112,17 @@ struct GeneralBC{T, L<:AbstractVector{T}, R<:AbstractVector{T}} <:AffineBC{T} | |
S_r = zeros(T, (nr-2, order+nr-2)) | ||
|
||
for i in 1:(nl-2) | ||
S_l[i,:] = [transpose(calculate_weights(i, one(T), Array(one(T):convert(T, order+i)))) transpose(zeros(T, Int(nl-2-i)))]./(dx_l.^i) | ||
S_l[i,:] = [transpose(calculate_weights(i, one(U), Array(one(U):convert(U, order+i)))) transpose(zeros(U, Int(nl-2-i)))]./(dx_l.^i) | ||
end | ||
|
||
for i in 1:(nr-2) | ||
S_r[i,:] = [transpose(calculate_weights(i, convert(T, order+i), Array(one(T):convert(T, order+i)))) transpose(zeros(T, Int(nr-2-i)))]./(dx_r.^i) | ||
S_r[i,:] = [transpose(calculate_weights(i, convert(U, order+i), Array(one(U):convert(U, order+i)))) transpose(zeros(U, Int(nr-2-i)))]./(dx_r.^i) | ||
end | ||
s0_l = S_l[:,1] ; Sl = S_l[:,2:end] | ||
s0_r = S_r[:,end] ; Sr = S_r[:,(end-1):-1:1] | ||
|
||
denoml = αl[2] .+ αl[3:end] ⋅ s0_l | ||
denomr = αr[2] .+ αr[3:end] ⋅ s0_r | ||
denoml = αl[2] .+ αl[3:end]' ⋅ s0_l | ||
denomr = αr[2] .+ αr[3:end]' ⋅ s0_r | ||
|
||
a_l = -transpose(transpose(αl[3:end]) * Sl) ./denoml | ||
a_r = reverse(-transpose(transpose(αr[3:end]) * Sr) ./denomr) | ||
|
@@ -136,16 +136,19 @@ end | |
|
||
|
||
#implement Neumann and Dirichlet as special cases of RobinBC | ||
NeumannBC(α::NTuple{2,T}, dx::Union{AbstractVector{T}, T}, order = 1) where T = RobinBC((zero(T), one(T), α[1]), (zero(T), one(T), α[2]), dx, order) | ||
DirichletBC(αl::T, αr::T) where T = RobinBC((one(T), zero(T), αl), (one(T), zero(T), αr), one(T), 2one(T) ) | ||
NeumannBC(α::NTuple{2,T}, dx::Union{AbstractVector{U}, U}, order = 1) where {T<:Number,U<:Real} = RobinBC((zero(T), one(T), α[1]), (zero(T), one(T), α[2]), dx, order) | ||
DirichletBC(αl::T, αr::T) where {T<:Real} = RobinBC((one(T), zero(T), αl), (one(T), zero(T), αr), one(T), 2one(T) ) | ||
DirichletBC(::Type{U},αl::T, αr::T) where {T<:Number,U<:Real} = RobinBC((one(T), zero(T), αl), (one(T), zero(T), αr), one(U), 2one(U) ) | ||
#specialized constructors for Neumann0 and Dirichlet0 | ||
Dirichlet0BC(T::Type) = DirichletBC(zero(T), zero(T)) | ||
Neumann0BC(dx::Union{AbstractVector{T}, T}, order = 1) where T = NeumannBC((zero(T), zero(T)), dx, order) | ||
Neumann0BC(dx::Union{AbstractVector{T}, T}, order = 1) where {T<:Real} = NeumannBC((zero(T), zero(T)), dx, order) | ||
Neumann0BC(::Type{U},dx::Union{AbstractVector{T}, T}, order = 1) where {T<:Real,U<:Number} = NeumannBC((zero(U), zero(U)), dx, order) | ||
|
||
# other acceptable argument signatures | ||
#RobinBC(al::T, bl::T, cl::T, dx_l::T, ar::T, br::T, cr::T, dx_r::T, order = 1) where T = RobinBC([al,bl, cl], [ar, br, cr], dx_l, order) | ||
|
||
Base.:*(Q::AffineBC, u::AbstractVector) = 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) | ||
Base.:*(Q::AffineBC, u::AbstractVector) = 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 ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea that the dot-product should not complex conjugate came from this line. I figured it should be the same for GeneralBC |
||
|
||
Base.:*(Q::PeriodicBC, u::AbstractVector) = BoundaryPaddedVector(u[end], u[1], u) | ||
|
||
Base.size(Q::AtomicBC) = (Inf, Inf) #Is this nessecary? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why adjoint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⋅(a,b)
complex conjugatesa
. I believe this should not be complex conjugated.Should probably have been
conj.
instead ofadjoint
(same result due to thedot
).