Mercurial > repos > public > sbplib_julia
diff src/SbpOperators/boundaryops/boundary_restriction.jl @ 572:64f1b269e9fc feature/boundary_ops
Implement apply_transpose for different regions and remove boundschecks to simplify
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 01 Dec 2020 16:02:44 +0100 |
parents | 205238c342da |
children | cae4d5b428d6 |
line wrap: on
line diff
--- a/src/SbpOperators/boundaryops/boundary_restriction.jl Tue Dec 01 16:01:08 2020 +0100 +++ b/src/SbpOperators/boundaryops/boundary_restriction.jl Tue Dec 01 16:02:44 2020 +0100 @@ -52,16 +52,20 @@ apply_stencil_backwards(e.stencil,v,e.size) end -function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Lower}, v::AbstractArray{T,0}, i) where T - @boundscheck if !(0 < Int(i) <= e.size) - throw(BoundsError()) - end +function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Lower}, v::AbstractArray{T,0}, i::Index{Lower}) where T return e.stencil[Int(i)-1]*v[] end -function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Upper}, v::AbstractArray{T,0}, i) where T - @boundscheck if !(0 < Int(i) <= e.size) - throw(BoundsError()) - end +function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Upper}, v::AbstractArray{T,0}, i::Index{Upper}) where T return e.stencil[e.size[1] - Int(i)]*v[] end + +# Catch all combinations of Lower, Upper and Inner not caught by the two previous methods. +function LazyTensors.apply_transpose(e::BoundaryRestriction{T}, v::AbstractArray{T,0}, i::Index) where T + return zero(T) +end + +function LazyTensors.apply_transpose(e::BoundaryRestriction{T}, v::AbstractArray{T,0}, i) where T + r = getregion(i, closuresize(e), e.size) + apply_transpose(e, v, Index(i,r)) +end