Mercurial > repos > public > sbplib_julia
annotate src/SbpOperators/boundaryops/boundary_operator.jl @ 1909:4209290cb377 feature/grids/parameter_spaces
Add missing using-statement
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Fri, 07 Feb 2025 15:28:01 +0100 |
| parents | 3714a391545a |
| children |
| 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 """ |
|
1672
3714a391545a
Make the boundary identifiers for EquidistantGrid subtype BoundaryIdentifer
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1365
diff
changeset
|
2 BoundaryOperator{T,B,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 | 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 |
|
1329
e94ddef5e72f
Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents:
1281
diff
changeset
|
6 `op` is the restriction of a grid function to the boundary using some closure |
|
1672
3714a391545a
Make the boundary identifiers for EquidistantGrid subtype BoundaryIdentifer
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1365
diff
changeset
|
7 `Stencil{T,N}`. The boundary to restrict to is determined by `B`. `op'` is the |
|
1329
e94ddef5e72f
Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents:
1281
diff
changeset
|
8 prolongation of a zero dimensional array to the whole grid using the same |
|
e94ddef5e72f
Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents:
1281
diff
changeset
|
9 closure stencil. |
|
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
|
10 """ |
|
1672
3714a391545a
Make the boundary identifiers for EquidistantGrid subtype BoundaryIdentifer
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1365
diff
changeset
|
11 struct BoundaryOperator{T,B<:BoundaryIdentifier,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
|
12 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
|
13 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
|
14 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
|
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 """ |
|
1672
3714a391545a
Make the boundary identifiers for EquidistantGrid subtype BoundaryIdentifer
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1365
diff
changeset
|
17 BoundaryOperator(grid::EquidistantGrid, closure_stencil, boundary) |
|
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
|
18 |
|
1329
e94ddef5e72f
Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents:
1281
diff
changeset
|
19 Constructs the BoundaryOperator with stencil `closure_stencil` for a |
|
e94ddef5e72f
Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents:
1281
diff
changeset
|
20 `EquidistantGrid` `grid`, restricting to to the boundary specified by |
|
1672
3714a391545a
Make the boundary identifiers for EquidistantGrid subtype BoundaryIdentifer
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1365
diff
changeset
|
21 `boundary`. |
|
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
|
22 """ |
|
1672
3714a391545a
Make the boundary identifiers for EquidistantGrid subtype BoundaryIdentifer
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1365
diff
changeset
|
23 function BoundaryOperator(grid::EquidistantGrid, closure_stencil::Stencil{T,N}, boundary::BoundaryIdentifier) where {T,N} |
|
3714a391545a
Make the boundary identifiers for EquidistantGrid subtype BoundaryIdentifer
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1365
diff
changeset
|
24 return BoundaryOperator{T,typeof(boundary),N}(closure_stencil,size(grid)[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
|
25 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
|
26 |
|
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 """ |
|
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 closure_size(::BoundaryOperator) |
|
1155
716e721ce3eb
Fix formatting in a few docstrings
Jonatan Werpers <jonatan@werpers.com>
parents:
1154
diff
changeset
|
29 |
|
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
|
30 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
|
31 """ |
|
1672
3714a391545a
Make the boundary identifiers for EquidistantGrid subtype BoundaryIdentifer
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1365
diff
changeset
|
32 closure_size(::BoundaryOperator{T,B,N}) where {T,B,N} = N |
|
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
|
33 |
|
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
34 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
|
35 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
|
36 |
|
1672
3714a391545a
Make the boundary identifiers for EquidistantGrid subtype BoundaryIdentifer
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1365
diff
changeset
|
37 function LazyTensors.apply(op::BoundaryOperator{<:Any,LowerBoundary}, 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
|
38 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
|
39 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
|
40 |
|
1672
3714a391545a
Make the boundary identifiers for EquidistantGrid subtype BoundaryIdentifer
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1365
diff
changeset
|
41 function LazyTensors.apply(op::BoundaryOperator{<:Any,UpperBoundary}, 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
|
42 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
|
43 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
|
44 |
|
1672
3714a391545a
Make the boundary identifiers for EquidistantGrid subtype BoundaryIdentifer
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1365
diff
changeset
|
45 function LazyTensors.apply_transpose(op::BoundaryOperator{<:Any,LowerBoundary}, 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
|
46 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
|
47 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
|
48 |
|
1672
3714a391545a
Make the boundary identifiers for EquidistantGrid subtype BoundaryIdentifer
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1365
diff
changeset
|
49 function LazyTensors.apply_transpose(op::BoundaryOperator{<:Any,UpperBoundary}, 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
|
50 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
|
51 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
|
52 |
|
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 # 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
|
54 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
|
55 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
|
56 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
|
57 |
|
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
|
58 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
|
59 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
|
60 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
|
61 end |
