Loading...
Searching...
No Matches
DofMap.h
// Copyright (C) 2007-2015 Anders Logg and Garth N. Wells
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
// Modified by Martin Alnes, 2008-2015
// Modified by Kent-Andre Mardal, 2009
// Modified by Ola Skavhaug, 2009
// Modified by Joachim B Haga, 2012
// Modified by Mikael Mortensen, 2012
// Modified by Jan Blechta, 2013
#ifndef __DOLFIN_DOF_MAP_H
#define __DOLFIN_DOF_MAP_H
#include <cstdlib>
#include <map>
#include <memory>
#include <unordered_map>
#include <utility>
#include <vector>
#include <Eigen/Dense>
#include <ufc.h>
#include <dolfin/common/types.h>
#include <dolfin/la/IndexMap.h>
#include <dolfin/mesh/Cell.h>
#include "GenericDofMap.h"
namespace dolfin
{
class GenericVector;
class DofMap : public GenericDofMap
{
public:
DofMap(std::shared_ptr<const ufc::dofmap> ufc_dofmap,
const Mesh& mesh);
DofMap(std::shared_ptr<const ufc::dofmap> ufc_dofmap,
const Mesh& mesh, std::shared_ptr<const SubDomain> constrained_domain);
private:
// Create a sub-dofmap (a view) from parent_dofmap
DofMap(const DofMap& parent_dofmap,
const std::vector<std::size_t>& component,
const Mesh& mesh);
// Create a collapsed dofmap from parent_dofmap
DofMap(std::unordered_map<std::size_t, std::size_t>& collapsed_map,
const DofMap& dofmap_view, const Mesh& mesh);
// Copy constructor
DofMap(const DofMap& dofmap);
public:
~DofMap();
bool is_view() const
{ return _is_view; }
std::size_t global_dimension() const;
std::size_t num_element_dofs(std::size_t cell_index) const;
std::size_t max_element_dofs() const;
virtual std::size_t num_entity_dofs(std::size_t entity_dim) const;
virtual std::size_t num_entity_closure_dofs(std::size_t entity_dim) const;
std::size_t num_facet_dofs() const;
std::pair<std::size_t, std::size_t> ownership_range() const;
const std::vector<int>& off_process_owner() const
{ return _index_map->off_process_owner(); }
const std::unordered_map<int, std::vector<int>>& shared_nodes() const;
const std::set<int>& neighbours() const;
void clear_sub_map_data()
{
//std::vector<int>().swap(_ufc_local_to_local);
_ufc_local_to_local.clear();
}
Eigen::Map<const Eigen::Array<dolfin::la_index, Eigen::Dynamic, 1>>
cell_dofs(std::size_t cell_index) const
{
const std::size_t index = cell_index*_cell_dimension;
dolfin_assert(index + _cell_dimension <= _dofmap.size());
return Eigen::Map<const Eigen::Array<dolfin::la_index, Eigen::Dynamic, 1>>(&_dofmap[index], _cell_dimension);
}
std::vector<dolfin::la_index>
entity_dofs(const Mesh& mesh, std::size_t entity_dim,
const std::vector<std::size_t> & entity_indices) const;
std::vector<dolfin::la_index>
entity_dofs(const Mesh& mesh, std::size_t entity_dim) const;
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;
std::vector<dolfin::la_index>
entity_closure_dofs(const Mesh& mesh, std::size_t entity_dim) const;
void tabulate_facet_dofs(std::vector<std::size_t>& element_dofs,
std::size_t cell_facet_index) const;
void tabulate_entity_dofs(std::vector<std::size_t>& element_dofs,
std::size_t entity_dim, std::size_t cell_entity_index) const;
void tabulate_entity_closure_dofs(std::vector<std::size_t>& element_dofs,
std::size_t entity_dim, std::size_t cell_entity_index) const;
void tabulate_global_dofs(std::vector<std::size_t>& element_dofs) const
{
dolfin_assert(_global_nodes.empty() || block_size() == 1);
element_dofs.resize(_global_nodes.size());
std::copy(_global_nodes.cbegin(), _global_nodes.cend(), element_dofs.begin());
}
std::shared_ptr<GenericDofMap> copy() const;
std::shared_ptr<GenericDofMap> create(const Mesh& new_mesh) const;
std::shared_ptr<GenericDofMap>
extract_sub_dofmap(const std::vector<std::size_t>& component,
const Mesh& mesh) const;
std::shared_ptr<GenericDofMap>
collapse(std::unordered_map<std::size_t, std::size_t>&
collapsed_map, const Mesh& mesh) const;
// FIXME: Document this function properly
std::vector<dolfin::la_index> dofs(const Mesh& mesh,
std::size_t dim) const;
// FIXME: Document this function
std::vector<dolfin::la_index> dofs() const;
void set(GenericVector& x, double value) const;
std::shared_ptr<const IndexMap> index_map() const
{ return _index_map; }
int block_size() const
{ return _index_map->block_size(); }
void tabulate_local_to_global_dofs(std::vector<std::size_t>& local_to_global_map) const;
std::size_t local_to_global_index(int local_index) const
{ return _index_map->local_to_global(local_index); }
const std::vector<std::size_t>& local_to_global_unowned() const
{ return _index_map->local_to_global_unowned(); }
std::string str(bool verbose) const;
private:
// Friends
friend class DofMapBuilder;
// Check dimensional consistency between UFC dofmap and the mesh
static void check_dimensional_consistency(const ufc::dofmap& dofmap,
const Mesh& mesh);
// Check that mesh provides the entities needed by dofmap
static void check_provided_entities(const ufc::dofmap& dofmap,
const Mesh& mesh);
// Cell-local-to-dof map (dofs for cell dofmap[i])
std::vector<dolfin::la_index> _dofmap;
// List of global nodes
std::set<std::size_t> _global_nodes;
// Cell dimension (fixed for all cells)
std::size_t _cell_dimension;
// UFC dof map
std::shared_ptr<const ufc::dofmap> _ufc_dofmap;
// Number global mesh entities. This is usually the same as what
// is reported by the mesh, but will differ for dofmaps
// constrained, e.g. dofmaps with periodic bcs. It is stored in
// order to compute the global dimension of dofmaps that are
// constructed from a sub-dofmap.
std::vector<std::size_t> _num_mesh_entities_global;
// Map from UFC dof numbering to renumbered dof (ufc_dof ->
// actual_dof, both using local indices)
std::vector<int> _ufc_local_to_local;
// Flag to determine if the DofMap is a view
bool _is_view;
// Global dimension. Note that this may differ from the global
// dimension of the UFC dofmap if the function space is periodic.
std::size_t _global_dimension;
// UFC dof map offset
std::size_t _ufc_offset;
// Multimesh dof map offset
std::size_t _multimesh_offset;
// Object containing information about dof distribution across
// processes
std::shared_ptr<IndexMap> _index_map;
// Temporary until MultiMeshDofMap runs in parallel
friend class MultiMeshDofMap;
// List of processes that share a given dof
std::unordered_map<int, std::vector<int>> _shared_nodes;
// Neighbours (processes that we share dofs with)
std::set<int> _neighbours;
};
}
#endif
dolfin::DofMapBuilder
Builds a DofMap on a Mesh.
Definition DofMapBuilder.h:51
dolfin::DofMap::extract_sub_dofmap
std::shared_ptr< GenericDofMap > extract_sub_dofmap(const std::vector< std::size_t > &component, const Mesh &mesh) const
Definition DofMap.cpp:466
dolfin::DofMap::num_facet_dofs
std::size_t num_facet_dofs() const
Definition DofMap.cpp:178
dolfin::DofMap::set
void set(GenericVector &x, double value) const
Definition DofMap.cpp:577
dolfin::DofMap::neighbours
const std::set< int > & neighbours() const
Definition DofMap.cpp:194
dolfin::DofMap::entity_dofs
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
dolfin::DofMap::tabulate_local_to_global_dofs
void tabulate_local_to_global_dofs(std::vector< std::size_t > &local_to_global_map) const
Definition DofMap.cpp:592
dolfin::DofMap::tabulate_entity_dofs
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
dolfin::DofMap::clear_sub_map_data
void clear_sub_map_data()
Definition DofMap.h:188
dolfin::DofMap::off_process_owner
const std::vector< int > & off_process_owner() const
Definition DofMap.h:170
dolfin::DofMap::shared_nodes
const std::unordered_map< int, std::vector< int > > & shared_nodes() const
Definition DofMap.cpp:189
dolfin::DofMap::collapse
std::shared_ptr< GenericDofMap > collapse(std::unordered_map< std::size_t, std::size_t > &collapsed_map, const Mesh &mesh) const
Definition DofMap.cpp:473
dolfin::DofMap::index_map
std::shared_ptr< const IndexMap > index_map() const
Return the map (const access).
Definition DofMap.h:365
dolfin::DofMap::block_size
int block_size() const
Definition DofMap.h:370
dolfin::DofMap::num_element_dofs
std::size_t num_element_dofs(std::size_t cell_index) const
Definition DofMap.cpp:155
dolfin::DofMap::local_to_global_unowned
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
dolfin::DofMap::dofs
std::vector< dolfin::la_index > dofs() const
Return list of global dof indices on this process.
Definition DofMap.cpp:551
dolfin::DofMap::num_entity_dofs
virtual std::size_t num_entity_dofs(std::size_t entity_dim) const
Definition DofMap.cpp:166
dolfin::DofMap::str
std::string str(bool verbose) const
Definition DofMap.cpp:634
dolfin::DofMap::local_to_global_index
std::size_t local_to_global_index(int local_index) const
Definition DofMap.h:387
dolfin::DofMap::~DofMap
~DofMap()
Destructor.
Definition DofMap.cpp:145
dolfin::DofMap::tabulate_global_dofs
void tabulate_global_dofs(std::vector< std::size_t > &element_dofs) const
Definition DofMap.h:295
dolfin::DofMap::max_element_dofs
std::size_t max_element_dofs() const
Definition DofMap.cpp:160
dolfin::DofMap::ownership_range
std::pair< std::size_t, std::size_t > ownership_range() const
Definition DofMap.cpp:184
dolfin::DofMap::copy
std::shared_ptr< GenericDofMap > copy() const
Definition DofMap.cpp:453
dolfin::DofMap::tabulate_entity_closure_dofs
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
dolfin::DofMap::is_view
bool is_view() const
Definition DofMap.h:103
dolfin::DofMap::num_entity_closure_dofs
virtual std::size_t num_entity_closure_dofs(std::size_t entity_dim) const
Definition DofMap.cpp:172
dolfin::DofMap::tabulate_facet_dofs
void tabulate_facet_dofs(std::vector< std::size_t > &element_dofs, std::size_t cell_facet_index) const
Definition DofMap.cpp:421
dolfin::DofMap::global_dimension
std::size_t global_dimension() const
Definition DofMap.cpp:150
dolfin::DofMap::cell_dofs
Eigen::Map< const Eigen::Array< dolfin::la_index, Eigen::Dynamic, 1 > > cell_dofs(std::size_t cell_index) const
Definition DofMap.h:201
dolfin::DofMap::create
std::shared_ptr< GenericDofMap > create(const Mesh &new_mesh) const
Definition DofMap.cpp:458
dolfin::DofMap::DofMap
DofMap(std::shared_ptr< const ufc::dofmap > ufc_dofmap, const Mesh &mesh)
Definition DofMap.cpp:42
dolfin::DofMap::entity_closure_dofs
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
dolfin::GenericDofMap::constrained_domain
std::shared_ptr< const SubDomain > constrained_domain
Definition GenericDofMap.h:212
dolfin::GenericDofMap::GenericDofMap
GenericDofMap()
Constructor.
Definition GenericDofMap.h:54
dolfin::GenericVector
This class defines a common interface for vectors.
Definition GenericVector.h:48
dolfin::Mesh
Definition Mesh.h:84
dolfin::MultiMeshDofMap
Definition MultiMeshDofMap.h:38
dolfin
Definition adapt.h:30