libMesh
distributed_mesh.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_DISTRIBUTED_MESH_H
21 #define LIBMESH_DISTRIBUTED_MESH_H
22 
23 // Local Includes
24 #include "libmesh_config.h"
25 
26 #if LIBMESH_MAPVECTOR_CHUNK_SIZE == 1
27 # include "libmesh/mapvector.h"
28 #else
29 # include "libmesh/chunked_mapvector.h"
30 #endif
31 
32 #include "libmesh/unstructured_mesh.h"
33 
34 // C++ Includes
35 #include <cstddef>
36 #include <memory>
37 #include <set>
38 
39 namespace libMesh
40 {
41 
42 // Forward declarations
43 class Elem;
44 class Node;
45 
46 
58 {
59 public:
60 
61  template <typename Obj>
62 #if LIBMESH_MAPVECTOR_CHUNK_SIZE == 1
64 #else
66 #endif
67 
73  explicit
74  DistributedMesh (const Parallel::Communicator & comm_in,
75  unsigned char dim=1);
76 
81  DistributedMesh (const UnstructuredMesh & other_mesh);
82 
87  DistributedMesh (const DistributedMesh & other_mesh);
88 
92  DistributedMesh(DistributedMesh &&) = delete;
93 
97  DistributedMesh & operator= (const DistributedMesh &) = delete;
98 
103  DistributedMesh & operator= (DistributedMesh && other_mesh);
104 
108  virtual MeshBase & assign(MeshBase && other_mesh) override;
109 
114  virtual bool subclass_locally_equals (const MeshBase & other_mesh) const override;
115 
119  virtual std::unique_ptr<MeshBase> clone () const override
120  { return std::make_unique<DistributedMesh>(*this); }
121 
125  virtual ~DistributedMesh();
126 
130  virtual void clear() override;
131 
135  virtual void clear_elems() override;
136 
142  virtual void redistribute () override;
143 
148  virtual void update_post_partitioning () override;
149 
154  virtual bool is_serial () const override final
155  { return _is_serial; }
156 
161  virtual bool is_serial_on_zero () const override final
162  { return _is_serial || _is_serial_on_proc_0; }
163 
168  virtual void set_distributed () override final
169  { _is_serial = false;
170  _is_serial_on_proc_0 = false; }
171 
176  virtual bool is_replicated () const override final
177  { return false; }
178 
184  template <typename T>
185  void libmesh_assert_valid_parallel_object_ids(const dofobject_container<T> &) const;
186 
192  virtual void libmesh_assert_valid_parallel_ids() const override;
193 
199 
206 
212  template <typename T>
213  dof_id_type renumber_dof_objects (dofobject_container<T> &);
214 
218  virtual void renumber_nodes_and_elements () override;
219 
224  virtual void allgather() override;
225 
230  virtual void gather_to_zero() override;
231 
237  virtual void delete_remote_elements() override;
238 
246  virtual void add_extra_ghost_elem(Elem * e);
247 
251  virtual void clear_extra_ghost_elems() { _extra_ghost_elems.clear(); }
252 
256  virtual void clear_extra_ghost_elems(const std::set<Elem *> & extra_ghost_elems);
257 
261  const std::set<Elem *> & extra_ghost_elems() const { return _extra_ghost_elems; }
262 
263  // Cached methods that can be called in serial
264  virtual dof_id_type n_nodes () const override final { return _n_nodes; }
265  virtual dof_id_type max_node_id () const override final { return _max_node_id; }
266  virtual void reserve_nodes (const dof_id_type) override final {}
267  virtual dof_id_type n_elem () const override final { return _n_elem; }
268  virtual dof_id_type n_active_elem () const override final;
269  virtual dof_id_type max_elem_id () const override final { return _max_elem_id; }
270  virtual void reserve_elem (const dof_id_type) override final {}
271 
272  // Parallel only method to update the caches
273  virtual void update_parallel_id_counts () override;
274 
275  // And more parallel only methods to test non-cached values
276  virtual dof_id_type parallel_n_nodes () const override;
278  virtual dof_id_type parallel_n_elem () const override;
280 
281 #ifdef LIBMESH_ENABLE_UNIQUE_ID
282  virtual unique_id_type parallel_max_unique_id () const override;
283  virtual void set_next_unique_id(unique_id_type id) override;
284 #endif
285 
286  virtual const Point & point (const dof_id_type i) const override final;
287 
288  virtual const Node * node_ptr (const dof_id_type i) const override final;
289  virtual Node * node_ptr (const dof_id_type i) override final;
290 
291  virtual const Node * query_node_ptr (const dof_id_type i) const override final;
292  virtual Node * query_node_ptr (const dof_id_type i) override final;
293 
294  virtual const Elem * elem_ptr (const dof_id_type i) const override final;
295  virtual Elem * elem_ptr (const dof_id_type i) override final;
296 
297  virtual const Elem * query_elem_ptr (const dof_id_type i) const override final;
298  virtual Elem * query_elem_ptr (const dof_id_type i) override final;
299 
303  virtual Node * add_point (const Point & p,
305  const processor_id_type proc_id = DofObject::invalid_processor_id) override final;
306  virtual Node * add_node (Node * n) override final;
307  virtual Node * add_node (std::unique_ptr<Node> n) override final;
308 
309 #ifdef LIBMESH_ENABLE_DEPRECATED
310 
314  virtual Node * insert_node(Node * n) override final;
315  virtual Node * insert_node(std::unique_ptr<Node> n) override final;
316 #endif
317 
324  virtual void own_node (Node & n) override final;
325 
326  virtual void delete_node (Node * n) override final;
327  virtual void renumber_node (dof_id_type old_id, dof_id_type new_id) override final;
328  virtual Elem * add_elem (Elem * e) override final;
329  virtual Elem * add_elem (std::unique_ptr<Elem> e) override final;
330  virtual Elem * insert_elem (Elem * e) override final;
331  virtual Elem * insert_elem (std::unique_ptr<Elem> e) override final;
332  virtual void delete_elem (Elem * e) override final;
333  virtual void renumber_elem (dof_id_type old_id, dof_id_type new_id) override final;
334 
341  virtual void fix_broken_node_and_element_numbering () override;
342 
343 public:
349  DECLARE_ELEM_ITERATORS(active_,,);
350  DECLARE_ELEM_ITERATORS(ancestor_,,)
351  DECLARE_ELEM_ITERATORS(subactive_,,)
352  DECLARE_ELEM_ITERATORS(local_,,)
353  DECLARE_ELEM_ITERATORS(unpartitioned_,,)
354  DECLARE_ELEM_ITERATORS(facelocal_,,)
355  DECLARE_ELEM_ITERATORS(level_, unsigned int level, level)
358 
359  DECLARE_ELEM_ITERATORS(active_subdomain_, subdomain_id_type sid, sid)
360  DECLARE_ELEM_ITERATORS(active_subdomain_set_, std::set<subdomain_id_type> ss, ss)
361 
362  // Backwards compatibility
363  virtual SimpleRange<element_iterator> active_subdomain_elements_ptr_range(subdomain_id_type sid) override final { return active_subdomain_element_ptr_range(sid); }
364  virtual SimpleRange<const_element_iterator> active_subdomain_elements_ptr_range(subdomain_id_type sid) const override final { return active_subdomain_element_ptr_range(sid); }
365  virtual SimpleRange<element_iterator> active_local_subdomain_elements_ptr_range(subdomain_id_type sid) override final { return active_local_subdomain_element_ptr_range(sid); }
366  virtual SimpleRange<const_element_iterator> active_local_subdomain_elements_ptr_range(subdomain_id_type sid) const override final { return active_local_subdomain_element_ptr_range(sid); }
367  virtual SimpleRange<element_iterator> active_subdomain_set_elements_ptr_range(std::set<subdomain_id_type> ss) override final { return active_subdomain_set_element_ptr_range(ss); }
368  virtual SimpleRange<const_element_iterator> active_subdomain_set_elements_ptr_range(std::set<subdomain_id_type> ss) const override final { return active_subdomain_set_element_ptr_range(ss); }
369 
370  DECLARE_ELEM_ITERATORS(not_active_,,);
371  DECLARE_ELEM_ITERATORS(not_ancestor_,,);
372  DECLARE_ELEM_ITERATORS(not_subactive_,,);
373  DECLARE_ELEM_ITERATORS(not_local_,,);
374  DECLARE_ELEM_ITERATORS(not_level_, unsigned int level, level)
375 
376  DECLARE_ELEM_ITERATORS(active_local_,,)
377  DECLARE_ELEM_ITERATORS(active_not_local_,,)
378  DECLARE_ELEM_ITERATORS(active_unpartitioned_,,)
379  DECLARE_ELEM_ITERATORS(active_type_, ElemType type, type)
381  DECLARE_ELEM_ITERATORS(local_level_, unsigned int level, level)
382  DECLARE_ELEM_ITERATORS(local_not_level_, unsigned int level, level)
383  DECLARE_ELEM_ITERATORS(active_local_subdomain_, subdomain_id_type sid, sid)
384  DECLARE_ELEM_ITERATORS(active_local_subdomain_set_, std::set<subdomain_id_type> ss, ss)
385 
386  DECLARE_ELEM_ITERATORS(semilocal_,,)
387  DECLARE_ELEM_ITERATORS(ghost_,,)
388  DECLARE_ELEM_ITERATORS(active_semilocal_,,)
389 
390  DECLARE_ELEM_ITERATORS(evaluable_, const DofMap & dof_map LIBMESH_COMMA unsigned int var_num = libMesh::invalid_uint, dof_map LIBMESH_COMMA var_num)
391  DECLARE_ELEM_ITERATORS(multi_evaluable_, std::vector<const DofMap *> dof_maps, dof_maps)
392 
393 #ifdef LIBMESH_ENABLE_AMR
394  DECLARE_ELEM_ITERATORS(flagged_, unsigned char rflag, rflag)
395 
396  // Elem::refinement_flag() == rflag && Elem::processor_id() == pid
397  DECLARE_ELEM_ITERATORS(flagged_pid_, unsigned char rflag LIBMESH_COMMA processor_id_type pid, rflag LIBMESH_COMMA pid)
398 #endif
399 
401  DECLARE_NODE_ITERATORS(active_,,)
402  DECLARE_NODE_ITERATORS(local_,,)
403  DECLARE_NODE_ITERATORS(bnd_,,)
406 
407  DECLARE_NODE_ITERATORS(evaluable_, const DofMap & dof_map LIBMESH_COMMA unsigned int var_num = libMesh::invalid_uint, dof_map LIBMESH_COMMA var_num)
408 
409  DECLARE_NODE_ITERATORS(multi_evaluable_, std::vector<const DofMap *> dof_maps, dof_maps)
410 
411 
412 protected:
413 
417  virtual void move_nodes_and_elements(MeshBase && other_mesh) override;
418 
423 
428 
433 
438 
445 
450 
459 
460 #ifdef LIBMESH_ENABLE_UNIQUE_ID
461 
465 #endif
466 
471  std::set<Elem *> _extra_ghost_elems;
472 
473 private:
474 
480 
486 };
487 
488 
489 } // namespace libMesh
490 
491 #endif // LIBMESH_DISTRIBUTED_MESH_H
The definition of the element_iterator struct.
Definition: mesh_base.h:2103
This mapvector templated class is intended to provide the performance characteristics of a std::map w...
Definition: mapvector.h:42
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id) override final
functions for adding /deleting nodes elements.
ElemType
Defines an enum for geometric element types.
The SimpleRange templated class is intended to make it easy to construct ranges from pairs of iterato...
Definition: simple_range.h:36
virtual void update_parallel_id_counts() override
Updates parallel caches so that methods like n_elem() accurately reflect changes on other processors...
virtual dof_id_type parallel_n_nodes() const override
virtual Elem * add_elem(Elem *e) override final
Add elem e to the end of the element array.
A Node is like a Point, but with more information.
Definition: node.h:52
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition: libmesh.h:286
virtual void libmesh_assert_valid_parallel_ids() const override
Verify id and processor_id consistency of our elements and nodes containers.
virtual void fix_broken_node_and_element_numbering() override
There is no reason for a user to ever call this function.
dofobject_container< Elem >::const_veclike_iterator const_elem_iterator_imp
virtual void set_distributed() override final
Asserts that not all elements and nodes of the mesh necessarily exist on the current processor...
virtual void renumber_elem(dof_id_type old_id, dof_id_type new_id) override final
Changes the id of element old_id, both by changing elem(old_id)->id() and by moving elem(old_id) in t...
unsigned int dim
bool _is_serial_on_proc_0
A boolean remembering whether we&#39;re serialized to proc 0 or not.
dof_id_type _n_nodes
Cached data from the last renumber_nodes_and_elements call.
virtual void clear() override
Clear all internal data.
virtual void renumber_nodes_and_elements() override
Remove nullptr elements from arrays.
virtual SimpleRange< const_element_iterator > active_subdomain_elements_ptr_range(subdomain_id_type sid) const override final
virtual dof_id_type n_nodes() const override final
dof_id_type _next_free_local_node_id
Guaranteed globally unused IDs for use when adding new nodes or elements.
virtual void allgather() override
Gathers all elements and nodes of the mesh onto every processor.
virtual SimpleRange< element_iterator > active_local_subdomain_elements_ptr_range(subdomain_id_type sid) override final
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
bool _is_serial
A boolean remembering whether we&#39;re serialized or not.
void libmesh_assert_valid_parallel_flags() const
Verify refinement_flag and p_refinement_flag consistency of our elements containers.
The libMesh namespace provides an interface to certain functionality in the library.
virtual void delete_elem(Elem *e) override final
Removes element e from the mesh.
virtual void add_extra_ghost_elem(Elem *e)
Inserts the element and adds it to a list of elements that should not get deleted or have their desce...
virtual Node * add_node(Node *n) override final
Add Node n to the end of the vertex array.
virtual const Point & point(const dof_id_type i) const override final
virtual unique_id_type parallel_max_unique_id() const override
dofobject_container< Node >::veclike_iterator node_iterator_imp
Typedefs for the container implementation.
virtual void delete_remote_elements() override
Deletes all nonlocal elements of the mesh except for "ghosts" which touch a local element...
void libmesh_assert_valid_parallel_object_ids(const dofobject_container< T > &) const
Verify id, processor_id, and if applicable unique_id consistency of a parallel objects container...
uint8_t processor_id_type
Definition: id_types.h:104
This is the MeshBase class.
Definition: mesh_base.h:74
void libmesh_assert_valid_parallel_p_levels() const
Verify p_level consistency of our elements containers.
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:169
processor_id_type pid unsigned int level std::set< subdomain_id_type > ss const DofMap &dof_map LIBMESH_COMMA unsigned int dof_map LIBMESH_COMMA var_num unsigned char rflag processor_id_type pid const DofMap &dof_map LIBMESH_COMMA unsigned int dof_map LIBMESH_COMMA var_num DECLARE_NODE_ITERATORS(multi_evaluable_, std::vector< const DofMap * > dof_maps, dof_maps) protected dofobject_container< Node > _nodes
Move node and elements from a DistributedMesh.
virtual const Elem * elem_ptr(const dof_id_type i) const override final
virtual dof_id_type parallel_n_elem() const override
int8_t boundary_id_type
Definition: id_types.h:51
virtual void move_nodes_and_elements(MeshBase &&other_mesh)=0
Move node and elements from other_mesh to this mesh.
static const 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:488
std::set< Elem * > _extra_ghost_elems
These are extra ghost elements that we want to make sure not to delete when we call delete_remote_ele...
The UnstructuredMesh class is derived from the MeshBase class.
processor_id_type pid unsigned int level std::set< subdomain_id_type > ss const DofMap &dof_map LIBMESH_COMMA unsigned int var_num
DECLARE_ELEM_ITERATORS(,,)
Elem and Node iterator accessor functions.
virtual bool is_serial_on_zero() const override final
virtual void set_next_unique_id(unique_id_type id) override
Sets the next available unique id to be used.
virtual void clear_elems() override
Clear internal Elem data.
virtual SimpleRange< const_element_iterator > active_local_subdomain_elements_ptr_range(subdomain_id_type sid) const override final
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:477
virtual void own_node(Node &n) override final
Takes ownership of node n on this partition of a distributed mesh, by setting n.processor_id() to thi...
processor_id_type pid unsigned int level std::set< subdomain_id_type > ss const DofMap &dof_map LIBMESH_COMMA unsigned int dof_map LIBMESH_COMMA var_num unsigned char rflag DECLARE_NODE_ITERATORS(active_,,) DECLARE_NODE_ITERATORS(local_
virtual void clear_extra_ghost_elems()
Clears extra ghost elements.
const std::set< Elem * > & extra_ghost_elems() const
Const accessor to the ghosted elements.
unsigned int level ElemType type std::set< subdomain_id_type > ss
virtual const Node * query_node_ptr(const dof_id_type i) const override final
virtual bool subclass_locally_equals(const MeshBase &other_mesh) const override
Shim to allow operator == (&) to behave like a virtual function without having to be one...
dof_id_type parallel_max_node_id() const
The DistributedMesh class is derived from the MeshBase class, and is intended to provide identical fu...
unsigned int level ElemType type
dof_id_type _next_free_unpartitioned_node_id
dofobject_container< Elem > _elements
The elements in the mesh.
virtual void delete_node(Node *n) override final
Removes the Node n from the mesh.
dofobject_container< Node >::const_veclike_iterator const_node_iterator_imp
virtual SimpleRange< const_element_iterator > active_subdomain_set_elements_ptr_range(std::set< subdomain_id_type > ss) const override final
virtual void renumber_node(dof_id_type old_id, dof_id_type new_id) override final
Changes the id of node old_id, both by changing node(old_id)->id() and by moving node(old_id) in the ...
virtual void redistribute() override
Redistribute elements between processors.
virtual std::unique_ptr< MeshBase > clone() const override
Virtual copy-constructor, creates a copy of this mesh.
DistributedMesh & operator=(const DistributedMesh &)=delete
Copy assignment is not allowed.
virtual dof_id_type n_active_elem() const override final
dof_id_type _next_free_unpartitioned_elem_id
DistributedMesh(const Parallel::Communicator &comm_in, unsigned char dim=1)
Constructor.
virtual bool is_replicated() const override final
virtual void gather_to_zero() override
Gathers all elements and nodes of the mesh onto processor zero.
virtual Elem * insert_elem(Elem *e) override final
Insert elem e to the element array, preserving its id and replacing/deleting any existing element wit...
virtual dof_id_type max_node_id() const override final
This chunked_mapvector templated class is intended to provide the asymptotic performance characterist...
unsigned int level ElemType type std::set< subdomain_id_type > virtual ss SimpleRange< element_iterator > active_subdomain_elements_ptr_range(subdomain_id_type sid) override final
virtual SimpleRange< element_iterator > active_subdomain_set_elements_ptr_range(std::set< subdomain_id_type > ss) override final
virtual void update_post_partitioning() override
Recalculate cached data after elements and nodes have been repartitioned.
unique_id_type _next_unpartitioned_unique_id
The next available unique id for assigning ids to unpartitioned DOF objects.
dofobject_container< Elem >::veclike_iterator elem_iterator_imp
Typedefs for the container implementation.
virtual MeshBase & assign(MeshBase &&other_mesh) override
Shim to call the move assignment operator for this class.
virtual dof_id_type n_elem() const override final
virtual ~DistributedMesh()
Destructor.
virtual Node * insert_node(Node *n) override final
These methods are deprecated.
virtual bool is_serial() const override final
virtual dof_id_type max_elem_id() const override final
dof_id_type _next_free_local_elem_id
processor_id_type pid unsigned int level std::set< subdomain_id_type > ss const DofMap &dof_map LIBMESH_COMMA unsigned int dof_map LIBMESH_COMMA var_num unsigned char rflag
bool _deleted_coarse_elements
A boolean remembering whether we&#39;ve recently deleted top-level elements or not.
virtual void reserve_elem(const dof_id_type) override final
Reserves space for a known number of elements.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
dof_id_type renumber_dof_objects(dofobject_container< T > &)
Renumber a parallel objects container.
uint8_t unique_id_type
Definition: id_types.h:86
dof_id_type parallel_max_elem_id() const
uint8_t dof_id_type
Definition: id_types.h:67
virtual const Node * node_ptr(const dof_id_type i) const override final
virtual void reserve_nodes(const dof_id_type) override final
Reserves space for a known number of nodes.
virtual const Elem * query_elem_ptr(const dof_id_type i) const override final