|
1 | 1 | """ |
2 | 2 | abstract type BoundaryFunction{F} |
3 | | - |
| 3 | +
|
4 | 4 | Abstract type for boundary condition functions with function type `F`. |
5 | 5 | """ |
6 | 6 | abstract type BoundaryFunction{F} end |
|
43 | 43 | bc.value(grid, loc, dim, I...) |
44 | 44 | end |
45 | 45 |
|
46 | | -# Create a continuous or discrete boundary function |
47 | | -# if discrete = true, the function has signature f(grid, loc, dim, inds...) |
48 | | -# if reduce_dims = false, the boundary condition function accepts the same number of coordinates as the number of indices |
| 46 | +""" |
| 47 | + BoundaryFunction(fun; discrete=false, parameters=nothing, reduce_dims=true) |
| 48 | +
|
| 49 | +Creates a "boundary function" object that can be use to define boundary conditions on fields. |
| 50 | +
|
| 51 | +## Arguments |
| 52 | +- `fun`: The function defining the boundary condition. |
| 53 | +- `discrete=false`: If `true`, the boundary function is discrete and has the signature `f(grid, loc, dim, inds...)`. |
| 54 | +- `parameters=nothing`: Optional parameters to be passed to the boundary function. |
| 55 | +- `reduce_dims=true`: If `true`, the boundary function reduces the number of dimensions it operates on. If `false`, the function accepts the same number of coordinates as the number of indices. |
| 56 | +
|
| 57 | +## Usage |
| 58 | +The example below shows how to use the boundary function to initialise a parabolic profile at the boundary of a 2D grid. |
| 59 | +
|
| 60 | +```julia |
| 61 | +using Chmy |
| 62 | +
|
| 63 | +arch = Arch(CPU()) |
| 64 | +grid = UniformGrid(arch; origin=(0, 0), extent=(2, 2), dims=(10, 10)) |
| 65 | +
|
| 66 | +f = Field(arch, grid, Center()) |
| 67 | +xbc = BoundaryFunction((x, ly) -> x * (ly - x); parameters=(2.0, )) |
| 68 | +
|
| 69 | +bc!(arch, grid, f => (x = Dirichlet(xbc), y = Neumann())) |
| 70 | +``` |
| 71 | +""" |
49 | 72 | function BoundaryFunction(fun::Function; discrete=false, parameters=nothing, reduce_dims=true) |
50 | 73 | RF = reduce_dims ? ReducedDimensions : FullDimensions |
51 | 74 | discrete ? DiscreteBoundaryFunction{RF}(fun, parameters) : ContinuousBoundaryFunction{RF}(fun, parameters) |
|
0 commit comments