DOLFIN
DOLFIN C++ interface
Loading...
Searching...
No Matches
DofMap.h
1// Copyright (C) 2007-2015 Anders Logg and Garth N. Wells
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 Martin Alnes, 2008-2015
19// Modified by Kent-Andre Mardal, 2009
20// Modified by Ola Skavhaug, 2009
21// Modified by Joachim B Haga, 2012
22// Modified by Mikael Mortensen, 2012
23// Modified by Jan Blechta, 2013
24
25#ifndef __DOLFIN_DOF_MAP_H
26#define __DOLFIN_DOF_MAP_H
27
28#include <cstdlib>
29#include <map>
30#include <memory>
31#include <unordered_map>
32#include <utility>
33#include <vector>
34#include <Eigen/Dense>
35#include <ufc.h>
36
37#include <dolfin/common/types.h>
38#include <dolfin/la/IndexMap.h>
39#include <dolfin/mesh/Cell.h>
40#include "GenericDofMap.h"
41
42namespace dolfin
43{
44
45 class GenericVector;
46
48
53
54 class DofMap : public GenericDofMap
55 {
56 public:
57
64 DofMap(std::shared_ptr<const ufc::dofmap> ufc_dofmap,
65 const Mesh& mesh);
66
75 DofMap(std::shared_ptr<const ufc::dofmap> ufc_dofmap,
76 const Mesh& mesh, std::shared_ptr<const SubDomain> constrained_domain);
77
78 private:
79
80 // Create a sub-dofmap (a view) from parent_dofmap
81 DofMap(const DofMap& parent_dofmap,
82 const std::vector<std::size_t>& component,
83 const Mesh& mesh);
84
85 // Create a collapsed dofmap from parent_dofmap
86 DofMap(std::unordered_map<std::size_t, std::size_t>& collapsed_map,
87 const DofMap& dofmap_view, const Mesh& mesh);
88
89 // Copy constructor
90 DofMap(const DofMap& dofmap);
91
92 public:
93
95 ~DofMap();
96
103 bool is_view() const
104 { return _is_view; }
105
112 std::size_t global_dimension() const;
113
122 std::size_t num_element_dofs(std::size_t cell_index) const;
123
130 std::size_t max_element_dofs() const;
131
139 virtual std::size_t num_entity_dofs(std::size_t entity_dim) const;
140
150 virtual std::size_t num_entity_closure_dofs(std::size_t entity_dim) const;
151
156 std::size_t num_facet_dofs() const;
157
163 std::pair<std::size_t, std::size_t> ownership_range() const;
164
170 const std::vector<int>& off_process_owner() const
171 { return _index_map->off_process_owner(); }
172
178 const std::unordered_map<int, std::vector<int>>& shared_nodes() const;
179
184 const std::set<int>& neighbours() const;
185
189 {
190 //std::vector<int>().swap(_ufc_local_to_local);
191 _ufc_local_to_local.clear();
192 }
193
200 Eigen::Map<const Eigen::Array<dolfin::la_index, Eigen::Dynamic, 1>>
201 cell_dofs(std::size_t cell_index) const
202 {
203 const std::size_t index = cell_index*_cell_dimension;
204 dolfin_assert(index + _cell_dimension <= _dofmap.size());
205 return Eigen::Map<const Eigen::Array<dolfin::la_index, Eigen::Dynamic, 1>>(&_dofmap[index], _cell_dimension);
206 }
207
218 std::vector<dolfin::la_index>
219 entity_dofs(const Mesh& mesh, std::size_t entity_dim,
220 const std::vector<std::size_t> & entity_indices) const;
221
230 std::vector<dolfin::la_index>
231 entity_dofs(const Mesh& mesh, std::size_t entity_dim) const;
232
244 std::vector<dolfin::la_index>
245 entity_closure_dofs(const Mesh& mesh, std::size_t entity_dim,
246 const std::vector<std::size_t> & entity_indices) const;
247
257 std::vector<dolfin::la_index>
258 entity_closure_dofs(const Mesh& mesh, std::size_t entity_dim) const;
259
266 void tabulate_facet_dofs(std::vector<std::size_t>& element_dofs,
267 std::size_t cell_facet_index) const;
268
277 void tabulate_entity_dofs(std::vector<std::size_t>& element_dofs,
278 std::size_t entity_dim, std::size_t cell_entity_index) const;
279
288 void tabulate_entity_closure_dofs(std::vector<std::size_t>& element_dofs,
289 std::size_t entity_dim, std::size_t cell_entity_index) const;
290
295 void tabulate_global_dofs(std::vector<std::size_t>& element_dofs) const
296 {
297 dolfin_assert(_global_nodes.empty() || block_size() == 1);
298 element_dofs.resize(_global_nodes.size());
299 std::copy(_global_nodes.cbegin(), _global_nodes.cend(), element_dofs.begin());
300 }
301
306 std::shared_ptr<GenericDofMap> copy() const;
307
315 std::shared_ptr<GenericDofMap> create(const Mesh& new_mesh) const;
316
317
327 std::shared_ptr<GenericDofMap>
328 extract_sub_dofmap(const std::vector<std::size_t>& component,
329 const Mesh& mesh) const;
330
340 std::shared_ptr<GenericDofMap>
341 collapse(std::unordered_map<std::size_t, std::size_t>&
342 collapsed_map, const Mesh& mesh) const;
343
344 // FIXME: Document this function properly
347 std::vector<dolfin::la_index> dofs(const Mesh& mesh,
348 std::size_t dim) const;
349
350 // FIXME: Document this function
351 std::vector<dolfin::la_index> dofs() const;
352
362 void set(GenericVector& x, double value) const;
363
365 std::shared_ptr<const IndexMap> index_map() const
366 { return _index_map; }
367
370 int block_size() const
371 { return _index_map->block_size(); }
372
378 void tabulate_local_to_global_dofs(std::vector<std::size_t>& local_to_global_map) const;
379
387 std::size_t local_to_global_index(int local_index) const
388 { return _index_map->local_to_global(local_index); }
389
391 const std::vector<std::size_t>& local_to_global_unowned() const
392 { return _index_map->local_to_global_unowned(); }
393
401 std::string str(bool verbose) const;
402
403 private:
404
405 // Friends
406 friend class DofMapBuilder;
407
408 // Check dimensional consistency between UFC dofmap and the mesh
409 static void check_dimensional_consistency(const ufc::dofmap& dofmap,
410 const Mesh& mesh);
411
412 // Check that mesh provides the entities needed by dofmap
413 static void check_provided_entities(const ufc::dofmap& dofmap,
414 const Mesh& mesh);
415
416 // Cell-local-to-dof map (dofs for cell dofmap[i])
417 std::vector<dolfin::la_index> _dofmap;
418
419 // List of global nodes
420 std::set<std::size_t> _global_nodes;
421
422 // Cell dimension (fixed for all cells)
423 std::size_t _cell_dimension;
424
425 // UFC dof map
426 std::shared_ptr<const ufc::dofmap> _ufc_dofmap;
427
428 // Number global mesh entities. This is usually the same as what
429 // is reported by the mesh, but will differ for dofmaps
430 // constrained, e.g. dofmaps with periodic bcs. It is stored in
431 // order to compute the global dimension of dofmaps that are
432 // constructed from a sub-dofmap.
433 std::vector<std::size_t> _num_mesh_entities_global;
434
435 // Map from UFC dof numbering to renumbered dof (ufc_dof ->
436 // actual_dof, both using local indices)
437 std::vector<int> _ufc_local_to_local;
438
439 // Flag to determine if the DofMap is a view
440 bool _is_view;
441
442 // Global dimension. Note that this may differ from the global
443 // dimension of the UFC dofmap if the function space is periodic.
444 std::size_t _global_dimension;
445
446 // UFC dof map offset
447 std::size_t _ufc_offset;
448
449 // Multimesh dof map offset
450 std::size_t _multimesh_offset;
451
452 // Object containing information about dof distribution across
453 // processes
454 std::shared_ptr<IndexMap> _index_map;
455
456 // Temporary until MultiMeshDofMap runs in parallel
457 friend class MultiMeshDofMap;
458
459 // List of processes that share a given dof
460 std::unordered_map<int, std::vector<int>> _shared_nodes;
461
462 // Neighbours (processes that we share dofs with)
463 std::set<int> _neighbours;
464
465 };
466}
467
468#endif
Builds a DofMap on a Mesh.
Definition DofMapBuilder.h:51
Degree-of-freedom map.
Definition DofMap.h:55
std::shared_ptr< GenericDofMap > extract_sub_dofmap(const std::vector< std::size_t > &component, const Mesh &mesh) const
Definition DofMap.cpp:466
std::size_t num_facet_dofs() const
Definition DofMap.cpp:178
void set(GenericVector &x, double value) const
Definition DofMap.cpp:577
const std::set< int > & neighbours() const
Definition DofMap.cpp:194
std::vector< dolfin::la_index > entity_dofs(const Mesh &mesh, std::size_t entity_dim, const std::vector< std::size_t > &entity_indices) const
Definition DofMap.cpp:310
void tabulate_local_to_global_dofs(std::vector< std::size_t > &local_to_global_map) const
Definition DofMap.cpp:592
void tabulate_entity_dofs(std::vector< std::size_t > &element_dofs, std::size_t entity_dim, std::size_t cell_entity_index) const
Definition DofMap.cpp:430
void clear_sub_map_data()
Definition DofMap.h:188
const std::vector< int > & off_process_owner() const
Definition DofMap.h:170
const std::unordered_map< int, std::vector< int > > & shared_nodes() const
Definition DofMap.cpp:189
std::shared_ptr< GenericDofMap > collapse(std::unordered_map< std::size_t, std::size_t > &collapsed_map, const Mesh &mesh) const
Definition DofMap.cpp:473
std::shared_ptr< const IndexMap > index_map() const
Return the map (const access)
Definition DofMap.h:365
int block_size() const
Definition DofMap.h:370
std::size_t num_element_dofs(std::size_t cell_index) const
Definition DofMap.cpp:155
const std::vector< std::size_t > & local_to_global_unowned() const
Return indices of dofs which are owned by other processes.
Definition DofMap.h:391
std::vector< dolfin::la_index > dofs() const
Return list of global dof indices on this process.
Definition DofMap.cpp:551
virtual std::size_t num_entity_dofs(std::size_t entity_dim) const
Definition DofMap.cpp:166
std::string str(bool verbose) const
Definition DofMap.cpp:631
std::size_t local_to_global_index(int local_index) const
Definition DofMap.h:387
~DofMap()
Destructor.
Definition DofMap.cpp:145
void tabulate_global_dofs(std::vector< std::size_t > &element_dofs) const
Definition DofMap.h:295
std::size_t max_element_dofs() const
Definition DofMap.cpp:160
std::pair< std::size_t, std::size_t > ownership_range() const
Definition DofMap.cpp:184
std::shared_ptr< GenericDofMap > copy() const
Definition DofMap.cpp:453
void tabulate_entity_closure_dofs(std::vector< std::size_t > &element_dofs, std::size_t entity_dim, std::size_t cell_entity_index) const
Definition DofMap.cpp:442
bool is_view() const
Definition DofMap.h:103
virtual std::size_t num_entity_closure_dofs(std::size_t entity_dim) const
Definition DofMap.cpp:172
void tabulate_facet_dofs(std::vector< std::size_t > &element_dofs, std::size_t cell_facet_index) const
Definition DofMap.cpp:421
std::size_t global_dimension() const
Definition DofMap.cpp:150
Eigen::Map< const Eigen::Array< dolfin::la_index, Eigen::Dynamic, 1 > > cell_dofs(std::size_t cell_index) const
Definition DofMap.h:201
std::shared_ptr< GenericDofMap > create(const Mesh &new_mesh) const
Definition DofMap.cpp:458
std::vector< dolfin::la_index > entity_closure_dofs(const Mesh &mesh, std::size_t entity_dim, const std::vector< std::size_t > &entity_indices) const
Definition DofMap.cpp:199
This class provides a generic interface for dof maps.
Definition GenericDofMap.h:50
std::shared_ptr< const SubDomain > constrained_domain
Definition GenericDofMap.h:212
This class defines a common interface for vectors.
Definition GenericVector.h:48
Definition Mesh.h:84
Definition MultiMeshDofMap.h:38
Definition adapt.h:30