changeset 511:f5f3b832f9c4 feature/boundary_ops

Fix boundschecking for BoundaryRestriction
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Mon, 23 Nov 2020 13:09:57 +0100
parents db64cfe4d9de
children 5a8cfcc0765d
files src/SbpOperators/boundaryops/boundary_restriction.jl
diffstat 1 files changed, 12 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/SbpOperators/boundaryops/boundary_restriction.jl	Sun Nov 22 14:45:32 2020 +0100
+++ b/src/SbpOperators/boundaryops/boundary_restriction.jl	Mon Nov 23 13:09:57 2020 +0100
@@ -4,37 +4,32 @@
 Implements the boundary operator `e` as a TensorMapping
 """
 struct BoundaryRestriction{T,M,R<:Region} <: TensorMapping{T,1,1}
-    closureStencil::Stencil{T,M}
+    stencil::Stencil{T,M}
     size::NTuple{1,Int}
 end
 export BoundaryRestriction
 
-
-function BoundaryRestriction(grid::EquidistantGrid{1,T}, closureStencil::Stencil{T,M},region::Region) where {T,M}
-    return BoundaryRestriction{T,M,typeof(region)}(closureStencil,size(grid))
+function BoundaryRestriction(grid::EquidistantGrid{1,T}, closureStencil::Stencil{T,M}, region::Region) where {T,M}
+    return BoundaryRestriction{T,M,typeof(region)}(stencil,size(grid))
 end
 
 LazyTensors.range_size(e::BoundaryRestriction) = (1,)
 LazyTensors.domain_size(e::BoundaryRestriction) = e.size
 
-" Restricts a grid function v on a grid of size (m,) to the scalar element v[1]"
-function LazyTensors.apply(e::BoundaryRestriction{T,M,Lower}, v::AbstractVector{T}, i) where {T,M}
-    # TODO: Currently closuresize = 4 for the stencil,
-    # but we should only be able to apply this for v[1] since the result is scalar.
-    @boundscheck if !(0 < Int(i) <= closuresize(e))
+" Restricts a grid function v on a grid of size m to the scalar element v[1]"
+function LazyTensors.apply(e::BoundaryRestriction{T,M,Lower}, v::AbstractVector{T}, i::Index{Lower}) where {T,M}
+    @boundscheck if Int(i)!=1
         throw(BoundsError())
     end
-    apply_stencil(e.closureStencil,v,Int(i))
+    apply_stencil(e.stencil,v,Int(i))
 end
 
-" Restricts a grid function v on a grid of size (m,) to the scalar element v[m]"
-function LazyTensors.apply(e::BoundaryRestriction{T,M,Upper}, v::AbstractVector{T}, i) where {T,M}
-    # TODO: Currently closuresize = 4 for the stencil,
-    # but we should only be able to apply this for v[1] since the result is scalar.
-    @boundscheck if !(e.size[1] - closuresize(e) < Int(i) <= e.size[1])
+" Restricts a grid function v on a grid of size m to the scalar element v[m]"
+function LazyTensors.apply(e::BoundaryRestriction{T,M,Upper}, v::AbstractVector{T}, i::Index{Upper}) where {T,M}
+    @boundscheck if Int(i) != e.size[1]
         throw(BoundsError())
     end
-    apply_stencil_backwards(e.closureStencil,v,Int(i))
+    apply_stencil_backwards(e.stencil,v,Int(i))
 end
 
 " Transpose of a restriction is an inflation or prolongation.
@@ -43,7 +38,5 @@
     @boundscheck if !(0 < Int(i) <= e.size[1])
         throw(BoundsError())
     end
-    return e.closureStencil[Int(i)-1]*v[1]
+    return e.stencil[Int(i)-1]*v[1]
 end
-
-closuresize(e::BoundaryRestriction{T,M}) where {T,M} = M