Mercurial > repos > public > sbplib_julia
annotate src/SbpOperators/laplace/secondderivative.jl @ 548:9330338d6ab5 refactor/tensor_index_coupling
Align index naming
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Sat, 28 Nov 2020 17:07:15 +0100 |
parents | 1a53eb83ed24 |
children | e71f2f81b5f8 |
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}} |
356
0844069ab5ff
Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents:
348
diff
changeset
|
11 size::NTuple{1,Int} |
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 |
311
f2d6ec89dfc5
Make apply dispatch on Index instead of Tuples of Index
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
299
diff
changeset
|
13 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
|
14 |
356
0844069ab5ff
Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents:
348
diff
changeset
|
15 function SecondDerivative(grid::EquidistantGrid{1}, innerStencil, closureStencils) |
381
dacbcba33d7d
Refactor EquidistantGrid to not store spacing or inverse spacing
Jonatan Werpers <jonatan@werpers.com>
parents:
380
diff
changeset
|
16 h_inv = inverse_spacing(grid)[1] |
380
81053b1992b6
Remove parity field from Secondderivative
Jonatan Werpers <jonatan@werpers.com>
parents:
361
diff
changeset
|
17 return SecondDerivative(h_inv, innerStencil, closureStencils, size(grid)) |
356
0844069ab5ff
Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents:
348
diff
changeset
|
18 end |
0844069ab5ff
Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents:
348
diff
changeset
|
19 |
0844069ab5ff
Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents:
348
diff
changeset
|
20 LazyTensors.range_size(D2::SecondDerivative) = D2.size |
0844069ab5ff
Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents:
348
diff
changeset
|
21 LazyTensors.domain_size(D2::SecondDerivative) = D2.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
|
22 |
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 # Apply for different regions Lower/Interior/Upper or Unknown region |
548
9330338d6ab5
Align index naming
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
543
diff
changeset
|
24 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, i::Index{Lower}) where T |
9330338d6ab5
Align index naming
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
543
diff
changeset
|
25 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
|
26 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
|
27 |
548
9330338d6ab5
Align index naming
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
543
diff
changeset
|
28 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, i::Index{Interior}) where T |
9330338d6ab5
Align index naming
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
543
diff
changeset
|
29 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
|
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 |
548
9330338d6ab5
Align index naming
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
543
diff
changeset
|
32 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
|
33 N = length(v) # TODO: Use domain_size here instead? N = domain_size(D2,size(v)) |
548
9330338d6ab5
Align index naming
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
543
diff
changeset
|
34 return @inbounds D2.h_inv*D2.h_inv*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
|
35 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
|
36 |
542
011ca1639153
Remove Index{Unknown} and replace with general Any implementations
Jonatan Werpers <jonatan@werpers.com>
parents:
381
diff
changeset
|
37 function LazyTensors.apply(D2::SecondDerivative{T}, v::AbstractVector{T}, i) where T |
287
dd621017b695
Change apply_2nd_derivative to Lazy Tensor apply
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
286
diff
changeset
|
38 N = length(v) # TODO: Use domain_size here instead? |
542
011ca1639153
Remove Index{Unknown} and replace with general Any implementations
Jonatan Werpers <jonatan@werpers.com>
parents:
381
diff
changeset
|
39 r = getregion(i, closuresize(D2), N) |
548
9330338d6ab5
Align index naming
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
543
diff
changeset
|
40 return LazyTensors.apply(D2, v, Index(i, r)) |
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 closuresize(D2::SecondDerivative{T,N,M,K}) where {T<:Real,N,M,K} = M |