Mercurial > repos > public > sbplib_julia
comparison src/BoundaryConditions/boundary_condition.jl @ 1602:3e7438e2a033 feature/boundary_conditions
Address review comments (1 left to be discussed)
author | Vidar Stiernström <vidar.stiernstrom@gmail.com> |
---|---|
date | Sat, 01 Jun 2024 17:39:54 -0700 |
parents | 37b05221beda |
children |
comparison
equal
deleted
inserted
replaced
1601:fad18896d20a | 1602:3e7438e2a033 |
---|---|
1 """ | 1 """ |
2 BoundaryCondition | 2 BoundaryCondition{BID} |
3 | 3 |
4 A type for implementing data needed in order to impose a boundary condition. | 4 A type for implementing boundary_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{T1,T2} end # REVIEW: No type parameters needed here. | 7 abstract type BoundaryCondition{BID} end |
8 | 8 |
9 """ | 9 """ |
10 id(::BoundaryCondition) | 10 boundary(::BoundaryCondition) |
11 | 11 |
12 The boundary identifier of the BoundaryCondition. | 12 The boundary identifier of the BoundaryCondition. |
13 Must be implemented by subtypes. | |
14 """ | 13 """ |
15 function id end | 14 boundary(::BoundaryCondition{BID}) where {BID} = BID() |
16 | 15 |
17 """ | 16 """ |
18 data(::BoundaryCondition) | 17 boundary_data(::BoundaryCondition) |
19 | 18 |
20 If implemented, the data associated with the BoundaryCondition | 19 If implemented, the data associated with the BoundaryCondition |
21 """ | 20 """ |
22 function data end | 21 function boundary_data end |
23 | 22 |
24 """ | 23 """ |
25 discretize(grid, bc::BoundaryCondition) | 24 discretize(grid, bc::BoundaryCondition) |
26 | 25 |
27 The grid function obtained from discretizing the `bc` data on the boundary grid | 26 The grid function obtained from discretizing the `bc` boundary_data on the boundary grid |
28 specified the by bc `id`. | 27 specified the by bc `id`. |
29 """ | 28 """ |
30 function discretize_data(grid, bc::BoundaryCondition) | 29 function discretize_data(grid, bc::BoundaryCondition) |
31 return eval_on(boundary_grid(grid, id(bc)), data(bc)) | 30 return eval_on(boundary_grid(grid, boundary(bc)), boundary_data(bc)) |
32 end | 31 end |
33 | 32 |
34 struct DirichletCondition{T1,T2} <: BoundaryCondition{T1,T2} | 33 struct DirichletCondition{T1,T2} <: BoundaryCondition{T2} |
35 data::T1 | 34 data::T1 |
36 id::T2 # REVIEW: This field not needed since BoundaryId are usually type parameters? | 35 function DirichletCondition(data, id) |
36 return new{typeof(data),typeof(id)}(data) | |
37 end | |
37 end | 38 end |
38 id(bc::DirichletCondition) = bc.id | 39 boundary_data(bc::DirichletCondition) = bc.data |
39 data(bc::DirichletCondition) = bc.data | |
40 | 40 |
41 struct NeumannCondition{T1,T2} <: BoundaryCondition{T1,T2} | 41 struct NeumannCondition{T1,T2} <: BoundaryCondition{T2} |
42 data::T1 | 42 data::T1 |
43 id::T2 # REVIEW: This field not needed since BoundaryId are usually type parameters? | 43 function NeumannCondition(data, id) |
44 return new{typeof(data),typeof(id)}(data) | |
45 end | |
44 end | 46 end |
45 id(bc::NeumannCondition) = bc.id | 47 boundary_data(bc::NeumannCondition) = bc.data |
46 data(bc::NeumannCondition) = bc.data | |
47 | 48 |