Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/boundaryops/boundary_restriction.jl @ 564:ccb41095def6 feature/boundary_ops
Clean up type parameters and remove obsolete todo
| author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
|---|---|
| date | Mon, 30 Nov 2020 23:18:33 +0100 |
| parents | 212e266043dd |
| children | 2a7a258eaaa6 |
comparison
equal
deleted
inserted
replaced
| 563:212e266043dd | 564:ccb41095def6 |
|---|---|
| 1 """ | 1 """ |
| 2 boundary_restriction(grid,closureStencil,boundary) | 2 boundary_restriction(grid,closureStencil,boundary) |
| 3 | 3 |
| 4 Creates a BoundaryRestriction operator for the specified boundary | 4 Creates a BoundaryRestriction operator for the specified boundary |
| 5 """ | 5 """ |
| 6 function boundary_restriction(grid::EquidistantGrid{1,T}, closureStencil::Stencil{T,M}, boundary::CartesianBoundary{1}) where {T,M} | 6 function boundary_restriction(grid::EquidistantGrid{1}, closureStencil::Stencil, boundary::CartesianBoundary{1}) |
| 7 return e = BoundaryRestriction(grid, closureStencil, region(boundary)) | 7 return e = BoundaryRestriction(grid, closureStencil, region(boundary)) |
| 8 end | 8 end |
| 9 | 9 |
| 10 function boundary_restriction(grid::EquidistantGrid{2,T}, closureStencil::Stencil{T,M}, boundary::CartesianBoundary{1}) where {T,M} | 10 function boundary_restriction(grid::EquidistantGrid{2,T}, closureStencil::Stencil{T}, boundary::CartesianBoundary{1}) where T |
| 11 e = BoundaryRestriction(restrict(grid, 1), closureStencil, region(boundary)) | 11 e = BoundaryRestriction(restrict(grid, 1), closureStencil, region(boundary)) |
| 12 I = IdentityMapping{T}(size(restrict(grid,2))) | 12 I = IdentityMapping{T}(size(restrict(grid,2))) |
| 13 return e⊗I | 13 return e⊗I |
| 14 end | 14 end |
| 15 | 15 |
| 16 function boundary_restriction(grid::EquidistantGrid{2,T}, closureStencil::Stencil{T,M}, boundary::CartesianBoundary{2}) where {T,M} | 16 function boundary_restriction(grid::EquidistantGrid{2,T}, closureStencil::Stencil{T}, boundary::CartesianBoundary{2}) where T |
| 17 e = BoundaryRestriction(restrict(grid, 2), closureStencil, region(boundary)) | 17 e = BoundaryRestriction(restrict(grid, 2), closureStencil, region(boundary)) |
| 18 I = IdentityMapping{T}(size(restrict(grid,1))) | 18 I = IdentityMapping{T}(size(restrict(grid,1))) |
| 19 return I⊗e | 19 return I⊗e |
| 20 end | 20 end |
| 21 export boundary_restriction | 21 export boundary_restriction |
| 23 """ | 23 """ |
| 24 BoundaryRestriction{T,N,R} <: TensorMapping{T,0,1} | 24 BoundaryRestriction{T,N,R} <: TensorMapping{T,0,1} |
| 25 | 25 |
| 26 Implements the boundary operator `e` as a TensorMapping | 26 Implements the boundary operator `e` as a TensorMapping |
| 27 """ | 27 """ |
| 28 struct BoundaryRestriction{T,M,R<:Region} <: TensorMapping{T,0,1} | 28 struct BoundaryRestriction{T,N,R<:Region} <: TensorMapping{T,0,1} |
| 29 stencil::Stencil{T,M} | 29 stencil::Stencil{T,N} |
| 30 size::NTuple{1,Int} | 30 size::NTuple{1,Int} |
| 31 end | 31 end |
| 32 export BoundaryRestriction | 32 export BoundaryRestriction |
| 33 | 33 |
| 34 function BoundaryRestriction(grid::EquidistantGrid{1,T}, closureStencil::Stencil{T,M}, region::Region) where {T,M,R} | 34 function BoundaryRestriction(grid::EquidistantGrid{1}, closureStencil::Stencil{T,N}, region::Region) where {T,N} |
| 35 return BoundaryRestriction{T,M,typeof(region)}(closureStencil,size(grid)) | 35 return BoundaryRestriction{T,N,typeof(region)}(closureStencil,size(grid)) |
| 36 end | 36 end |
| 37 | 37 |
| 38 LazyTensors.range_size(e::BoundaryRestriction) = () | 38 LazyTensors.range_size(e::BoundaryRestriction) = () |
| 39 LazyTensors.domain_size(e::BoundaryRestriction) = e.size | 39 LazyTensors.domain_size(e::BoundaryRestriction) = e.size |
| 40 | 40 |
| 41 # TODO: Should we support indexing into the 0-dimensional lazyarray? This is | |
| 42 # supported for arrays with linear index style (i.e for e.g | |
| 43 # u = fill(1), u[] and u[1] are both valid.) This currently not supported by | |
| 44 # LazyTensorMappingApplication. | |
| 45 " Restricts a grid function v on a grid of size m to the scalar element v[1]" | 41 " Restricts a grid function v on a grid of size m to the scalar element v[1]" |
| 46 function LazyTensors.apply(e::BoundaryRestriction{T,M,Lower}, v::AbstractVector{T}) where {T,M} | 42 function LazyTensors.apply(e::BoundaryRestriction{T,N,Lower}, v::AbstractVector{T}) where {T,N} |
| 47 apply_stencil(e.stencil,v,1) | 43 apply_stencil(e.stencil,v,1) |
| 48 end | 44 end |
| 49 | 45 |
| 50 " Restricts a grid function v on a grid of size m to the scalar element v[m]" | 46 " Restricts a grid function v on a grid of size m to the scalar element v[m]" |
| 51 function LazyTensors.apply(e::BoundaryRestriction{T,M,Upper}, v::AbstractVector{T}) where {T,M} | 47 function LazyTensors.apply(e::BoundaryRestriction{T,N,Upper}, v::AbstractVector{T}) where {T,N} |
| 52 apply_stencil_backwards(e.stencil,v,e.size[1]) | 48 apply_stencil_backwards(e.stencil,v,e.size[1]) |
| 53 end | 49 end |
| 54 | 50 |
| 55 " Transpose of a restriction is an inflation or prolongation. | 51 " Transpose of a restriction is an inflation or prolongation. |
| 56 Inflates the scalar (1-element) vector to a vector of size of the grid" | 52 Inflates the scalar (1-element) vector to a vector of size of the grid" |
| 57 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,M,Lower}, v::AbstractArray{T,0}, i) where {T,M} | 53 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,N,Lower}, v::AbstractArray{T,0}, i) where {T,N} |
| 58 @boundscheck if !(0 < Int(i) <= e.size[1]) | 54 @boundscheck if !(0 < Int(i) <= e.size[1]) |
| 59 throw(BoundsError()) | 55 throw(BoundsError()) |
| 60 end | 56 end |
| 61 return e.stencil[Int(i)-1]*v[] | 57 return e.stencil[Int(i)-1]*v[] |
| 62 end | 58 end |
| 63 | 59 |
| 64 " Transpose of a restriction is an inflation or prolongation. | 60 " Transpose of a restriction is an inflation or prolongation. |
| 65 Inflates the scalar (1-element) vector to a vector of size of the grid" | 61 Inflates the scalar (1-element) vector to a vector of size of the grid" |
| 66 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,M,Upper}, v::AbstractArray{T,0}, i) where {T,M} | 62 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,N,Upper}, v::AbstractArray{T,0}, i) where {T,N} |
| 67 @boundscheck if !(0 < Int(i) <= e.size[1]) | 63 @boundscheck if !(0 < Int(i) <= e.size[1]) |
| 68 throw(BoundsError()) | 64 throw(BoundsError()) |
| 69 end | 65 end |
| 70 return e.stencil[e.size[1] - Int(i)]*v[] | 66 return e.stencil[e.size[1] - Int(i)]*v[] |
| 71 end | 67 end |
