comparison src/SbpOperators/boundaryops/boundary_operator.jl @ 1221:b3b4d29b46c3 refactor/grids

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 10 Feb 2023 08:36:56 +0100
parents 716e721ce3eb
children f1c2a4fa0ee1 1cc45207817e 102ebdaf7c11
comparison
equal deleted inserted replaced
1220:93bba649aea2 1221:b3b4d29b46c3
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 # Create 1D boundary operator
16 r = region(boundary)
17 d = dim(boundary)
18 op = BoundaryOperator(restrict(grid, d), closure_stencil, r)
19
20 # Create 1D IdentityTensors for each coordinate direction
21 one_d_grids = restrict.(Ref(grid), Tuple(dims(grid)))
22 Is = IdentityTensor{eltype(grid)}.(size.(one_d_grids))
23
24 # Formulate the correct outer product sequence of the identity mappings and
25 # the boundary operator
26 parts = Base.setindex(Is, op, d)
27 return foldl(⊗, parts)
28 end
29
30 """ 1 """
31 BoundaryOperator{T,R,N} <: LazyTensor{T,0,1} 2 BoundaryOperator{T,R,N} <: LazyTensor{T,0,1}
32 3
33 Implements the boundary operator `op` for 1D as a `LazyTensor` 4 Implements the boundary operator `op` for 1D as a `LazyTensor`
34 5
39 struct BoundaryOperator{T,R<:Region,N} <: LazyTensor{T,0,1} 10 struct BoundaryOperator{T,R<:Region,N} <: LazyTensor{T,0,1}
40 stencil::Stencil{T,N} 11 stencil::Stencil{T,N}
41 size::Int 12 size::Int
42 end 13 end
43 14
44 BoundaryOperator{R}(stencil::Stencil{T,N}, size::Int) where {T,R,N} = BoundaryOperator{T,R,N}(stencil, size)
45
46 """ 15 """
47 BoundaryOperator(grid::EquidistantGrid{1}, closure_stencil, region) 16 BoundaryOperator(grid::EquidistantGrid{1}, closure_stencil, region)
48 17
49 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
50 to the boundary specified by `region`. 19 to the boundary specified by `region`.
53 return BoundaryOperator{T,typeof(region),N}(closure_stencil,size(grid)[1]) 22 return BoundaryOperator{T,typeof(region),N}(closure_stencil,size(grid)[1])
54 end 23 end
55 24
56 """ 25 """
57 closure_size(::BoundaryOperator) 26 closure_size(::BoundaryOperator)
27
58 The size of the closure stencil. 28 The size of the closure stencil.
59 """ 29 """
60 closure_size(::BoundaryOperator{T,R,N}) where {T,R,N} = N 30 closure_size(::BoundaryOperator{T,R,N}) where {T,R,N} = N
61 31
62 LazyTensors.range_size(op::BoundaryOperator) = () 32 LazyTensors.range_size(op::BoundaryOperator) = ()