26 #ifndef __MESH_PARTITIONING_H 27 #define __MESH_PARTITIONING_H 33 #include <boost/multi_array.hpp> 34 #include <dolfin/log/log.h> 35 #include <dolfin/common/Set.h> 37 #include "DistributedMeshTools.h" 38 #include "LocalMeshValueCollection.h" 50 template <
typename T>
class MeshFunction;
51 template <
typename T>
class MeshValueCollection;
74 const std::string ghost_mode);
79 const std::string ghost_mode);
95 void partition_cells(
const MPI_Comm& mpi_comm,
97 const std::string partitioner,
98 std::vector<int>& cell_partition,
99 std::map<std::int64_t, std::vector<int>>& ghost_procs);
104 const std::vector<int>& cell_partition,
105 const std::map<std::int64_t, std::vector<int>>& ghost_procs,
106 const std::string ghost_mode);
112 void distribute_cell_layer(MPI_Comm mpi_comm,
113 const int num_regular_cells,
114 const std::int64_t num_global_vertices,
115 std::map<std::int32_t, std::set<unsigned int>>& shared_cells,
116 boost::multi_array<std::int64_t, 2>& cell_vertices,
117 std::vector<std::int64_t>& global_cell_indices,
118 std::vector<int>& cell_partition);
124 void reorder_cells_gps(MPI_Comm mpi_comm,
125 const unsigned int num_regular_cells,
127 const std::map<std::int32_t, std::set<unsigned int>>& shared_cells,
128 const boost::multi_array<std::int64_t, 2>& cell_vertices,
129 const std::vector<std::int64_t>& global_cell_indices,
130 std::map<std::int32_t, std::set<unsigned int>>& reordered_shared_cells,
131 boost::multi_array<std::int64_t, 2>& reordered_cell_vertices,
132 std::vector<std::int64_t>& reordered_global_cell_indices);
139 reorder_vertices_gps(MPI_Comm mpi_comm,
140 const std::int32_t num_regular_vertices,
141 const std::int32_t num_regular_cells,
142 const int num_cell_vertices,
143 const boost::multi_array<std::int64_t, 2>& cell_vertices,
144 const std::vector<std::int64_t>& vertex_indices,
145 const std::map<std::int64_t, std::int32_t>& vertex_global_to_local,
146 std::vector<std::int64_t>& reordered_vertex_indices,
147 std::map<std::int64_t, std::int32_t>& reordered_vertex_global_to_local);
159 distribute_cells(
const MPI_Comm mpi_comm,
161 const std::vector<int>& cell_partition,
162 const std::map<std::int64_t, std::vector<int>>& ghost_procs,
163 boost::multi_array<std::int64_t, 2>& new_cell_vertices,
164 std::vector<std::int64_t>& new_global_cell_indices,
165 std::vector<int>& new_cell_partition,
166 std::map<std::int32_t, std::set<unsigned int>>& shared_cells);
171 static void build_shared_vertices(MPI_Comm mpi_comm,
172 std::map<std::int32_t, std::set<unsigned int>>& shared_vertices,
173 const std::map<std::int64_t, std::int32_t>& vertex_global_to_local_indices,
174 const std::vector<std::vector<std::size_t>>& received_vertex_indices);
179 distribute_vertices(
const MPI_Comm mpi_comm,
181 const std::vector<std::int64_t>& vertex_indices,
182 boost::multi_array<double, 2>& new_vertex_coordinates,
183 std::map<std::int64_t, std::int32_t>& vertex_global_to_local_indices,
184 std::map<std::int32_t, std::set<unsigned int>>& shared_vertices_local);
189 static std::int32_t compute_vertex_mapping(MPI_Comm mpi_comm,
190 const std::int32_t num_regular_cells,
191 const boost::multi_array<std::int64_t, 2>& cell_vertices,
192 std::vector<std::int64_t>& vertex_indices,
193 std::map<std::int64_t, std::int32_t>& vertex_global_to_local);
197 static void build_local_mesh(
Mesh& mesh,
198 const std::vector<std::int64_t>& global_cell_indices,
199 const boost::multi_array<std::int64_t, 2>& cell_global_vertices,
202 const std::int64_t num_global_cells,
203 const std::vector<std::int64_t>& vertex_indices,
204 const boost::multi_array<double, 2>& vertex_coordinates,
206 const std::int64_t num_global_vertices,
207 const std::map<std::int64_t, std::int32_t>& vertex_global_to_local_indices);
214 template<
typename T,
typename MeshValueCollection>
215 static void build_mesh_value_collection(
const Mesh& mesh,
216 const std::vector<std::pair<std::pair<std::size_t, std::size_t>, T>>& local_value_data,
225 const std::vector<std::pair<std::pair<std::size_t, std::size_t>, T>>& local_values
229 build_mesh_value_collection(mesh, local_values, values);
232 template<
typename T,
typename MeshValueCollection>
233 void MeshPartitioning::build_mesh_value_collection(
const Mesh& mesh,
234 const std::vector<std::pair<std::pair<std::size_t, std::size_t>, T>>& local_value_data,
238 const MPI_Comm mpi_comm = mesh.
mpi_comm();
242 const std::size_t dim = mesh_values.
dim();
259 const std::vector< std::pair<std::pair<std::size_t, std::size_t>, T>>&
260 ldata = local_value_data;
266 "build mesh value collection",
267 "Do not have have_global_entity_indices");
274 std::vector<std::size_t> off_process_global_cell_entities;
277 std::map<std::size_t, std::size_t> map_of_global_entity_indices;
278 for (std::size_t i = 0; i < global_entity_indices.size(); i++)
279 map_of_global_entity_indices[global_entity_indices[i]] = i;
281 for (std::size_t i = 0; i < ldata.size(); ++i)
283 const std::map<std::int32_t, std::set<unsigned int>>& sharing_map
286 const std::size_t global_cell_index = ldata[i].first.first;
287 std::map<std::size_t, std::size_t>::const_iterator data
288 = map_of_global_entity_indices.find(global_cell_index);
289 if (data != map_of_global_entity_indices.end())
291 const std::size_t local_cell_index = data->second;
292 const std::size_t entity_local_index = ldata[i].first.second;
293 const T value = ldata[i].second;
294 markers.
set_value(local_cell_index, entity_local_index, value);
297 if (sharing_map.find(local_cell_index) != sharing_map.end())
298 off_process_global_cell_entities.push_back(global_cell_index);
301 off_process_global_cell_entities.push_back(global_cell_index);
306 const std::map<std::size_t, std::set<std::pair<std::size_t, std::size_t>>>
312 const std::size_t num_processes =
MPI::size(mpi_comm);
315 std::vector<std::vector<std::size_t>> send_data0(num_processes);
316 std::vector<std::vector<T>> send_data1(num_processes);
317 std::map<std::size_t, std::set<std::pair<std::size_t, std::size_t>>>::const_iterator entity_host;
322 std::map<std::size_t, std::set<std::size_t>> map_of_ldata;
323 for (std::size_t i = 0; i < ldata.size(); ++i)
324 map_of_ldata[ldata[i].first.first].insert(i);
326 for (entity_host = entity_hosts.begin(); entity_host != entity_hosts.end();
329 const std::size_t host_global_cell_index = entity_host->first;
330 const std::set<std::pair<std::size_t, std::size_t>>& processes_data
331 = entity_host->second;
334 std::map<std::size_t, std::set<std::size_t>>::const_iterator ldata_it
335 = map_of_ldata.find(host_global_cell_index);
336 if (ldata_it != map_of_ldata.end())
338 for (std::set<std::size_t>::const_iterator it = ldata_it->second.begin();
339 it != ldata_it->second.end(); it++)
341 const std::size_t local_entity_index = ldata[*it].first.second;
342 const T domain_value = ldata[*it].second;
344 std::set<std::pair<std::size_t, std::size_t>>::const_iterator process_data;
345 for (process_data = processes_data.begin();
346 process_data != processes_data.end(); ++process_data)
348 const std::size_t proc = process_data->first;
349 const std::size_t local_cell_entity = process_data->second;
350 send_data0[proc].push_back(local_cell_entity);
351 send_data0[proc].push_back(local_entity_index);
352 send_data1[proc].push_back(domain_value);
360 std::vector<std::size_t> received_data0;
361 std::vector<T> received_data1;
364 dolfin_assert(2*received_data1.size() == received_data0.size());
367 for (std::size_t i = 0; i < received_data1.size(); ++i)
369 const std::size_t local_cell_entity = received_data0[2*i];
370 const std::size_t local_entity_index = received_data0[2*i + 1];
371 const T value = received_data1[i];
372 dolfin_assert(local_cell_entity < mesh.
num_cells());
373 markers.
set_value(local_cell_entity, local_entity_index, value);
std::map< std::int32_t, std::set< unsigned int > > & shared_entities(unsigned int dim)
Definition: MeshTopology.cpp:186
static void build_distributed_mesh(Mesh &mesh)
Build a distributed mesh from a local mesh on process 0.
Definition: MeshPartitioning.cpp:82
MPI_Comm mpi_comm() const
Definition: Mesh.h:497
void clear()
Clear all values.
Definition: MeshValueCollection.h:534
This class stores mesh data on a local processor corresponding to a portion of a (larger) global mesh...
Definition: LocalMeshData.h:58
std::size_t init(std::size_t dim) const
Definition: Mesh.cpp:138
Definition: MeshPartitioning.h:62
static unsigned int size(MPI_Comm comm)
Definition: MPI.cpp:154
Type
Enum for different cell types.
Definition: CellType.h:51
static void all_to_all(MPI_Comm comm, std::vector< std::vector< T >> &in_values, std::vector< std::vector< T >> &out_values)
Definition: MPI.h:345
bool have_global_indices(std::size_t dim) const
Definition: MeshTopology.h:115
bool set_value(std::size_t cell_index, std::size_t local_entity, const T &value)
Definition: MeshValueCollection.h:415
std::size_t dim() const
Definition: MeshValueCollection.h:389
Definition: CellType.h:46
MeshTopology & topology()
Definition: Mesh.h:219
const std::vector< std::pair< std::pair< std::size_t, std::size_t >, T > > & values() const
Return data.
Definition: LocalMeshValueCollection.h:62
Definition: GenericFile.h:38
std::size_t num_cells() const
Definition: Mesh.h:166
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition: log.cpp:129
const std::vector< std::int64_t > & global_indices(std::size_t d) const
Definition: MeshTopology.h:107
static void build_distributed_value_collection(MeshValueCollection< T > &values, const LocalMeshValueCollection< T > &local_data, const Mesh &mesh)
Build a MeshValueCollection based on LocalMeshValueCollection.
Definition: MeshPartitioning.h:221
Definition: LocalMeshValueCollection.h:45
std::size_t dim() const
Return topological dimension.
Definition: MeshTopology.cpp:70