Skip to content

Commit 856ebb5

Browse files
luraessutkinis
andauthored
Document BoundaryFunction (#83)
Co-authored-by: Ivan Utkin <iutkin@ethz.ch>
1 parent 1fe244f commit 856ebb5

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

src/BoundaryConditions/boundary_function.jl

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
abstract type BoundaryFunction{F}
3-
3+
44
Abstract type for boundary condition functions with function type `F`.
55
"""
66
abstract type BoundaryFunction{F} end
@@ -43,9 +43,32 @@ end
4343
bc.value(grid, loc, dim, I...)
4444
end
4545

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+
"""
4972
function BoundaryFunction(fun::Function; discrete=false, parameters=nothing, reduce_dims=true)
5073
RF = reduce_dims ? ReducedDimensions : FullDimensions
5174
discrete ? DiscreteBoundaryFunction{RF}(fun, parameters) : ContinuousBoundaryFunction{RF}(fun, parameters)

src/Fields/function_field.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Create a `FunctionField` on the given `grid` using the specified function `func`
2929
- `func::F`: The function used to generate the field values.
3030
- `grid::StructuredGrid{N}`: The structured grid defining the computational domain.
3131
- `loc`: The nodal location on the grid grid where the function field is defined on.
32-
- `discrete::Bool=false`: A flag indicating whether the field should be discrete. Defaults to `false`.
32+
- `discrete=false`: A flag indicating whether the field should be discrete. Defaults to `false`.
3333
- `parameters=nothing`: Additional parameters to be used by the function. Defaults to `nothing`.
3434
"""
3535
function FunctionField(func::F, grid::StructuredGrid{N}, loc; discrete=false, parameters=nothing) where {F,N}

0 commit comments

Comments
 (0)