Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/boundaryops/boundary_restriction.jl @ 570:a8fe91861116 feature/boundary_ops
Change order of type parameters R and N to allow skipping N
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 01 Dec 2020 15:36:35 +0100 |
parents | 2a7a258eaaa6 |
children | 205238c342da |
comparison
equal
deleted
inserted
replaced
569:2a7a258eaaa6 | 570:a8fe91861116 |
---|---|
19 return I⊗e | 19 return I⊗e |
20 end | 20 end |
21 export boundary_restriction | 21 export boundary_restriction |
22 | 22 |
23 """ | 23 """ |
24 BoundaryRestriction{T,N,R} <: TensorMapping{T,0,1} | 24 BoundaryRestriction{T,R,N} <: TensorMapping{T,0,1} |
25 | 25 |
26 Implements the boundary operator `e` for 1D as a TensorMapping | 26 Implements the boundary operator `e` for 1D as a TensorMapping |
27 `e` is the restriction of a grid function to the boundary using some `closureStencil`. | 27 `e` is the restriction of a grid function to the boundary using some `closureStencil`. |
28 The boundary to restrict to is determined by `R`. | 28 The boundary to restrict to is determined by `R`. |
29 | 29 |
30 `e'` is the prolongation of a zero dimensional array to the whole grid using the same `closureStencil`. | 30 `e'` is the prolongation of a zero dimensional array to the whole grid using the same `closureStencil`. |
31 """ | 31 """ |
32 struct BoundaryRestriction{T,N,R<:Region} <: TensorMapping{T,0,1} | 32 struct BoundaryRestriction{T,R<:Region,N} <: TensorMapping{T,0,1} |
33 stencil::Stencil{T,N} | 33 stencil::Stencil{T,N} |
34 size::NTuple{1,Int} | 34 size::Int |
35 end | 35 end |
36 export BoundaryRestriction | 36 export BoundaryRestriction |
37 | 37 |
38 function BoundaryRestriction(grid::EquidistantGrid{1}, closureStencil::Stencil{T,N}, region::Region) where {T,N} | 38 function BoundaryRestriction(grid::EquidistantGrid{1}, closureStencil::Stencil{T,N}, region::Region) where {T,N} |
39 return BoundaryRestriction{T,N,typeof(region)}(closureStencil,size(grid)) | 39 return BoundaryRestriction{T,typeof(region),N}(closureStencil,size(grid)[1]) |
40 end | 40 end |
41 | 41 |
42 LazyTensors.range_size(e::BoundaryRestriction) = () | 42 LazyTensors.range_size(e::BoundaryRestriction) = () |
43 LazyTensors.domain_size(e::BoundaryRestriction) = e.size | 43 LazyTensors.domain_size(e::BoundaryRestriction) = (e.size,) |
44 | 44 |
45 function LazyTensors.apply(e::BoundaryRestriction{T,N,Lower}, v::AbstractVector{T}) where {T,N} | 45 function LazyTensors.apply(e::BoundaryRestriction{T,Lower}, v::AbstractVector{T}) where T |
46 apply_stencil(e.stencil,v,1) | 46 apply_stencil(e.stencil,v,1) |
47 end | 47 end |
48 | 48 |
49 function LazyTensors.apply(e::BoundaryRestriction{T,N,Upper}, v::AbstractVector{T}) where {T,N} | 49 function LazyTensors.apply(e::BoundaryRestriction{T,Upper}, v::AbstractVector{T}) where T |
50 apply_stencil_backwards(e.stencil,v,e.size[1]) | 50 apply_stencil_backwards(e.stencil,v,e.size) |
51 end | 51 end |
52 | 52 |
53 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,N,Lower}, v::AbstractArray{T,0}, i) where {T,N} | 53 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Lower}, v::AbstractArray{T,0}, i) where T |
54 @boundscheck if !(0 < Int(i) <= e.size[1]) | 54 @boundscheck if !(0 < Int(i) <= e.size) |
55 throw(BoundsError()) | 55 throw(BoundsError()) |
56 end | 56 end |
57 return e.stencil[Int(i)-1]*v[] | 57 return e.stencil[Int(i)-1]*v[] |
58 end | 58 end |
59 | 59 |
60 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,N,Upper}, v::AbstractArray{T,0}, i) where {T,N} | 60 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Upper}, v::AbstractArray{T,0}, i) where T |
61 @boundscheck if !(0 < Int(i) <= e.size[1]) | 61 @boundscheck if !(0 < Int(i) <= e.size) |
62 throw(BoundsError()) | 62 throw(BoundsError()) |
63 end | 63 end |
64 return e.stencil[e.size[1] - Int(i)]*v[] | 64 return e.stencil[e.size[1] - Int(i)]*v[] |
65 end | 65 end |