DOLFIN-X
DOLFIN-X C++ interface
FunctionSpace.h
1 // Copyright (C) 2008-2019 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 <cstddef>
11 #include <functional>
12 #include <map>
13 #include <memory>
14 #include <vector>
15 
16 namespace dolfinx
17 {
18 
19 namespace fem
20 {
21 class DofMap;
22 class FiniteElement;
23 } // namespace fem
24 
25 namespace mesh
26 {
27 class Mesh;
28 }
29 
30 namespace function
31 {
32 
36 
38 {
39 public:
44  FunctionSpace(std::shared_ptr<const mesh::Mesh> mesh,
45  std::shared_ptr<const fem::FiniteElement> element,
46  std::shared_ptr<const fem::DofMap> dofmap);
47 
48  // Copy constructor (deleted)
49  FunctionSpace(const FunctionSpace& V) = delete;
50 
52  FunctionSpace(FunctionSpace&& V) = default;
53 
55  virtual ~FunctionSpace() = default;
56 
57  // Assignment operator (delete)
58  FunctionSpace& operator=(const FunctionSpace& V) = delete;
59 
61  FunctionSpace& operator=(FunctionSpace&& V) = default;
62 
65  bool operator==(const FunctionSpace& V) const;
66 
69  bool operator!=(const FunctionSpace& V) const;
70 
73  std::int64_t dim() const;
74 
78  std::shared_ptr<FunctionSpace> sub(const std::vector<int>& component) const;
79 
83  bool contains(const FunctionSpace& V) const;
84 
88  std::pair<std::shared_ptr<FunctionSpace>, std::vector<std::int32_t>>
89  collapse() const;
90 
94  bool has_element(const fem::FiniteElement& element) const;
95 
99  std::vector<int> component() const;
100 
103  Eigen::Array<double, Eigen::Dynamic, 3, Eigen::RowMajor>
104  tabulate_dof_coordinates() const;
105 
111  Eigen::Array<double, Eigen::Dynamic, 3, Eigen::RowMajor>
113 
115  std::size_t id() const;
116 
118  std::shared_ptr<const mesh::Mesh> mesh() const;
119 
121  std::shared_ptr<const fem::FiniteElement> element() const;
122 
124  std::shared_ptr<const fem::DofMap> dofmap() const;
125 
126 private:
127  // The mesh
128  std::shared_ptr<const mesh::Mesh> _mesh;
129 
130  // The finite element
131  std::shared_ptr<const fem::FiniteElement> _element;
132 
133  // The dofmap
134  std::shared_ptr<const fem::DofMap> _dofmap;
135 
136  // The component w.r.t. to root space
137  std::vector<int> _component;
138 
139  // Unique identifier
140  std::size_t _id;
141 
142  // The identifier of root space
143  std::size_t _root_space_id;
144 
145  // Cache of subspaces
146  mutable std::map<std::vector<int>, std::weak_ptr<FunctionSpace>> _subspaces;
147 };
148 } // namespace function
149 } // namespace dolfinx
dolfinx::function::FunctionSpace::~FunctionSpace
virtual ~FunctionSpace()=default
Destructor.
dolfinx::function::FunctionSpace::sub
std::shared_ptr< FunctionSpace > sub(const std::vector< int > &component) const
Extract subspace for component.
Definition: FunctionSpace.cpp:151
dolfinx::function::FunctionSpace::collapse
std::pair< std::shared_ptr< FunctionSpace >, std::vector< std::int32_t > > collapse() const
Collapse a subspace and return a new function space and a map from new to old dofs.
Definition: FunctionSpace.cpp:188
dolfinx::function::FunctionSpace::mesh
std::shared_ptr< const mesh::Mesh > mesh() const
The mesh.
Definition: FunctionSpace.cpp:240
dolfinx::function::FunctionSpace::dofmap
std::shared_ptr< const fem::DofMap > dofmap() const
The dofmap.
Definition: FunctionSpace.cpp:247
dolfinx::function::FunctionSpace::element
std::shared_ptr< const fem::FiniteElement > element() const
The finite element.
Definition: FunctionSpace.cpp:242
dolfinx::fem::FiniteElement
Finite Element, containing the dof layout on a reference element, and various methods for evaluating ...
Definition: FiniteElement.h:24
dolfinx::function::FunctionSpace::dim
std::int64_t dim() const
Return global dimension of the function space.
Definition: FunctionSpace.cpp:136
dolfinx::function::FunctionSpace::component
std::vector< int > component() const
Get the component with respect to the root superspace.
Definition: FunctionSpace.cpp:211
dolfinx::function::FunctionSpace::FunctionSpace
FunctionSpace(std::shared_ptr< const mesh::Mesh > mesh, std::shared_ptr< const fem::FiniteElement > element, std::shared_ptr< const fem::DofMap > dofmap)
Create function space for given mesh, element and dofmap.
Definition: FunctionSpace.cpp:114
dolfinx::function::FunctionSpace::has_element
bool has_element(const fem::FiniteElement &element) const
Check if function space has given element.
Definition: FunctionSpace.cpp:206
dolfinx::function::FunctionSpace::tabulate_dof_coordinates
Eigen::Array< double, Eigen::Dynamic, 3, Eigen::RowMajor > tabulate_dof_coordinates() const
Tabulate the physical coordinates of all dofs on this process.
Definition: FunctionSpace.cpp:214
dolfinx::function::FunctionSpace::operator==
bool operator==(const FunctionSpace &V) const
Equality operator.
Definition: FunctionSpace.cpp:123
dolfinx::function::FunctionSpace::id
std::size_t id() const
Unique identifier.
Definition: FunctionSpace.cpp:238
dolfinx::function::FunctionSpace::contains
bool contains(const FunctionSpace &V) const
Check whether V is subspace of this, or this itself.
Definition: FunctionSpace.cpp:252
dolfinx::function::FunctionSpace::tabulate_scalar_subspace_dof_coordinates
Eigen::Array< double, Eigen::Dynamic, 3, Eigen::RowMajor > tabulate_scalar_subspace_dof_coordinates() const
Tabulate the physical coordinates of all dofs of scalar subspace on this process. For a VectorFunctio...
Definition: FunctionSpace.cpp:227
dolfinx::function::FunctionSpace
This class represents a finite element function space defined by a mesh, a finite element,...
Definition: FunctionSpace.h:37
dolfinx::function::FunctionSpace::operator!=
bool operator!=(const FunctionSpace &V) const
Inequality operator.
Definition: FunctionSpace.cpp:130