Mercurial > repos > public > sbplib_julia
diff src/SbpOperators/laplace/secondderivative.jl @ 556:37a81dad36b9
Merge refactor/tensor_index_coupling
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Sun, 29 Nov 2020 21:18:45 +0100 |
parents | 9330338d6ab5 |
children | e71f2f81b5f8 |
line wrap: on
line diff
--- a/src/SbpOperators/laplace/secondderivative.jl Thu Nov 26 17:53:40 2020 +0100 +++ b/src/SbpOperators/laplace/secondderivative.jl Sun Nov 29 21:18:45 2020 +0100 @@ -20,29 +20,24 @@ LazyTensors.range_size(D2::SecondDerivative) = D2.size LazyTensors.domain_size(D2::SecondDerivative) = D2.size -#TODO: The 1D tensor mappings should not have to dispatch on 1D tuples if we write LazyTensor.apply for vararg right?!?! -# Currently have to index the Tuple{Index} in each method in order to call the stencil methods which is ugly. -# I thought I::Vararg{Index,R} fell back to just Index for R = 1 +# Apply for different regions Lower/Interior/Upper or Unknown region +function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, i::Index{Lower}) where T + return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.closureStencils[Int(i)], v, Int(i)) +end -# Apply for different regions Lower/Interior/Upper or Unknown region -function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Lower}) where T - return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.closureStencils[Int(I)], v, Int(I)) +function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, i::Index{Interior}) where T + return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.innerStencil, v, Int(i)) end -function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Interior}) where T - return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.innerStencil, v, Int(I)) +function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, i::Index{Upper}) where T + N = length(v) # TODO: Use domain_size here instead? N = domain_size(D2,size(v)) + return @inbounds D2.h_inv*D2.h_inv*apply_stencil_backwards(D2.closureStencils[N-Int(i)+1], v, Int(i)) end -function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Upper}) where T - N = length(v) # TODO: Use domain_size here instead? N = domain_size(D2,size(v)) - return @inbounds D2.h_inv*D2.h_inv*apply_stencil_backwards(D2.closureStencils[N-Int(I)+1], v, Int(I)) -end - -function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, index::Index{Unknown}) where T +function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, i) where T N = length(v) # TODO: Use domain_size here instead? - r = getregion(Int(index), closuresize(D2), N) - I = Index(Int(index), r) - return LazyTensors.apply(D2, v, I) + r = getregion(i, closuresize(D2), N) + return LazyTensors.apply(D2, v, Index(i, r)) end closuresize(D2::SecondDerivative{T,N,M,K}) where {T<:Real,N,M,K} = M