Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/boundaryops/boundary_restriction.jl @ 515:d55008f5e2f3 feature/boundary_ops
Fix the range of the BoundaryRestriction tensor mapping (the range is zero for the 1D operator). Add some documentation and todos.
| author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
|---|---|
| date | Tue, 24 Nov 2020 15:28:10 +0100 |
| parents | 14e722e8607d |
| children | 2edacece1637 |
comparison
equal
deleted
inserted
replaced
| 514:14e722e8607d | 515:d55008f5e2f3 |
|---|---|
| 1 """ | |
| 2 boundary_restriction(grid,closureStencil,boundary) | |
| 3 | |
| 4 Creates a BoundaryRestriction operator for the specified boundary | |
| 5 """ | |
| 1 function boundary_restriction(grid::EquidistantGrid{1,T}, closureStencil::Stencil{T,M}, boundary::CartesianBoundary{1}) where {T,M} | 6 function boundary_restriction(grid::EquidistantGrid{1,T}, closureStencil::Stencil{T,M}, boundary::CartesianBoundary{1}) where {T,M} |
| 2 r = region(boundary) | 7 r = region(boundary) |
| 3 return e = BoundaryRestriction(grid, closureStencil, r()) | 8 return e = BoundaryRestriction(grid, closureStencil, r()) |
| 4 end | 9 end |
| 5 | 10 |
| 14 r = region(boundary) | 19 r = region(boundary) |
| 15 e = BoundaryRestriction(restrict(grid, 2), closureStencil, r()) | 20 e = BoundaryRestriction(restrict(grid, 2), closureStencil, r()) |
| 16 I = IdentityMapping{T}(size(restrict(grid,1))) | 21 I = IdentityMapping{T}(size(restrict(grid,1))) |
| 17 return I⊗e | 22 return I⊗e |
| 18 end | 23 end |
| 19 | |
| 20 export boundary_restriction | 24 export boundary_restriction |
| 21 | 25 |
| 22 """ | 26 """ |
| 23 BoundaryRestriction{T,N,R} <: TensorMapping{T,1,1} | 27 BoundaryRestriction{T,N,R} <: TensorMapping{T,0,1} |
| 24 | 28 |
| 25 Implements the boundary operator `e` as a TensorMapping | 29 Implements the boundary operator `e` as a TensorMapping |
| 26 """ | 30 """ |
| 27 struct BoundaryRestriction{T,M,R<:Region} <: TensorMapping{T,1,1} | 31 struct BoundaryRestriction{T,M,R<:Region} <: TensorMapping{T,0,1} |
| 28 stencil::Stencil{T,M} | 32 stencil::Stencil{T,M} |
| 29 size::NTuple{1,Int} | 33 size::NTuple{1,Int} |
| 30 end | 34 end |
| 31 export BoundaryRestriction | 35 export BoundaryRestriction |
| 32 | 36 |
| 33 function BoundaryRestriction(grid::EquidistantGrid{1,T}, closureStencil::Stencil{T,M}, region::Region) where {T,M,R} | 37 function BoundaryRestriction(grid::EquidistantGrid{1,T}, closureStencil::Stencil{T,M}, region::Region) where {T,M,R} |
| 34 return BoundaryRestriction{T,M,typeof(region)}(closureStencil,size(grid)) | 38 return BoundaryRestriction{T,M,typeof(region)}(closureStencil,size(grid)) |
| 35 end | 39 end |
| 36 | 40 |
| 37 LazyTensors.range_size(e::BoundaryRestriction) = (1,) | 41 LazyTensors.range_size(e::BoundaryRestriction) = (0,) |
| 38 LazyTensors.domain_size(e::BoundaryRestriction) = e.size | 42 LazyTensors.domain_size(e::BoundaryRestriction) = e.size |
| 39 | 43 |
| 44 # TODO: Currently not working. | |
| 45 # We need to handle getindex for LazyTensorMappingApplication such that we pass more #indices than the | |
| 46 # range size of the TensorMapping. Or we need to be able to handle the case where we dont pass any index, for | |
| 47 # 0-dimensional tensormappings. | |
| 40 " Restricts a grid function v on a grid of size m to the scalar element v[1]" | 48 " Restricts a grid function v on a grid of size m to the scalar element v[1]" |
| 41 function LazyTensors.apply(e::BoundaryRestriction{T,M,Lower}, v::AbstractVector{T}, i::Index{Lower}) where {T,M} | 49 function LazyTensors.apply(e::BoundaryRestriction{T,M,Lower}, v::AbstractVector{T}, i::Index{Lower}) where {T,M} |
| 42 @boundscheck if Int(i)!=1 | 50 @boundscheck if Int(i)!=1 |
| 43 throw(BoundsError()) | 51 throw(BoundsError()) |
| 44 end | 52 end |
| 53 apply_stencil_backwards(e.stencil,v,Int(i)) | 61 apply_stencil_backwards(e.stencil,v,Int(i)) |
| 54 end | 62 end |
| 55 | 63 |
| 56 " Transpose of a restriction is an inflation or prolongation. | 64 " Transpose of a restriction is an inflation or prolongation. |
| 57 Inflates the scalar (1-element) vector to a vector of size of the grid" | 65 Inflates the scalar (1-element) vector to a vector of size of the grid" |
| 58 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,M,Lower}, v::AbstractVector{T}, i) where {T,M} | 66 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,M,Lower}, v::AbstractArray{T,0}, i) where {T,M} |
| 59 @boundscheck if !(0 < Int(i) <= e.size[1]) | 67 @boundscheck if !(0 < Int(i) <= e.size[1]) |
| 60 throw(BoundsError()) | 68 throw(BoundsError()) |
| 61 end | 69 end |
| 62 return e.stencil[Int(i)-1]*v[1] | 70 return e.stencil[Int(i)-1]*v[] |
| 63 end | 71 end |
| 64 | 72 |
| 65 " Transpose of a restriction is an inflation or prolongation. | 73 " Transpose of a restriction is an inflation or prolongation. |
| 66 Inflates the scalar (1-element) vector to a vector of size of the grid" | 74 Inflates the scalar (1-element) vector to a vector of size of the grid" |
| 67 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,M,Upper}, v::AbstractVector{T}, i) where {T,M} | 75 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,M,Upper}, v::AbstractArray{T,0}, i) where {T,M} |
| 68 @boundscheck if !(0 < Int(i) <= e.size[1]) | 76 @boundscheck if !(0 < Int(i) <= e.size[1]) |
| 69 throw(BoundsError()) | 77 throw(BoundsError()) |
| 70 end | 78 end |
| 71 return e.stencil[e.size[1] - Int(i)]*v[1] | 79 return e.stencil[e.size[1] - Int(i)]*v[] |
| 72 end | 80 end |
