annotate src/SbpOperators/volumeops/volume_operator.jl @ 1023:52f07c77299d refactor/sbpoperators/inflation

Merge refactor/lazy_tensors
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 21 Mar 2022 09:51:07 +0100
parents bbbc31953367 1ba8a398af9c
children 14cb97284373 05a25a5063bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
611
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
1 """
774
d8c0916853fc Remove unneeded type parameter and rewirte documentation for volume_operator
Jonatan Werpers <jonatan@werpers.com>
parents: 773
diff changeset
2 volume_operator(grid, inner_stencil, closure_stencils, parity, direction)
d8c0916853fc Remove unneeded type parameter and rewirte documentation for volume_operator
Jonatan Werpers <jonatan@werpers.com>
parents: 773
diff changeset
3
611
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
4 Creates a volume operator on a `Dim`-dimensional grid acting along the
774
d8c0916853fc Remove unneeded type parameter and rewirte documentation for volume_operator
Jonatan Werpers <jonatan@werpers.com>
parents: 773
diff changeset
5 specified coordinate `direction`. The action of the operator is determined by
d8c0916853fc Remove unneeded type parameter and rewirte documentation for volume_operator
Jonatan Werpers <jonatan@werpers.com>
parents: 773
diff changeset
6 the stencils `inner_stencil` and `closure_stencils`. When `Dim=1`, the
d8c0916853fc Remove unneeded type parameter and rewirte documentation for volume_operator
Jonatan Werpers <jonatan@werpers.com>
parents: 773
diff changeset
7 corresponding `VolumeOperator` tensor mapping is returned. When `Dim>1`, the
d8c0916853fc Remove unneeded type parameter and rewirte documentation for volume_operator
Jonatan Werpers <jonatan@werpers.com>
parents: 773
diff changeset
8 returned operator is the appropriate outer product of a one-dimensional
995
1ba8a398af9c Rename types
Jonatan Werpers <jonatan@werpers.com>
parents: 946
diff changeset
9 operators and `IdentityTensor`s, e.g for `Dim=3` the volume operator in the
778
b6c0963100cd Fix mistakes in the fix of the documentation
Jonatan Werpers <jonatan@werpers.com>
parents: 774
diff changeset
10 y-direction is `I⊗op⊗I`.
611
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
11 """
818
ae28f1d7ef5e Accept review comments
Jonatan Werpers <jonatan@werpers.com>
parents: 810
diff changeset
12 function volume_operator(grid::EquidistantGrid, inner_stencil, closure_stencils, parity, direction)
627
9f27f451d0a0 Add todo for checking valid inputs to boundary_operator and volume_operators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 619
diff changeset
13 #TODO: Check that direction <= Dim?
9f27f451d0a0 Add todo for checking valid inputs to boundary_operator and volume_operators
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 619
diff changeset
14
611
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
15 op = VolumeOperator(restrict(grid, direction), inner_stencil, closure_stencils, parity)
1022
bbbc31953367 Introduce an inflate function in lazy tensors and use it in volume_operator and boundary_operator
Jonatan Werpers <jonatan@werpers.com>
parents: 946
diff changeset
16 return LazyTensors.inflate(op, size(grid), direction)
611
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
17 end
1022
bbbc31953367 Introduce an inflate function in lazy tensors and use it in volume_operator and boundary_operator
Jonatan Werpers <jonatan@werpers.com>
parents: 946
diff changeset
18 # TBD: Should the inflation happen here or should we remove this method and do it at the caller instead?
611
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
19
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
20 """
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
21 VolumeOperator{T,N,M,K} <: TensorOperator{T,1}
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
22 Implements a one-dimensional constant coefficients volume operator
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
23 """
995
1ba8a398af9c Rename types
Jonatan Werpers <jonatan@werpers.com>
parents: 946
diff changeset
24 struct VolumeOperator{T,N,M,K} <: LazyTensor{T,1,1}
611
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
25 inner_stencil::Stencil{T,N}
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
26 closure_stencils::NTuple{M,Stencil{T,K}}
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
27 size::NTuple{1,Int}
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
28 parity::Parity
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
29 end
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
30
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
31 function VolumeOperator(grid::EquidistantGrid{1}, inner_stencil, closure_stencils, parity)
773
86bb3606b215 Make volume_operators() less restrictive in the type of collection of closure_stencils
Jonatan Werpers <jonatan@werpers.com>
parents: 627
diff changeset
32 return VolumeOperator(inner_stencil, Tuple(closure_stencils), size(grid), parity)
611
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
33 end
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
34
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
35 closure_size(::VolumeOperator{T,N,M}) where {T,N,M} = M
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
36
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
37 LazyTensors.range_size(op::VolumeOperator) = op.size
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
38 LazyTensors.domain_size(op::VolumeOperator) = op.size
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
39
946
469ed954b493 Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents: 818
diff changeset
40 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i::Index{Lower})
611
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
41 return @inbounds apply_stencil(op.closure_stencils[Int(i)], v, Int(i))
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
42 end
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
43
946
469ed954b493 Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents: 818
diff changeset
44 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i::Index{Interior})
611
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
45 return apply_stencil(op.inner_stencil, v, Int(i))
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
46 end
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
47
946
469ed954b493 Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents: 818
diff changeset
48 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i::Index{Upper})
611
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
49 return @inbounds Int(op.parity)*apply_stencil_backwards(op.closure_stencils[op.size[1]-Int(i)+1], v, Int(i))
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
50 end
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
51
946
469ed954b493 Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents: 818
diff changeset
52 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i)
611
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
53 r = getregion(i, closure_size(op), op.size[1])
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
54 return LazyTensors.apply(op, v, Index(i, r))
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
55 end
1022
bbbc31953367 Introduce an inflate function in lazy tensors and use it in volume_operator and boundary_operator
Jonatan Werpers <jonatan@werpers.com>
parents: 946
diff changeset
56 # TODO: Move this to LazyTensors when we have the region communication down.