comparison src/SbpOperators/boundaryops/boundary_restriction.jl @ 510:db64cfe4d9de feature/boundary_ops

Start sketching on 1D boundary restriction operators.
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Sun, 22 Nov 2020 14:45:32 +0100
parents
children f5f3b832f9c4
comparison
equal deleted inserted replaced
509:b7e42384053a 510:db64cfe4d9de
1 """
2 BoundaryRestriction{T,N,R} <: TensorMapping{T,1,1}
3
4 Implements the boundary operator `e` as a TensorMapping
5 """
6 struct BoundaryRestriction{T,M,R<:Region} <: TensorMapping{T,1,1}
7 closureStencil::Stencil{T,M}
8 size::NTuple{1,Int}
9 end
10 export BoundaryRestriction
11
12
13 function BoundaryRestriction(grid::EquidistantGrid{1,T}, closureStencil::Stencil{T,M},region::Region) where {T,M}
14 return BoundaryRestriction{T,M,typeof(region)}(closureStencil,size(grid))
15 end
16
17 LazyTensors.range_size(e::BoundaryRestriction) = (1,)
18 LazyTensors.domain_size(e::BoundaryRestriction) = e.size
19
20 " Restricts a grid function v on a grid of size (m,) to the scalar element v[1]"
21 function LazyTensors.apply(e::BoundaryRestriction{T,M,Lower}, v::AbstractVector{T}, i) where {T,M}
22 # TODO: Currently closuresize = 4 for the stencil,
23 # but we should only be able to apply this for v[1] since the result is scalar.
24 @boundscheck if !(0 < Int(i) <= closuresize(e))
25 throw(BoundsError())
26 end
27 apply_stencil(e.closureStencil,v,Int(i))
28 end
29
30 " Restricts a grid function v on a grid of size (m,) to the scalar element v[m]"
31 function LazyTensors.apply(e::BoundaryRestriction{T,M,Upper}, v::AbstractVector{T}, i) where {T,M}
32 # TODO: Currently closuresize = 4 for the stencil,
33 # but we should only be able to apply this for v[1] since the result is scalar.
34 @boundscheck if !(e.size[1] - closuresize(e) < Int(i) <= e.size[1])
35 throw(BoundsError())
36 end
37 apply_stencil_backwards(e.closureStencil,v,Int(i))
38 end
39
40 " Transpose of a restriction is an inflation or prolongation.
41 Inflates the scalar (1-element) vector to a vector of size of the grid"
42 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,M,Lower}, v::AbstractVector{T}, i) where {T,M}
43 @boundscheck if !(0 < Int(i) <= e.size[1])
44 throw(BoundsError())
45 end
46 return e.closureStencil[Int(i)-1]*v[1]
47 end
48
49 closuresize(e::BoundaryRestriction{T,M}) where {T,M} = M