annotate SbpOperators/src/laplace/secondderivative.jl @ 320:d705b397aa33

Clean up Notes.md and TODO.md
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 10 Sep 2020 11:03:22 +0200
parents f2d6ec89dfc5
children 9cc5d1498b2d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 """
311
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
6
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
7 struct SecondDerivative{T,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
8 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
9 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
10 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
11 parity::Parity
287
dd621017b695 Change apply_2nd_derivative to Lazy Tensor apply
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 286
diff changeset
12 #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
13 end
311
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
14 export SecondDerivative
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
15
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
16 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
17
311
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
18 #TODO: The 1D tensor mappings should not have to dispatch on 1D tuples if we write LazyTensor.apply for vararg right?!?!
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
19 # Currently have to index the Tuple{Index} in each method in order to call the stencil methods which is ugly.
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
20 # I thought I::Vararg{Index,R} fell back to just Index for R = 1
299
27a0bca5e1f2 Add apply_transpose and fix minor issues
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 293
diff changeset
21
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
22 # Apply for different regions Lower/Interior/Upper or Unknown region
311
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
23 @inline function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Lower}) where T
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
24 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
25 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
26
311
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
27 @inline function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Interior}) where T
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
28 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
29 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
30
311
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
31 @inline function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Upper}) where T
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
32 N = length(v) # TODO: Use domain_size here instead? N = domain_size(D2,size(v))
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
33 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
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
311
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
36 @inline function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, index::Index{Unknown}) where T
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?
311
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
38 r = getregion(Int(index), closuresize(D2), N)
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
39 I = Index(Int(index), r)
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
40 return LazyTensors.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
41 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
42
311
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
43
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
44 @inline function LazyTensors.apply_transpose(D2::SecondDerivative, v::AbstractVector, I::Index)
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
45 return LazyTensors.apply(D2, v, I)
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
46 end
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
47
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
48
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
49 function closuresize(D2::SecondDerivative{T,N,M,K}) where {T<:Real,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
50 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
51 end