Mercurial > repos > public > sbplib_julia
comparison 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 |
comparison
equal
deleted
inserted
replaced
1210:fa0800591306 | 1355:102ebdaf7c11 |
---|---|
1 """ | |
2 boundary_operator(grid,closure_stencil,boundary) | |
3 | |
4 Creates a boundary operator on a `Dim`-dimensional grid for the | |
5 specified `boundary`. The action of the operator is determined by `closure_stencil`. | |
6 | |
7 When `Dim=1`, the corresponding `BoundaryOperator` tensor mapping is returned. | |
8 When `Dim>1`, the `BoundaryOperator` `op` is inflated by the outer product | |
9 of `IdentityTensors` in orthogonal coordinate directions, e.g for `Dim=3`, | |
10 the boundary restriction operator in the y-direction direction is `Ix⊗op⊗Iz`. | |
11 """ | |
12 function boundary_operator(grid::EquidistantGrid, closure_stencil, boundary::CartesianBoundary) | |
13 #TODO:Check that dim(boundary) <= Dim? | |
14 | |
15 d = dim(boundary) | |
16 op = BoundaryOperator(restrict(grid, d), closure_stencil, region(boundary)) | |
17 | |
18 # Create 1D IdentityTensors for each coordinate direction | |
19 one_d_grids = restrict.(Ref(grid), Tuple(1:dimension(grid))) | |
20 Is = IdentityTensor{eltype(grid)}.(size.(one_d_grids)) | |
21 | |
22 return LazyTensors.inflate(op, size(grid), d) | |
23 end | |
24 | |
25 """ | 1 """ |
26 BoundaryOperator{T,R,N} <: LazyTensor{T,0,1} | 2 BoundaryOperator{T,R,N} <: LazyTensor{T,0,1} |
27 | 3 |
28 Implements the boundary operator `op` for 1D as a `LazyTensor` | 4 Implements the boundary operator `op` for 1D as a `LazyTensor` |
29 | 5 |
34 struct BoundaryOperator{T,R<:Region,N} <: LazyTensor{T,0,1} | 10 struct BoundaryOperator{T,R<:Region,N} <: LazyTensor{T,0,1} |
35 stencil::Stencil{T,N} | 11 stencil::Stencil{T,N} |
36 size::Int | 12 size::Int |
37 end | 13 end |
38 | 14 |
39 BoundaryOperator{R}(stencil::Stencil{T,N}, size::Int) where {T,R,N} = BoundaryOperator{T,R,N}(stencil, size) | |
40 | |
41 """ | 15 """ |
42 BoundaryOperator(grid::EquidistantGrid{1}, closure_stencil, region) | 16 BoundaryOperator(grid::EquidistantGrid{1}, closure_stencil, region) |
43 | 17 |
44 Constructs the BoundaryOperator with stencil `closure_stencil` for a one-dimensional `grid`, restricting to | 18 Constructs the BoundaryOperator with stencil `closure_stencil` for a one-dimensional `grid`, restricting to |
45 to the boundary specified by `region`. | 19 to the boundary specified by `region`. |
48 return BoundaryOperator{T,typeof(region),N}(closure_stencil,size(grid)[1]) | 22 return BoundaryOperator{T,typeof(region),N}(closure_stencil,size(grid)[1]) |
49 end | 23 end |
50 | 24 |
51 """ | 25 """ |
52 closure_size(::BoundaryOperator) | 26 closure_size(::BoundaryOperator) |
27 | |
53 The size of the closure stencil. | 28 The size of the closure stencil. |
54 """ | 29 """ |
55 closure_size(::BoundaryOperator{T,R,N}) where {T,R,N} = N | 30 closure_size(::BoundaryOperator{T,R,N}) where {T,R,N} = N |
56 | 31 |
57 LazyTensors.range_size(op::BoundaryOperator) = () | 32 LazyTensors.range_size(op::BoundaryOperator) = () |