DOLFINx
DOLFINx C++ interface
FunctionSpace.h
1// Copyright (C) 2008-2022 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 <boost/uuid/uuid.hpp>
10#include <cstddef>
11#include <cstdint>
12#include <map>
13#include <memory>
14#include <vector>
15#include <xtensor/xtensor.hpp>
16
17namespace dolfinx::mesh
18{
19class Mesh;
20}
21
22namespace dolfinx::fem
23{
24class DofMap;
25class FiniteElement;
26
30
32{
33public:
38 FunctionSpace(std::shared_ptr<const mesh::Mesh> mesh,
39 std::shared_ptr<const FiniteElement> element,
40 std::shared_ptr<const DofMap> dofmap);
41
42 // Copy constructor (deleted)
43 FunctionSpace(const FunctionSpace& V) = delete;
44
47
49 virtual ~FunctionSpace() = default;
50
51 // Assignment operator (delete)
52 FunctionSpace& operator=(const FunctionSpace& V) = delete;
53
56
60 std::shared_ptr<FunctionSpace> sub(const std::vector<int>& component) const;
61
66 bool contains(const FunctionSpace& V) const;
67
71 std::pair<FunctionSpace, std::vector<std::int32_t>> collapse() const;
72
76 std::vector<int> component() const;
77
87 xt::xtensor<double, 2> tabulate_dof_coordinates(bool transpose) const;
88
90 std::shared_ptr<const mesh::Mesh> mesh() const;
91
93 std::shared_ptr<const FiniteElement> element() const;
94
96 std::shared_ptr<const DofMap> dofmap() const;
97
98private:
99 // The mesh
100 std::shared_ptr<const mesh::Mesh> _mesh;
101
102 // The finite element
103 std::shared_ptr<const FiniteElement> _element;
104
105 // The dofmap
106 std::shared_ptr<const DofMap> _dofmap;
107
108 // The component w.r.t. to root space
109 std::vector<int> _component;
110
111 // Unique identifier for the space and for its root space
112 boost::uuids::uuid _id;
113 boost::uuids::uuid _root_space_id;
114
115 // Cache of subspaces
116 mutable std::map<std::vector<int>, std::weak_ptr<FunctionSpace>> _subspaces;
117};
118
128std::array<std::vector<std::shared_ptr<const FunctionSpace>>, 2>
130 const std::vector<
131 std::vector<std::array<std::shared_ptr<const FunctionSpace>, 2>>>& V);
132} // namespace dolfinx::fem
This class represents a finite element function space defined by a mesh, a finite element,...
Definition: FunctionSpace.h:32
std::vector< int > component() const
Get the component with respect to the root superspace.
Definition: FunctionSpace.cpp:120
FunctionSpace & operator=(FunctionSpace &&V)=default
Move assignment operator.
xt::xtensor< double, 2 > tabulate_dof_coordinates(bool transpose) const
Tabulate the physical coordinates of all dofs on this process.
Definition: FunctionSpace.cpp:123
std::pair< 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:104
std::shared_ptr< const DofMap > dofmap() const
The dofmap.
Definition: FunctionSpace.cpp:248
FunctionSpace(std::shared_ptr< const mesh::Mesh > mesh, std::shared_ptr< const FiniteElement > element, std::shared_ptr< const DofMap > dofmap)
Create function space for given mesh, element and dofmap.
Definition: FunctionSpace.cpp:26
bool contains(const FunctionSpace &V) const
Check whether V is subspace of this, or this itself.
Definition: FunctionSpace.cpp:72
virtual ~FunctionSpace()=default
Destructor.
std::shared_ptr< const mesh::Mesh > mesh() const
The mesh.
Definition: FunctionSpace.cpp:241
std::shared_ptr< FunctionSpace > sub(const std::vector< int > &component) const
Extract subspace for component.
Definition: FunctionSpace.cpp:36
std::shared_ptr< const FiniteElement > element() const
The finite element.
Definition: FunctionSpace.cpp:243
FunctionSpace(FunctionSpace &&V)=default
Move constructor.
Finite element method functionality.
Definition: assemble_matrix_impl.h:24
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:251
Mesh data structures and algorithms on meshes.
Definition: DofMap.h:30