comparison 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
comparison
equal deleted inserted replaced
571:205238c342da 572:64f1b269e9fc
50 50
51 function LazyTensors.apply(e::BoundaryRestriction{T,Upper}, v::AbstractVector{T}) where T 51 function LazyTensors.apply(e::BoundaryRestriction{T,Upper}, v::AbstractVector{T}) where T
52 apply_stencil_backwards(e.stencil,v,e.size) 52 apply_stencil_backwards(e.stencil,v,e.size)
53 end 53 end
54 54
55 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Lower}, v::AbstractArray{T,0}, i) where T 55 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Lower}, v::AbstractArray{T,0}, i::Index{Lower}) where T
56 @boundscheck if !(0 < Int(i) <= e.size)
57 throw(BoundsError())
58 end
59 return e.stencil[Int(i)-1]*v[] 56 return e.stencil[Int(i)-1]*v[]
60 end 57 end
61 58
62 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Upper}, v::AbstractArray{T,0}, i) where T 59 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Upper}, v::AbstractArray{T,0}, i::Index{Upper}) where T
63 @boundscheck if !(0 < Int(i) <= e.size)
64 throw(BoundsError())
65 end
66 return e.stencil[e.size[1] - Int(i)]*v[] 60 return e.stencil[e.size[1] - Int(i)]*v[]
67 end 61 end
62
63 # Catch all combinations of Lower, Upper and Inner not caught by the two previous methods.
64 function LazyTensors.apply_transpose(e::BoundaryRestriction{T}, v::AbstractArray{T,0}, i::Index) where T
65 return zero(T)
66 end
67
68 function LazyTensors.apply_transpose(e::BoundaryRestriction{T}, v::AbstractArray{T,0}, i) where T
69 r = getregion(i, closuresize(e), e.size)
70 apply_transpose(e, v, Index(i,r))
71 end