diff src/SbpOperators/boundary_conditions/boundary_condition.jl @ 1603:fca4a01d60c9 feature/boundary_conditions

Remove module BoundaryConditions, moving its content to SbpOperators
author Vidar Stiernström <vidar.stiernstrom@gmail.com>
date Tue, 04 Jun 2024 16:46:14 -0700
parents src/BoundaryConditions/boundary_condition.jl@3e7438e2a033
children 1388149b54ad
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/SbpOperators/boundary_conditions/boundary_condition.jl	Tue Jun 04 16:46:14 2024 -0700
@@ -0,0 +1,48 @@
+"""
+    BoundaryCondition{BID}
+
+A type for implementing boundary_data needed in order to impose a boundary condition.
+Subtypes refer to perticular types of boundary conditions, e.g. Neumann conditions.
+"""
+abstract type BoundaryCondition{BID} end
+
+"""
+    boundary(::BoundaryCondition)
+
+The boundary identifier of the BoundaryCondition.
+"""
+boundary(::BoundaryCondition{BID}) where {BID} = BID()
+
+"""
+    boundary_data(::BoundaryCondition)
+
+If implemented, the data associated with the BoundaryCondition
+"""
+function boundary_data end
+
+"""
+    discretize(grid, bc::BoundaryCondition)
+
+The grid function obtained from discretizing the `bc` boundary_data on the boundary grid
+    specified the by bc `id`.
+"""
+function discretize_data(grid, bc::BoundaryCondition)
+    return eval_on(boundary_grid(grid, boundary(bc)), boundary_data(bc))
+end
+
+struct DirichletCondition{T1,T2} <: BoundaryCondition{T2}
+    data::T1
+    function DirichletCondition(data, id)
+        return new{typeof(data),typeof(id)}(data)
+    end
+end
+boundary_data(bc::DirichletCondition) = bc.data
+
+struct NeumannCondition{T1,T2} <: BoundaryCondition{T2}
+    data::T1
+    function NeumannCondition(data, id)
+        return new{typeof(data),typeof(id)}(data)
+    end
+end
+boundary_data(bc::NeumannCondition) = bc.data
+