Mercurial > repos > public > sbplib_julia
diff src/SbpOperators/volumeops/laplace/laplace.jl @ 973:4c17a7d6ae5e feature/first_derivative
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 15 Mar 2022 06:53:06 +0100 |
parents | 1bb28e47990f |
children | 7bf3121c6864 1ba8a398af9c |
line wrap: on
line diff
--- a/src/SbpOperators/volumeops/laplace/laplace.jl Mon Mar 14 16:01:33 2022 +0100 +++ b/src/SbpOperators/volumeops/laplace/laplace.jl Tue Mar 15 06:53:06 2022 +0100 @@ -1,5 +1,37 @@ """ - laplace(grid::EquidistantGrid{Dim}, inner_stencil, closure_stencils) + Laplace{T, Dim, TM} <: TensorMapping{T, Dim, Dim} + +Implements the Laplace operator, approximating ∑d²/xᵢ² , i = 1,...,`Dim` as a +`TensorMapping`. Additionally `Laplace` stores the stencil set (parsed from TOML) +used to construct the `TensorMapping`. +""" +struct Laplace{T, Dim, TM<:TensorMapping{T, Dim, Dim}} <: TensorMapping{T, Dim, Dim} + D::TM # Difference operator + stencil_set # Stencil set of the operator +end + +""" + Laplace(grid::Equidistant, stencil_set) + +Creates the `Laplace` operator `Δ` on `grid` given a parsed TOML +`stencil_set`. See also [`laplace`](@ref). +""" +function Laplace(grid::EquidistantGrid, stencil_set) + inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) + closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) + Δ = laplace(grid, inner_stencil,closure_stencils) + return Laplace(Δ,stencil_set) +end + +LazyTensors.range_size(L::Laplace) = LazyTensors.range_size(L.D) +LazyTensors.domain_size(L::Laplace) = LazyTensors.domain_size(L.D) +LazyTensors.apply(L::Laplace, v::AbstractArray, I...) = LazyTensors.apply(L.D,v,I...) + +# TODO: Implement pretty printing of Laplace once pretty printing of TensorMappings is implemented. +# Base.show(io::IO, L::Laplace) = ... + +""" + laplace(grid::EquidistantGrid, inner_stencil, closure_stencils) Creates the Laplace operator operator `Δ` as a `TensorMapping` @@ -10,6 +42,8 @@ On a one-dimensional `grid`, `Δ` is equivalent to `second_derivative`. On a multi-dimensional `grid`, `Δ` is the sum of multi-dimensional `second_derivative`s where the sum is carried out lazily. + +See also: [`second_derivative`](@ref). """ function laplace(grid::EquidistantGrid, inner_stencil, closure_stencils) Δ = second_derivative(grid, inner_stencil, closure_stencils, 1) @@ -18,4 +52,3 @@ end return Δ end -export laplace