Mercurial > repos > public > sbplib_julia
comparison SbpOperators/src/laplace/secondderivative.jl @ 293:f63232aeb1c6
Move laplace.jl from DiffOps to SbpOperators. Rename constandlaplace to secondderivative
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 22 Jun 2020 22:08:56 +0200 |
parents | SbpOperators/src/constantlaplace.jl@3747e5636eef |
children | 27a0bca5e1f2 |
comparison
equal
deleted
inserted
replaced
292:3747e5636eef | 293:f63232aeb1c6 |
---|---|
1 """ | |
2 SecondDerivative{T<:Real,N,M,K} <: TensorOperator{T,1} | |
3 Implements the Laplace tensor operator `L` with constant grid spacing and coefficients | |
4 in 1D dimension | |
5 """ | |
6 struct SecondDerivative{T<:Real,N,M,K} <: TensorOperator{T,1} | |
7 h_inv::T # The grid spacing could be included in the stencil already. Preferable? | |
8 innerStencil::Stencil{T,N} | |
9 closureStencils::NTuple{M,Stencil{T,K}} | |
10 parity::Parity | |
11 #TODO: Write a nice constructor | |
12 end | |
13 | |
14 @enum Parity begin | |
15 odd = -1 | |
16 even = 1 | |
17 end | |
18 | |
19 LazyTensors.domain_size(D2::SecondDerivative, range_size::NTuple{1,Integer}) = range_size | |
20 | |
21 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::NTuple{1,Index}) where T | |
22 return apply(D2, v, I[1]) | |
23 end | |
24 | |
25 # Apply for different regions Lower/Interior/Upper or Unknown region | |
26 @inline function LazyTensors.apply(D2::SecondDerivative, v::AbstractVector, i::Index{Lower}) | |
27 return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.closureStencils[Int(i)], v, Int(i)) | |
28 end | |
29 | |
30 @inline function LazyTensors.apply(D2::SecondDerivative, v::AbstractVector, i::Index{Interior}) | |
31 return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.innerStencil, v, Int(i)) | |
32 end | |
33 | |
34 @inline function LazyTensors.apply(D2::SecondDerivative, v::AbstractVector, i::Index{Upper}) | |
35 N = length(v) # TODO: Use domain_size here instead? | |
36 return @inbounds D2.h_inv*D2.h_inv*Int(D2.parity)*apply_stencil_backwards(D2.closureStencils[N-Int(i)+1], v, Int(i)) | |
37 end | |
38 | |
39 @inline function LazyTensors.apply(D2::SecondDerivative, v::AbstractVector, index::Index{Unknown}) | |
40 N = length(v) # TODO: Use domain_size here instead? | |
41 r = getregion(Int(index), closuresize(L), N) | |
42 i = Index(Int(index), r) | |
43 return apply(D2, v, i) | |
44 end | |
45 | |
46 function closuresize(D2::SecondDerivative{T<:Real,N,M,K}) where T,N,M,K | |
47 return M | |
48 end |