DOLFIN
DOLFIN C++ interface
Loading...
Searching...
No Matches
DofMapBuilder.h
1// Copyright (C) 2008-2015 Anders Logg, Ola Skavhaug 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 Niclas Jansson 2009.
19// Modified by Garth Wells 2009-2012
20// Modified by Mikael Mortensen 2012.
21// Modified by Martin Alnaes, 2015
22
23#ifndef __DOF_MAP_BUILDER_H
24#define __DOF_MAP_BUILDER_H
25
26#include <map>
27#include <memory>
28#include <set>
29#include <unordered_map>
30#include <utility>
31#include <vector>
32
33namespace ufc
34{
35 class dofmap;
36}
37
38namespace dolfin
39{
40
41 class DofMap;
42 class Mesh;
43 class IndexMap;
44 class SubDomain;
45 class UFC;
46 class Cell;
47
49
51 {
52
53 public:
54
61 static void build(DofMap& dofmap, const Mesh& dolfin_mesh,
62 std::shared_ptr<const SubDomain> constrained_domain);
63
70 static void build_sub_map_view(DofMap& sub_dofmap,
71 const DofMap& parent_dofmap,
72 const std::vector<std::size_t>& component,
73 const Mesh& mesh);
74
75 private:
76
77 // Build modified global entity indices that account for periodic
78 // bcs
79 static std::size_t build_constrained_vertex_indices(
80 const Mesh& mesh,
81 const std::map<unsigned int, std::pair<unsigned int,
82 unsigned int>>& slave_to_master_vertices,
83 std::vector<std::int64_t>& modified_vertex_indices_global);
84
85 // Build simple local UFC-based dofmap data structure (does not
86 // account for master/slave constraints)
87 static void
88 build_local_ufc_dofmap(std::vector<std::vector<dolfin::la_index>>& dofmap,
89 const ufc::dofmap& ufc_dofmap,
90 const Mesh& mesh);
91
92 // Compute which process 'owns' each node (point at which dofs live)
93 // - node_ownership = -1 -> dof shared but not 'owned' by this
94 // process
95 // - node_ownership = 0 -> dof owned by this process and shared
96 // with other processes
97 // - node_ownership = 1 -> dof owned by this process and not
98 // shared
99 //
100 // Also computes map from shared node to sharing processes and a
101 // set of process that share dofs on this process.
102 // Returns: number of locally owned nodes
103 static int compute_node_ownership(
104 std::vector<short int>& node_ownership,
105 std::unordered_map<int, std::vector<int>>& shared_node_to_processes,
106 std::set<int>& neighbours,
107 const std::vector<std::vector<la_index>>& node_dofmap,
108 const std::vector<int>& boundary_nodes,
109 const std::set<std::size_t>& global_nodes,
110 const std::vector<std::size_t>& node_local_to_global,
111 const Mesh& mesh,
112 const std::size_t global_dim);
113
114 // Build dofmap based on re-ordered nodes
115 static void
116 build_dofmap(std::vector<std::vector<la_index>>& dofmap,
117 const std::vector<std::vector<la_index>>& node_dofmap,
118 const std::vector<int>& old_to_new_node_local,
119 const std::size_t block_size);
120
121 // Compute set of global dofs (e.g. Reals associated with global
122 // Lagrange multipliers) based on UFC numbering. Global dofs are
123 // not associated with any mesh entity. The returned indices are
124 // local to the process.
125 static std::set<std::size_t>
126 compute_global_dofs(std::shared_ptr<const ufc::dofmap> ufc_dofmap,
127 const std::vector<std::size_t>& num_mesh_entities_local);
128
129 // Iterate recursively over all sub-dof maps to find global
130 // degrees of freedom
131 static void
132 compute_global_dofs(std::set<std::size_t>& global_dofs,
133 std::size_t& offset_local,
134 std::shared_ptr<const ufc::dofmap> ufc_dofmap,
135 const std::vector<std::size_t>& num_mesh_entities_local);
136
137 // Recursively extract UFC sub-dofmap and compute offset
138 static std::shared_ptr<ufc::dofmap> extract_ufc_sub_dofmap(
139 const ufc::dofmap& ufc_dofmap,
140 std::size_t& offset,
141 const std::vector<std::size_t>& component,
142 const std::vector<std::size_t>& num_global_mesh_entities);
143
144 // Compute block size, e.g. in 3D elasticity block_size = 3
145 static std::size_t compute_blocksize(const ufc::dofmap& ufc_dofmap);
146
147 static void compute_constrained_mesh_indices(
148 std::vector<std::vector<std::int64_t>>& global_entity_indices,
149 std::vector<std::size_t>& num_mesh_entities_global,
150 const std::vector<bool>& needs_mesh_entities,
151 const Mesh& mesh,
152 const SubDomain& constrained_domain);
153
154 static std::shared_ptr<const ufc::dofmap>
155 build_ufc_node_graph(
156 std::vector<std::vector<la_index>>& node_dofmap,
157 std::vector<std::size_t>& node_local_to_global,
158 std::vector<std::size_t>& num_mesh_entities_global,
159 std::shared_ptr<const ufc::dofmap> ufc_dofmap,
160 const Mesh& mesh,
161 std::shared_ptr<const SubDomain> constrained_domain,
162 const std::size_t block_size);
163
164 static std::shared_ptr<const ufc::dofmap>
165 build_ufc_node_graph_constrained(
166 std::vector<std::vector<la_index>>& node_dofmap,
167 std::vector<std::size_t>& node_local_to_global,
168 std::vector<int>& node_ufc_local_to_local,
169 std::vector<std::size_t>& num_mesh_entities_global,
170 std::shared_ptr<const ufc::dofmap> ufc_dofmap,
171 const Mesh& mesh,
172 std::shared_ptr<const SubDomain> constrained_domain,
173 const std::size_t block_size);
174
175
176 // Mark shared nodes. Boundary nodes are assigned a random
177 // positive integer, interior nodes are marked as -1, interior
178 // nodes in ghost layer of other processes are marked -2, and
179 // ghost nodes are marked as -3
180 static void compute_shared_nodes(
181 std::vector<int>& boundary_nodes,
182 const std::vector<std::vector<la_index>>& node_dofmap,
183 const std::size_t num_nodes_local,
184 const ufc::dofmap& ufc_dofmap,
185 const Mesh& mesh);
186
187 static void compute_node_reordering(
188 IndexMap& index_map,
189 std::vector<int>& old_to_new_local,
190 const std::unordered_map<int, std::vector<int>>& node_to_sharing_processes,
191 const std::vector<std::size_t>& old_local_to_global,
192 const std::vector<std::vector<la_index>>& node_dofmap,
193 const std::vector<short int>& node_ownership,
194 const std::set<std::size_t>& global_nodes,
195 const MPI_Comm mpi_comm);
196
197 static void get_cell_entities_local(const Cell& cell,
198 std::vector<std::vector<std::size_t>>& entity_indices,
199 const std::vector<bool>& needs_mesh_entities);
200
201 static void get_cell_entities_global(const Cell& cell,
202 std::vector<std::vector<std::size_t>>& entity_indices,
203 const std::vector<bool>& needs_mesh_entities);
204
205 static void get_cell_entities_global_constrained(const Cell& cell,
206 std::vector<std::vector<std::size_t>>& entity_indices,
207 const std::vector<std::vector<std::int64_t>>& global_entity_indices,
208 const std::vector<bool>& needs_mesh_entities);
209
210 // Compute number of mesh entities for dimensions required by
211 // dofmap
212 static std::vector<std::size_t> compute_num_mesh_entities_local(
213 const Mesh& mesh, const std::vector<bool>& needs_mesh_entities);
214
215 };
216}
217
218#endif
A Cell is a MeshEntity of topological codimension 0.
Definition Cell.h:43
Builds a DofMap on a Mesh.
Definition DofMapBuilder.h:51
static void build(DofMap &dofmap, const Mesh &dolfin_mesh, std::shared_ptr< const SubDomain > constrained_domain)
Definition DofMapBuilder.cpp:54
static void build_sub_map_view(DofMap &sub_dofmap, const DofMap &parent_dofmap, const std::vector< std::size_t > &component, const Mesh &mesh)
Definition DofMapBuilder.cpp:290
Degree-of-freedom map.
Definition DofMap.h:55
Definition IndexMap.h:36
Definition Mesh.h:84
Definition SubDomain.h:43
Definition adapt.h:30