libMesh
Loading...
Searching...
No Matches
Public Member Functions | List of all members
libMesh::MeshCommunication Class Reference

This is the MeshCommunication class. More...

#include <mesh_communication.h>

Public Member Functions

 MeshCommunication ()=default
 Constructor.
 
 ~MeshCommunication ()=default
 Destructor.
 
void clear ()
 Clears all data structures and resets to a pristine state.
 
void broadcast (MeshBase &) const
 This method takes a mesh (which is assumed to reside on processor 0) and broadcasts it to all the other processors.
 
void redistribute (DistributedMesh &mesh, bool newly_coarsened_only=false) const
 This method takes a parallel distributed mesh and redistributes the elements.
 
void gather_neighboring_elements (DistributedMesh &) const
 
void send_coarse_ghosts (MeshBase &) const
 Examine a just-coarsened mesh, and for any newly-coarsened elements, send the associated ghosted elements to the processor which needs them.
 
void gather (const processor_id_type root_id, MeshBase &) const
 This method takes an input DistributedMesh which may be distributed among all the processors.
 
void allgather (MeshBase &mesh) const
 This method takes an input DistributedMesh which may be distributed among all the processors.
 
void delete_remote_elements (DistributedMesh &, const std::set< Elem * > &) const
 This method takes an input DistributedMesh which may be distributed among all the processors.
 
void assign_global_indices (MeshBase &) const
 This method assigns globally unique, partition-agnostic indices to the nodes and elements in the mesh.
 
void check_for_duplicate_global_indices (MeshBase &) const
 Throw an error if we have any index clashes in the numbering used by assign_global_indices.
 
template<typename ForwardIterator >
void find_local_indices (const libMesh::BoundingBox &, const ForwardIterator &, const ForwardIterator &, std::unordered_map< dof_id_type, dof_id_type > &) const
 This method determines a locally unique, contiguous index for each object in the input range.
 
template<typename ForwardIterator >
void find_global_indices (const Parallel::Communicator &communicator, const libMesh::BoundingBox &, const ForwardIterator &, const ForwardIterator &, std::vector< dof_id_type > &) const
 This method determines a globally unique, partition-agnostic index for each object in the input range.
 
void make_elems_parallel_consistent (MeshBase &)
 Copy ids of ghost elements from their local processors.
 
void make_p_levels_parallel_consistent (MeshBase &)
 Copy p levels of ghost elements from their local processors.
 
void make_node_ids_parallel_consistent (MeshBase &)
 Assuming all ids on local nodes are globally unique, and assuming all processor ids are parallel consistent, this function makes all other ids parallel consistent.
 
void make_node_unique_ids_parallel_consistent (MeshBase &)
 Assuming all unique_ids on local nodes are globally unique, and assuming all processor ids are parallel consistent, this function makes all ghost unique_ids parallel consistent.
 
void make_node_bcids_parallel_consistent (MeshBase &)
 Assuming all processor ids are parallel consistent, this function makes all ghost boundary ids on nodes parallel consistent.
 
void make_node_proc_ids_parallel_consistent (MeshBase &)
 Assuming all processor ids on nodes touching local elements are parallel consistent, this function makes all other processor ids parallel consistent as well.
 
void make_new_node_proc_ids_parallel_consistent (MeshBase &)
 Assuming all processor ids on nodes touching local elements are parallel consistent, this function makes processor ids on new nodes on other processors parallel consistent as well.
 
void make_nodes_parallel_consistent (MeshBase &)
 Copy processor_ids and ids on ghost nodes from their local processors.
 
void make_new_nodes_parallel_consistent (MeshBase &)
 Copy processor_ids and ids on new nodes from their local processors.
 

Detailed Description

This is the MeshCommunication class.

It handles all the details of communicating mesh information from one processor to another. All parallelization of the Mesh data structures is done via this class.

Author
Benjamin S. Kirk
Date
2003

Definition at line 53 of file mesh_communication.h.

Constructor & Destructor Documentation

◆ MeshCommunication()

libMesh::MeshCommunication::MeshCommunication ( )
default

Constructor.

◆ ~MeshCommunication()

libMesh::MeshCommunication::~MeshCommunication ( )
default

Destructor.

Member Function Documentation

◆ allgather()

void libMesh::MeshCommunication::allgather ( MeshBase &  mesh) const
inline

This method takes an input DistributedMesh which may be distributed among all the processors.

Each processor then sends its local nodes and elements to the other processors. The end result is that a previously distributed DistributedMesh will be serialized on each processor. Since this method is collective it must be called by all processors.

Definition at line 138 of file mesh_communication.h.

static constexpr processor_id_type invalid_processor_id
An invalid processor_id to distinguish DoFs that have not been assigned to a processor.
Definition dof_object.h:484
void gather(const processor_id_type root_id, MeshBase &) const
This method takes an input DistributedMesh which may be distributed among all the processors.
MeshBase & mesh

References gather(), libMesh::DofObject::invalid_processor_id, and mesh.

Referenced by libMesh::DistributedMesh::allgather(), libMesh::Nemesis_IO::read(), and libMesh::ReplicatedMesh::ReplicatedMesh().

◆ assign_global_indices()

void libMesh::MeshCommunication::assign_global_indices ( MeshBase &  mesh) const

This method assigns globally unique, partition-agnostic indices to the nodes and elements in the mesh.

The approach is to compute the Hilbert space-filling curve key and use its value to assign an index in [0,N_global). Since the Hilbert key is unique for each spatial location, two objects occupying the same location will be assigned the same global id. Thus, this method can also be useful for identifying duplicate nodes which may occur during parallel refinement.

Definition at line 204 of file mesh_communication_global_indices.C.

205{
206 LOG_SCOPE ("assign_global_indices()", "MeshCommunication");
207
208 // This method determines partition-agnostic global indices
209 // for nodes and elements.
210
211 // Algorithm:
212 // (1) compute the Hilbert key for each local node/element
213 // (2) perform a parallel sort of the Hilbert key
214 // (3) get the min/max value on each processor
215 // (4) determine the position in the global ranking for
216 // each local object
217
219
220#ifdef DEBUG
221 // This is going to be a mess if geometry is out of sync
224#endif
225
226 // Global bounding box. We choose the nodal bounding box for
227 // backwards compatibility; the element bounding box may be looser
228 // on curved elements.
229 const BoundingBox bbox =
231
232 const Point bboxinv = invert_bbox(bbox);
233
234 //-------------------------------------------------------------
235 // (1) compute Hilbert keys
236 std::vector<Parallel::DofObjectKey>
237 node_keys, elem_keys;
238
239 {
240 // Nodes first
241 {
243 node_keys.resize (nr.size());
244 Threads::parallel_for (nr, ComputeHilbertKeys (bbox, bboxinv, node_keys));
245
246 // // It's O(N^2) to check that these keys don't duplicate before the
247 // // sort...
248 //
249 // MeshBase::const_node_iterator nodei = mesh.local_nodes_begin();
250 // for (std::size_t i = 0; i != node_keys.size(); ++i, ++nodei)
251 // {
252 // MeshBase::const_node_iterator nodej = mesh.local_nodes_begin();
253 // for (std::size_t j = 0; j != i; ++j, ++nodej)
254 // {
255 // if (node_keys[i] == node_keys[j])
256 // {
257 // CFixBitVec icoords[3], jcoords[3];
258 // get_hilbert_coords(**nodej, bbox, bboxinv, jcoords);
259 // libMesh::err << "node " << (*nodej)->id() << ", " << static_cast<Point &>(**nodej) << " has HilbertIndices " << node_keys[j] << std::endl;
260 // get_hilbert_coords(**nodei, bbox, bboxinv, icoords);
261 // libMesh::err << "node " << (*nodei)->id() << ", " << static_cast<Point &>(**nodei) << " has HilbertIndices " << node_keys[i] << std::endl;
262 // libmesh_error_msg("Error: nodes with duplicate Hilbert keys!");
263 // }
264 // }
265 // }
266 }
267
268 // Elements next
269 {
271 elem_keys.resize (er.size());
272 Threads::parallel_for (er, ComputeHilbertKeys (bbox, bboxinv, elem_keys));
273
274 // // For elements, the keys can be (and in the case of TRI, are
275 // // expected to be) duplicates, but only if the elements are at
276 // // different levels
277 // MeshBase::const_element_iterator elemi = mesh.local_elements_begin();
278 // for (std::size_t i = 0; i != elem_keys.size(); ++i, ++elemi)
279 // {
280 // MeshBase::const_element_iterator elemj = mesh.local_elements_begin();
281 // for (std::size_t j = 0; j != i; ++j, ++elemj)
282 // {
283 // if ((elem_keys[i] == elem_keys[j]) &&
284 // ((*elemi)->level() == (*elemj)->level()))
285 // {
286 // libMesh::err << "level " << (*elemj)->level()
287 // << " elem\n" << (**elemj)
288 // << " vertex average " << (*elemj)->vertex_average()
289 // << " has HilbertIndices " << elem_keys[j]
290 // << " or " << get_dofobject_key((**elemj), bbox, bboxinv)
291 // << std::endl;
292 // libMesh::err << "level " << (*elemi)->level()
293 // << " elem\n" << (**elemi)
294 // << " vertex average " << (*elemi)->vertex_average()
295 // << " has HilbertIndices " << elem_keys[i]
296 // << " or " << get_dofobject_key((**elemi), bbox, bboxinv)
297 // << std::endl;
298 // libmesh_error_msg("Error: level " << (*elemi)->level() << " elements with duplicate Hilbert keys!");
299 // }
300 // }
301 // }
302 }
303 } // done computing Hilbert keys
304
305
306
307 //-------------------------------------------------------------
308 // (2) parallel sort the Hilbert keys
309 Parallel::Sort<Parallel::DofObjectKey> node_sorter (communicator,
310 node_keys);
311 node_sorter.sort(); /* done with node_keys */ //node_keys.clear();
312
313 const std::vector<Parallel::DofObjectKey> & my_node_bin =
314 node_sorter.bin();
315
316 Parallel::Sort<Parallel::DofObjectKey> elem_sorter (communicator,
317 elem_keys);
318 elem_sorter.sort(); /* done with elem_keys */ //elem_keys.clear();
319
320 const std::vector<Parallel::DofObjectKey> & my_elem_bin =
321 elem_sorter.bin();
322
323
324
325 //-------------------------------------------------------------
326 // (3) get the max value on each processor
327 std::vector<Parallel::DofObjectKey>
328 node_upper_bounds(communicator.size()),
329 elem_upper_bounds(communicator.size());
330
331 { // limit scope of temporaries
332 std::vector<Parallel::DofObjectKey> recvbuf(2*communicator.size());
333 std::vector<unsigned short int> /* do not use a vector of bools here since it is not always so! */
334 empty_nodes (communicator.size()),
335 empty_elem (communicator.size());
336 std::vector<Parallel::DofObjectKey> my_max(2);
337
338 communicator.allgather (static_cast<unsigned short int>(my_node_bin.empty()), empty_nodes);
339 communicator.allgather (static_cast<unsigned short int>(my_elem_bin.empty()), empty_elem);
340
341 if (!my_node_bin.empty()) my_max[0] = my_node_bin.back();
342 if (!my_elem_bin.empty()) my_max[1] = my_elem_bin.back();
343
344 communicator.allgather (my_max, /* identical_buffer_sizes = */ true);
345
346 // Be careful here. The *_upper_bounds will be used to find the processor
347 // a given object belongs to. So, if a processor contains no objects (possible!)
348 // then copy the bound from the lower processor id.
349 for (auto p : make_range(communicator.size()))
350 {
351 node_upper_bounds[p] = my_max[2*p+0];
352 elem_upper_bounds[p] = my_max[2*p+1];
353
354 if (p > 0) // default hilbert index value is the OK upper bound for processor 0.
355 {
356 if (empty_nodes[p]) node_upper_bounds[p] = node_upper_bounds[p-1];
357 if (empty_elem[p]) elem_upper_bounds[p] = elem_upper_bounds[p-1];
358 }
359 }
360 }
361
362
363
364 //-------------------------------------------------------------
365 // (4) determine the position in the global ranking for
366 // each local object
367 {
368 //----------------------------------------------
369 // Nodes first -- all nodes, not just local ones
370 {
371 // Request sets to send to each processor
372 std::map<processor_id_type, std::vector<Parallel::DofObjectKey>>
373 requested_ids;
374 // Results to gather from each processor - kept in a map so we
375 // do only one loop over nodes after all receives are done.
376 std::map<dof_id_type, std::vector<dof_id_type>>
377 filled_request;
378
379 // build up list of requests
380 for (const auto & node : mesh.node_ptr_range())
381 {
382 libmesh_assert(node);
383 const Parallel::DofObjectKey hi =
384 get_dofobject_key (*node, bbox, bboxinv);
385 const processor_id_type pid =
386 cast_int<processor_id_type>
387 (std::distance (node_upper_bounds.begin(),
388 std::lower_bound(node_upper_bounds.begin(),
389 node_upper_bounds.end(),
390 hi)));
391
392 libmesh_assert_less (pid, communicator.size());
393
394 requested_ids[pid].push_back(hi);
395 }
396
397 // The number of objects in my_node_bin on each processor
398 std::vector<dof_id_type> node_bin_sizes(communicator.size());
399 communicator.allgather (static_cast<dof_id_type>(my_node_bin.size()), node_bin_sizes);
400
401 // The offset of my first global index
402 dof_id_type my_offset = 0;
403 for (auto pid : make_range(communicator.rank()))
404 my_offset += node_bin_sizes[pid];
405
406 auto gather_functor =
407 [
408#ifndef NDEBUG
409 & node_upper_bounds,
410 & communicator,
411#endif
412 & my_node_bin,
413 my_offset
414 ]
416 const std::vector<Parallel::DofObjectKey> & keys,
417 std::vector<dof_id_type> & global_ids)
418 {
419 // Fill the requests
420 const std::size_t keys_size = keys.size();
421 global_ids.reserve(keys_size);
422 for (std::size_t idx=0; idx != keys_size; idx++)
423 {
424 const Parallel::DofObjectKey & hi = keys[idx];
425 libmesh_assert_less_equal (hi, node_upper_bounds[communicator.rank()]);
426
427 // find the requested index in my node bin
428 std::vector<Parallel::DofObjectKey>::const_iterator pos =
429 std::lower_bound (my_node_bin.begin(), my_node_bin.end(), hi);
430 libmesh_assert (pos != my_node_bin.end());
431 libmesh_assert_equal_to (*pos, hi);
432
433 // Finally, assign the global index based off the position of the index
434 // in my array, properly offset.
435 global_ids.push_back(cast_int<dof_id_type>(std::distance(my_node_bin.begin(), pos) + my_offset));
436 }
437 };
438
439 auto action_functor =
440 [&filled_request]
442 const std::vector<Parallel::DofObjectKey> &,
443 const std::vector<dof_id_type> & global_ids)
444 {
445 filled_request[pid] = global_ids;
446 };
447
448 // Trade requests with other processors
449 const dof_id_type * ex = nullptr;
451 (communicator, requested_ids, gather_functor, action_functor, ex);
452
453 // We now have all the filled requests, so we can loop through our
454 // nodes once and assign the global index to each one.
455 {
456 std::map<dof_id_type, std::vector<dof_id_type>::const_iterator>
457 next_obj_on_proc;
458 for (auto & p : filled_request)
459 next_obj_on_proc[p.first] = p.second.begin();
460
461 for (auto & node : mesh.node_ptr_range())
462 {
463 libmesh_assert(node);
464 const Parallel::DofObjectKey hi =
465 get_dofobject_key (*node, bbox, bboxinv);
466 const processor_id_type pid =
467 cast_int<processor_id_type>
468 (std::distance (node_upper_bounds.begin(),
469 std::lower_bound(node_upper_bounds.begin(),
470 node_upper_bounds.end(),
471 hi)));
472
473 libmesh_assert_less (pid, communicator.size());
474 libmesh_assert (next_obj_on_proc[pid] != filled_request[pid].end());
475
476 const dof_id_type global_index = *next_obj_on_proc[pid];
477 libmesh_assert_less (global_index, mesh.n_nodes());
478 node->set_id() = global_index;
479
480 ++next_obj_on_proc[pid];
481 }
482 }
483 }
484
485 //---------------------------------------------------
486 // elements next -- all elements, not just local ones
487 {
488 // Request sets to send to each processor
489 std::map<processor_id_type, std::vector<Parallel::DofObjectKey>>
490 requested_ids;
491 // Results to gather from each processor - kept in a map so we
492 // do only one loop over elements after all receives are done.
493 std::map<dof_id_type, std::vector<dof_id_type>>
494 filled_request;
495
496 for (const auto & elem : mesh.element_ptr_range())
497 {
498 libmesh_assert(elem);
499 const Parallel::DofObjectKey hi =
500 get_dofobject_key (*elem, bbox, bboxinv);
501 const processor_id_type pid =
502 cast_int<processor_id_type>
503 (std::distance (elem_upper_bounds.begin(),
504 std::lower_bound(elem_upper_bounds.begin(),
505 elem_upper_bounds.end(),
506 hi)));
507
508 libmesh_assert_less (pid, communicator.size());
509
510 requested_ids[pid].push_back(hi);
511 }
512
513 // The number of objects in my_elem_bin on each processor
514 std::vector<dof_id_type> elem_bin_sizes(communicator.size());
515 communicator.allgather (static_cast<dof_id_type>(my_elem_bin.size()), elem_bin_sizes);
516
517 // The offset of my first global index
518 dof_id_type my_offset = 0;
519 for (auto pid : make_range(communicator.rank()))
520 my_offset += elem_bin_sizes[pid];
521
522 auto gather_functor =
523 [
524#ifndef NDEBUG
525 & elem_upper_bounds,
526 & communicator,
527#endif
528 & my_elem_bin,
529 my_offset
530 ]
532 const std::vector<Parallel::DofObjectKey> & keys,
533 std::vector<dof_id_type> & global_ids)
534 {
535 // Fill the requests
536 const std::size_t keys_size = keys.size();
537 global_ids.reserve(keys_size);
538 for (std::size_t idx=0; idx != keys_size; idx++)
539 {
540 const Parallel::DofObjectKey & hi = keys[idx];
541 libmesh_assert_less_equal (hi, elem_upper_bounds[communicator.rank()]);
542
543 // find the requested index in my elem bin
544 std::vector<Parallel::DofObjectKey>::const_iterator pos =
545 std::lower_bound (my_elem_bin.begin(), my_elem_bin.end(), hi);
546 libmesh_assert (pos != my_elem_bin.end());
547 libmesh_assert_equal_to (*pos, hi);
548
549 // Finally, assign the global index based off the position of the index
550 // in my array, properly offset.
551 global_ids.push_back (cast_int<dof_id_type>(std::distance(my_elem_bin.begin(), pos) + my_offset));
552 }
553 };
554
555 auto action_functor =
556 [&filled_request]
558 const std::vector<Parallel::DofObjectKey> &,
559 const std::vector<dof_id_type> & global_ids)
560 {
561 filled_request[pid] = global_ids;
562 };
563
564 // Trade requests with other processors
565 const dof_id_type * ex = nullptr;
567 (communicator, requested_ids, gather_functor, action_functor, ex);
568
569 // We now have all the filled requests, so we can loop through our
570 // elements once and assign the global index to each one.
571 {
572 std::vector<std::vector<dof_id_type>::const_iterator>
573 next_obj_on_proc; next_obj_on_proc.reserve(communicator.size());
574 for (auto pid : make_range(communicator.size()))
575 next_obj_on_proc.push_back(filled_request[pid].begin());
576
577 for (auto & elem : mesh.element_ptr_range())
578 {
579 libmesh_assert(elem);
580 const Parallel::DofObjectKey hi =
581 get_dofobject_key (*elem, bbox, bboxinv);
582 const processor_id_type pid =
583 cast_int<processor_id_type>
584 (std::distance (elem_upper_bounds.begin(),
585 std::lower_bound(elem_upper_bounds.begin(),
586 elem_upper_bounds.end(),
587 hi)));
588
589 libmesh_assert_less (pid, communicator.size());
590 libmesh_assert (next_obj_on_proc[pid] != filled_request[pid].end());
591
592 const dof_id_type global_index = *next_obj_on_proc[pid];
593 libmesh_assert_less (global_index, mesh.n_elem());
594 elem->set_id() = global_index;
595
596 ++next_obj_on_proc[pid];
597 }
598 }
599 }
600 }
601}
Defines a Cartesian bounding box by the two corner extremum.
virtual dof_id_type n_elem() const =0
const ConstNodeRange & const_local_node_stored_range() const
Definition mesh_base.C:2254
virtual dof_id_type n_nodes() const =0
const ConstElemRange & const_local_element_stored_range() const
Definition mesh_base.C:2173
const Parallel::Communicator & comm() const
The parallel sorting method is templated on the type of data which is to be sorted.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:41
The StoredRange class defines a contiguous, divisible set of objects.
std::size_t size() const
void pull_parallel_vector_data(const Communicator &comm, const MapToVectors &queries, GatherFunctor &gather_data, const ActionFunctor &act_on_data, const datum *example)
DIE A HORRIBLE DEATH HERE typedef MPI_Comm communicator
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
A useful inline function which replaces the macros used previously.
void libmesh_assert_equal_connectivity(const MeshBase &mesh)
A function for testing that element nodal connectivities match across processors.
libMesh::BoundingBox create_nodal_bounding_box(const MeshBase &mesh)
Definition mesh_tools.C:655
void libmesh_assert_equal_points(const MeshBase &mesh)
A function for testing that node locations match across processors.
std::pair< Hilbert::HilbertIndices, unique_id_type > DofObjectKey
void parallel_for(const Range &range, const Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided function object in parallel on the specified range.
libmesh_assert(ctx)
uint8_t dof_id_type
Definition id_types.h:67
uint8_t processor_id_type
Definition id_types.h:104
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176

References libMesh::Parallel::Sort< KeyType, IdxType >::bin(), libMesh::ParallelObject::comm(), libMesh::MeshBase::const_local_element_stored_range(), libMesh::MeshBase::const_local_node_stored_range(), libMesh::MeshTools::create_nodal_bounding_box(), libMesh::libmesh_assert(), libMesh::MeshTools::libmesh_assert_equal_connectivity(), libMesh::MeshTools::libmesh_assert_equal_points(), libMesh::make_range(), mesh, libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_nodes(), libMesh::Threads::parallel_for(), TIMPI::pull_parallel_vector_data(), libMesh::StoredRange< iterator_type, object_type >::size(), and libMesh::Parallel::Sort< KeyType, IdxType >::sort().

Referenced by libMesh::MeshTools::Private::globally_renumber_nodes_and_elements().

◆ broadcast()

void libMesh::MeshCommunication::broadcast ( MeshBase &  mesh) const

This method takes a mesh (which is assumed to reside on processor 0) and broadcasts it to all the other processors.

It also broadcasts any boundary information the mesh has associated with it.

Definition at line 1171 of file mesh_communication.C.

1172{
1173 // no MPI == one processor, no need for this method...
1174 return;
1175}

Referenced by main(), libMesh::CheckpointIO::read(), libMesh::NameBasedIO::read(), ExodusTest< elem_type >::test_read_gold(), ExodusTest< elem_type >::test_write(), XdrIOTest< elem_type >::test_write(), ExodusC0PolyhedronTest::test_write_and_read_hexagonal_prism(), ExodusC0PolyhedronTest::test_write_and_read_mixed_hex_tet_block_names_impl(), ExodusC0PolyhedronTest::test_write_and_read_mixed_poly_hex_impl(), ExodusC0PolygonTest::test_write_and_read_pentagon(), MeshInputTest::testAbaqusRead(), MeshInputTest::testCopyElementSolutionImpl(), MeshInputTest::testCopyElementVectorImpl(), MeshInputTest::testCopyNodalSolutionImpl(), MeshInputTest::testDynaFileMappings(), MeshInputTest::testDynaNoSplines(), MeshInputTest::testDynaReadElem(), MeshInputTest::testDynaReadPatch(), MeshInputTest::testExodusCopyHighOrderElementSolution(), MeshInputTest::testExodusFileMappings(), MeshInputTest::testExodusIGASidesets(), MeshInputTest::testExodusWriteElementDataFromDiscontinuousNodalData(), MeshInputTest::testGmshBCIDOverlap(), MeshInputTest::testGoodGmsh(), MeshInputTest::testGoodSTL(), MeshInputTest::testGoodSTLBinary(), MeshInputTest::testLowOrderEdgeBlocks(), MeshInputTest::testSTLGzipped(), MeshInputTest::testTetgenIO(), and libMesh::NetGenMeshInterface::triangulate().

◆ check_for_duplicate_global_indices()

void libMesh::MeshCommunication::check_for_duplicate_global_indices ( MeshBase &  mesh) const

Throw an error if we have any index clashes in the numbering used by assign_global_indices.

Definition at line 610 of file mesh_communication_global_indices.C.

611{
612 LOG_SCOPE ("check_for_duplicate_global_indices()", "MeshCommunication");
613
614 // Global bounding box. We choose the nodal bounding box for
615 // backwards compatibility; the element bounding box may be looser
616 // on curved elements.
617 const BoundingBox bbox =
619
620 const Point bboxinv = invert_bbox(bbox);
621
622 std::vector<Parallel::DofObjectKey>
623 node_keys, elem_keys;
624
625 {
626 // Nodes first
627 {
629 Threads::parallel_for (nr, ComputeHilbertKeys (bbox, bboxinv, node_keys));
630
631 // It's O(N^2) to check that these keys don't duplicate before the
632 // sort...
633 MeshBase::const_node_iterator nodei = mesh.local_nodes_begin();
634 for (std::size_t i = 0; i != node_keys.size(); ++i, ++nodei)
635 {
636 MeshBase::const_node_iterator nodej = mesh.local_nodes_begin();
637 for (std::size_t j = 0; j != i; ++j, ++nodej)
638 {
639 if (node_keys[i] == node_keys[j])
640 {
641 CFixBitVec icoords[3], jcoords[3];
642 get_hilbert_coords(**nodej, bbox, bboxinv, jcoords);
643 libMesh::err <<
644 "node " << (*nodej)->id() << ", " <<
645 *(const Point *)(*nodej) << " has HilbertIndices " <<
646 node_keys[j] << std::endl;
647 get_hilbert_coords(**nodei, bbox, bboxinv, icoords);
648 libMesh::err <<
649 "node " << (*nodei)->id() << ", " <<
650 *(const Point *)(*nodei) << " has HilbertIndices " <<
651 node_keys[i] << std::endl;
652 libmesh_error_msg("Error: nodes with duplicate Hilbert keys!");
653 }
654 }
655 }
656 }
657
658 // Elements next
659 {
661 elem_keys.resize (er.size());
662 Threads::parallel_for (er, ComputeHilbertKeys (bbox, bboxinv, elem_keys));
663
664 // For elements, the keys can be (and in the case of TRI, are
665 // expected to be) duplicates, but only if the elements are at
666 // different levels
667 MeshBase::const_element_iterator elemi = mesh.local_elements_begin();
668 for (std::size_t i = 0; i != elem_keys.size(); ++i, ++elemi)
669 {
670 MeshBase::const_element_iterator elemj = mesh.local_elements_begin();
671 for (std::size_t j = 0; j != i; ++j, ++elemj)
672 {
673 if ((elem_keys[i] == elem_keys[j]) &&
674 ((*elemi)->level() == (*elemj)->level()))
675 {
676 libMesh::err <<
677 "level " << (*elemj)->level() << " elem\n" <<
678 (**elemj) << " vertex average " <<
679 (*elemj)->vertex_average() << " has HilbertIndices " <<
680 elem_keys[j] << " or " <<
681 get_dofobject_key((**elemj), bbox, bboxinv) <<
682 std::endl;
683 libMesh::err <<
684 "level " << (*elemi)->level() << " elem\n" <<
685 (**elemi) << " vertex average " <<
686 (*elemi)->vertex_average() << " has HilbertIndices " <<
687 elem_keys[i] << " or " <<
688 get_dofobject_key((**elemi), bbox, bboxinv) <<
689 std::endl;
690 libmesh_error_msg("Error: level " << (*elemi)->level() << " elements with duplicate Hilbert keys!");
691 }
692 }
693 }
694 }
695 } // done checking Hilbert keys
696}
OStreamProxy err
The definition of the const_element_iterator struct.
Definition mesh_base.h:2726
The definition of the const_node_iterator struct.
Definition mesh_base.h:2777

References libMesh::MeshBase::const_local_element_stored_range(), libMesh::MeshBase::const_local_node_stored_range(), libMesh::MeshTools::create_nodal_bounding_box(), libMesh::err, mesh, libMesh::Threads::parallel_for(), and libMesh::StoredRange< iterator_type, object_type >::size().

◆ clear()

void libMesh::MeshCommunication::clear ( )

Clears all data structures and resets to a pristine state.

Definition at line 424 of file mesh_communication.C.

425{
426 // _neighboring_processors.clear();
427}

◆ delete_remote_elements()

void libMesh::MeshCommunication::delete_remote_elements ( DistributedMesh &  mesh,
const std::set< Elem * > &  extra_ghost_elem_ids 
) const

This method takes an input DistributedMesh which may be distributed among all the processors.

Each processor deletes all elements which are neither local elements nor "ghost" elements which touch local elements, and deletes all nodes which are not contained in local or ghost elements. The end result is that a previously serial DistributedMesh will be distributed between processors. Since this method is collective it must be called by all processors.

The std::set is a list of extra elements that you don't want to delete. These will be left on the current processor along with local elements and ghosted neighbors.

Definition at line 2152 of file mesh_communication.C.

2154{
2155 // The mesh should know it's about to be parallelized
2157
2158 LOG_SCOPE("delete_remote_elements()", "MeshCommunication");
2159
2160#ifdef DEBUG
2161 // We expect maximum ids to be in sync so we can use them to size
2162 // vectors
2165 const dof_id_type par_max_node_id = mesh.parallel_max_node_id();
2166 const dof_id_type par_max_elem_id = mesh.parallel_max_elem_id();
2167 libmesh_assert_equal_to (par_max_node_id, mesh.max_node_id());
2168 libmesh_assert_equal_to (par_max_elem_id, mesh.max_elem_id());
2169
2170 // n_constraint_rows might not be cached, but we're in dbg mode,
2171 // let's just (re)count them
2172 const dof_id_type n_constraint_rows = mesh.count_constraint_rows();
2173#endif
2174
2175 connected_elem_set_type elements_to_keep;
2176
2177 // Don't delete elements that we were explicitly told not to
2178 for (const auto & elem : extra_ghost_elem_ids)
2179 {
2180 std::vector<const Elem *> active_family;
2181#ifdef LIBMESH_ENABLE_AMR
2182 if (!elem->subactive())
2183 elem->active_family_tree(active_family);
2184 else
2185#endif
2186 active_family.push_back(elem);
2187
2188 for (const auto & f : active_family)
2189 elements_to_keep.insert(f);
2190 }
2191
2192 // See which elements we still need to keep ghosted, given that
2193 // we're keeping local and unpartitioned elements.
2196 mesh.active_pid_elements_begin(mesh.processor_id()),
2197 mesh.active_pid_elements_end(mesh.processor_id()),
2198 elements_to_keep);
2201 mesh.active_pid_elements_begin(DofObject::invalid_processor_id),
2202 mesh.active_pid_elements_end(DofObject::invalid_processor_id),
2203 elements_to_keep);
2204
2205 // The inactive elements we need to send should have their
2206 // immediate children present.
2207 connect_children(mesh, mesh.pid_elements_begin(mesh.processor_id()),
2208 mesh.pid_elements_end(mesh.processor_id()),
2209 elements_to_keep);
2211 mesh.pid_elements_begin(DofObject::invalid_processor_id),
2212 mesh.pid_elements_end(DofObject::invalid_processor_id),
2213 elements_to_keep);
2214
2215 // And see which elements and nodes they depend on
2216 connected_node_set_type connected_nodes;
2217 connect_element_dependencies(mesh, elements_to_keep, connected_nodes);
2218
2219 // Delete all the elements we have no reason to save,
2220 // starting with the most refined so that the mesh
2221 // is valid at all intermediate steps
2222 unsigned int n_levels = MeshTools::n_levels(mesh);
2223
2224 for (int l = n_levels - 1; l >= 0; --l)
2225 for (auto & elem : as_range(mesh.level_elements_begin(l),
2226 mesh.level_elements_end(l)))
2227 {
2228 libmesh_assert (elem);
2229 // Make sure we don't leave any invalid pointers
2230 const bool keep_me = elements_to_keep.count(elem);
2231
2232 if (!keep_me)
2233 elem->make_links_to_me_remote();
2234
2235 // delete_elem doesn't currently invalidate element
2236 // iterators... that had better not change
2237 if (!keep_me)
2238 mesh.delete_elem(elem);
2239 }
2240
2241 // Delete all the nodes we have no reason to save
2242 for (auto & node : mesh.node_ptr_range())
2243 {
2244 libmesh_assert(node);
2245 if (!connected_nodes.count(node))
2246 {
2247 libmesh_assert_not_equal_to(node->processor_id(),
2248 mesh.processor_id());
2249 mesh.delete_node(node);
2250 }
2251 }
2252
2253 // If we had a point locator, it's invalid now that some of the
2254 // elements it pointed to have been deleted.
2256
2257 // We now have all remote elements and nodes deleted; our ghosting
2258 // functors should be ready to delete any now-redundant cached data
2259 // they use too.
2260 for (auto & gf : as_range(mesh.ghosting_functors_begin(), mesh.ghosting_functors_end()))
2262
2263#ifdef DEBUG
2264 const dof_id_type n_new_constraint_rows = mesh.count_constraint_rows();
2265 libmesh_assert_equal_to(n_constraint_rows, n_new_constraint_rows);
2266
2269#endif
2270}
timpi_pure bool verify(const T &r) const
virtual bool is_serial() const
Definition mesh_base.h:365
virtual void delete_node(Node *n)=0
Removes the Node n from the mesh.
virtual void delete_elem(Elem *e)=0
Removes element e from the mesh.
virtual dof_id_type max_node_id() const =0
virtual dof_id_type max_elem_id() const =0
void clear_point_locator()
Releases the current PointLocator object.
Definition mesh_base.C:1985
dof_id_type count_constraint_rows()
Helper function for subclasses to use to set _n_constraint_rows.
Definition mesh_base.C:2819
void delete_remote_elements(DistributedMesh &, const std::set< Elem * > &) const
This method takes an input DistributedMesh which may be distributed among all the processors.
processor_id_type processor_id() const
void libmesh_assert_valid_constraint_rows(const MeshBase &mesh)
A function for verifying that all mesh constraint rows express relations between nodes and elements t...
void libmesh_assert_valid_refinement_tree(const MeshBase &mesh)
A function for verifying that elements on this processor have valid descendants and consistent active...
Definition mesh_tools.h:685
unsigned int n_levels(const MeshBase &mesh)
Definition mesh_tools.C:889
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.
std::set< const Elem *, CompareElemIdsByLevel > connected_elem_set_type
void query_ghosting_functors(const MeshBase &mesh, processor_id_type pid, MeshBase::const_element_iterator elem_it, MeshBase::const_element_iterator elem_end, connected_elem_set_type &connected_elements)
std::set< const Node * > connected_node_set_type
void connect_element_dependencies(const MeshBase &mesh, connected_elem_set_type &connected_elements, connected_node_set_type &connected_nodes)
void connect_children(const MeshBase &mesh, MeshBase::const_element_iterator elem_it, MeshBase::const_element_iterator elem_end, connected_elem_set_type &connected_elements)

References libMesh::Elem::active_family_tree(), libMesh::as_range(), libMesh::MeshBase::clear_point_locator(), libMesh::ParallelObject::comm(), libMesh::connect_children(), libMesh::connect_element_dependencies(), libMesh::MeshBase::count_constraint_rows(), libMesh::MeshBase::delete_elem(), libMesh::MeshBase::delete_node(), libMesh::MeshBase::ghosting_functors_begin(), libMesh::MeshBase::ghosting_functors_end(), libMesh::DofObject::invalid_processor_id, libMesh::MeshBase::is_serial(), libMesh::libmesh_assert(), libMesh::MeshTools::libmesh_assert_valid_constraint_rows(), libMesh::MeshTools::libmesh_assert_valid_refinement_tree(), libMesh::Elem::make_links_to_me_remote(), libMesh::MeshBase::max_elem_id(), libMesh::MeshBase::max_node_id(), mesh, libMesh::MeshTools::n_levels(), libMesh::DofObject::processor_id(), libMesh::ParallelObject::processor_id(), libMesh::query_ghosting_functors(), libMesh::Elem::subactive(), and libMesh::Parallel::Communicator::verify().

Referenced by libMesh::DistributedMesh::delete_remote_elements().

◆ find_global_indices()

template<typename ForwardIterator >
void libMesh::MeshCommunication::find_global_indices ( const Parallel::Communicator &  communicator,
const libMesh::BoundingBox &  bbox,
const ForwardIterator &  begin,
const ForwardIterator &  end,
std::vector< dof_id_type > &  index_map 
) const

This method determines a globally unique, partition-agnostic index for each object in the input range.

Definition at line 743 of file mesh_communication_global_indices.C.

748{
749 LOG_SCOPE ("find_global_indices()", "MeshCommunication");
750
751 // This method determines partition-agnostic global indices
752 // for nodes and elements.
753
754 // Algorithm:
755 // (1) compute the Hilbert key for each local node/element
756 // (2) perform a parallel sort of the Hilbert key
757 // (3) get the min/max value on each processor
758 // (4) determine the position in the global ranking for
759 // each local object
760 index_map.clear();
761 std::size_t n_objects = std::distance (begin, end);
762 index_map.reserve(n_objects);
763
764 const Point bboxinv = invert_bbox(bbox);
765
766 //-------------------------------------------------------------
767 // (1) compute Hilbert keys
768 // These aren't trivial to compute, and we will need them again.
769 // But the binsort will sort the input vector, trashing the order
770 // that we'd like to rely on. So, two vectors...
771 std::vector<Parallel::DofObjectKey>
772 sorted_hilbert_keys,
773 hilbert_keys;
774 sorted_hilbert_keys.reserve(n_objects);
775 hilbert_keys.reserve(n_objects);
776 {
777 LOG_SCOPE("compute_hilbert_indices()", "MeshCommunication");
778 const processor_id_type my_pid = communicator.rank();
779 for (ForwardIterator it=begin; it!=end; ++it)
780 {
781 const Parallel::DofObjectKey hi(get_dofobject_key (**it, bbox, bboxinv));
782 hilbert_keys.push_back(hi);
783
784 const processor_id_type pid = (*it)->processor_id();
785
786 if (pid == my_pid)
787 sorted_hilbert_keys.push_back(hi);
788
789 // someone needs to take care of unpartitioned objects!
790 if ((my_pid == 0) &&
792 sorted_hilbert_keys.push_back(hi);
793 }
794 }
795
796 //-------------------------------------------------------------
797 // (2) parallel sort the Hilbert keys
798 START_LOG ("parallel_sort()", "MeshCommunication");
799 Parallel::Sort<Parallel::DofObjectKey> sorter (communicator,
800 sorted_hilbert_keys);
801 sorter.sort();
802 STOP_LOG ("parallel_sort()", "MeshCommunication");
803 const std::vector<Parallel::DofObjectKey> & my_bin = sorter.bin();
804
805 // The number of objects in my_bin on each processor
806 std::vector<unsigned int> bin_sizes(communicator.size());
807 communicator.allgather (static_cast<unsigned int>(my_bin.size()), bin_sizes);
808
809 // The offset of my first global index
810 unsigned int my_offset = 0;
811 for (auto pid : make_range(communicator.rank()))
812 my_offset += bin_sizes[pid];
813
814 //-------------------------------------------------------------
815 // (3) get the max value on each processor
816 std::vector<Parallel::DofObjectKey>
817 upper_bounds(1);
818
819 if (!my_bin.empty())
820 upper_bounds[0] = my_bin.back();
821
822 communicator.allgather (upper_bounds, /* identical_buffer_sizes = */ true);
823
824 // Be careful here. The *_upper_bounds will be used to find the processor
825 // a given object belongs to. So, if a processor contains no objects (possible!)
826 // then copy the bound from the lower processor id.
827 for (auto p : IntRange<processor_id_type>(1, communicator.size()))
828 if (!bin_sizes[p]) upper_bounds[p] = upper_bounds[p-1];
829
830
831 //-------------------------------------------------------------
832 // (4) determine the position in the global ranking for
833 // each local object
834 {
835 //----------------------------------------------
836 // all objects, not just local ones
837
838 // Request sets to send to each processor
839 std::map<processor_id_type, std::vector<Parallel::DofObjectKey>>
840 requested_ids;
841 // Results to gather from each processor
842 std::map<processor_id_type, std::vector<dof_id_type>>
843 filled_request;
844
845 // build up list of requests
846 std::vector<Parallel::DofObjectKey>::const_iterator hi =
847 hilbert_keys.begin();
848
849 for (ForwardIterator it = begin; it != end; ++it)
850 {
851 libmesh_assert (hi != hilbert_keys.end());
852
853 std::vector<Parallel::DofObjectKey>::iterator lb =
854 std::lower_bound(upper_bounds.begin(), upper_bounds.end(),
855 *hi);
856
857 const processor_id_type pid =
858 cast_int<processor_id_type>
859 (std::distance (upper_bounds.begin(), lb));
860
861 libmesh_assert_less (pid, communicator.size());
862
863 requested_ids[pid].push_back(*hi);
864
865 ++hi;
866 // go ahead and put pid in index_map, that way we
867 // don't have to repeat the std::lower_bound()
868 index_map.push_back(pid);
869 }
870
871 auto gather_functor =
872 [
873#ifndef NDEBUG
874 & upper_bounds,
875 & communicator,
876#endif
877 & bbox,
878 & my_bin,
879 my_offset
880 ]
881 (processor_id_type, const std::vector<Parallel::DofObjectKey> & keys,
882 std::vector<dof_id_type> & global_ids)
883 {
884 // Ignore unused lambda capture warnings in devel mode
885 libmesh_ignore(bbox);
886
887 // Fill the requests
888 const std::size_t keys_size = keys.size();
889 global_ids.clear();
890 global_ids.reserve(keys_size);
891 for (std::size_t idx=0; idx != keys_size; idx++)
892 {
893 const Parallel::DofObjectKey & hilbert_indices = keys[idx];
894 libmesh_assert_less_equal (hilbert_indices, upper_bounds[communicator.rank()]);
895
896 // find the requested index in my node bin
897 std::vector<Parallel::DofObjectKey>::const_iterator pos =
898 std::lower_bound (my_bin.begin(), my_bin.end(), hilbert_indices);
899 libmesh_assert (pos != my_bin.end());
900#ifdef DEBUG
901 // If we could not find the requested Hilbert index in
902 // my_bin, something went terribly wrong, possibly the
903 // Mesh was displaced differently on different processors,
904 // and therefore the Hilbert indices don't agree.
905 if (*pos != hilbert_indices)
906 {
907 // The input will be hilbert_indices. We convert it
908 // to BitVecType using the operator= provided by the
909 // BitVecType class. BitVecType is a CBigBitVec!
910 Hilbert::BitVecType input;
911#ifdef LIBMESH_ENABLE_UNIQUE_ID
912 input = hilbert_indices.first;
913#else
914 input = hilbert_indices;
915#endif
916
917 // Get output in a vector of CBigBitVec
918 std::vector<CBigBitVec> output(3);
919
920 // Call the indexToCoords function
921 Hilbert::indexToCoords(output.data(), 8*sizeof(Hilbert::inttype), 3, input);
922
923 // The entries in the output racks are integers in the
924 // range [0, Hilbert::inttype::max] which can be
925 // converted to floating point values in [0,1] and
926 // finally to actual values using the bounding box.
927 const Real max_int_as_real =
928 static_cast<Real>(std::numeric_limits<Hilbert::inttype>::max());
929
930 // Get the points in [0,1]^3. The zeroth rack of each entry in
931 // 'output' maps to the normalized x, y, and z locations,
932 // respectively.
933 Point p_hat(static_cast<Real>(output[0].racks()[0]) / max_int_as_real,
934 static_cast<Real>(output[1].racks()[0]) / max_int_as_real,
935 static_cast<Real>(output[2].racks()[0]) / max_int_as_real);
936
937 // Convert the points from [0,1]^3 to their actual (x,y,z) locations
938 Real
939 xmin = bbox.first(0),
940 xmax = bbox.second(0),
941 ymin = bbox.first(1),
942 ymax = bbox.second(1),
943 zmin = bbox.first(2),
944 zmax = bbox.second(2);
945
946 // Convert the points from [0,1]^3 to their actual (x,y,z) locations
947 Point p(xmin + (xmax-xmin)*p_hat(0),
948 ymin + (ymax-ymin)*p_hat(1),
949 zmin + (zmax-zmin)*p_hat(2));
950
951 libmesh_error_msg("Could not find hilbert indices: "
952 << hilbert_indices
953 << " corresponding to point " << p);
954 }
955#endif
956
957 // Finally, assign the global index based off the position of the index
958 // in my array, properly offset.
959 global_ids.push_back (cast_int<dof_id_type>(std::distance(my_bin.begin(), pos) + my_offset));
960 }
961 };
962
963 auto action_functor =
964 [&filled_request]
966 const std::vector<Parallel::DofObjectKey> &,
967 const std::vector<dof_id_type> & global_ids)
968 {
969 filled_request[pid] = global_ids;
970 };
971
972 const dof_id_type * ex = nullptr;
974 (communicator, requested_ids, gather_functor, action_functor, ex);
975
976 // We now have all the filled requests, so we can loop through our
977 // nodes once and assign the global index to each one.
978 {
979 std::vector<std::vector<dof_id_type>::const_iterator>
980 next_obj_on_proc; next_obj_on_proc.reserve(communicator.size());
981 for (auto pid : make_range(communicator.size()))
982 next_obj_on_proc.push_back(filled_request[pid].begin());
983
984 unsigned int cnt=0;
985 for (ForwardIterator it = begin; it != end; ++it, cnt++)
986 {
987 const processor_id_type pid = cast_int<processor_id_type>
988 (index_map[cnt]);
989
990 libmesh_assert_less (pid, communicator.size());
991 libmesh_assert (next_obj_on_proc[pid] != filled_request[pid].end());
992
993 const dof_id_type global_index = *next_obj_on_proc[pid];
994 index_map[cnt] = global_index;
995
996 ++next_obj_on_proc[pid];
997 }
998 }
999 }
1000
1001 libmesh_assert_equal_to(index_map.size(), n_objects);
1002}
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
Definition int_range.h:54
void libmesh_ignore(const Args &...)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::Parallel::Sort< KeyType, IdxType >::bin(), libMesh::DofObject::invalid_processor_id, libMesh::libmesh_assert(), libMesh::libmesh_ignore(), libMesh::make_range(), TIMPI::pull_parallel_vector_data(), libMesh::Real, and libMesh::Parallel::Sort< KeyType, IdxType >::sort().

Referenced by libMesh::ParmetisPartitioner::initialize(), libMesh::MetisPartitioner::partition_range(), and libMesh::Partitioner::partition_unpartitioned_elements().

◆ find_local_indices()

template<typename ForwardIterator >
void libMesh::MeshCommunication::find_local_indices ( const libMesh::BoundingBox &  bbox,
const ForwardIterator &  begin,
const ForwardIterator &  end,
std::unordered_map< dof_id_type, dof_id_type > &  index_map 
) const

This method determines a locally unique, contiguous index for each object in the input range.

Definition at line 705 of file mesh_communication_global_indices.C.

709{
710 LOG_SCOPE ("find_local_indices()", "MeshCommunication");
711
712 // This method determines id-agnostic local indices
713 // for nodes and elements by sorting Hilbert keys.
714
715 index_map.clear();
716
717 const Point bboxinv = invert_bbox(bbox);
718
719 //-------------------------------------------------------------
720 // (1) compute Hilbert keys
721 // These aren't trivial to compute, and we will need them again.
722 // But the binsort will sort the input vector, trashing the order
723 // that we'd like to rely on. So, two vectors...
724 std::map<Parallel::DofObjectKey, dof_id_type> hilbert_keys;
725 {
726 LOG_SCOPE("local_hilbert_indices", "MeshCommunication");
727 for (ForwardIterator it=begin; it!=end; ++it)
728 {
729 const Parallel::DofObjectKey hi(get_dofobject_key ((**it), bbox, bboxinv));
730 hilbert_keys.emplace(hi, (*it)->id());
731 }
732 }
733
734 {
735 dof_id_type cnt = 0;
736 for (auto key_val : hilbert_keys)
737 index_map[key_val.second] = cnt++;
738 }
739}

Referenced by libMesh::Partitioner::_find_global_index_by_pid_map().

◆ gather()

void libMesh::MeshCommunication::gather ( const processor_id_type  root_id,
MeshBase &  mesh 
) const

This method takes an input DistributedMesh which may be distributed among all the processors.

Each processor then sends its local nodes and elements to processor root_id. The end result is that a previously distributed DistributedMesh will be serialized on processor root_id. Since this method is collective it must be called by all processors. For the special case of root_id equal to DofObject::invalid_processor_id this function performs an allgather.

Definition at line 1319 of file mesh_communication.C.

1320{
1321 // no MPI == one processor, no need for this method...
1322 return;
1323}

Referenced by allgather(), and libMesh::DistributedMesh::gather_to_zero().

◆ gather_neighboring_elements()

void libMesh::MeshCommunication::gather_neighboring_elements ( DistributedMesh &  mesh) const

Definition at line 670 of file mesh_communication.C.

671{
672 // no MPI == one processor, no need for this method...
673 return;
674}

Referenced by libMesh::Nemesis_IO::read().

◆ make_elems_parallel_consistent()

void libMesh::MeshCommunication::make_elems_parallel_consistent ( MeshBase &  mesh)

Copy ids of ghost elements from their local processors.

Definition at line 1807 of file mesh_communication.C.

1808{
1809 // This function must be run on all processors at once
1810 libmesh_parallel_only(mesh.comm());
1811
1812 LOG_SCOPE ("make_elems_parallel_consistent()", "MeshCommunication");
1813
1814 SyncIds syncids(mesh, &MeshBase::renumber_elem);
1816 (mesh, mesh.active_elements_begin(),
1817 mesh.active_elements_end(), syncids);
1818
1819#ifdef LIBMESH_ENABLE_UNIQUE_ID
1820 SyncUniqueIds<Elem> syncuniqueids(mesh, &MeshBase::query_elem_ptr);
1822 (mesh.comm(), mesh.active_elements_begin(),
1823 mesh.active_elements_end(), syncuniqueids);
1824#endif
1825}
virtual void renumber_elem(dof_id_type old_id, dof_id_type new_id)=0
Changes the id of element old_id, both by changing elem(old_id)->id() and by moving elem(old_id) in t...
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
void sync_element_data_by_parent_id(MeshBase &mesh, const Iterator &range_begin, const Iterator &range_end, SyncFunctor &sync)
Request data about a range of ghost elements uniquely identified by their parent id and which child t...
void sync_dofobject_data_by_id(const Communicator &comm, const Iterator &range_begin, const Iterator &range_end, SyncFunctor &sync)
Request data about a range of ghost dofobjects uniquely identified by their id.

References libMesh::ParallelObject::comm(), mesh, libMesh::MeshBase::query_elem_ptr(), libMesh::MeshBase::renumber_elem(), libMesh::Parallel::sync_dofobject_data_by_id(), and libMesh::Parallel::sync_element_data_by_parent_id().

Referenced by libMesh::MeshRefinement::_refine_elements().

◆ make_new_node_proc_ids_parallel_consistent()

void libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent ( MeshBase &  mesh)

Assuming all processor ids on nodes touching local elements are parallel consistent, this function makes processor ids on new nodes on other processors parallel consistent as well.

Definition at line 1987 of file mesh_communication.C.

1988{
1989 LOG_SCOPE ("make_new_node_proc_ids_parallel_consistent()", "MeshCommunication");
1990
1991 // This function must be run on all processors at once
1992 libmesh_parallel_only(mesh.comm());
1993
1994 // When this function is called, each section of a parallelized mesh
1995 // should be in the following state:
1996 //
1997 // Local nodes should have unique authoritative ids,
1998 // and new nodes should be unpartitioned.
1999 //
2000 // New ghost nodes touching local elements should be unpartitioned.
2001
2002 // We may not have consistent processor ids for new nodes (because a
2003 // node may be old and partitioned on one processor but new and
2004 // unpartitioned on another) when we start
2005#ifdef DEBUG
2007 // MeshTools::libmesh_assert_parallel_consistent_new_node_procids(mesh);
2008#endif
2009
2010 // We have two kinds of new nodes. *NEW* nodes are unpartitioned on
2011 // all processors: we need to use a id-independent (i.e. dumb)
2012 // heuristic to partition them. But "new" nodes are newly created
2013 // on some processors (when ghost elements are refined) yet
2014 // correspond to existing nodes on other processors: we need to use
2015 // the existing processor id for them.
2016 //
2017 // A node which is "new" on one processor will be associated with at
2018 // least one ghost element, and we can just query that ghost
2019 // element's owner to find out the correct processor id.
2020
2021 auto node_unpartitioned =
2022 [](const Elem * elem, unsigned int local_node_num)
2023 { return elem->node_ref(local_node_num).processor_id() ==
2025
2026 SyncProcIds sync(mesh);
2027
2029 (mesh, mesh.not_local_elements_begin(),
2030 mesh.not_local_elements_end(), Parallel::SyncEverything(),
2031 node_unpartitioned, sync);
2032
2033 // Nodes should now be unpartitioned iff they are truly new; those
2034 // are the *only* nodes we will touch.
2035#ifdef DEBUG
2037#endif
2038
2039 NodeWasNew node_was_new(mesh);
2040
2041 // Set the lowest processor id we can on truly new nodes
2042 for (auto & elem : mesh.element_ptr_range())
2043 for (auto & node : elem->node_ref_range())
2044 if (node_was_new.was_new.count(&node))
2045 {
2046 processor_id_type & pid = node.processor_id();
2047 pid = std::min(pid, elem->processor_id());
2048 }
2049
2050 // Then finally see if other processors have a lower option
2052 (mesh, mesh.elements_begin(), mesh.elements_end(),
2053 ElemNodesMaybeNew(), node_was_new, sync);
2054
2055 // We should have consistent processor ids when we're done.
2056#ifdef DEBUG
2059#endif
2060}
processor_id_type processor_id() const
Definition dof_object.h:895
This is the base class from which all geometric element types are derived.
Definition elem.h:96
const Node & node_ref(const unsigned int i) const
Definition elem.h:2659
std::unordered_set< const Node * > was_new
void libmesh_assert_parallel_consistent_new_node_procids(const MeshBase &mesh)
A function for verifying that processor assignment is parallel consistent (every processor agrees on ...
void libmesh_assert_parallel_consistent_procids< Node >(const MeshBase &mesh)
bool sync_node_data_by_element_id_once(MeshBase &mesh, const MeshBase::const_element_iterator &range_begin, const MeshBase::const_element_iterator &range_end, const ElemCheckFunctor &elem_check, const NodeCheckFunctor &node_check, SyncFunctor &sync)
Synchronize data about a range of ghost nodes uniquely identified by an element id and local node id,...
void sync_node_data_by_element_id(MeshBase &mesh, const MeshBase::const_element_iterator &range_begin, const MeshBase::const_element_iterator &range_end, const ElemCheckFunctor &elem_check, const NodeCheckFunctor &node_check, SyncFunctor &sync)
Synchronize data about a range of ghost nodes uniquely identified by an element id and local node id,...

References libMesh::ParallelObject::comm(), libMesh::DofObject::invalid_processor_id, libMesh::MeshTools::libmesh_assert_parallel_consistent_new_node_procids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), mesh, libMesh::Elem::node_ref(), libMesh::Elem::node_ref_range(), libMesh::DofObject::processor_id(), and libMesh::Parallel::sync_node_data_by_element_id().

Referenced by make_new_nodes_parallel_consistent().

◆ make_new_nodes_parallel_consistent()

void libMesh::MeshCommunication::make_new_nodes_parallel_consistent ( MeshBase &  mesh)

Copy processor_ids and ids on new nodes from their local processors.

Definition at line 2110 of file mesh_communication.C.

2111{
2112 // This function must be run on all processors at once
2113 libmesh_parallel_only(mesh.comm());
2114
2115 // When this function is called, each section of a parallelized mesh
2116 // should be in the following state:
2117 //
2118 // All nodes should have the exact same physical location on every
2119 // processor where they exist.
2120 //
2121 // Local nodes should have unique authoritative ids,
2122 // and new nodes should be unpartitioned.
2123 //
2124 // New ghost nodes touching local elements should be unpartitioned.
2125 //
2126 // New ghost nodes should have ids which are either already correct
2127 // or which are in the "unpartitioned" id space.
2128 //
2129 // Non-new nodes should have correct ids and processor ids already.
2130
2131 // First, let's sync up new nodes' processor ids.
2132
2134
2135 // Second, sync up dofobject ids.
2137
2138 // Third, sync up dofobject unique_ids if applicable.
2140
2141 // Fourth, sync up any nodal boundary conditions
2143
2144 // Finally, correct the processor ids to make DofMap happy
2146}
void make_node_unique_ids_parallel_consistent(MeshBase &)
Assuming all unique_ids on local nodes are globally unique, and assuming all processor ids are parall...
void make_node_bcids_parallel_consistent(MeshBase &)
Assuming all processor ids are parallel consistent, this function makes all ghost boundary ids on nod...
void make_node_ids_parallel_consistent(MeshBase &)
Assuming all ids on local nodes are globally unique, and assuming all processor ids are parallel cons...
void make_new_node_proc_ids_parallel_consistent(MeshBase &)
Assuming all processor ids on nodes touching local elements are parallel consistent,...
void correct_node_proc_ids(MeshBase &)
Changes the processor ids on each node so be the same as the id of the lowest element touching that n...

References libMesh::ParallelObject::comm(), libMesh::MeshTools::correct_node_proc_ids(), make_new_node_proc_ids_parallel_consistent(), make_node_bcids_parallel_consistent(), make_node_ids_parallel_consistent(), make_node_unique_ids_parallel_consistent(), and mesh.

Referenced by libMesh::MeshRefinement::_refine_elements().

◆ make_node_bcids_parallel_consistent()

void libMesh::MeshCommunication::make_node_bcids_parallel_consistent ( MeshBase &  mesh)

Assuming all processor ids are parallel consistent, this function makes all ghost boundary ids on nodes parallel consistent.

Definition at line 1785 of file mesh_communication.C.

1786{
1787 // Avoid unused variable warnings if unique ids aren't enabled.
1789
1790 // This function must be run on all processors at once
1791 libmesh_parallel_only(mesh.comm());
1792
1793 LOG_SCOPE ("make_node_bcids_parallel_consistent()", "MeshCommunication");
1794
1795 SyncBCIds<Node> syncbcids(mesh);
1797 mesh.nodes_begin(),
1798 mesh.nodes_end(),
1799 syncbcids);
1800}

References libMesh::ParallelObject::comm(), libMesh::libmesh_ignore(), mesh, and libMesh::Parallel::sync_dofobject_data_by_id().

Referenced by make_new_nodes_parallel_consistent().

◆ make_node_ids_parallel_consistent()

void libMesh::MeshCommunication::make_node_ids_parallel_consistent ( MeshBase &  mesh)

Assuming all ids on local nodes are globally unique, and assuming all processor ids are parallel consistent, this function makes all other ids parallel consistent.

Definition at line 1735 of file mesh_communication.C.

1736{
1737 // This function must be run on all processors at once
1738 libmesh_parallel_only(mesh.comm());
1739
1740 // We need to agree on which processor owns every node, but we can't
1741 // easily assert that here because we don't currently agree on which
1742 // id every node has, and some of our temporary ids on unrelated
1743 // nodes will "overlap".
1744//#ifdef DEBUG
1745// MeshTools::libmesh_assert_parallel_consistent_procids<Node> (mesh);
1746//#endif // DEBUG
1747
1748 LOG_SCOPE ("make_node_ids_parallel_consistent()", "MeshCommunication");
1749
1750 SyncNodeIds syncids(mesh);
1752 (mesh, mesh.elements_begin(), mesh.elements_end(),
1754
1755 // At this point, with both ids and processor ids synced, we can
1756 // finally check for topological consistency of node processor ids.
1757#ifdef DEBUG
1759#endif
1760}
void libmesh_assert_topology_consistent_procids< Node >(const MeshBase &mesh)

References libMesh::ParallelObject::comm(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), mesh, and libMesh::Parallel::sync_node_data_by_element_id().

Referenced by make_new_nodes_parallel_consistent(), make_nodes_parallel_consistent(), and libMesh::SimplexRefiner::refine_via_edges().

◆ make_node_proc_ids_parallel_consistent()

void libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent ( MeshBase &  mesh)

Assuming all processor ids on nodes touching local elements are parallel consistent, this function makes all other processor ids parallel consistent as well.

Definition at line 1958 of file mesh_communication.C.

1959{
1960 LOG_SCOPE ("make_node_proc_ids_parallel_consistent()", "MeshCommunication");
1961
1962 // This function must be run on all processors at once
1963 libmesh_parallel_only(mesh.comm());
1964
1965 // When this function is called, each section of a parallelized mesh
1966 // should be in the following state:
1967 //
1968 // All nodes should have the exact same physical location on every
1969 // processor where they exist.
1970 //
1971 // Local nodes should have unique authoritative ids,
1972 // and processor ids consistent with all processors which own
1973 // an element touching them.
1974 //
1975 // Ghost nodes touching local elements should have processor ids
1976 // consistent with all processors which own an element touching
1977 // them.
1978 SyncProcIds sync(mesh);
1980 (mesh, mesh.elements_begin(), mesh.elements_end(),
1982}

References libMesh::ParallelObject::comm(), mesh, and libMesh::Parallel::sync_node_data_by_element_id().

Referenced by make_nodes_parallel_consistent(), and libMesh::SimplexRefiner::refine_via_edges().

◆ make_node_unique_ids_parallel_consistent()

void libMesh::MeshCommunication::make_node_unique_ids_parallel_consistent ( MeshBase &  mesh)

Assuming all unique_ids on local nodes are globally unique, and assuming all processor ids are parallel consistent, this function makes all ghost unique_ids parallel consistent.

Definition at line 1764 of file mesh_communication.C.

1765{
1766 // Avoid unused variable warnings if unique ids aren't enabled.
1768
1769 // This function must be run on all processors at once
1770 libmesh_parallel_only(mesh.comm());
1771
1772#ifdef LIBMESH_ENABLE_UNIQUE_ID
1773 LOG_SCOPE ("make_node_unique_ids_parallel_consistent()", "MeshCommunication");
1774
1775 SyncUniqueIds<Node> syncuniqueids(mesh, &MeshBase::query_node_ptr);
1777 mesh.nodes_begin(),
1778 mesh.nodes_end(),
1779 syncuniqueids);
1780
1781#endif
1782}
virtual const Node * query_node_ptr(const dof_id_type i) const =0

References libMesh::ParallelObject::comm(), libMesh::libmesh_ignore(), mesh, libMesh::MeshBase::query_node_ptr(), and libMesh::Parallel::sync_dofobject_data_by_id().

Referenced by libMesh::BoundaryInfo::add_elements(), make_new_nodes_parallel_consistent(), make_nodes_parallel_consistent(), libMesh::Nemesis_IO::read(), and libMesh::SimplexRefiner::refine_via_edges().

◆ make_nodes_parallel_consistent()

void libMesh::MeshCommunication::make_nodes_parallel_consistent ( MeshBase &  mesh)

Copy processor_ids and ids on ghost nodes from their local processors.

This is useful for code which wants to add nodes to a distributed mesh.

Definition at line 2065 of file mesh_communication.C.

2066{
2067 // This function must be run on all processors at once
2068 libmesh_parallel_only(mesh.comm());
2069
2070 // When this function is called, each section of a parallelized mesh
2071 // should be in the following state:
2072 //
2073 // Element ids and locations should be consistent on every processor
2074 // where they exist.
2075 //
2076 // All nodes should have the exact same physical location on every
2077 // processor where they exist.
2078 //
2079 // Local nodes should have unique authoritative ids,
2080 // and processor ids consistent with all processors which own
2081 // an element touching them.
2082 //
2083 // Ghost nodes touching local elements should have processor ids
2084 // consistent with all processors which own an element touching
2085 // them.
2086 //
2087 // Ghost nodes should have ids which are either already correct
2088 // or which are in the "unpartitioned" id space.
2089
2090 // First, let's sync up processor ids. Some of these processor ids
2091 // may be "wrong" from coarsening, but they're right in the sense
2092 // that they'll tell us who has the authoritative dofobject ids for
2093 // each node.
2094
2096
2097 // Second, sync up dofobject ids.
2099
2100 // Third, sync up dofobject unique_ids if applicable.
2102
2103 // Finally, correct the processor ids to make DofMap happy
2105}
void make_node_proc_ids_parallel_consistent(MeshBase &)
Assuming all processor ids on nodes touching local elements are parallel consistent,...

References libMesh::ParallelObject::comm(), libMesh::MeshTools::correct_node_proc_ids(), make_node_ids_parallel_consistent(), make_node_proc_ids_parallel_consistent(), make_node_unique_ids_parallel_consistent(), and mesh.

Referenced by libMesh::MeshRefinement::_coarsen_elements(), and libMesh::MeshTools::Modification::all_tri().

◆ make_p_levels_parallel_consistent()

void libMesh::MeshCommunication::make_p_levels_parallel_consistent ( MeshBase &  mesh)

Copy p levels of ghost elements from their local processors.

Definition at line 1831 of file mesh_communication.C.

1832{
1833 // This function must be run on all processors at once
1834 libmesh_parallel_only(mesh.comm());
1835
1836 LOG_SCOPE ("make_p_levels_parallel_consistent()", "MeshCommunication");
1837
1838 SyncPLevels syncplevels(mesh);
1840 (mesh.comm(), mesh.elements_begin(), mesh.elements_end(),
1841 syncplevels);
1842}

References libMesh::ParallelObject::comm(), mesh, and libMesh::Parallel::sync_dofobject_data_by_id().

Referenced by libMesh::MeshRefinement::_coarsen_elements(), and libMesh::MeshRefinement::_refine_elements().

◆ redistribute()

void libMesh::MeshCommunication::redistribute ( DistributedMesh &  mesh,
bool  newly_coarsened_only = false 
) const

This method takes a parallel distributed mesh and redistributes the elements.

Specifically, any elements stored on a given processor are sent to the processor which "owns" them. Similarly, any elements assigned to the current processor but stored on another are received. Once this step is completed any required ghost elements are updated. The final result is that each processor stores only the elements it actually owns and any ghost elements required to satisfy data dependencies. This method can be invoked after a partitioning step to affect the new partitioning.

Redistribution can also be done with newly coarsened elements' neighbors only.

Definition at line 433 of file mesh_communication.C.

434{
435 // no MPI == one processor, no redistribution
436 return;
437}

Referenced by libMesh::DistributedMesh::redistribute().

◆ send_coarse_ghosts()

void libMesh::MeshCommunication::send_coarse_ghosts ( MeshBase &  mesh) const

Examine a just-coarsened mesh, and for any newly-coarsened elements, send the associated ghosted elements to the processor which needs them.

Definition at line 1049 of file mesh_communication.C.

1050{
1051 // no MPI == one processor, no need for this method...
1052 return;
1053}

Referenced by libMesh::MeshRefinement::_coarsen_elements().


The documentation for this class was generated from the following files: