Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/laplace/secondderivative.jl @ 333:01b851161018 refactor/combine_to_one_package
Start converting to one package by moving all the files to their correct location
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Fri, 25 Sep 2020 13:06:02 +0200 |
| parents | SbpOperators/src/laplace/secondderivative.jl@9cc5d1498b2d |
| children | 7fe43d902a27 |
comparison
equal
deleted
inserted
replaced
| 332:535f1bff4bcc | 333:01b851161018 |
|---|---|
| 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 | |
| 7 struct SecondDerivative{T,N,M,K} <: TensorOperator{T,1} | |
| 8 h_inv::T # The grid spacing could be included in the stencil already. Preferable? | |
| 9 innerStencil::Stencil{T,N} | |
| 10 closureStencils::NTuple{M,Stencil{T,K}} | |
| 11 parity::Parity | |
| 12 #TODO: Write a nice constructor | |
| 13 end | |
| 14 export SecondDerivative | |
| 15 | |
| 16 LazyTensors.domain_size(D2::SecondDerivative, range_size::NTuple{1,Integer}) = range_size | |
| 17 | |
| 18 #TODO: The 1D tensor mappings should not have to dispatch on 1D tuples if we write LazyTensor.apply for vararg right?!?! | |
| 19 # Currently have to index the Tuple{Index} in each method in order to call the stencil methods which is ugly. | |
| 20 # I thought I::Vararg{Index,R} fell back to just Index for R = 1 | |
| 21 | |
| 22 # Apply for different regions Lower/Interior/Upper or Unknown region | |
| 23 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Lower}) where T | |
| 24 return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.closureStencils[Int(I)], v, Int(I)) | |
| 25 end | |
| 26 | |
| 27 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Interior}) where T | |
| 28 return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.innerStencil, v, Int(I)) | |
| 29 end | |
| 30 | |
| 31 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Upper}) where T | |
| 32 N = length(v) # TODO: Use domain_size here instead? N = domain_size(D2,size(v)) | |
| 33 return @inbounds D2.h_inv*D2.h_inv*Int(D2.parity)*apply_stencil_backwards(D2.closureStencils[N-Int(I)+1], v, Int(I)) | |
| 34 end | |
| 35 | |
| 36 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, index::Index{Unknown}) where T | |
| 37 N = length(v) # TODO: Use domain_size here instead? | |
| 38 r = getregion(Int(index), closuresize(D2), N) | |
| 39 I = Index(Int(index), r) | |
| 40 return LazyTensors.apply(D2, v, I) | |
| 41 end | |
| 42 | |
| 43 LazyTensors.apply_transpose(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index) where {T} = LazyTensors.apply(D2, v, I) | |
| 44 | |
| 45 closuresize(D2::SecondDerivative{T,N,M,K}) where {T<:Real,N,M,K} = M |
