10 #include <dolfinx/function/Function.h>
11 #include <dolfinx/la/utils.h>
60 Eigen::Array<std::int32_t, Eigen::Dynamic, Eigen::Dynamic>
62 const std::vector<std::reference_wrapper<function::FunctionSpace>>& V,
63 const int dim,
const Eigen::Ref<const Eigen::ArrayXi>& entities,
82 Eigen::Array<std::int32_t, Eigen::Dynamic, Eigen::Dynamic>
84 const std::vector<std::reference_wrapper<function::FunctionSpace>>& V,
85 const std::function<Eigen::Array<bool, Eigen::Dynamic, 1>(
86 const Eigen::Ref<
const Eigen::Array<
double, 3, Eigen::Dynamic,
87 Eigen::RowMajor>>&)>& marker);
100 template <
typename T>
113 const Eigen::Ref<
const Eigen::Array<std::int32_t, Eigen::Dynamic, 1>>&
120 const int owned_size = _function_space->dofmap()->index_map->block_size()
121 * _function_space->dofmap()->index_map->size_local();
122 auto* it = std::lower_bound(_dofs.col(0).data(),
123 _dofs.col(0).data() + _dofs.rows(), owned_size);
124 _owned_indices = std::distance(_dofs.col(0).data(), it);
138 const Eigen::Ref<
const Eigen::Array<std::int32_t, Eigen::Dynamic, 2>>&
140 std::shared_ptr<const function::FunctionSpace> V)
141 : _function_space(V), _g(g), _dofs(V_g_dofs)
143 const int owned_size = _function_space->dofmap()->index_map->block_size()
144 * _function_space->dofmap()->index_map->size_local();
145 auto* it = std::lower_bound(_dofs.col(0).data(),
146 _dofs.col(0).data() + _dofs.rows(), owned_size);
147 _owned_indices = std::distance(_dofs.col(0).data(), it);
172 return _function_space;
177 std::shared_ptr<const function::Function<T>>
value()
const {
return _g; }
181 const Eigen::Array<std::int32_t, Eigen::Dynamic, 2>&
dofs()
const
189 const Eigen::Ref<const Eigen::Array<std::int32_t, Eigen::Dynamic, 2>>
192 return _dofs.block<Eigen::Dynamic, 2>(0, 0, _owned_indices, 2);
197 void set(Eigen::Ref<Eigen::Matrix<T, Eigen::Dynamic, 1>> x,
198 double scale = 1.0)
const
202 auto& g = _g->x()->array();
203 for (Eigen::Index i = 0; i < _dofs.rows(); ++i)
205 if (_dofs(i, 0) < x.rows())
206 x[_dofs(i, 0)] = scale * g[_dofs(i, 1)];
212 void set(Eigen::Ref<Eigen::Matrix<T, Eigen::Dynamic, 1>> x,
213 const Eigen::Ref<
const Eigen::Matrix<T, Eigen::Dynamic, 1>>& x0,
214 double scale = 1.0)
const
218 auto& g = _g->x()->array();
219 assert(x.rows() <= x0.rows());
220 for (Eigen::Index i = 0; i < _dofs.rows(); ++i)
222 if (_dofs(i, 0) < x.rows())
223 x[_dofs(i, 0)] = scale * (g[_dofs(i, 1)] - x0[_dofs(i, 0)]);
230 void dof_values(Eigen::Ref<Eigen::Matrix<T, Eigen::Dynamic, 1>> values)
const
233 auto& g = _g->x()->array();
234 for (Eigen::Index i = 0; i < _dofs.rows(); ++i)
235 values[_dofs(i, 0)] = g[_dofs(i, 1)];
243 for (Eigen::Index i = 0; i < _dofs.rows(); ++i)
245 assert(_dofs(i, 0) < (std::int32_t)markers.size());
246 markers[_dofs(i, 0)] =
true;
252 std::shared_ptr<const function::FunctionSpace> _function_space;
255 std::shared_ptr<const function::Function<T>> _g;
259 Eigen::Array<std::int32_t, Eigen::Dynamic, 2> _dofs;
262 int _owned_indices = -1;
Interface for setting (strong) Dirichlet boundary conditions.
Definition: DirichletBC.h:102
DirichletBC & operator=(const DirichletBC &bc)=default
Assignment operator.
const Eigen::Array< std::int32_t, Eigen::Dynamic, 2 > & dofs() const
Get array of dof indices to which a Dirichlet boundary condition is applied. The array is sorted and ...
Definition: DirichletBC.h:181
DirichletBC & operator=(DirichletBC &&bc)=default
Move assignment operator.
DirichletBC(DirichletBC &&bc)=default
Move constructor.
~DirichletBC()=default
Destructor.
const Eigen::Ref< const Eigen::Array< std::int32_t, Eigen::Dynamic, 2 > > dofs_owned() const
Get array of dof indices owned by this process to which a Dirichlet BC is applied....
Definition: DirichletBC.h:190
DirichletBC(const std::shared_ptr< const function::Function< T >> &g, const Eigen::Ref< const Eigen::Array< std::int32_t, Eigen::Dynamic, 1 >> &dofs)
Create boundary condition.
Definition: DirichletBC.h:111
void dof_values(Eigen::Ref< Eigen::Matrix< T, Eigen::Dynamic, 1 >> values) const
Set boundary condition value for entres with an applied boundary condition. Other entries are not mod...
Definition: DirichletBC.h:230
void set(Eigen::Ref< Eigen::Matrix< T, Eigen::Dynamic, 1 >> x, double scale=1.0) const
Set bc entries in x to scale*x_bc.
Definition: DirichletBC.h:197
std::shared_ptr< const function::Function< T > > value() const
Return boundary value function g.
Definition: DirichletBC.h:177
std::shared_ptr< const function::FunctionSpace > function_space() const
The function space to which boundary conditions are applied.
Definition: DirichletBC.h:170
DirichletBC(const DirichletBC &bc)=default
Copy constructor.
DirichletBC(const std::shared_ptr< const function::Function< T >> &g, const Eigen::Ref< const Eigen::Array< std::int32_t, Eigen::Dynamic, 2 >> &V_g_dofs, std::shared_ptr< const function::FunctionSpace > V)
Create boundary condition.
Definition: DirichletBC.h:136
void set(Eigen::Ref< Eigen::Matrix< T, Eigen::Dynamic, 1 >> x, const Eigen::Ref< const Eigen::Matrix< T, Eigen::Dynamic, 1 >> &x0, double scale=1.0) const
Set bc entries in x to scale*(x0 - x_bc).
Definition: DirichletBC.h:212
void mark_dofs(std::vector< bool > &markers) const
Set markers[i] = true if dof i has a boundary condition applied. Value of markers[i] is not changed o...
Definition: DirichletBC.h:241
This class represents a function in a finite element function space , given by.
Definition: Function.h:42
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:47
Eigen::Array< std::int32_t, Eigen::Dynamic, Eigen::Dynamic > locate_dofs_topological(const std::vector< std::reference_wrapper< function::FunctionSpace >> &V, const int dim, const Eigen::Ref< const Eigen::ArrayXi > &entities, bool remote=true)
Build an array of degree-of-freedom indices that are associated with give mesh entities (topological)
Definition: DirichletBC.cpp:496
Eigen::Array< std::int32_t, Eigen::Dynamic, Eigen::Dynamic > locate_dofs_geometrical(const std::vector< std::reference_wrapper< function::FunctionSpace >> &V, const std::function< Eigen::Array< bool, Eigen::Dynamic, 1 >(const Eigen::Ref< const Eigen::Array< double, 3, Eigen::Dynamic, Eigen::RowMajor >> &)> &marker)
Build an array of degree-of-freedom indices based on coordinates of the degree-of-freedom (geometric)...
Definition: DirichletBC.cpp:510