changeset 676:bf48761c1345 feature/laplace_opset

Merge with feature/boundary_quads
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Sat, 06 Feb 2021 14:03:14 +0100
parents 2d56a53a1646 (diff) 538ccbaeb1f8 (current diff)
children 011863b3f24c
files
diffstat 2 files changed, 71 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Notes.md	Sat Feb 06 12:04:06 2021 +0100
+++ b/Notes.md	Sat Feb 06 14:03:14 2021 +0100
@@ -130,6 +130,7 @@
  - [ ] How do we handle mixes of periodic and non-periodic grids? Seems it should be supported on the grid level and on the 1d operator level. Between there it should be transparent.
  - [ ] Can we have a trait to tell if a TensorMapping is transposable?
  - [ ] Is it ok to have "Constructors" for abstract types which create subtypes? For example a Grids() functions that gives different kind of grids based on input?
+ - [ ] Figure out how to treat the borrowing parameters of operators. Include in into the struct? Expose via function dispatched on the operator type and grid?
 
 ## Regions and tensormappings
 - [ ] Use a trait to indicate if a TensorMapping uses indices with regions.
--- a/src/SbpOperators/volumeops/laplace/laplace.jl	Sat Feb 06 12:04:06 2021 +0100
+++ b/src/SbpOperators/volumeops/laplace/laplace.jl	Sat Feb 06 14:03:14 2021 +0100
@@ -1,5 +1,72 @@
 """
-    Laplace(grid::EquidistantGrid{Dim}, inner_stencil, closure_stencils)
+    Laplace{T,Dim,...}()
+    Laplace(grid::EquidistantGrid, fn; order)
+
+Implements the Laplace operator, approximating ∑d²/xᵢ² , i = 1,...,`Dim` as a
+`TensorMapping`. Additionally, `Laplace` stores the quadrature, and boundary
+operators relevant for constructing a SBP finite difference scheme as `TensorMapping`s.
+"""
+struct Laplace{T, Dim, Rb, TMdiffop<:TensorMapping{T,Dim,Dim}, # Differential operator tensor mapping
+                           TMqop<:TensorMapping{T,Dim,Dim}, # Quadrature operator tensor mapping
+                           TMbop<:TensorMapping{T,Rb,Dim}, # Boundary operator tensor mapping
+                           TMbqop<:TensorMapping{T,Rb,Rb}, # Boundary quadrature tensor mapping
+                           BID<:BoundaryIdentifier} <: TensorMapping{T,Dim,Dim}
+    D::TMdiffop # Difference operator
+    H::TMqop # Quadrature (norm) operator
+    H_inv::TMqop # Inverse quadrature (norm) operator
+    e::Dict{BID,TMbop} # Boundary restriction operators
+    d::Dict{BID,TMbop} # Normal derivative operators
+    H_boundary::Dict{BID,TMbqop} # Boundary quadrature operators
+end
+export Laplace
+
+function Laplace(grid::EquidistantGrid, fn; order)
+    # TODO: Removed once we can construct the volume and
+    # boundary operators by op(grid, fn; order,...).
+    # Read stencils
+    op = read_D2_operator(fn; order)
+    D_inner_stecil = op.innerStencil
+    D_closure_stencils = op.closureStencils
+    H_closure_stencils = op.quadratureClosure
+    e_closure_stencil = op.eClosure
+    d_closure_stencil = op.dClosure
+
+    # Volume operators
+    Δ =  laplace(grid, D_inner_stecil, D_closure_stencils)
+    H =  DiagonalQuadrature(grid, H_closure_stencils)
+    H⁻¹ =  InverseDiagonalQuadrature(grid, H_closure_stencils)
+
+    # Pair operators with boundary ids
+    bids = boundary_identifiers(grid)
+    # Boundary operators
+    e_pairs = ntuple(i -> Pair(bids[i],BoundaryRestriction(grid,e_closure_stencil,bids[i])),length(bids))
+    d_pairs = ntuple(i -> Pair(bids[i],NormalDerivative(grid,d_closure_stencil,bids[i])),length(bids))
+    # Boundary quadratures are constructed on the lower-dimensional grid defined
+    # by the coordinite directions orthogonal to that of the boundary.
+    dims = collect(1:dimension(grid))
+    orth_grids = ntuple(i -> restrict(grid,dims[dims .!= dim(bids[i])]),length(bids))
+    Hᵧ_pairs = ntuple(i -> Pair(bids[i],DiagonalQuadrature(orth_grids[i],H_closure_stencils)),length(bids))
+
+    return Laplace(Δ, H, H⁻¹, Dict(e_pairs), Dict(d_pairs), Dict(Hᵧ_pairs))
+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...)
+
+quadrature(L::Laplace) = L.H
+export quadrature
+inverse_quadrature(L::Laplace) = L.H_inv
+export inverse_quadrature
+boundary_restriction(L::Laplace,bid::BoundaryIdentifier) = L.e[bid]
+export boundary_restriction
+normal_derivative(L::Laplace,bid::BoundaryIdentifier) = L.d[bid]
+export normal_derivative
+boundary_quadrature(L::Laplace,bid::BoundaryIdentifier) = L.H_boundary[bid]
+export boundary_quadrature
+
+"""
+    laplace(grid::EquidistantGrid{Dim}, inner_stencil, closure_stencils)
 
 Creates the Laplace operator operator `Δ` as a `TensorMapping`
 
@@ -10,11 +77,11 @@
 On a one-dimensional `grid`, `Δ` is a `SecondDerivative`. On a multi-dimensional `grid`, `Δ` is the sum of
 multi-dimensional `SecondDerivative`s where the sum is carried out lazily.
 """
-function Laplace(grid::EquidistantGrid{Dim}, inner_stencil, closure_stencils) where Dim
+function laplace(grid::EquidistantGrid{Dim}, inner_stencil, closure_stencils) where Dim
     Δ = SecondDerivative(grid, inner_stencil, closure_stencils, 1)
     for d = 2:Dim
         Δ += SecondDerivative(grid, inner_stencil, closure_stencils, d)
     end
     return Δ
 end
-export Laplace
+export laplace