DOLFIN
DOLFIN C++ interface
FunctionSpace.h
1 // Copyright (C) 2008-2011 Anders Logg
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // Modified by Garth N. Wells 2008-2011
19 // Modified by Kent-Andre Mardal 2009
20 // Modified by Ola Skavhaug 2009
21 //
22 // First added: 2008-09-11
23 // Last changed: 2014-06-11
24 
25 #ifndef __FUNCTION_SPACE_H
26 #define __FUNCTION_SPACE_H
27 
28 #include <cstddef>
29 #include <map>
30 #include <vector>
31 
32 #include <memory>
33 #include <unordered_map>
34 #include <dolfin/common/Array.h>
35 #include <dolfin/common/Variable.h>
36 #include <dolfin/common/Hierarchical.h>
37 #include <dolfin/fem/FiniteElement.h>
38 #include <dolfin/mesh/Cell.h>
39 
40 namespace dolfin
41 {
42 
43  class Function;
44  class GenericDofMap;
45  class GenericFunction;
46  class GenericVector;
47  class Mesh;
48 
52 
53  class FunctionSpace : public Variable, public Hierarchical<FunctionSpace>
54  {
55  public:
56 
67  FunctionSpace(std::shared_ptr<const Mesh> mesh,
68  std::shared_ptr<const FiniteElement> element,
69  std::shared_ptr<const GenericDofMap> dofmap);
70 
71  protected:
72 
82  explicit FunctionSpace(std::shared_ptr<const Mesh> mesh);
83 
84  public:
85 
91  FunctionSpace(const FunctionSpace& V);
92 
94  virtual ~FunctionSpace();
95 
96  protected:
97 
105  void attach(std::shared_ptr<const FiniteElement> element,
106  std::shared_ptr<const GenericDofMap> dofmap);
107 
108  public:
109 
115  const FunctionSpace& operator= (const FunctionSpace& V);
116 
122  bool operator== (const FunctionSpace& V) const;
123 
129  bool operator!= (const FunctionSpace& V) const;
130 
136  std::shared_ptr<const Mesh> mesh() const;
137 
143  std::shared_ptr<const FiniteElement> element() const;
144 
150  std::shared_ptr<const GenericDofMap> dofmap() const;
151 
158  std::size_t dim() const;
159 
168  void interpolate(GenericVector& expansion_coefficients,
169  const GenericFunction& v) const;
170 
179  std::shared_ptr<FunctionSpace> operator[] (std::size_t i) const;
180 
189  std::shared_ptr<FunctionSpace> sub(std::size_t component) const
190  { return extract_sub_space({component}); }
191 
200  std::shared_ptr<FunctionSpace>
201  sub(const std::vector<std::size_t>& component) const
202  { return extract_sub_space(component); }
203 
213  std::shared_ptr<FunctionSpace>
214  extract_sub_space(const std::vector<std::size_t>& component) const;
215 
225  bool contains(const FunctionSpace& V) const;
226 
232  std::shared_ptr<FunctionSpace> collapse() const;
233 
244  std::shared_ptr<FunctionSpace>
245  collapse(std::unordered_map<std::size_t, std::size_t>& collapsed_dofs) const;
246 
256  bool has_cell(const Cell& cell) const
257  { return &cell.mesh() == &(*_mesh); }
258 
268  bool has_element(const FiniteElement& element) const
269  { return element.hash() == _element->hash(); }
270 
277  std::vector<std::size_t> component() const;
278 
291  std::vector<double> tabulate_dof_coordinates() const;
292 
308  void set_x(GenericVector& x, double value, std::size_t component) const;
309 
319  std::string str(bool verbose) const;
320 
322  void print_dofmap() const;
323 
324  private:
325 
326  // General interpolation from any GenericFunction on any mesh
327  void interpolate_from_any(GenericVector& expansion_coefficients,
328  const GenericFunction& v) const;
329 
330  // Specialised interpolate routine when functions are related by a
331  // parent mesh
332  void interpolate_from_parent(GenericVector& expansion_coefficients,
333  const GenericFunction& v) const;
334 
335  // The mesh
336  std::shared_ptr<const Mesh> _mesh;
337 
338  // The finite element
339  std::shared_ptr<const FiniteElement> _element;
340 
341  // The dofmap
342  std::shared_ptr<const GenericDofMap> _dofmap;
343 
344  // The component w.r.t. to root space
345  std::vector<std::size_t> _component;
346 
347  // The identifier of root space
348  std::size_t _root_space_id;
349 
350  // Cache of subspaces
351  mutable std::map<std::vector<std::size_t>,
352  std::shared_ptr<FunctionSpace> > _subspaces;
353 
354  };
355 
356 }
357 
358 #endif
std::shared_ptr< FunctionSpace > operator[](std::size_t i) const
Definition: FunctionSpace.cpp:259
std::shared_ptr< const Mesh > mesh() const
Definition: FunctionSpace.cpp:104
Common base class for DOLFIN variables.
Definition: Variable.h:35
std::string str(bool verbose) const
Definition: FunctionSpace.cpp:431
std::shared_ptr< FunctionSpace > collapse() const
Definition: FunctionSpace.cpp:309
bool has_cell(const Cell &cell) const
Definition: FunctionSpace.h:256
Definition: Hierarchical.h:43
virtual ~FunctionSpace()
Destructor.
Definition: FunctionSpace.cpp:63
void print_dofmap() const
Print dofmap (useful for debugging)
Definition: FunctionSpace.cpp:447
const FunctionSpace & operator=(const FunctionSpace &V)
Definition: FunctionSpace.cpp:75
Definition: adapt.h:29
bool contains(const FunctionSpace &V) const
Definition: FunctionSpace.cpp:462
FunctionSpace(std::shared_ptr< const Mesh > mesh, std::shared_ptr< const FiniteElement > element, std::shared_ptr< const GenericDofMap > dofmap)
Definition: FunctionSpace.cpp:41
std::size_t dim() const
Definition: FunctionSpace.cpp:119
Definition: FunctionSpace.h:53
std::vector< std::size_t > component() const
Definition: FunctionSpace.cpp:337
std::shared_ptr< FunctionSpace > sub(std::size_t component) const
Definition: FunctionSpace.h:189
std::shared_ptr< FunctionSpace > extract_sub_space(const std::vector< std::size_t > &component) const
Definition: FunctionSpace.cpp:267
std::shared_ptr< FunctionSpace > sub(const std::vector< std::size_t > &component) const
Definition: FunctionSpace.h:201
bool operator!=(const FunctionSpace &V) const
Definition: FunctionSpace.cpp:98
A Cell is a MeshEntity of topological codimension 0.
Definition: Cell.h:42
bool has_element(const FiniteElement &element) const
Definition: FunctionSpace.h:268
std::shared_ptr< const GenericDofMap > dofmap() const
Definition: FunctionSpace.cpp:114
std::vector< double > tabulate_dof_coordinates() const
Definition: FunctionSpace.cpp:342
Definition: GenericFunction.h:53
const Mesh & mesh() const
Definition: MeshEntity.h:99
void attach(std::shared_ptr< const FiniteElement > element, std::shared_ptr< const GenericDofMap > dofmap)
Definition: FunctionSpace.cpp:68
std::size_t hash() const
Return simple hash of the signature string.
Definition: FiniteElement.h:216
std::shared_ptr< const FiniteElement > element() const
Definition: FunctionSpace.cpp:109
void set_x(GenericVector &x, double value, std::size_t component) const
Definition: FunctionSpace.cpp:398
This class defines a common interface for vectors.
Definition: GenericVector.h:47
This is a wrapper for a UFC finite element (ufc::finite_element).
Definition: FiniteElement.h:35
bool operator==(const FunctionSpace &V) const
Definition: FunctionSpace.cpp:90
void interpolate(GenericVector &expansion_coefficients, const GenericFunction &v) const
Definition: FunctionSpace.cpp:205