Mercurial > repos > public > sbplib_julia
changeset 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 |
files | src/SbpOperators/boundaryops/boundary_restriction.jl test/testSbpOperators.jl |
diffstat | 2 files changed, 14 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/boundaryops/boundary_restriction.jl Tue Dec 01 15:21:01 2020 +0100 +++ b/src/SbpOperators/boundaryops/boundary_restriction.jl Tue Dec 01 15:36:35 2020 +0100 @@ -21,7 +21,7 @@ export boundary_restriction """ - BoundaryRestriction{T,N,R} <: TensorMapping{T,0,1} + BoundaryRestriction{T,R,N} <: TensorMapping{T,0,1} Implements the boundary operator `e` for 1D as a TensorMapping `e` is the restriction of a grid function to the boundary using some `closureStencil`. @@ -29,36 +29,36 @@ `e'` is the prolongation of a zero dimensional array to the whole grid using the same `closureStencil`. """ -struct BoundaryRestriction{T,N,R<:Region} <: TensorMapping{T,0,1} +struct BoundaryRestriction{T,R<:Region,N} <: TensorMapping{T,0,1} stencil::Stencil{T,N} - size::NTuple{1,Int} + size::Int end export BoundaryRestriction function BoundaryRestriction(grid::EquidistantGrid{1}, closureStencil::Stencil{T,N}, region::Region) where {T,N} - return BoundaryRestriction{T,N,typeof(region)}(closureStencil,size(grid)) + return BoundaryRestriction{T,typeof(region),N}(closureStencil,size(grid)[1]) end LazyTensors.range_size(e::BoundaryRestriction) = () -LazyTensors.domain_size(e::BoundaryRestriction) = e.size +LazyTensors.domain_size(e::BoundaryRestriction) = (e.size,) -function LazyTensors.apply(e::BoundaryRestriction{T,N,Lower}, v::AbstractVector{T}) where {T,N} +function LazyTensors.apply(e::BoundaryRestriction{T,Lower}, v::AbstractVector{T}) where T apply_stencil(e.stencil,v,1) end -function LazyTensors.apply(e::BoundaryRestriction{T,N,Upper}, v::AbstractVector{T}) where {T,N} - apply_stencil_backwards(e.stencil,v,e.size[1]) +function LazyTensors.apply(e::BoundaryRestriction{T,Upper}, v::AbstractVector{T}) where T + apply_stencil_backwards(e.stencil,v,e.size) end -function LazyTensors.apply_transpose(e::BoundaryRestriction{T,N,Lower}, v::AbstractArray{T,0}, i) where {T,N} - @boundscheck if !(0 < Int(i) <= e.size[1]) +function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Lower}, v::AbstractArray{T,0}, i) where T + @boundscheck if !(0 < Int(i) <= e.size) throw(BoundsError()) end return e.stencil[Int(i)-1]*v[] end -function LazyTensors.apply_transpose(e::BoundaryRestriction{T,N,Upper}, v::AbstractArray{T,0}, i) where {T,N} - @boundscheck if !(0 < Int(i) <= e.size[1]) +function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Upper}, v::AbstractArray{T,0}, i) where T + @boundscheck if !(0 < Int(i) <= e.size) throw(BoundsError()) end return e.stencil[e.size[1] - Int(i)]*v[]
--- a/test/testSbpOperators.jl Tue Dec 01 15:21:01 2020 +0100 +++ b/test/testSbpOperators.jl Tue Dec 01 15:36:35 2020 +0100 @@ -180,12 +180,12 @@ @testset "Constructors" begin # 1D - e_l = BoundaryRestriction{Float64,4,Lower}(op.eClosure,size(g_1D)) + e_l = BoundaryRestriction{Float64,Lower,4}(op.eClosure,size(g_1D)[1]) @test e_l == BoundaryRestriction(g_1D,op.eClosure,Lower()) @test e_l == boundary_restriction(g_1D,op.eClosure,CartesianBoundary{1,Lower}()) @test e_l isa TensorMapping{T,0,1} where T - e_r = BoundaryRestriction{Float64,4,Upper}(op.eClosure,size(g_1D)) + e_r = BoundaryRestriction{Float64,Upper,4}(op.eClosure,size(g_1D)[1]) @test e_r == BoundaryRestriction(g_1D,op.eClosure,Upper()) @test e_r == boundary_restriction(g_1D,op.eClosure,CartesianBoundary{1,Upper}()) @test e_r isa TensorMapping{T,0,1} where T