Skip to content

Instantly share code, notes, and snippets.

@ChrisRackauckas
Last active June 7, 2019 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisRackauckas/54aa5298ec173652455221ccbacbfb6a to your computer and use it in GitHub Desktop.
Save ChrisRackauckas/54aa5298ec173652455221ccbacbfb6a to your computer and use it in GitHub Desktop.
DirichletBC
struct DirichletBC{T}
l::T
r::T
end
struct BoundaryPaddedArray{T,T2 <: AbstractVector{T}}
l::T
r::T
u::T2
end
Base.:*(Q::DirichletBC,u) = BoundaryPaddedArray(Q.l,Q.r,u)
Base.length(Q::BoundaryPaddedArray) = length(Q.u) + 2
Base.lastindex(Q::BoundaryPaddedArray) = Base.length(Q)
function Base.getindex(Q::BoundaryPaddedArray,i)
@show i
if i == 1
return Q.l
elseif i == length(Q)
return Q.r
else
return Q.u[i-1]
end
end
x = range(-2π,stop=2π,length=100)[2:end-1]
u = @. (x-2π)*(x+2π)
Q = DirichletBC(0.0,0.0)
v = Q*u
v[1]
v[2]
v[end-1]
v[end]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment