Mercurial > repos > public > sbplib_julia
annotate SbpOperators/src/laplace/secondderivative.jl @ 299:27a0bca5e1f2
Add apply_transpose and fix minor issues
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Tue, 23 Jun 2020 17:31:50 +0200 |
parents | f63232aeb1c6 |
children | f2d6ec89dfc5 |
rev | line source |
---|---|
286
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
1 """ |
293
f63232aeb1c6
Move laplace.jl from DiffOps to SbpOperators. Rename constandlaplace to secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
292
diff
changeset
|
2 SecondDerivative{T<:Real,N,M,K} <: TensorOperator{T,1} |
286
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
3 Implements the Laplace tensor operator `L` with constant grid spacing and coefficients |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
4 in 1D dimension |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
5 """ |
293
f63232aeb1c6
Move laplace.jl from DiffOps to SbpOperators. Rename constandlaplace to secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
292
diff
changeset
|
6 struct SecondDerivative{T<:Real,N,M,K} <: TensorOperator{T,1} |
286
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
7 h_inv::T # The grid spacing could be included in the stencil already. Preferable? |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
8 innerStencil::Stencil{T,N} |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
9 closureStencils::NTuple{M,Stencil{T,K}} |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
10 parity::Parity |
287
dd621017b695
Change apply_2nd_derivative to Lazy Tensor apply
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
286
diff
changeset
|
11 #TODO: Write a nice constructor |
286
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
12 end |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
13 |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
14 @enum Parity begin |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
15 odd = -1 |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
16 even = 1 |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
17 end |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
18 |
293
f63232aeb1c6
Move laplace.jl from DiffOps to SbpOperators. Rename constandlaplace to secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
292
diff
changeset
|
19 LazyTensors.domain_size(D2::SecondDerivative, range_size::NTuple{1,Integer}) = range_size |
286
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
20 |
299
27a0bca5e1f2
Add apply_transpose and fix minor issues
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
293
diff
changeset
|
21 @inline function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::NTuple{1,Index}) where T |
27a0bca5e1f2
Add apply_transpose and fix minor issues
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
293
diff
changeset
|
22 return @inbounds apply(D2, v, I[1]) |
286
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
23 end |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
24 |
299
27a0bca5e1f2
Add apply_transpose and fix minor issues
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
293
diff
changeset
|
25 function LazyTensors.apply_transpose(D2::SecondDerivative{T}, v::AbstractVector{T}, I::NTuple{1,Index}) where T = LazyTensors.apply(D2, v, I) |
27a0bca5e1f2
Add apply_transpose and fix minor issues
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
293
diff
changeset
|
26 |
286
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
27 # Apply for different regions Lower/Interior/Upper or Unknown region |
293
f63232aeb1c6
Move laplace.jl from DiffOps to SbpOperators. Rename constandlaplace to secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
292
diff
changeset
|
28 @inline function LazyTensors.apply(D2::SecondDerivative, v::AbstractVector, i::Index{Lower}) |
f63232aeb1c6
Move laplace.jl from DiffOps to SbpOperators. Rename constandlaplace to secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
292
diff
changeset
|
29 return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.closureStencils[Int(i)], v, Int(i)) |
286
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
30 end |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
31 |
293
f63232aeb1c6
Move laplace.jl from DiffOps to SbpOperators. Rename constandlaplace to secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
292
diff
changeset
|
32 @inline function LazyTensors.apply(D2::SecondDerivative, v::AbstractVector, i::Index{Interior}) |
f63232aeb1c6
Move laplace.jl from DiffOps to SbpOperators. Rename constandlaplace to secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
292
diff
changeset
|
33 return @inbounds D2.h_inv*D2.h_inv*apply_stencil(D2.innerStencil, v, Int(i)) |
286
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
34 end |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
35 |
293
f63232aeb1c6
Move laplace.jl from DiffOps to SbpOperators. Rename constandlaplace to secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
292
diff
changeset
|
36 @inline function LazyTensors.apply(D2::SecondDerivative, v::AbstractVector, i::Index{Upper}) |
287
dd621017b695
Change apply_2nd_derivative to Lazy Tensor apply
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
286
diff
changeset
|
37 N = length(v) # TODO: Use domain_size here instead? |
293
f63232aeb1c6
Move laplace.jl from DiffOps to SbpOperators. Rename constandlaplace to secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
292
diff
changeset
|
38 return @inbounds D2.h_inv*D2.h_inv*Int(D2.parity)*apply_stencil_backwards(D2.closureStencils[N-Int(i)+1], v, Int(i)) |
286
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
39 end |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
40 |
293
f63232aeb1c6
Move laplace.jl from DiffOps to SbpOperators. Rename constandlaplace to secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
292
diff
changeset
|
41 @inline function LazyTensors.apply(D2::SecondDerivative, v::AbstractVector, index::Index{Unknown}) |
287
dd621017b695
Change apply_2nd_derivative to Lazy Tensor apply
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
286
diff
changeset
|
42 N = length(v) # TODO: Use domain_size here instead? |
286
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
43 r = getregion(Int(index), closuresize(L), N) |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
44 i = Index(Int(index), r) |
293
f63232aeb1c6
Move laplace.jl from DiffOps to SbpOperators. Rename constandlaplace to secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
292
diff
changeset
|
45 return apply(D2, v, i) |
286
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
46 end |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
47 |
299
27a0bca5e1f2
Add apply_transpose and fix minor issues
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
293
diff
changeset
|
48 function closuresize(D2::SecondDerivative{T<:Real,N,M,K}) where {T,N,M,K} |
286
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
49 return M |
7247e85dc1e8
Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
50 end |