Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/volumeops/laplace/laplace.jl @ 1291:356ec6a72974 refactor/grids
Implement changes in SbpOperators
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 07 Mar 2023 09:48:00 +0100 |
parents | dfbd62c7eb09 |
children | e94ddef5e72f |
comparison
equal
deleted
inserted
replaced
1290:31d0b7638304 | 1291:356ec6a72974 |
---|---|
1 """ | 1 """ |
2 Laplace{T, Dim, TM} <: LazyTensor{T, Dim, Dim} | 2 Laplace{T, Dim, TM} <: LazyTensor{T, Dim, Dim} |
3 | 3 |
4 Implements the Laplace operator, approximating ∑d²/xᵢ² , i = 1,...,`Dim` as a | 4 Implements the Laplace operator, approximating ∑d²/xᵢ² , i = 1,...,`Dim` as a |
5 `LazyTensor`. Additionally `Laplace` stores the `StencilSet` | 5 `LazyTensor`. Additionally `Laplace` stores the `StencilSet` |
6 used to construct the `LazyTensor `. | 6 used to construct the `LazyTensor`. |
7 """ | 7 """ |
8 struct Laplace{T, Dim, TM<:LazyTensor{T, Dim, Dim}} <: LazyTensor{T, Dim, Dim} | 8 struct Laplace{T, Dim, TM<:LazyTensor{T, Dim, Dim}} <: LazyTensor{T, Dim, Dim} |
9 D::TM # Difference operator | 9 D::TM # Difference operator |
10 stencil_set::StencilSet # Stencil set of the operator | 10 stencil_set::StencilSet # Stencil set of the operator |
11 end | 11 end |
15 | 15 |
16 Creates the `Laplace` operator `Δ` on `grid` given a `stencil_set`. | 16 Creates the `Laplace` operator `Δ` on `grid` given a `stencil_set`. |
17 | 17 |
18 See also [`laplace`](@ref). | 18 See also [`laplace`](@ref). |
19 """ | 19 """ |
20 function Laplace(grid::EquidistantGrid, stencil_set::StencilSet) | 20 function Laplace(g::Grid, stencil_set::StencilSet) |
21 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) | 21 Δ = laplace(g, stencil_set) |
22 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) | 22 return Laplace(Δ, stencil_set) |
23 Δ = laplace(grid, inner_stencil,closure_stencils) | |
24 return Laplace(Δ,stencil_set) | |
25 end | 23 end |
26 | 24 |
27 LazyTensors.range_size(L::Laplace) = LazyTensors.range_size(L.D) | 25 LazyTensors.range_size(L::Laplace) = LazyTensors.range_size(L.D) |
28 LazyTensors.domain_size(L::Laplace) = LazyTensors.domain_size(L.D) | 26 LazyTensors.domain_size(L::Laplace) = LazyTensors.domain_size(L.D) |
29 LazyTensors.apply(L::Laplace, v::AbstractArray, I...) = LazyTensors.apply(L.D,v,I...) | 27 LazyTensors.apply(L::Laplace, v::AbstractArray, I...) = LazyTensors.apply(L.D,v,I...) |
30 | 28 |
31 # TODO: Implement pretty printing of Laplace once pretty printing of LazyTensors is implemented. | 29 # TODO: Implement pretty printing of Laplace once pretty printing of LazyTensors is implemented. |
32 # Base.show(io::IO, L::Laplace) = ... | 30 # Base.show(io::IO, L::Laplace) = ... |
33 | 31 |
34 """ | 32 """ |
35 laplace(grid::EquidistantGrid, inner_stencil, closure_stencils) | 33 laplace(g::Grid, stencil_set) |
36 | 34 |
37 Creates the Laplace operator operator `Δ` as a `LazyTensor` | 35 Creates the Laplace operator operator `Δ` as a `LazyTensor` on the given grid |
38 | 36 |
39 `Δ` approximates the Laplace operator ∑d²/xᵢ² , i = 1,...,`Dim` on `grid`, using | 37 `Δ` approximates the Laplace operator ∑d²/xᵢ² , i = 1,...,`Dim` on `g`. The |
40 the stencil `inner_stencil` in the interior and a set of stencils `closure_stencils` | 38 approximation depends on the type of grid and the stencil set. |
41 for the points in the closure regions. | |
42 | |
43 On a one-dimensional `grid`, `Δ` is equivalent to `second_derivative`. On a | |
44 multi-dimensional `grid`, `Δ` is the sum of multi-dimensional `second_derivative`s | |
45 where the sum is carried out lazily. | |
46 | 39 |
47 See also: [`second_derivative`](@ref). | 40 See also: [`second_derivative`](@ref). |
48 """ | 41 """ |
49 function laplace(grid::EquidistantGrid, inner_stencil, closure_stencils) | 42 function laplace end |
50 Δ = second_derivative(grid, inner_stencil, closure_stencils, 1) | 43 function laplace(g::TensorGrid, stencil_set) |
51 for d = 2:ndims(grid) | 44 # return mapreduce(+, enumerate(g.grids)) do (i, gᵢ) |
52 Δ += second_derivative(grid, inner_stencil, closure_stencils, d) | 45 # Δᵢ = laplace(gᵢ, stencil_set) |
46 # LazyTensors.inflate(Δᵢ, size(g), i) | |
47 # end | |
48 | |
49 Δ = LazyTensors.inflate(laplace(g.grids[1], stencil_set), size(g), 1) | |
50 for d = 2:ndims(g) | |
51 Δ += LazyTensors.inflate(laplace(g.grids[d], stencil_set), size(g), d) | |
53 end | 52 end |
54 return Δ | 53 return Δ |
55 end | 54 end |
55 laplace(g::EquidistantGrid, stencil_set) = second_derivative(g, stencil_set) |