Mercurial > repos > public > sbplib_julia
annotate src/SbpOperators/boundaryops/boundary_operator.jl @ 1355:102ebdaf7c11 feature/variable_derivatives
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 08 Feb 2023 21:21:28 +0100 |
parents | 5a3281429a48 716e721ce3eb |
children | 49d03d1169ef |
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 | 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 | 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 | 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) |
1155
716e721ce3eb
Fix formatting in a few docstrings
Jonatan Werpers <jonatan@werpers.com>
parents:
1154
diff
changeset
|
27 |
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
|
28 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
|
29 """ |
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 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
|
31 |
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.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
|
33 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
|
34 |
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
|
35 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
|
36 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
|
37 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
|
38 |
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
|
39 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
|
40 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
|
41 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
|
42 |
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
|
43 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
|
44 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
|
45 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
|
46 |
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
|
47 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
|
48 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
|
49 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
|
50 |
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 # 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
|
52 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
|
53 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
|
54 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
|
55 |
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
|
56 function LazyTensors.apply_transpose(op::BoundaryOperator, v::AbstractArray{<:Any,0}, i) |
919
b41180efb6c2
Start refactor to improve type stability for apply(op,::TensorApplication,...)
Jonatan Werpers <jonatan@werpers.com>
parents:
834
diff
changeset
|
57 return LazyTensors.apply_transpose_with_region(op, v, closure_size(op), op.size[1], 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
|
58 end |