comparison src/BoundaryConditions/boundary_condition.jl @ 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 481960ca366f
children 37b05221beda
comparison
equal deleted inserted replaced
1480:4550beef9694 1481:ee242c3fe4af
2 BoundaryCondition 2 BoundaryCondition
3 3
4 A type for implementing data needed in order to impose a boundary condition. 4 A type for implementing data needed in order to impose a boundary condition.
5 Subtypes refer to perticular types of boundary conditions, e.g. Neumann conditions. 5 Subtypes refer to perticular types of boundary conditions, e.g. Neumann conditions.
6 """ 6 """
7 abstract type BoundaryCondition{T} end 7 abstract type BoundaryCondition{T1,T2} end
8 8
9 """ 9 """
10 id(::BoundaryCondition) 10 id(::BoundaryCondition)
11 11
12 The boundary identifier of the BoundaryCondition. 12 The boundary identifier of the BoundaryCondition.
20 If implemented, the data associated with the BoundaryCondition 20 If implemented, the data associated with the BoundaryCondition
21 """ 21 """
22 function data end 22 function data end
23 23
24 """ 24 """
25 discretize(::BoundaryData, boundary_grid) 25 discretize(grid, bc::BoundaryCondition)
26 26
27 Returns an anonymous time-dependent function f, such that f(t) is 27 The grid function obtained from discretizing the `bc` data on the boundary grid
28 a `LazyArray` holding the `BoundaryData` discretized on `boundary_grid`. 28 specified the by bc `id`.
29 """ 29 """
30 function discretize_data(grid, bc::BoundaryCondition) 30 function discretize_data(grid, bc::BoundaryCondition)
31 return eval_on(boundary_grid(grid, id(bc)), data(bc)) 31 return eval_on(boundary_grid(grid, id(bc)), data(bc))
32 end 32 end
33 33
34 struct DirichletCondition{T} <: BoundaryCondition{T} 34 struct DirichletCondition{T1,T2} <: BoundaryCondition{T1,T2}
35 data::T 35 data::T1
36 id::BoundaryIdentifier 36 id::T2
37 end 37 end
38 id(bc::DirichletCondition) = bc.id 38 id(bc::DirichletCondition) = bc.id
39 data(bc::DirichletCondition) = bc.data 39 data(bc::DirichletCondition) = bc.data
40 40
41 struct NeumannCondition{T} <: BoundaryCondition{T} 41 struct NeumannCondition{T1,T2} <: BoundaryCondition{T1,T2}
42 data::T 42 data::T1
43 id::BoundaryIdentifier 43 id::T2
44 end 44 end
45 id(bc::NeumannCondition) = bc.id 45 id(bc::NeumannCondition) = bc.id
46 data(bc::NeumannCondition) = bc.data 46 data(bc::NeumannCondition) = bc.data
47 47