10 #include <dolfinx/fem/Function.h>
11 #include <dolfinx/fem/FunctionSpace.h>
12 #include <dolfinx/la/utils.h>
16 #include <xtensor/xtensor.hpp>
17 #include <xtl/xspan.hpp>
54 const std::array<std::reference_wrapper<const fem::FunctionSpace>, 2>& V,
55 const int dim,
const xtl::span<const std::int32_t>& entities,
79 std::vector<std::int32_t>
81 const xtl::span<const std::int32_t>& entities,
98 const std::array<std::reference_wrapper<const fem::FunctionSpace>, 2>& V,
99 const std::function<xt::xtensor<bool, 1>(
const xt::xtensor<double, 2>&)>&
115 const std::function<xt::xtensor<bool, 1>(
const xt::xtensor<double, 2>&)>&
129 template <
typename T>
148 template <
typename U>
151 _dofs0(std::forward<U>(dofs))
153 const int owned_size0 = _function_space->dofmap()->index_map->size_local();
154 auto it = std::lower_bound(_dofs0.begin(), _dofs0.end(), owned_size0);
155 const int map0_bs = _function_space->dofmap()->index_map_bs();
156 _owned_indices0 = map0_bs * std::distance(_dofs0.begin(), it);
158 const int bs = _function_space->dofmap()->bs();
162 const std::vector<std::int32_t> dof_tmp = _dofs0;
163 _dofs0.resize(bs * dof_tmp.size());
164 for (std::size_t i = 0; i < dof_tmp.size(); ++i)
166 for (
int k = 0; k < bs; ++k)
167 _dofs0[bs * i + k] = bs * dof_tmp[i] + k;
193 const std::array<std::vector<std::int32_t>, 2>& V_g_dofs,
194 std::shared_ptr<const fem::FunctionSpace> V)
195 : _function_space(V), _g(g), _dofs0(V_g_dofs[0]), _dofs1_g(V_g_dofs[1])
197 assert(_dofs0.size() == _dofs1_g.size());
198 assert(_function_space);
201 const int map0_bs = _function_space->dofmap()->index_map_bs();
202 const int map0_size = _function_space->dofmap()->index_map->size_local();
203 const int owned_size0 = map0_bs * map0_size;
204 auto it0 = std::lower_bound(_dofs0.begin(), _dofs0.end(), owned_size0);
205 _owned_indices0 = std::distance(_dofs0.begin(), it0);
230 return _function_space;
235 std::shared_ptr<const fem::Function<T>>
value()
const {
return _g; }
243 std::pair<xtl::span<const std::int32_t>, std::int32_t>
dof_indices()
const
245 return {tcb::make_span(_dofs0), _owned_indices0};
259 void set(xtl::span<T> x,
double scale = 1.0)
const
262 const std::vector<T>& g = _g->x()->array();
263 for (std::size_t i = 0; i < _dofs0.size(); ++i)
265 if (_dofs0[i] < (std::int32_t)x.size())
267 assert(_dofs1_g[i] < (std::int32_t)g.size());
268 x[_dofs0[i]] = scale * g[_dofs1_g[i]];
277 void set(xtl::span<T> x,
const xtl::span<const T>& x0,
278 double scale = 1.0)
const
281 const std::vector<T>& g = _g->x()->array();
282 assert(x.size() <= x0.size());
283 for (std::size_t i = 0; i < _dofs0.size(); ++i)
285 if (_dofs0[i] < (std::int32_t)x.size())
287 assert(_dofs1_g[i] < (std::int32_t)g.size());
288 x[_dofs0[i]] = scale * (g[_dofs1_g[i]] - x0[_dofs0[i]]);
304 const std::vector<T>& g = _g->x()->array();
305 for (std::size_t i = 0; i < _dofs1_g.size(); ++i)
306 values[_dofs0[i]] = g[_dofs1_g[i]];
317 for (std::size_t i = 0; i < _dofs0.size(); ++i)
319 assert(_dofs0[i] < (std::int32_t)markers.size());
320 markers[_dofs0[i]] =
true;
326 std::shared_ptr<const fem::FunctionSpace> _function_space;
329 std::shared_ptr<const fem::Function<T>> _g;
333 std::vector<std::int32_t> _dofs0, _dofs1_g;
336 int _owned_indices0 = -1;
337 int _owned_indices1 = -1;
Interface for setting (strong) Dirichlet boundary conditions.
Definition: DirichletBC.h:131
DirichletBC & operator=(const DirichletBC &bc)=default
Assignment operator.
DirichletBC & operator=(DirichletBC &&bc)=default
Move assignment operator.
DirichletBC(DirichletBC &&bc)=default
Move constructor.
~DirichletBC()=default
Destructor.
void dof_values(xtl::span< T > values) const
Definition: DirichletBC.h:301
DirichletBC(const std::shared_ptr< const fem::Function< T >> &g, const std::array< std::vector< std::int32_t >, 2 > &V_g_dofs, std::shared_ptr< const fem::FunctionSpace > V)
Create a representation of a Dirichlet boundary condition where the space being constrained and the f...
Definition: DirichletBC.h:192
void set(xtl::span< T > x, const xtl::span< const T > &x0, double scale=1.0) const
Set bc entries in x to scale * (x0 - x_bc)
Definition: DirichletBC.h:277
DirichletBC(const DirichletBC &bc)=default
Copy constructor.
void set(xtl::span< T > x, double scale=1.0) const
Set bc entries in x to scale * x_bc
Definition: DirichletBC.h:259
std::shared_ptr< const fem::FunctionSpace > function_space() const
The function space to which boundary conditions are applied.
Definition: DirichletBC.h:228
std::pair< xtl::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 app...
Definition: DirichletBC.h:243
DirichletBC(const std::shared_ptr< const fem::Function< T >> &g, U &&dofs)
Create a representation of a Dirichlet boundary condition where the space being constrained is the sa...
Definition: DirichletBC.h:149
std::shared_ptr< const fem::Function< T > > value() const
Return boundary value function g.
Definition: DirichletBC.h:235
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:315
This class represents a finite element function space defined by a mesh, a finite element,...
Definition: FunctionSpace.h:34
This class represents a function in a finite element function space , given by.
Definition: Function.h:48
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:56
std::array< std::vector< std::int32_t >, 2 > locate_dofs_topological(const std::array< std::reference_wrapper< const fem::FunctionSpace >, 2 > &V, const int dim, const xtl::span< const std::int32_t > &entities, bool remote=true)
Find degrees-of-freedom which belong to the provided mesh entities (topological). Note that degrees-o...
Definition: DirichletBC.cpp:244
std::array< std::vector< std::int32_t >, 2 > locate_dofs_geometrical(const std::array< std::reference_wrapper< const fem::FunctionSpace >, 2 > &V, const std::function< xt::xtensor< bool, 1 >(const xt::xtensor< double, 2 > &)> &marker_fn)
Finds degrees of freedom whose geometric coordinate is true for the provided marking function.
Definition: DirichletBC.cpp:450