cashocs.create_dirichlet_bcs#
- cashocs.create_dirichlet_bcs(function_space: fenics.FunctionSpace, value: fenics.Constant | fenics.Expression | fenics.Function | float | tuple[float], boundaries: fenics.MeshFunction, idcs: list[int | str] | int | str, **kwargs: Any) list[fenics.DirichletBC] [source]#
Create several Dirichlet boundary conditions at once.
Wraps multiple Dirichlet boundary conditions into a list, in case they have the same value but are to be defined for multiple boundaries with different markers. Particularly useful for defining homogeneous boundary conditions.
- Parameters:
function_space (fenics.FunctionSpace) – The function space onto which the BCs should be imposed on.
value (fenics.Constant | fenics.Expression | fenics.Function | float | tuple[float]) – The value of the boundary condition. Has to be compatible with the function_space, so that it could also be used as
fenics.DirichletBC(function_space, value, ...)
.boundaries (fenics.MeshFunction) – The
fenics.MeshFunction
object representing the boundaries.idcs (list[int | str] | int | str) – A list of indices / boundary markers that determine the boundaries onto which the Dirichlet boundary conditions should be applied to. Can also be a single entry for a single boundary. If your mesh file is named, then you can also use the names of the boundaries to define the boundary conditions.
**kwargs (Any) – Keyword arguments for fenics.DirichletBC
- Returns:
A list of DirichletBC objects that represent the boundary conditions.
- Return type:
list[fenics.DirichletBC]
Examples
Generate homogeneous Dirichlet boundary conditions for all 4 sides of the unit square
import fenics import cashocs mesh, _, _, _, _, _ = cashocs.regular_mesh(25) V = fenics.FunctionSpace(mesh, 'CG', 1) bcs = cashocs.create_dirichlet_bcs(V, fenics.Constant(0), boundaries, [1,2,3,4])