Mercurial > repos > public > sbplib_julia
comparison SbpOperators/src/constantlaplace.jl @ 287:dd621017b695 tensor_mappings
Change apply_2nd_derivative to Lazy Tensor apply
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 22 Jun 2020 21:31:32 +0200 |
parents | 7247e85dc1e8 |
children | 3747e5636eef |
comparison
equal
deleted
inserted
replaced
286:7247e85dc1e8 | 287:dd621017b695 |
---|---|
12 h_inv::T # The grid spacing could be included in the stencil already. Preferable? | 12 h_inv::T # The grid spacing could be included in the stencil already. Preferable? |
13 a::T # TODO: Better name? | 13 a::T # TODO: Better name? |
14 innerStencil::Stencil{T,N} | 14 innerStencil::Stencil{T,N} |
15 closureStencils::NTuple{M,Stencil{T,K}} | 15 closureStencils::NTuple{M,Stencil{T,K}} |
16 parity::Parity | 16 parity::Parity |
17 #TODO: Write a nice constructor | |
17 end | 18 end |
18 | 19 |
19 @enum Parity begin | 20 @enum Parity begin |
20 odd = -1 | 21 odd = -1 |
21 even = 1 | 22 even = 1 |
22 end | 23 end |
23 | 24 |
24 LazyTensors.domain_size(L::ConstantLaplaceOperator, range_size::NTuple{1,Integer}) = range_size | 25 LazyTensors.domain_size(L::ConstantLaplaceOperator, range_size::NTuple{1,Integer}) = range_size |
25 | 26 |
26 function LazyTensors.apply(L::ConstantLaplaceOperator{T}, v::AbstractVector{T}, I::NTuple{1,Index}) where T | 27 function LazyTensors.apply(L::ConstantLaplaceOperator{T}, v::AbstractVector{T}, I::NTuple{1,Index}) where T |
27 return L.a*apply_2nd_derivative(L, L.h_inv, v, I[1]) | 28 return apply(L, v, I[1]) |
28 end | 29 end |
29 | 30 |
30 # Apply for different regions Lower/Interior/Upper or Unknown region | 31 # Apply for different regions Lower/Interior/Upper or Unknown region |
31 @inline function apply_2nd_derivative(L::ConstantLaplaceOperator, h_inv::Real, v::AbstractVector, i::Index{Lower}) | 32 @inline function LazyTensors.apply(L::ConstantLaplaceOperator, v::AbstractVector, i::Index{Lower}) |
32 return @inbounds h_inv*h_inv*apply_stencil(L.closureStencils[Int(i)], v, Int(i)) | 33 return @inbounds L.a*L.h_inv*L.h_inv*apply_stencil(L.closureStencils[Int(i)], v, Int(i)) |
33 end | 34 end |
34 | 35 |
35 @inline function apply_2nd_derivative(L::ConstantLaplaceOperator, h_inv::Real, v::AbstractVector, i::Index{Interior}) | 36 @inline function LazyTensors.apply(L::ConstantLaplaceOperator, v::AbstractVector, i::Index{Interior}) |
36 return @inbounds h_inv*h_inv*apply_stencil(L.innerStencil, v, Int(i)) | 37 return @inbounds L.a*L.h_inv*L.h_inv*apply_stencil(L.innerStencil, v, Int(i)) |
37 end | 38 end |
38 | 39 |
39 @inline function apply_2nd_derivative(L::ConstantLaplaceOperator, h_inv::Real, v::AbstractVector, i::Index{Upper}) | 40 @inline function LazyTensors.apply(L::ConstantLaplaceOperator, v::AbstractVector, i::Index{Upper}) |
40 N = length(v) # Can we use range_size here instead? | 41 N = length(v) # TODO: Use domain_size here instead? |
41 return @inbounds h_inv*h_inv*Int(L.parity)*apply_stencil_backwards(L.closureStencils[N-Int(i)+1], v, Int(i)) | 42 return @inbounds L.a*L.h_inv*L.h_inv*Int(L.parity)*apply_stencil_backwards(L.closureStencils[N-Int(i)+1], v, Int(i)) |
42 end | 43 end |
43 | 44 |
44 @inline function apply_2nd_derivative(L::ConstantLaplaceOperator, h_inv::Real, v::AbstractVector, index::Index{Unknown}) | 45 @inline function LazyTensors.apply(L::ConstantLaplaceOperator, v::AbstractVector, index::Index{Unknown}) |
45 N = length(v) # Can we use range_size here instead? | 46 N = length(v) # TODO: Use domain_size here instead? |
46 r = getregion(Int(index), closuresize(L), N) | 47 r = getregion(Int(index), closuresize(L), N) |
47 i = Index(Int(index), r) | 48 i = Index(Int(index), r) |
48 return apply_2nd_derivative(op, h_inv, v, i) | 49 return apply(L, v, i) |
49 end | 50 end |
50 | 51 |
51 function closuresize(L::ConstantLaplaceOperator{T<:Real,N,M,K})::Int | 52 function closuresize(L::ConstantLaplaceOperator{T<:Real,N,M,K}) where T,N,M,K |
52 return M | 53 return M |
53 end | 54 end |