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 <cstddef>
10 #include <dolfinx/common/span.hpp>
11 #include <functional>
12 #include <map>
13 #include <memory>
14 #include <vector>
15 #include <xtensor/xtensor.hpp>
16 
17 namespace dolfinx
18 {
19 
20 namespace mesh
21 {
22 class Mesh;
23 }
24 
25 namespace fem
26 {
27 class DofMap;
28 class FiniteElement;
29 
33 
35 {
36 public:
41  FunctionSpace(std::shared_ptr<const mesh::Mesh> mesh,
42  std::shared_ptr<const fem::FiniteElement> element,
43  std::shared_ptr<const fem::DofMap> dofmap);
44 
45  // Copy constructor (deleted)
46  FunctionSpace(const FunctionSpace& V) = delete;
47 
49  FunctionSpace(FunctionSpace&& V) = default;
50 
52  virtual ~FunctionSpace() = default;
53 
54  // Assignment operator (delete)
55  FunctionSpace& operator=(const FunctionSpace& V) = delete;
56 
59 
62  bool operator==(const FunctionSpace& V) const;
63 
66  bool operator!=(const FunctionSpace& V) const;
67 
71  std::shared_ptr<FunctionSpace> sub(const std::vector<int>& component) const;
72 
76  bool contains(const FunctionSpace& V) const;
77 
81  std::pair<std::shared_ptr<FunctionSpace>, std::vector<std::int32_t>>
82  collapse() const;
83 
87  std::vector<int> component() const;
88 
97  xt::xtensor<double, 2> tabulate_dof_coordinates(bool transpose) const;
98 
100  std::size_t id() const;
101 
103  std::shared_ptr<const mesh::Mesh> mesh() const;
104 
106  std::shared_ptr<const fem::FiniteElement> element() const;
107 
109  std::shared_ptr<const fem::DofMap> dofmap() const;
110 
111 private:
112  // The mesh
113  std::shared_ptr<const mesh::Mesh> _mesh;
114 
115  // The finite element
116  std::shared_ptr<const fem::FiniteElement> _element;
117 
118  // The dofmap
119  std::shared_ptr<const fem::DofMap> _dofmap;
120 
121  // The component w.r.t. to root space
122  std::vector<int> _component;
123 
124  // Unique identifier
125  std::size_t _id;
126 
127  // The identifier of root space
128  std::size_t _root_space_id;
129 
130  // Cache of subspaces
131  mutable std::map<std::vector<int>, std::weak_ptr<FunctionSpace>> _subspaces;
132 };
133 
143 std::array<std::vector<std::shared_ptr<const FunctionSpace>>, 2>
145  const std::vector<
146  std::vector<std::array<std::shared_ptr<const FunctionSpace>, 2>>>& V);
147 } // namespace fem
148 } // namespace dolfinx
This class represents a finite element function space defined by a mesh, a finite element,...
Definition: FunctionSpace.h:35
virtual ~FunctionSpace()=default
Destructor.
std::vector< int > component() const
Get the component with respect to the root superspace.
Definition: FunctionSpace.cpp:100
std::shared_ptr< FunctionSpace > sub(const std::vector< int > &component) const
Extract subspace for component.
Definition: FunctionSpace.cpp:45
xt::xtensor< double, 2 > tabulate_dof_coordinates(bool transpose) const
Definition: FunctionSpace.cpp:103
bool contains(const FunctionSpace &V) const
Check whether V is subspace of this, or this itself.
Definition: FunctionSpace.cpp:222
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:82
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:25
std::shared_ptr< const fem::DofMap > dofmap() const
The dofmap.
Definition: FunctionSpace.cpp:217
std::shared_ptr< const fem::FiniteElement > element() const
The finite element.
Definition: FunctionSpace.cpp:212
bool operator!=(const FunctionSpace &V) const
Inequality operator.
Definition: FunctionSpace.cpp:39
FunctionSpace(FunctionSpace &&V)=default
Move constructor.
bool operator==(const FunctionSpace &V) const
Equality operator.
Definition: FunctionSpace.cpp:34
FunctionSpace & operator=(FunctionSpace &&V)=default
Move assignment operator.
std::shared_ptr< const mesh::Mesh > mesh() const
The mesh.
Definition: FunctionSpace.cpp:210
std::size_t id() const
Unique identifier.
Definition: FunctionSpace.cpp:208
std::array< std::vector< std::shared_ptr< const FunctionSpace > >, 2 > common_function_spaces(const std::vector< std::vector< std::array< std::shared_ptr< const FunctionSpace >, 2 >>> &V)
Extract FunctionSpaces for (0) rows blocks and (1) columns blocks from a rectangular array of (test,...
Definition: FunctionSpace.cpp:241