comparison 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
comparison
equal deleted inserted replaced
540:013ca4892540 556:37a81dad36b9
18 end 18 end
19 19
20 LazyTensors.range_size(D2::SecondDerivative) = D2.size 20 LazyTensors.range_size(D2::SecondDerivative) = D2.size
21 LazyTensors.domain_size(D2::SecondDerivative) = D2.size 21 LazyTensors.domain_size(D2::SecondDerivative) = D2.size
22 22
23 #TODO: The 1D tensor mappings should not have to dispatch on 1D tuples if we write LazyTensor.apply for vararg right?!?!
24 # Currently have to index the Tuple{Index} in each method in order to call the stencil methods which is ugly.
25 # I thought I::Vararg{Index,R} fell back to just Index for R = 1
26
27 # Apply for different regions Lower/Interior/Upper or Unknown region 23 # Apply for different regions Lower/Interior/Upper or Unknown region
28 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Lower}) where T 24 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, i::Index{Lower}) where T
29 return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.closureStencils[Int(I)], v, Int(I)) 25 return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.closureStencils[Int(i)], v, Int(i))
30 end 26 end
31 27
32 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Interior}) where T 28 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, i::Index{Interior}) where T
33 return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.innerStencil, v, Int(I)) 29 return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.innerStencil, v, Int(i))
34 end 30 end
35 31
36 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Upper}) where T 32 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, i::Index{Upper}) where T
37 N = length(v) # TODO: Use domain_size here instead? N = domain_size(D2,size(v)) 33 N = length(v) # TODO: Use domain_size here instead? N = domain_size(D2,size(v))
38 return @inbounds D2.h_inv*D2.h_inv*apply_stencil_backwards(D2.closureStencils[N-Int(I)+1], v, Int(I)) 34 return @inbounds D2.h_inv*D2.h_inv*apply_stencil_backwards(D2.closureStencils[N-Int(i)+1], v, Int(i))
39 end 35 end
40 36
41 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, index::Index{Unknown}) where T 37 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, i) where T
42 N = length(v) # TODO: Use domain_size here instead? 38 N = length(v) # TODO: Use domain_size here instead?
43 r = getregion(Int(index), closuresize(D2), N) 39 r = getregion(i, closuresize(D2), N)
44 I = Index(Int(index), r) 40 return LazyTensors.apply(D2, v, Index(i, r))
45 return LazyTensors.apply(D2, v, I)
46 end 41 end
47 42
48 closuresize(D2::SecondDerivative{T,N,M,K}) where {T<:Real,N,M,K} = M 43 closuresize(D2::SecondDerivative{T,N,M,K}) where {T<:Real,N,M,K} = M