Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/boundaryops/boundary_operator.jl @ 1751:f3d7e2d7a43f feature/sbp_operators/laplace_curvilinear
Merge feature/grids/manifolds
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 11 Sep 2024 16:26:19 +0200 |
parents | 3714a391545a |
children |
comparison
equal
deleted
inserted
replaced
1731:3684db043add | 1751:f3d7e2d7a43f |
---|---|
1 """ | 1 """ |
2 BoundaryOperator{T,R,N} <: LazyTensor{T,0,1} | 2 BoundaryOperator{T,B,N} <: LazyTensor{T,0,1} |
3 | 3 |
4 Implements the boundary operator `op` for 1D as a `LazyTensor` | 4 Implements the boundary operator `op` for 1D as a `LazyTensor` |
5 | 5 |
6 `op` is the restriction of a grid function to the boundary using some closure | 6 `op` is the restriction of a grid function to the boundary using some closure |
7 `Stencil{T,N}`. The boundary to restrict to is determined by `R`. `op'` is the | 7 `Stencil{T,N}`. The boundary to restrict to is determined by `B`. `op'` is the |
8 prolongation of a zero dimensional array to the whole grid using the same | 8 prolongation of a zero dimensional array to the whole grid using the same |
9 closure stencil. | 9 closure stencil. |
10 """ | 10 """ |
11 struct BoundaryOperator{T,R<:Region,N} <: LazyTensor{T,0,1} | 11 struct BoundaryOperator{T,B<:BoundaryIdentifier,N} <: LazyTensor{T,0,1} |
12 stencil::Stencil{T,N} | 12 stencil::Stencil{T,N} |
13 size::Int | 13 size::Int |
14 end | 14 end |
15 | 15 |
16 """ | 16 """ |
17 BoundaryOperator(grid::EquidistantGrid, closure_stencil, region) | 17 BoundaryOperator(grid::EquidistantGrid, closure_stencil, boundary) |
18 | 18 |
19 Constructs the BoundaryOperator with stencil `closure_stencil` for a | 19 Constructs the BoundaryOperator with stencil `closure_stencil` for a |
20 `EquidistantGrid` `grid`, restricting to to the boundary specified by | 20 `EquidistantGrid` `grid`, restricting to to the boundary specified by |
21 `region`. | 21 `boundary`. |
22 """ | 22 """ |
23 function BoundaryOperator(grid::EquidistantGrid, closure_stencil::Stencil{T,N}, region::Region) where {T,N} | 23 function BoundaryOperator(grid::EquidistantGrid, closure_stencil::Stencil{T,N}, boundary::BoundaryIdentifier) where {T,N} |
24 return BoundaryOperator{T,typeof(region),N}(closure_stencil,size(grid)[1]) | 24 return BoundaryOperator{T,typeof(boundary),N}(closure_stencil,size(grid)[1]) |
25 end | 25 end |
26 | 26 |
27 """ | 27 """ |
28 closure_size(::BoundaryOperator) | 28 closure_size(::BoundaryOperator) |
29 | 29 |
30 The size of the closure stencil. | 30 The size of the closure stencil. |
31 """ | 31 """ |
32 closure_size(::BoundaryOperator{T,R,N}) where {T,R,N} = N | 32 closure_size(::BoundaryOperator{T,B,N}) where {T,B,N} = N |
33 | 33 |
34 LazyTensors.range_size(op::BoundaryOperator) = () | 34 LazyTensors.range_size(op::BoundaryOperator) = () |
35 LazyTensors.domain_size(op::BoundaryOperator) = (op.size,) | 35 LazyTensors.domain_size(op::BoundaryOperator) = (op.size,) |
36 | 36 |
37 function LazyTensors.apply(op::BoundaryOperator{<:Any,Lower}, v::AbstractVector) | 37 function LazyTensors.apply(op::BoundaryOperator{<:Any,LowerBoundary}, v::AbstractVector) |
38 apply_stencil(op.stencil,v,1) | 38 apply_stencil(op.stencil,v,1) |
39 end | 39 end |
40 | 40 |
41 function LazyTensors.apply(op::BoundaryOperator{<:Any,Upper}, v::AbstractVector) | 41 function LazyTensors.apply(op::BoundaryOperator{<:Any,UpperBoundary}, v::AbstractVector) |
42 apply_stencil_backwards(op.stencil,v,op.size) | 42 apply_stencil_backwards(op.stencil,v,op.size) |
43 end | 43 end |
44 | 44 |
45 function LazyTensors.apply_transpose(op::BoundaryOperator{<:Any,Lower}, v::AbstractArray{<:Any,0}, i::Index{Lower}) | 45 function LazyTensors.apply_transpose(op::BoundaryOperator{<:Any,LowerBoundary}, v::AbstractArray{<:Any,0}, i::Index{Lower}) |
46 return op.stencil[Int(i)-1]*v[] | 46 return op.stencil[Int(i)-1]*v[] |
47 end | 47 end |
48 | 48 |
49 function LazyTensors.apply_transpose(op::BoundaryOperator{<:Any,Upper}, v::AbstractArray{<:Any,0}, i::Index{Upper}) | 49 function LazyTensors.apply_transpose(op::BoundaryOperator{<:Any,UpperBoundary}, v::AbstractArray{<:Any,0}, i::Index{Upper}) |
50 return op.stencil[op.size[1] - Int(i)]*v[] | 50 return op.stencil[op.size[1] - Int(i)]*v[] |
51 end | 51 end |
52 | 52 |
53 # Catch all combinations of Lower, Upper and Interior not caught by the two previous methods. | 53 # Catch all combinations of Lower, Upper and Interior not caught by the two previous methods. |
54 function LazyTensors.apply_transpose(op::BoundaryOperator, v::AbstractArray{<:Any,0}, i::Index) | 54 function LazyTensors.apply_transpose(op::BoundaryOperator, v::AbstractArray{<:Any,0}, i::Index) |