annotate src/SbpOperators/laplace/secondderivative.jl @ 348:7fe43d902a27 refactor/remove_dynamic_size_tensormapping

Start trying to change LazyTensors
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 26 Sep 2020 15:20:18 +0200
parents 01b851161018
children 0844069ab5ff
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
348
7fe43d902a27 Start trying to change LazyTensors
Jonatan Werpers <jonatan@werpers.com>
parents: 333
diff changeset
7 struct SecondDerivative{T,N,M,K} <: TensorMapping{T,1,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
328
9cc5d1498b2d Refactor 1D diagonal inner product in quadrature.jl to separate file. Write tests for quadratures. Clean up laplace and secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 311
diff changeset
23 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Lower}) where T
311
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
328
9cc5d1498b2d Refactor 1D diagonal inner product in quadrature.jl to separate file. Write tests for quadratures. Clean up laplace and secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 311
diff changeset
27 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Interior}) where T
311
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
328
9cc5d1498b2d Refactor 1D diagonal inner product in quadrature.jl to separate file. Write tests for quadratures. Clean up laplace and secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 311
diff changeset
31 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index{Upper}) where T
311
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
328
9cc5d1498b2d Refactor 1D diagonal inner product in quadrature.jl to separate file. Write tests for quadratures. Clean up laplace and secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 311
diff changeset
36 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
328
9cc5d1498b2d Refactor 1D diagonal inner product in quadrature.jl to separate file. Write tests for quadratures. Clean up laplace and secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 311
diff changeset
43 LazyTensors.apply_transpose(D2::SecondDerivative{T}, v::AbstractVector{T}, I::Index) where {T} = LazyTensors.apply(D2, v, I)
311
f2d6ec89dfc5 Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 299
diff changeset
44
328
9cc5d1498b2d Refactor 1D diagonal inner product in quadrature.jl to separate file. Write tests for quadratures. Clean up laplace and secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 311
diff changeset
45 closuresize(D2::SecondDerivative{T,N,M,K}) where {T<:Real,N,M,K} = M