annotate src/SbpOperators/boundaryops/boundary_operator.jl @ 1154:ae006e844870 refactor/sbpoperators/inflation

Remove convenience constructor for BoundaryOperator according to review comments
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 01 Nov 2022 22:10:51 +0100
parents f1bb1b6d85dd
children 716e721ce3eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
610
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
1 """
995
1ba8a398af9c Rename types
Jonatan Werpers <jonatan@werpers.com>
parents: 946
diff changeset
2 BoundaryOperator{T,R,N} <: LazyTensor{T,0,1}
610
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
3
995
1ba8a398af9c Rename types
Jonatan Werpers <jonatan@werpers.com>
parents: 946
diff changeset
4 Implements the boundary operator `op` for 1D as a `LazyTensor`
610
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
5
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
6 `op` is the restriction of a grid function to the boundary using some closure `Stencil{T,N}`.
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
7 The boundary to restrict to is determined by `R`.
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
8 `op'` is the prolongation of a zero dimensional array to the whole grid using the same closure stencil.
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
9 """
995
1ba8a398af9c Rename types
Jonatan Werpers <jonatan@werpers.com>
parents: 946
diff changeset
10 struct BoundaryOperator{T,R<:Region,N} <: LazyTensor{T,0,1}
610
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
11 stencil::Stencil{T,N}
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
12 size::Int
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
13 end
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
14
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
15 """
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
16 BoundaryOperator(grid::EquidistantGrid{1}, closure_stencil, region)
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
17
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
18 Constructs the BoundaryOperator with stencil `closure_stencil` for a one-dimensional `grid`, restricting to
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
19 to the boundary specified by `region`.
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
20 """
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
21 function BoundaryOperator(grid::EquidistantGrid{1}, closure_stencil::Stencil{T,N}, region::Region) where {T,N}
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
22 return BoundaryOperator{T,typeof(region),N}(closure_stencil,size(grid)[1])
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
23 end
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
24
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
25 """
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
26 closure_size(::BoundaryOperator)
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
27 The size of the closure stencil.
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
28 """
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
29 closure_size(::BoundaryOperator{T,R,N}) where {T,R,N} = N
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
30
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
31 LazyTensors.range_size(op::BoundaryOperator) = ()
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
32 LazyTensors.domain_size(op::BoundaryOperator) = (op.size,)
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
33
946
469ed954b493 Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents: 834
diff changeset
34 function LazyTensors.apply(op::BoundaryOperator{<:Any,Lower}, v::AbstractVector)
610
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
35 apply_stencil(op.stencil,v,1)
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
36 end
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
37
946
469ed954b493 Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents: 834
diff changeset
38 function LazyTensors.apply(op::BoundaryOperator{<:Any,Upper}, v::AbstractVector)
610
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
39 apply_stencil_backwards(op.stencil,v,op.size)
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
40 end
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
41
946
469ed954b493 Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents: 834
diff changeset
42 function LazyTensors.apply_transpose(op::BoundaryOperator{<:Any,Lower}, v::AbstractArray{<:Any,0}, i::Index{Lower})
610
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
43 return op.stencil[Int(i)-1]*v[]
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
44 end
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
45
946
469ed954b493 Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents: 834
diff changeset
46 function LazyTensors.apply_transpose(op::BoundaryOperator{<:Any,Upper}, v::AbstractArray{<:Any,0}, i::Index{Upper})
610
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
47 return op.stencil[op.size[1] - Int(i)]*v[]
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
48 end
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
49
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
50 # Catch all combinations of Lower, Upper and Interior not caught by the two previous methods.
946
469ed954b493 Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents: 834
diff changeset
51 function LazyTensors.apply_transpose(op::BoundaryOperator, v::AbstractArray{<:Any,0}, i::Index)
469ed954b493 Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents: 834
diff changeset
52 return zero(eltype(v))
610
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
53 end
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
54
946
469ed954b493 Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents: 834
diff changeset
55 function LazyTensors.apply_transpose(op::BoundaryOperator, v::AbstractArray{<:Any,0}, i)
610
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
56 r = getregion(i, closure_size(op), op.size)
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
57 apply_transpose(op, v, Index(i,r))
e40e7439d1b4 Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
58 end