Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/volumeops/laplace/laplace.jl @ 975:5be8e25c81b3 feature/tensormapping_application_promotion
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 15 Mar 2022 07:37:11 +0100 |
parents | 1bb28e47990f |
children | 7bf3121c6864 1ba8a398af9c |
comparison
equal
deleted
inserted
replaced
957:86889fc5b63f | 975:5be8e25c81b3 |
---|---|
1 """ | 1 """ |
2 laplace(grid::EquidistantGrid{Dim}, inner_stencil, closure_stencils) | 2 Laplace{T, Dim, TM} <: TensorMapping{T, Dim, Dim} |
3 | |
4 Implements the Laplace operator, approximating ∑d²/xᵢ² , i = 1,...,`Dim` as a | |
5 `TensorMapping`. Additionally `Laplace` stores the stencil set (parsed from TOML) | |
6 used to construct the `TensorMapping`. | |
7 """ | |
8 struct Laplace{T, Dim, TM<:TensorMapping{T, Dim, Dim}} <: TensorMapping{T, Dim, Dim} | |
9 D::TM # Difference operator | |
10 stencil_set # 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 parsed TOML | |
17 `stencil_set`. See also [`laplace`](@ref). | |
18 """ | |
19 function Laplace(grid::EquidistantGrid, stencil_set) | |
20 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) | |
21 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) | |
22 Δ = laplace(grid, inner_stencil,closure_stencils) | |
23 return Laplace(Δ,stencil_set) | |
24 end | |
25 | |
26 LazyTensors.range_size(L::Laplace) = LazyTensors.range_size(L.D) | |
27 LazyTensors.domain_size(L::Laplace) = LazyTensors.domain_size(L.D) | |
28 LazyTensors.apply(L::Laplace, v::AbstractArray, I...) = LazyTensors.apply(L.D,v,I...) | |
29 | |
30 # TODO: Implement pretty printing of Laplace once pretty printing of TensorMappings is implemented. | |
31 # Base.show(io::IO, L::Laplace) = ... | |
32 | |
33 """ | |
34 laplace(grid::EquidistantGrid, inner_stencil, closure_stencils) | |
3 | 35 |
4 Creates the Laplace operator operator `Δ` as a `TensorMapping` | 36 Creates the Laplace operator operator `Δ` as a `TensorMapping` |
5 | 37 |
6 `Δ` approximates the Laplace operator ∑d²/xᵢ² , i = 1,...,`Dim` on `grid`, using | 38 `Δ` 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` | 39 the stencil `inner_stencil` in the interior and a set of stencils `closure_stencils` |
8 for the points in the closure regions. | 40 for the points in the closure regions. |
9 | 41 |
10 On a one-dimensional `grid`, `Δ` is equivalent to `second_derivative`. On a | 42 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 | 43 multi-dimensional `grid`, `Δ` is the sum of multi-dimensional `second_derivative`s |
12 where the sum is carried out lazily. | 44 where the sum is carried out lazily. |
45 | |
46 See also: [`second_derivative`](@ref). | |
13 """ | 47 """ |
14 function laplace(grid::EquidistantGrid, inner_stencil, closure_stencils) | 48 function laplace(grid::EquidistantGrid, inner_stencil, closure_stencils) |
15 Δ = second_derivative(grid, inner_stencil, closure_stencils, 1) | 49 Δ = second_derivative(grid, inner_stencil, closure_stencils, 1) |
16 for d = 2:dimension(grid) | 50 for d = 2:dimension(grid) |
17 Δ += second_derivative(grid, inner_stencil, closure_stencils, d) | 51 Δ += second_derivative(grid, inner_stencil, closure_stencils, d) |
18 end | 52 end |
19 return Δ | 53 return Δ |
20 end | 54 end |
21 export laplace |