changeset 1106:b4ee47f2aafb feature/boundary_conditions

Start implementing functions for boundary conditions associated with Laplace
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Mon, 13 Jun 2022 13:46:24 +0200
parents 74c54996de6a
children b2afacd57635
files src/BoundaryConditions/BoundaryConditions.jl src/BoundaryConditions/boundary_condition.jl src/LazyTensors/lazy_tensor_operations.jl src/SbpOperators/SbpOperators.jl src/SbpOperators/volumeops/laplace/laplace.jl src/Sbplib.jl
diffstat 6 files changed, 57 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/BoundaryConditions/BoundaryConditions.jl	Mon Jun 13 13:46:24 2022 +0200
@@ -0,0 +1,12 @@
+module BoundaryConditions
+
+export BoundaryCondition
+export BoundaryConditionType
+export Neumann
+export Dirichlet
+
+using Sbplib.Grids
+
+include("boundary_condition.jl")
+
+end # module
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/BoundaryConditions/boundary_condition.jl	Mon Jun 13 13:46:24 2022 +0200
@@ -0,0 +1,11 @@
+abstract type BoundaryConditionType end
+struct Dirichlet <: BoundaryConditionType end
+struct Neumann <: BoundaryConditionType end
+
+struct BoundaryCondition{BCType <: BoundaryConditionType, ID <: BoundaryIdentifier, DType}
+    id::ID
+    data::DType
+    BoundaryCondition{BCType}(id::ID, data::DType) where {BCType <: BoundaryConditionType,
+                                                          ID <: BoundaryIdentifier,
+                                                          DType} = new{BCType,ID,DType}(id, data)
+end
\ No newline at end of file
--- a/src/LazyTensors/lazy_tensor_operations.jl	Sun May 08 11:35:22 2022 +0200
+++ b/src/LazyTensors/lazy_tensor_operations.jl	Mon Jun 13 13:46:24 2022 +0200
@@ -121,6 +121,7 @@
 
 Base.:*(a::T, tm::LazyTensor{T}) where T = TensorComposition(ScalingTensor{T,range_dim(tm)}(a,range_size(tm)), tm)
 Base.:*(tm::LazyTensor{T}, a::T) where T = a*tm
+Base.:-(tm::LazyTensor{T}) where T = (-one(T))*tm
 
 """
     InflatedTensor{T,R,D} <: LazyTensor{T,R,D}
--- a/src/SbpOperators/SbpOperators.jl	Sun May 08 11:35:22 2022 +0200
+++ b/src/SbpOperators/SbpOperators.jl	Mon Jun 13 13:46:24 2022 +0200
@@ -20,9 +20,12 @@
 export first_derivative
 export second_derivative
 
+export sat
+
 using Sbplib.RegionIndices
 using Sbplib.LazyTensors
 using Sbplib.Grids
+using Sbplib.BoundaryConditions
 
 @enum Parity begin
     odd = -1
--- a/src/SbpOperators/volumeops/laplace/laplace.jl	Sun May 08 11:35:22 2022 +0200
+++ b/src/SbpOperators/volumeops/laplace/laplace.jl	Mon Jun 13 13:46:24 2022 +0200
@@ -53,3 +53,31 @@
     end
     return Δ
 end
+
+sat(Δ::Laplace, g::EquidistantGrid, bc::BoundaryCondition{Neumann}) = neumann_sat(Δ, g, bc.id)
+
+function neumann_sat(Δ::Laplace, g::EquidistantGrid{1}, id::BoundaryIdentifier)
+    set  = Δ.stencil_set
+    H⁻¹ = inverse_inner_product(g,set)
+    e = boundary_restriction(g, set, id)
+    d = normal_derivative(g, set, id)
+    return f(u,data) = H⁻¹∘e'∘(d*u .- data)
+    #closure = H⁻¹∘e'∘d
+    #penalty = -H⁻¹∘e'
+    #return closure, penalty
+end
+
+
+
+function neumann_sat(Δ::Laplace, g::EquidistantGrid, id::BoundaryIdentifier)
+    set  = Δ.stencil_set
+    H⁻¹ = inverse_inner_product(g, set)
+    orth_dims = Tuple(filter(i -> i != dimension(g), 1:dimension(g)))
+    Hᵧ = inner_product(restrict(g, orth_dims...), set)
+    e = boundary_restriction(g, set, id)
+    d = normal_derivative(g, set, id)
+    return f(u,data) = H⁻¹∘e'∘Hᵧ∘(d*u .- data)
+    #closure = H⁻¹∘e'∘Hᵧ∘d
+    #penalty = -H⁻¹∘e'∘Hᵧ
+    #return closure, penalty
+end
--- a/src/Sbplib.jl	Sun May 08 11:35:22 2022 +0200
+++ b/src/Sbplib.jl	Mon Jun 13 13:46:24 2022 +0200
@@ -4,6 +4,7 @@
 include("RegionIndices/RegionIndices.jl")
 include("LazyTensors/LazyTensors.jl")
 include("Grids/Grids.jl")
+include("BoundaryConditions/BoundaryConditions.jl")
 include("SbpOperators/SbpOperators.jl")
 include("DiffOps/DiffOps.jl")
 
@@ -12,5 +13,6 @@
 export Grids
 export SbpOperators
 export DiffOps
+export BoundaryConditions
 
 end