Mercurial > repos > public > sbplib_julia
annotate src/SbpOperators/volumeops/volume_operator.jl @ 810:a4d7ca5de3c6 refactor/sbp_operators_method_signatures
Review: Suggested changes to volume_operator.jl
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 20 Sep 2021 20:36:20 +0200 |
parents | b6c0963100cd |
children | ae28f1d7ef5e |
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 |
778
b6c0963100cd
Fix mistakes in the fix of the documentation
Jonatan Werpers <jonatan@werpers.com>
parents:
774
diff
changeset
|
9 operators and `IdentityMapping`s, e.g for `Dim=3` the volume operator in the |
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 """ |
810
a4d7ca5de3c6
Review: Suggested changes to volume_operator.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
778
diff
changeset
|
12 # Review: The type parameters Dim, T in the signature can be removed, |
a4d7ca5de3c6
Review: Suggested changes to volume_operator.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
778
diff
changeset
|
13 # by the following changes: |
a4d7ca5de3c6
Review: Suggested changes to volume_operator.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
778
diff
changeset
|
14 # one_d_grids = restrict.(Ref(grid), Tuple(1:Dim)) --> |
a4d7ca5de3c6
Review: Suggested changes to volume_operator.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
778
diff
changeset
|
15 # one_d_grids = restrict.(Ref(grid), Tuple(1:dimension(grid))) |
a4d7ca5de3c6
Review: Suggested changes to volume_operator.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
778
diff
changeset
|
16 # and |
a4d7ca5de3c6
Review: Suggested changes to volume_operator.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
778
diff
changeset
|
17 # Is = IdentityMapping{T}.(size.(one_d_grids)) --> |
a4d7ca5de3c6
Review: Suggested changes to volume_operator.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
778
diff
changeset
|
18 # Is = IdentityMapping{eltype(grid)}.(size.(one_d_grids)) |
774
d8c0916853fc
Remove unneeded type parameter and rewirte documentation for volume_operator
Jonatan Werpers <jonatan@werpers.com>
parents:
773
diff
changeset
|
19 function volume_operator(grid::EquidistantGrid{Dim,T}, inner_stencil, closure_stencils, parity, direction) where {Dim,T} |
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
|
20 #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
|
21 |
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
|
22 # Create 1D volume operator in along coordinate direction |
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 op = VolumeOperator(restrict(grid, direction), inner_stencil, closure_stencils, 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
|
24 # Create 1D IdentityMappings for each coordinate direction |
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 one_d_grids = restrict.(Ref(grid), Tuple(1:Dim)) |
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 Is = IdentityMapping{T}.(size.(one_d_grids)) |
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 # Formulate the correct outer product sequence of the identity mappings and |
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 # the 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
|
29 parts = Base.setindex(Is, op, direction) |
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 return foldl(⊗, parts) |
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 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
|
32 |
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 """ |
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 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
|
35 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
|
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 struct VolumeOperator{T,N,M,K} <: TensorMapping{T,1,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
|
38 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
|
39 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
|
40 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
|
41 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
|
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 |
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
|
44 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
|
45 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
|
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 |
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
|
48 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
|
49 |
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 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
|
51 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
|
52 |
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 function LazyTensors.apply(op::VolumeOperator{T}, v::AbstractVector{T}, i::Index{Lower}) where T |
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 @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
|
55 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
|
56 |
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
|
57 function LazyTensors.apply(op::VolumeOperator{T}, v::AbstractVector{T}, i::Index{Interior}) where T |
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
|
58 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
|
59 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
|
60 |
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
|
61 function LazyTensors.apply(op::VolumeOperator{T}, v::AbstractVector{T}, i::Index{Upper}) where T |
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
|
62 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
|
63 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
|
64 |
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
|
65 function LazyTensors.apply(op::VolumeOperator{T}, v::AbstractVector{T}, i) where T |
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
|
66 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
|
67 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
|
68 end |