comparison src/SbpOperators/volumeops/laplace/laplace.jl @ 869:4bd35ba8f34a feature/laplace_opset

REVIEW: Add a few comments and suggest code changes
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 25 Jan 2022 07:21:58 +0100
parents 1784b1c0af3e
children c4dd4ceb2d40
comparison
equal deleted inserted replaced
866:1784b1c0af3e 869:4bd35ba8f34a
1 # REVIEW: The style of name `Laplace` might clash with other concepts. When
2 # thinking about implementing the variable second derivative I think I will
3 # have to create it as a full TM for the full dimensional problem instead of
4 # building it as a 1D operator and then use that with outer products. The
5 # natural name there would be `VariableSecondDerivative` (or something
6 # similar). But the similarity of the two names would suggest that `Laplace`
7 # and `VariableSecondDerivative` are the same kind of thing, which they
8 # wouldn't be.
9 #
10 # How do we distinguish the kind of type we are implementing here and what we
11 # could potentially do for the variable second derivative?
12 #
13 # I see two ways out:
14 # * Come up with a name for these sets of operators and change `Laplace` accordingly.
15 # * Come up with a name for the bare operators and change `VariableSecondDerivative` accordingly.
16
1 """ 17 """
2 Laplace{T, Dim, TMdiffop} <: TensorMapping{T,Dim,Dim} 18 Laplace{T, Dim, TMdiffop} <: TensorMapping{T,Dim,Dim}
3 Laplace(grid, filename; order) 19 Laplace(grid, filename; order)
4 20
5 Implements the Laplace operator, approximating ∑d²/xᵢ² , i = 1,...,`Dim` as a 21 Implements the Laplace operator, approximating ∑d²/xᵢ² , i = 1,...,`Dim` as a
35 D_closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) 51 D_closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
36 H_inner_stencils = parse_scalar(stencil_set["H"]["inner"]) 52 H_inner_stencils = parse_scalar(stencil_set["H"]["inner"])
37 H_closure_stencils = parse_tuple(stencil_set["H"]["closure"]) 53 H_closure_stencils = parse_tuple(stencil_set["H"]["closure"])
38 e_closure_stencil = parse_stencil(stencil_set["e"]["closure"]) 54 e_closure_stencil = parse_stencil(stencil_set["e"]["closure"])
39 d_closure_stencil = parse_stencil(stencil_set["d1"]["closure"]) 55 d_closure_stencil = parse_stencil(stencil_set["d1"]["closure"])
56 # REVIEW: Do we add the methods to get rid of this in this branch or a new one?
40 57
41 # Volume operators 58 # Volume operators
42 Δ = laplace(grid, D_inner_stecil, D_closure_stencils) 59 Δ = laplace(grid, D_inner_stecil, D_closure_stencils)
43 H = inner_product(grid, H_inner_stencils, H_closure_stencils) 60 H = inner_product(grid, H_inner_stencils, H_closure_stencils)
44 H⁻¹ = inverse_inner_product(grid, H_inner_stencils, H_closure_stencils) 61 H⁻¹ = inverse_inner_product(grid, H_inner_stencils, H_closure_stencils)
45 62
46 # Boundary operator - id pairs 63 # Boundary operator - id pairs
47 ids = boundary_identifiers(grid) 64 ids = boundary_identifiers(grid)
48 n_ids = length(ids) 65 # REVIEW: Change suggestion: Seems more readable to me but pretty subjective so feel free to ignore
49 e_pairs = ntuple(i -> ids[i] => boundary_restriction(grid, e_closure_stencil, ids[i]), n_ids) 66 e_pairs = map(id -> Pair(id, boundary_restriction(grid, e_closure_stencil, id)), ids)
50 d_pairs = ntuple(i -> ids[i] => normal_derivative(grid, d_closure_stencil, ids[i]), n_ids) 67 d_pairs = map(id -> Pair(id, normal_derivative(grid, d_closure_stencil, id)), ids)
51 Hᵧ_pairs = ntuple(i -> ids[i] => inner_product(boundary_grid(grid, ids[i]), H_inner_stencils, H_closure_stencils), n_ids) 68 Hᵧ_pairs = map(id -> Pair(id, inner_product(boundary_grid(grid, id), H_inner_stencils, H_closure_stencils)), ids)
52 69
53 return Laplace(Δ, H, H⁻¹, StaticDict(e_pairs), StaticDict(d_pairs), StaticDict(Hᵧ_pairs)) 70 return Laplace(Δ, H, H⁻¹, StaticDict(e_pairs), StaticDict(d_pairs), StaticDict(Hᵧ_pairs))
54 end 71 end
55 72
56 # TODO: Consider pretty printing of the following form 73 # TODO: Consider pretty printing of the following form
57 # Base.show(io::IO, L::Laplace{T, Dim}) where {T,Dim,TM} = print(io, "Laplace{$T, $Dim, $TM}(", L.D, L.H, L.H_inv, L.e, L.d, L.H_boundary, ")") 74 # Base.show(io::IO, L::Laplace{T, Dim}) where {T,Dim,TM} = print(io, "Laplace{$T, $Dim, $TM}(", L.D, L.H, L.H_inv, L.e, L.d, L.H_boundary, ")")
75 # REVIEW: Should leave a todo here to update this once we have some pretty printing for tensor mappings in general.
58 76
59 LazyTensors.range_size(L::Laplace) = LazyTensors.range_size(L.D) 77 LazyTensors.range_size(L::Laplace) = LazyTensors.range_size(L.D)
60 LazyTensors.domain_size(L::Laplace) = LazyTensors.domain_size(L.D) 78 LazyTensors.domain_size(L::Laplace) = LazyTensors.domain_size(L.D)
61 LazyTensors.apply(L::Laplace, v::AbstractArray, I...) = LazyTensors.apply(L.D,v,I...) 79 LazyTensors.apply(L::Laplace, v::AbstractArray, I...) = LazyTensors.apply(L.D,v,I...)
62 80
81 export inverse_inner_product 99 export inverse_inner_product
82 100
83 101
84 """ 102 """
85 boundary_restriction(L::Laplace, id::BoundaryIdentifier) 103 boundary_restriction(L::Laplace, id::BoundaryIdentifier)
86 boundary_restriction(L::Laplace, ids::NTuple{N,BoundaryIdentifier}) 104 boundary_restriction(L::Laplace, ids::Tuple)
87 boundary_restriction(L::Laplace, ids...) 105 boundary_restriction(L::Laplace, ids...)
88 106
89 Returns boundary restriction operator(s) associated with `L` for the boundary(s) 107 Returns boundary restriction operator(s) associated with `L` for the boundary(s)
90 identified by id(s). 108 identified by id(s).
91 109
92 """ 110 """
93 boundary_restriction(L::Laplace, id::BoundaryIdentifier) = L.e[id] 111 boundary_restriction(L::Laplace, id::BoundaryIdentifier) = L.e[id]
94 boundary_restriction(L::Laplace, ids::NTuple{N,BoundaryIdentifier}) where N = ntuple(i->L.e[ids[i]],N) 112 boundary_restriction(L::Laplace, ids::Tuple) = map(id-> L.e[id], ids)
95 boundary_restriction(L::Laplace, ids::Vararg{BoundaryIdentifier,N}) where N = ntuple(i->L.e[ids[i]],N) 113 boundary_restriction(L::Laplace, ids...) = boundary_restriction(L, ids)
114 # REVIEW: I propose changing the following implementations according to the
115 # above. There are some things we're missing with regards to
116 # `BoundaryIdentifier`, for example we should be able to handle groups of
117 # boundaries as a single `BoundaryIdentifier`. I don't know if we can figure
118 # out the interface for that now or if we save it for the future but either
119 # way these methods will be affected.
120
96 export boundary_restriction 121 export boundary_restriction
97 122
98 123
99 """ 124 """
100 normal_derivative(L::Laplace, id::BoundaryIdentifier) 125 normal_derivative(L::Laplace, id::BoundaryIdentifier)