DOLFIN
DOLFIN C++ interface
DistributedMeshTools.h
1 // Copyright (C) 2011-2013 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 // First added: 2011-09-17
19 // Last changed: 2013-01-29
20 
21 #ifndef __MESH_DISTRIBUTED_TOOLS_H
22 #define __MESH_DISTRIBUTED_TOOLS_H
23 
24 #include <array>
25 #include <map>
26 #include <numeric>
27 #include <set>
28 #include <utility>
29 #include <unordered_map>
30 #include <vector>
31 #include <dolfin/common/MPI.h>
32 
33 namespace dolfin
34 {
35 
36  class Mesh;
37 
40 
42  {
43  public:
44 
46  static void number_entities(const Mesh& mesh, std::size_t d);
47 
50  static std::size_t number_entities(
51  const Mesh& mesh,
52  const std::map<unsigned int, std::pair<unsigned int, unsigned int>>& slave_entities,
53  std::vector<std::int64_t>& global_entity_indices,
54  std::map<std::int32_t, std::set<unsigned int>>& shared_entities,
55  std::size_t d);
56 
60  static void init_facet_cell_connections(Mesh& mesh);
61 
66  static
67  std::map<std::size_t, std::set<std::pair<std::size_t, std::size_t> > >
68  locate_off_process_entities(const std::vector<std::size_t>&
69  entity_indices,
70  std::size_t dim, const Mesh& mesh);
71 
75  static std::unordered_map<unsigned int,
76  std::vector<std::pair<unsigned int, unsigned int> > >
77  compute_shared_entities(const Mesh& mesh, std::size_t d);
78 
82  static std::vector<double>
84 
87  static void reorder_values_by_global_indices(const Mesh& mesh,
88  std::vector<double>& data,
89  const std::size_t width);
90 
93  static void reorder_values_by_global_indices(MPI_Comm mpi_comm,
94  std::vector<double>& values,
95  const std::size_t width,
96  const std::vector<std::int64_t>& global_indices);
97 
98  private:
99 
100  // Data structure for a mesh entity (list of vertices, using
101  // global indices)
102  typedef std::vector<std::size_t> Entity;
103 
104  // Data structure to mesh entity data
105  struct EntityData
106  {
107  // Constructor
108  EntityData() : local_index(0) {}
109 
110  // Constructor (index is local)
111  explicit EntityData(unsigned int index) : local_index(index) {}
112 
113  // Constructor (index is local)
114  EntityData(unsigned int index, const std::vector<unsigned int>& procs)
115  : local_index(index), processes(procs) {}
116 
117  // Constructor (index is local)
118  EntityData(unsigned int index, unsigned int process)
119  : local_index(index), processes(1, process) {}
120 
121  // Local (this process) entity index
122  unsigned int local_index;
123 
124  // Processes on which entity resides
125  std::vector<unsigned int> processes;
126  };
127 
128  // Compute ownership of entities ([entity vertices], data)
129  // [0]: owned exclusively (will be numbered by this process)
130  // [1]: owned and shared (will be numbered by this process, and number
131  // communicated to other processes)
132  // [2]: not owned but shared (will be numbered by another process,
133  // and number communicated to this processes)
134  static void compute_entity_ownership(
135  const MPI_Comm mpi_comm,
136  const std::map<std::vector<std::size_t>, unsigned int>& entities,
137  const std::map<std::int32_t, std::set<unsigned int> >& shared_vertices_local,
138  const std::vector<std::int64_t>& global_vertex_indices,
139  std::size_t d,
140  std::vector<std::size_t>& owned_entities,
141  std::array<std::map<Entity, EntityData>, 2>& shared_entities);
142 
143  // Build preliminary 'guess' of shared entities. This function does
144  // not involve any inter-process communication.
145  static void compute_preliminary_entity_ownership(
146  const MPI_Comm mpi_comm,
147  const std::map<std::size_t, std::set<unsigned int> >& shared_vertices,
148  const std::map<Entity, unsigned int>& entities,
149  std::vector<std::size_t>& owned_entities,
150  std::array<std::map<Entity, EntityData>, 2>& entity_ownership);
151 
152  // Communicate with other processes to finalise entity ownership
153  static void
154  compute_final_entity_ownership(const MPI_Comm mpi_comm,
155  std::vector<std::size_t>& owned_entities,
156  std::array<std::map<Entity,
157  EntityData>, 2>& entity_ownership);
158 
159  // Check if all entity vertices are the shared vertices in overlap
160  static bool is_shared(const std::vector<std::size_t>& entity_vertices,
161  const std::map<std::size_t, std::set<unsigned int> >& shared_vertices);
162 
163  // Compute and return (number of global entities, process offset)
164  static std::pair<std::size_t, std::size_t>
165  compute_num_global_entities(const MPI_Comm mpi_comm,
166  std::size_t num_local_entities,
167  std::size_t num_processes,
168  std::size_t process_number);
169 
170  };
171 
172 }
173 
174 #endif
static void reorder_values_by_global_indices(const Mesh &mesh, std::vector< double > &data, const std::size_t width)
Definition: DistributedMeshTools.cpp:1124
static std::vector< double > reorder_vertices_by_global_indices(const Mesh &mesh)
Definition: DistributedMeshTools.cpp:1116
Definition: adapt.h:29
static void init_facet_cell_connections(Mesh &mesh)
Definition: DistributedMeshTools.cpp:1012
static std::unordered_map< unsigned int, std::vector< std::pair< unsigned int, unsigned int > > > compute_shared_entities(const Mesh &mesh, std::size_t d)
Definition: DistributedMeshTools.cpp:513
Definition: DistributedMeshTools.h:41
static std::map< std::size_t, std::set< std::pair< std::size_t, std::size_t > > > locate_off_process_entities(const std::vector< std::size_t > &entity_indices, std::size_t dim, const Mesh &mesh)
Definition: DistributedMeshTools.cpp:357
Definition: Mesh.h:82
static void number_entities(const Mesh &mesh, std::size_t d)
Create global entity indices for entities of dimension d.
Definition: DistributedMeshTools.cpp:42