DOLFIN-X
DOLFIN-X C++ interface
DirichletBC.h
1 // Copyright (C) 2007-2020 Michal Habera, Anders Logg and Garth N. Wells
2 //
3 // This file is part of DOLFINX (https://www.fenicsproject.org)
4 //
5 // SPDX-License-Identifier: LGPL-3.0-or-later
6 
7 #pragma once
8 
9 #include <Eigen/Dense>
10 #include <functional>
11 #include <memory>
12 #include <petscsys.h>
13 #include <vector>
14 
15 namespace dolfinx
16 {
17 
18 namespace function
19 {
20 class Function;
21 class FunctionSpace;
22 } // namespace function
23 
24 namespace mesh
25 {
26 class Mesh;
27 } // namespace mesh
28 
29 namespace fem
30 {
31 
58 Eigen::Array<std::int32_t, Eigen::Dynamic, Eigen::Dynamic>
60  const std::vector<std::reference_wrapper<function::FunctionSpace>>& V,
61  const int dim, const Eigen::Ref<const Eigen::ArrayXi>& entities,
62  bool remote = true);
63 
80 Eigen::Array<std::int32_t, Eigen::Dynamic, Eigen::Dynamic>
82  const std::vector<std::reference_wrapper<function::FunctionSpace>>& V,
83  const std::function<Eigen::Array<bool, Eigen::Dynamic, 1>(
84  const Eigen::Ref<const Eigen::Array<double, 3, Eigen::Dynamic,
85  Eigen::RowMajor>>&)>& marker);
86 
97 
99 {
100 
101 public:
108  DirichletBC(
109  const std::shared_ptr<const function::Function>& g,
110  const Eigen::Ref<const Eigen::Array<std::int32_t, Eigen::Dynamic, 1>>&
111  dofs);
112 
122  DirichletBC(
123  const std::shared_ptr<const function::Function>& g,
124  const Eigen::Ref<const Eigen::Array<std::int32_t, Eigen::Dynamic, 2>>&
125  V_g_dofs,
126  std::shared_ptr<const function::FunctionSpace> V);
127 
130  DirichletBC(const DirichletBC& bc) = default;
131 
134  DirichletBC(DirichletBC&& bc) = default;
135 
137  ~DirichletBC() = default;
138 
141  DirichletBC& operator=(const DirichletBC& bc) = default;
142 
144  DirichletBC& operator=(DirichletBC&& bc) = default;
145 
148  std::shared_ptr<const function::FunctionSpace> function_space() const;
149 
152  std::shared_ptr<const function::Function> value() const;
153 
156  const Eigen::Array<std::int32_t, Eigen::Dynamic, 2>& dofs() const;
157 
161  const Eigen::Ref<const Eigen::Array<std::int32_t, Eigen::Dynamic, 2>>
162  dofs_owned() const;
163 
166  void set(Eigen::Ref<Eigen::Matrix<PetscScalar, Eigen::Dynamic, 1>> x,
167  double scale = 1.0) const;
168 
171  void
172  set(Eigen::Ref<Eigen::Matrix<PetscScalar, Eigen::Dynamic, 1>> x,
173  const Eigen::Ref<const Eigen::Matrix<PetscScalar, Eigen::Dynamic, 1>>& x0,
174  double scale = 1.0) const;
175 
179  void dof_values(
180  Eigen::Ref<Eigen::Matrix<PetscScalar, Eigen::Dynamic, 1>> values) const;
181 
185  void mark_dofs(std::vector<bool>& markers) const;
186 
187 private:
188  // The function space (possibly a sub function space)
189  std::shared_ptr<const function::FunctionSpace> _function_space;
190 
191  // The function
192  std::shared_ptr<const function::Function> _g;
193 
194  // Indices of dofs in _function_space and in the space of _g
195  Eigen::Array<std::int32_t, Eigen::Dynamic, 2> _dofs;
196 
197  // The first _owned_indices in _dofs are owned by this process
198  int _owned_indices = -1;
199 };
200 } // namespace fem
201 } // namespace dolfinx
dolfinx::fem::DirichletBC::~DirichletBC
~DirichletBC()=default
Destructor.
dolfinx::fem::DirichletBC::dofs_owned
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.cpp:584
dolfinx::fem::locate_dofs_topological
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:506
dolfinx::fem::locate_dofs_geometrical
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:520
dolfinx::fem::DirichletBC::function_space
std::shared_ptr< const function::FunctionSpace > function_space() const
The function space to which boundary conditions are applied.
Definition: DirichletBC.cpp:568
dolfinx::fem::DirichletBC
Interface for setting (strong) Dirichlet boundary conditions.
Definition: DirichletBC.h:98
dolfinx::fem::DirichletBC::set
void set(Eigen::Ref< Eigen::Matrix< PetscScalar, Eigen::Dynamic, 1 >> x, double scale=1.0) const
Set bc entries in x to scale*x_bc.
Definition: DirichletBC.cpp:589
dolfinx::fem::DirichletBC::dof_values
void dof_values(Eigen::Ref< Eigen::Matrix< PetscScalar, Eigen::Dynamic, 1 >> values) const
Set boundary condition value for entres with an applied boundary condition. Other entries are not mod...
Definition: DirichletBC.cpp:619
dolfinx::fem::DirichletBC::DirichletBC
DirichletBC(const std::shared_ptr< const function::Function > &g, const Eigen::Ref< const Eigen::Array< std::int32_t, Eigen::Dynamic, 1 >> &dofs)
Create boundary condition.
Definition: DirichletBC.cpp:536
dolfinx::fem::DirichletBC::dofs
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.cpp:578
dolfinx::fem::DirichletBC::operator=
DirichletBC & operator=(const DirichletBC &bc)=default
Assignment operator.
dolfinx::fem::DirichletBC::mark_dofs
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.cpp:628
dolfinx::fem::DirichletBC::value
std::shared_ptr< const function::Function > value() const
Return boundary value function g.
Definition: DirichletBC.cpp:573