Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/dolfinx/v0.9.0/cpp/doxygen/db/d9f/classdolfinx_1_1fem_1_1DirichletBC.html
DOLFINx  0.5.1
DOLFINx C++ interface
Public Member Functions | List of all members
DirichletBC< T > Class Template Reference

Object for setting (strong) Dirichlet boundary conditions. More...

#include <DirichletBC.h>

Public Member Functions

template<typename S , typename U , typename = std::enable_if_t< std::is_convertible_v< S, T> or std::is_convertible_v<S, std::span<const T>>>>
 DirichletBC (const S &g, U &&dofs, const std::shared_ptr< const FunctionSpace > &V)
 Create a representation of a Dirichlet boundary condition constrained by a scalar- or vector-valued constant. More...
 
template<typename U >
 DirichletBC (const std::shared_ptr< const Constant< T >> &g, U &&dofs, const std::shared_ptr< const FunctionSpace > &V)
 Create a representation of a Dirichlet boundary condition constrained by a fem::Constant. More...
 
template<typename U >
 DirichletBC (const std::shared_ptr< const Function< T >> &g, U &&dofs)
 Create a representation of a Dirichlet boundary condition where the space being constrained is the same as the function that defines the constraint Function, i.e. share the same fem::FunctionSpace. More...
 
template<typename U >
 DirichletBC (const std::shared_ptr< const Function< T >> &g, U &&V_g_dofs, const std::shared_ptr< const FunctionSpace > &V)
 Create a representation of a Dirichlet boundary condition where the space being constrained and the function that defines the constraint values do not share the same fem::FunctionSpace. More...
 
 DirichletBC (const DirichletBC &bc)=default
 Copy constructor. More...
 
 DirichletBC (DirichletBC &&bc)=default
 Move constructor. More...
 
 ~DirichletBC ()=default
 Destructor.
 
DirichletBCoperator= (const DirichletBC &bc)=default
 Assignment operator. More...
 
DirichletBCoperator= (DirichletBC &&bc)=default
 Move assignment operator.
 
std::shared_ptr< const FunctionSpacefunction_space () const
 The function space to which boundary conditions are applied. More...
 
std::variant< std::shared_ptr< const Function< T > >, std::shared_ptr< const Constant< T > > > value () const
 Return boundary value function g. More...
 
std::pair< std::span< const std::int32_t >, std::int32_t > dof_indices () const
 Access dof indices (local indices, unrolled), including ghosts, to which a Dirichlet condition is applied, and the index to the first non-owned (ghost) index. The array of indices is sorted. More...
 
void set (std::span< T > x, double scale=1.0) const
 Set bc entries in x to scale * x_bc More...
 
void set (std::span< T > x, const std::span< const T > &x0, double scale=1.0) const
 Set bc entries in x to scale * (x0 - x_bc) More...
 
void dof_values (std::span< T > values) const
 
void mark_dofs (const std::span< std::int8_t > &markers) const
 Set markers[i] = true if dof i has a boundary condition applied. Value of markers[i] is not changed otherwise. More...
 

Detailed Description

template<typename T>
class dolfinx::fem::DirichletBC< T >

Object for setting (strong) Dirichlet boundary conditions.

\(u = g \ \text{on} \ G\),

where \(u\) is the solution to be computed, \(g\) is a function and \(G\) is a sub domain of the mesh.

A DirichletBC is specified by the function \(g\), the function space (trial space) and degrees of freedom to which the boundary condition applies.

Constructor & Destructor Documentation

◆ DirichletBC() [1/6]

DirichletBC ( const S &  g,
U &&  dofs,
const std::shared_ptr< const FunctionSpace > &  V 
)
inline

Create a representation of a Dirichlet boundary condition constrained by a scalar- or vector-valued constant.

Precondition
dofs must be sorted.
Parameters
[in]gThe boundary condition value (T or convertible to std::span<const T>)
[in]dofsDegree-of-freedom block indices ( std::vector<std::int32_t>) to be constrained. The indices must be sorted.
[in]VThe function space to be constrained
Note
Can be used only with point-evaluation elements.
The indices in dofs are for blocks, e.g. a block index corresponds to 3 degrees-of-freedom if the dofmap associated with g has block size 3.
The size of of g must be equal to the block size if V. Use the Function version if this is not the case, e.g. for some mixed spaces.

◆ DirichletBC() [2/6]

DirichletBC ( const std::shared_ptr< const Constant< T >> &  g,
U &&  dofs,
const std::shared_ptr< const FunctionSpace > &  V 
)
inline

Create a representation of a Dirichlet boundary condition constrained by a fem::Constant.

Precondition
dofs must be sorted.
Parameters
[in]gThe boundary condition value.
[in]dofsDegree-of-freedom block indices (std::vector<std::int32_t>) to be constrained.
[in]VThe function space to be constrained
Note
Can be used only with point-evaluation elements.
The indices in dofs are for blocks, e.g. a block index corresponds to 3 degrees-of-freedom if the dofmap associated with g has block size 3.
The size of of g must be equal to the block size if V. Use the Function version if this is not the case, e.g. for some mixed spaces.

◆ DirichletBC() [3/6]

DirichletBC ( const std::shared_ptr< const Function< T >> &  g,
U &&  dofs 
)
inline

Create a representation of a Dirichlet boundary condition where the space being constrained is the same as the function that defines the constraint Function, i.e. share the same fem::FunctionSpace.

Precondition
dofs must be sorted.
Parameters
[in]gThe boundary condition value.
[in]dofsDegree-of-freedom block indices (std::vector<std::int32_t>) to be constrained.
Note
The indices in dofs are for blocks, e.g. a block index corresponds to 3 degrees-of-freedom if the dofmap associated with g has block size 3.

◆ DirichletBC() [4/6]

DirichletBC ( const std::shared_ptr< const Function< T >> &  g,
U &&  V_g_dofs,
const std::shared_ptr< const FunctionSpace > &  V 
)
inline

Create a representation of a Dirichlet boundary condition where the space being constrained and the function that defines the constraint values do not share the same fem::FunctionSpace.

A typical example is when applying a constraint on a subspace. The (sub)space and the constrain function must have the same finite element.

Precondition
The two degree-of-freedom arrays in V_g_dofs must be sorted by the indices in the first array.
Parameters
[in]gThe boundary condition value
[in]V_g_dofsTwo arrays of degree-of-freedom indices (std::array<std::vector<std::int32_t>, 2>). First array are indices in the space where boundary condition is applied (V), second array are indices in the space of the boundary condition value function g. The dof indices are unrolled, i.e. are not by dof block.
[in]VThe function (sub)space on which the boundary condition is applied
Note
The indices in dofs are unrolled and not for blocks.

◆ DirichletBC() [5/6]

DirichletBC ( const DirichletBC< T > &  bc)
default

Copy constructor.

Parameters
[in]bcThe object to be copied

◆ DirichletBC() [6/6]

DirichletBC ( DirichletBC< T > &&  bc)
default

Move constructor.

Parameters
[in]bcThe object to be moved

Member Function Documentation

◆ dof_indices()

std::pair<std::span<const std::int32_t>, std::int32_t> dof_indices ( ) const
inline

Access dof indices (local indices, unrolled), including ghosts, to which a Dirichlet condition is applied, and the index to the first non-owned (ghost) index. The array of indices is sorted.

Returns
Sorted array of dof indices (unrolled) and index to the first entry in the dof index array that is not owned. Entries dofs[:pos] are owned and entries dofs[pos:] are ghosts.

◆ dof_values()

void dof_values ( std::span< T >  values) const
inline
Todo:
Review this function - it is almost identical to the 'DirichletBC::set' function

Set boundary condition value for entries with an applied boundary condition. Other entries are not modified.

Parameters
[out]valuesThe array in which to set the dof values. The array must be at least as long as the array associated with V1 (the space of the function that provides the dof values)

◆ function_space()

std::shared_ptr<const FunctionSpace> function_space ( ) const
inline

The function space to which boundary conditions are applied.

Returns
The function space

◆ mark_dofs()

void mark_dofs ( const std::span< std::int8_t > &  markers) const
inline

Set markers[i] = true if dof i has a boundary condition applied. Value of markers[i] is not changed otherwise.

Parameters
[in,out]markersEntry makers[i] is set to true if dof i in V0 had a boundary condition applied, i.e. dofs which are fixed by a boundary condition. Other entries in markers are left unchanged.

◆ operator=()

DirichletBC& operator= ( const DirichletBC< T > &  bc)
default

Assignment operator.

Parameters
[in]bcAnother DirichletBC object

◆ set() [1/2]

void set ( std::span< T >  x,
const std::span< const T > &  x0,
double  scale = 1.0 
) const
inline

Set bc entries in x to scale * (x0 - x_bc)

Parameters
[in]xThe array in which to set scale * (x0 - x_bc)
[in]x0The array used in compute the value to set
[in]scaleThe scaling value to apply

◆ set() [2/2]

void set ( std::span< T >  x,
double  scale = 1.0 
) const
inline

Set bc entries in x to scale * x_bc

Parameters
[in]xThe array in which to set scale * x_bc[i], where x_bc[i] is the boundary value of x[i]. Entries in x that do not have a Dirichlet condition applied to them are unchanged. The length of x must be less than or equal to the index of the greatest boundary dof index. To set values only for degrees-of-freedom that are owned by the calling rank, the length of the array x should be equal to the number of dofs owned by this rank.
[in]scaleThe scaling value to apply

◆ value()

std::variant<std::shared_ptr<const Function<T> >, std::shared_ptr<const Constant<T> > > value ( ) const
inline

Return boundary value function g.

Returns
The boundary values Function

The documentation for this class was generated from the following files: