comparison src/SbpOperators/volumeops/laplace/laplace.jl @ 1207:f1c2a4fa0ee1 performance/get_region_type_inference

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 03 Feb 2023 22:14:47 +0100
parents dfbd62c7eb09
children a8c8517a310f 356ec6a72974
comparison
equal deleted inserted replaced
919:b41180efb6c2 1207:f1c2a4fa0ee1
1 """ 1 """
2 laplace(grid::EquidistantGrid{Dim}, inner_stencil, closure_stencils) 2 Laplace{T, Dim, TM} <: LazyTensor{T, Dim, Dim}
3 3
4 Creates the Laplace operator operator `Δ` as a `TensorMapping` 4 Implements the Laplace operator, approximating ∑d²/xᵢ² , i = 1,...,`Dim` as a
5 `LazyTensor`. Additionally `Laplace` stores the `StencilSet`
6 used to construct the `LazyTensor `.
7 """
8 struct Laplace{T, Dim, TM<:LazyTensor{T, Dim, Dim}} <: LazyTensor{T, Dim, Dim}
9 D::TM # Difference operator
10 stencil_set::StencilSet # Stencil set of the operator
11 end
12
13 """
14 Laplace(grid::Equidistant, stencil_set)
15
16 Creates the `Laplace` operator `Δ` on `grid` given a `stencil_set`.
17
18 See also [`laplace`](@ref).
19 """
20 function Laplace(grid::EquidistantGrid, stencil_set::StencilSet)
21 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
22 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
23 Δ = laplace(grid, inner_stencil,closure_stencils)
24 return Laplace(Δ,stencil_set)
25 end
26
27 LazyTensors.range_size(L::Laplace) = LazyTensors.range_size(L.D)
28 LazyTensors.domain_size(L::Laplace) = LazyTensors.domain_size(L.D)
29 LazyTensors.apply(L::Laplace, v::AbstractArray, I...) = LazyTensors.apply(L.D,v,I...)
30
31 # TODO: Implement pretty printing of Laplace once pretty printing of LazyTensors is implemented.
32 # Base.show(io::IO, L::Laplace) = ...
33
34 """
35 laplace(grid::EquidistantGrid, inner_stencil, closure_stencils)
36
37 Creates the Laplace operator operator `Δ` as a `LazyTensor`
5 38
6 `Δ` approximates the Laplace operator ∑d²/xᵢ² , i = 1,...,`Dim` on `grid`, using 39 `Δ` approximates the Laplace operator ∑d²/xᵢ² , i = 1,...,`Dim` on `grid`, using
7 the stencil `inner_stencil` in the interior and a set of stencils `closure_stencils` 40 the stencil `inner_stencil` in the interior and a set of stencils `closure_stencils`
8 for the points in the closure regions. 41 for the points in the closure regions.
9 42
10 On a one-dimensional `grid`, `Δ` is equivalent to `second_derivative`. On a 43 On a one-dimensional `grid`, `Δ` is equivalent to `second_derivative`. On a
11 multi-dimensional `grid`, `Δ` is the sum of multi-dimensional `second_derivative`s 44 multi-dimensional `grid`, `Δ` is the sum of multi-dimensional `second_derivative`s
12 where the sum is carried out lazily. 45 where the sum is carried out lazily.
46
47 See also: [`second_derivative`](@ref).
13 """ 48 """
14 function laplace(grid::EquidistantGrid, inner_stencil, closure_stencils) 49 function laplace(grid::EquidistantGrid, inner_stencil, closure_stencils)
15 Δ = second_derivative(grid, inner_stencil, closure_stencils, 1) 50 Δ = second_derivative(grid, inner_stencil, closure_stencils, 1)
16 for d = 2:dimension(grid) 51 for d = 2:ndims(grid)
17 Δ += second_derivative(grid, inner_stencil, closure_stencils, d) 52 Δ += second_derivative(grid, inner_stencil, closure_stencils, d)
18 end 53 end
19 return Δ 54 return Δ
20 end 55 end
21 export laplace