changeset 1481:ee242c3fe4af feature/boundary_conditions

Support boundary identifiers for 1D grids
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Mon, 25 Dec 2023 19:23:09 +0100
parents 4550beef9694
children 329720b9ba0d
files src/BoundaryConditions/boundary_condition.jl test/BoundaryConditions/boundary_condition_test.jl
diffstat 2 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/BoundaryConditions/boundary_condition.jl	Sat Dec 23 23:03:13 2023 +0100
+++ b/src/BoundaryConditions/boundary_condition.jl	Mon Dec 25 19:23:09 2023 +0100
@@ -4,7 +4,7 @@
 A type for implementing data needed in order to impose a boundary condition.
 Subtypes refer to perticular types of boundary conditions, e.g. Neumann conditions.
 """
-abstract type BoundaryCondition{T} end
+abstract type BoundaryCondition{T1,T2} end
 
 """
     id(::BoundaryCondition)
@@ -22,25 +22,25 @@
 function data end
 
 """
-    discretize(::BoundaryData, boundary_grid)
+    discretize(grid, bc::BoundaryCondition)
 
-Returns an anonymous time-dependent function f, such that f(t) is
-a `LazyArray` holding the `BoundaryData` discretized on `boundary_grid`.
+The grid function obtained from discretizing the `bc` data on the boundary grid
+    specified the by bc `id`.
 """
 function discretize_data(grid, bc::BoundaryCondition)
     return eval_on(boundary_grid(grid, id(bc)), data(bc))
 end
 
-struct DirichletCondition{T} <: BoundaryCondition{T}
-    data::T
-    id::BoundaryIdentifier
+struct DirichletCondition{T1,T2} <: BoundaryCondition{T1,T2}
+    data::T1
+    id::T2
 end
 id(bc::DirichletCondition) = bc.id
 data(bc::DirichletCondition) = bc.data
 
-struct NeumannCondition{T} <: BoundaryCondition{T}
-    data::T
-    id::BoundaryIdentifier 
+struct NeumannCondition{T1,T2} <: BoundaryCondition{T1,T2}
+    data::T1
+    id::T2
 end
 id(bc::NeumannCondition) = bc.id
 data(bc::NeumannCondition) = bc.data
--- a/test/BoundaryConditions/boundary_condition_test.jl	Sat Dec 23 23:03:13 2023 +0100
+++ b/test/BoundaryConditions/boundary_condition_test.jl	Mon Dec 25 19:23:09 2023 +0100
@@ -4,16 +4,20 @@
 using Sbplib.Grids
 
 @testset "BoundaryCondition" begin
+    grid_1d = equidistant_grid(11, 0.0, 1.0)
     grid_2d = equidistant_grid((11,15), (0.0, 0.0), (1.0,1.0))
     grid_3d = equidistant_grid((11,15,13), (0.0, 0.0, 0.0), (1.0,1.0, 1.0))
+    (id_l,_) = boundary_identifiers(grid_1d)
     (_,_,_,id_n) = boundary_identifiers(grid_2d)
     (_,_,_,_,id_b,_) = boundary_identifiers(grid_3d)
 
     g = 3.14
     f(x,y,z) = x^2+y^2+z^2
+    @test DirichletCondition(g,id_l) isa BoundaryCondition{Float64}
     @test DirichletCondition(g,id_n) isa BoundaryCondition{Float64}
     @test NeumannCondition(f,id_b) isa BoundaryCondition{<:Function}
 
+    @test fill(g) ≈ discretize_data(grid_1d,DirichletCondition(g,id_l))
     @test g*ones(11,1) ≈ discretize_data(grid_2d,DirichletCondition(g,id_n))
     X = repeat(0:1/10:1, inner = (1,15))
     Y = repeat(0:1/14:1, outer = (1,11))