libMesh
Loading...
Searching...
No Matches
distributed_mesh.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
39namespace libMesh
40{
41
42// Forward declarations
43class Elem;
44class Node;
45
46
58{
59public:
60
61 template <typename Obj>
62#if LIBMESH_MAPVECTOR_CHUNK_SIZE == 1
64#else
66#endif
67
73 explicit
75 unsigned char dim=1);
76
81 DistributedMesh (const MeshBase & other_mesh);
82
87 DistributedMesh (const DistributedMesh & other_mesh);
88
93
98
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 {
121 auto returnval = std::make_unique<DistributedMesh>(*this);
122#ifdef DEBUG
123 libmesh_assert(*returnval == *this);
124#endif
125 return returnval;
126 }
127
131 virtual ~DistributedMesh();
132
136 virtual void clear() override;
137
141 virtual void clear_elems() override;
142
148 virtual void redistribute () override;
149
154 virtual void update_post_partitioning () override;
155
160 virtual bool is_serial () const override final
161 { return _is_serial; }
162
167 virtual bool is_serial_on_zero () const override final
168 { return _is_serial || _is_serial_on_proc_0; }
169
174 virtual void set_distributed () override final
175 { _is_serial = false;
176 _is_serial_on_proc_0 = false; }
177
182 virtual bool is_replicated () const override final
183 { return false; }
184
190 template <typename T>
191 void libmesh_assert_valid_parallel_object_ids(const dofobject_container<T> &) const;
192
198 virtual void libmesh_assert_valid_parallel_ids() const override;
199
205
212
218 template <typename T>
219 dof_id_type renumber_dof_objects (dofobject_container<T> &);
220
224 virtual void renumber_nodes_and_elements () override;
225
230 virtual void allgather() override;
231
236 virtual void gather_to_zero() override;
237
243 virtual void delete_remote_elements() override;
244
252 virtual void add_extra_ghost_elem(Elem * e);
253
257 virtual void clear_extra_ghost_elems() { _extra_ghost_elems.clear(); }
258
262 virtual void clear_extra_ghost_elems(const std::set<Elem *> & extra_ghost_elems);
263
267 const std::set<Elem *> & extra_ghost_elems() const { return _extra_ghost_elems; }
268
269 // Cached methods that can be called in serial
270 virtual dof_id_type n_nodes () const override final { return _n_nodes; }
271 virtual dof_id_type max_node_id () const override final { return _max_node_id; }
272 virtual void reserve_nodes (const dof_id_type) override final {}
273 virtual dof_id_type n_elem () const override final { return _n_elem; }
274 virtual dof_id_type n_active_elem () const override final;
275 virtual dof_id_type max_elem_id () const override final { return _max_elem_id; }
276 virtual void reserve_elem (const dof_id_type) override final {}
277
278 // Parallel only method to update the caches
279 virtual void update_parallel_id_counts () override;
280
281 // And more parallel only methods to test non-cached values
282 virtual dof_id_type parallel_n_nodes () const override;
284 virtual dof_id_type parallel_n_elem () const override;
286
287#ifdef LIBMESH_ENABLE_UNIQUE_ID
288 virtual unique_id_type parallel_max_unique_id () const override;
289 virtual void set_next_unique_id(unique_id_type id) override;
290#endif
291
292 virtual const Point & point (const dof_id_type i) const override final;
293
294 virtual const Node * node_ptr (const dof_id_type i) const override final;
295 virtual Node * node_ptr (const dof_id_type i) override final;
296
297 virtual const Node * query_node_ptr (const dof_id_type i) const override final;
298 virtual Node * query_node_ptr (const dof_id_type i) override final;
299
300 virtual const Elem * elem_ptr (const dof_id_type i) const override final;
301 virtual Elem * elem_ptr (const dof_id_type i) override final;
302
303 virtual const Elem * query_elem_ptr (const dof_id_type i) const override final;
304 virtual Elem * query_elem_ptr (const dof_id_type i) override final;
305
309 virtual Node * add_point (const Point & p,
311 const processor_id_type proc_id = DofObject::invalid_processor_id) override final;
312 virtual Node * add_node (Node * n) override final;
313 virtual Node * add_node (std::unique_ptr<Node> n) override final;
314
321 virtual void own_node (Node & n) override final;
322
323 virtual void delete_node (Node * n) override final;
324 virtual void renumber_node (dof_id_type old_id, dof_id_type new_id) override final;
325 virtual Elem * add_elem (Elem * e) override final;
326 virtual Elem * add_elem (std::unique_ptr<Elem> e) override final;
327 virtual Elem * insert_elem (Elem * e) override final;
328 virtual Elem * insert_elem (std::unique_ptr<Elem> e) override final;
329 virtual void delete_elem (Elem * e) override final;
330 virtual void renumber_elem (dof_id_type old_id, dof_id_type new_id) override final;
331
338 virtual void fix_broken_node_and_element_numbering () override;
339
340public:
348 DECLARE_ELEM_ITERATORS(subactive_,,)
350 DECLARE_ELEM_ITERATORS(unpartitioned_,,)
352 DECLARE_ELEM_ITERATORS(level_, unsigned int level, level)
355
356 DECLARE_ELEM_ITERATORS(active_subdomain_, subdomain_id_type sid, sid)
357 DECLARE_ELEM_ITERATORS(active_subdomain_set_, std::set<subdomain_id_type> ss, ss)
358
359 // Backwards compatibility
360 virtual SimpleRange<element_iterator> active_subdomain_elements_ptr_range(subdomain_id_type sid) override final { return active_subdomain_element_ptr_range(sid); }
361 virtual SimpleRange<const_element_iterator> active_subdomain_elements_ptr_range(subdomain_id_type sid) const override final { return active_subdomain_element_ptr_range(sid); }
362 virtual SimpleRange<element_iterator> active_local_subdomain_elements_ptr_range(subdomain_id_type sid) override final { return active_local_subdomain_element_ptr_range(sid); }
363 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); }
364 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); }
365 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); }
366
368 DECLARE_ELEM_ITERATORS(not_ancestor_,,);
369 DECLARE_ELEM_ITERATORS(not_subactive_,,);
371 DECLARE_ELEM_ITERATORS(not_level_, unsigned int level, level)
372
373 DECLARE_ELEM_ITERATORS(active_local_,,)
374 DECLARE_ELEM_ITERATORS(active_not_local_,,)
375 DECLARE_ELEM_ITERATORS(active_unpartitioned_,,)
378 DECLARE_ELEM_ITERATORS(local_level_, unsigned int level, level)
379 DECLARE_ELEM_ITERATORS(local_not_level_, unsigned int level, level)
380 DECLARE_ELEM_ITERATORS(active_local_subdomain_, subdomain_id_type sid, sid)
381 DECLARE_ELEM_ITERATORS(active_local_subdomain_set_, std::set<subdomain_id_type> ss, ss)
382
384 DECLARE_ELEM_ITERATORS(ghost_,,)
385 DECLARE_ELEM_ITERATORS(active_semilocal_,,)
386
387 DECLARE_ELEM_ITERATORS(evaluable_, const DofMap & dof_map LIBMESH_COMMA unsigned int var_num = libMesh::invalid_uint, dof_map LIBMESH_COMMA var_num)
388 DECLARE_ELEM_ITERATORS(multi_evaluable_, std::vector<const DofMap *> dof_maps, dof_maps)
389
390#ifdef LIBMESH_ENABLE_AMR
391 DECLARE_ELEM_ITERATORS(flagged_, unsigned char rflag, rflag)
392
393 // Elem::refinement_flag() == rflag && Elem::processor_id() == pid
394 DECLARE_ELEM_ITERATORS(flagged_pid_, unsigned char rflag LIBMESH_COMMA processor_id_type pid, rflag LIBMESH_COMMA pid)
395#endif
396
399 DECLARE_NODE_ITERATORS(local_,,)
403
404 DECLARE_NODE_ITERATORS(evaluable_, const DofMap & dof_map LIBMESH_COMMA unsigned int var_num = libMesh::invalid_uint, dof_map LIBMESH_COMMA var_num)
405
406 DECLARE_NODE_ITERATORS(multi_evaluable_, std::vector<const DofMap *> dof_maps, dof_maps)
407
408
409protected:
410
414 virtual void move_nodes_and_elements(MeshBase && other_mesh) override;
415
420
425
430
435
442
447
456
457#ifdef LIBMESH_ENABLE_UNIQUE_ID
462#endif
463
468 std::set<Elem *> _extra_ghost_elems;
469
470private:
471
477
483};
484
485
486} // namespace libMesh
487
488#endif // LIBMESH_DISTRIBUTED_MESH_H
unsigned int dim
The DistributedMesh class is derived from the MeshBase class, and is intended to provide identical fu...
virtual bool is_replicated() const override final
unsigned int level ElemType type
virtual Elem * add_elem(Elem *e) override final
Add elem e to the end of the element array.
virtual void delete_elem(Elem *e) override final
Removes element e from the mesh.
virtual SimpleRange< const_element_iterator > active_subdomain_elements_ptr_range(subdomain_id_type sid) const override final
dof_id_type parallel_max_node_id() const
virtual dof_id_type n_active_elem() const override final
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 dof_id_type n_nodes() const override final
DistributedMesh(DistributedMesh &&)=delete
Move-constructor deleted in MeshBase.
dof_id_type _n_nodes
Cached data from the last renumber_nodes_and_elements call.
DECLARE_ELEM_ITERATORS(not_active_,,)
dofobject_container< Elem >::const_veclike_iterator const_elem_iterator_imp
virtual const Point & point(const dof_id_type i) const override final
virtual void redistribute() override
Redistribute elements between processors.
dof_id_type renumber_dof_objects(dofobject_container< T > &)
Renumber a parallel objects container.
virtual void fix_broken_node_and_element_numbering() override
There is no reason for a user to ever call this function.
virtual void clear() override
Clear all internal data.
DECLARE_ELEM_ITERATORS(not_subactive_,,)
processor_id_type pid unsigned int level std::set< subdomain_id_type > ss const DofMap &dof_map LIBMESH_COMMA unsigned int var_num
dof_id_type _next_free_unpartitioned_node_id
virtual void clear_extra_ghost_elems()
Clears extra ghost elements.
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...
virtual const Elem * elem_ptr(const dof_id_type i) const override final
virtual void delete_node(Node *n) override final
Removes the Node n from the mesh.
virtual const Node * query_node_ptr(const dof_id_type i) const override final
virtual void set_distributed() override final
Asserts that not all elements and nodes of the mesh necessarily exist on the current processor.
void libmesh_assert_valid_parallel_flags() const
Verify refinement_flag and p_refinement_flag consistency of our elements containers.
void libmesh_assert_valid_parallel_p_levels() const
Verify p_level consistency of our elements containers.
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...
DECLARE_ELEM_ITERATORS(not_local_,,)
virtual void reserve_elem(const dof_id_type) override final
Reserves space for a known number of elements.
virtual void renumber_nodes_and_elements() override
Remove nullptr elements from arrays.
virtual dof_id_type parallel_n_elem() const override
virtual std::unique_ptr< MeshBase > clone() const override
Virtual copy-constructor, creates a copy of this mesh.
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
virtual unique_id_type parallel_max_unique_id() const override
DECLARE_ELEM_ITERATORS(ancestor_,,) DECLARE_ELEM_ITERATORS(subactive_
virtual dof_id_type max_node_id() const override final
virtual void set_next_unique_id(unique_id_type id) override
Sets the next available unique id to be used.
virtual bool is_serial() const override final
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.
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.
virtual dof_id_type parallel_n_nodes() const override
const std::set< Elem * > & extra_ghost_elems() const
Const accessor to the ghosted elements.
dof_id_type _next_free_unpartitioned_elem_id
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...
unsigned int level ElemType type std::set< subdomain_id_type > ss
virtual SimpleRange< element_iterator > active_subdomain_set_elements_ptr_range(std::set< subdomain_id_type > ss) override final
DistributedMesh & operator=(const DistributedMesh &)=delete
Copy assignment is not allowed.
virtual SimpleRange< element_iterator > active_local_subdomain_elements_ptr_range(subdomain_id_type sid) override final
virtual dof_id_type max_elem_id() const override final
dofobject_container< Elem > _elements
The elements in the mesh.
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 void clear_elems() override
Clear internal Elem data.
virtual void update_post_partitioning() override
Recalculate cached data after elements and nodes have been repartitioned.
virtual ~DistributedMesh()
Destructor.
virtual bool is_serial_on_zero() const override final
dof_id_type parallel_max_elem_id() const
virtual void reserve_nodes(const dof_id_type) override final
Reserves space for a known number of nodes.
virtual void delete_remote_elements() override
Deletes all nonlocal elements of the mesh except for "ghosts" which touch a local element,...
dof_id_type _next_free_local_node_id
Guaranteed globally unused IDs for use when adding new nodes or elements.
dofobject_container< Elem >::veclike_iterator elem_iterator_imp
Typedefs for the container implementation.
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 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...
bool _is_serial
A boolean remembering whether we're serialized or not.
virtual SimpleRange< const_element_iterator > active_local_subdomain_elements_ptr_range(subdomain_id_type sid) const override final
bool _deleted_coarse_elements
A boolean remembering whether we've recently deleted top-level elements or not.
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...
DECLARE_ELEM_ITERATORS(,,)
Elem and Node iterator accessor functions.
virtual dof_id_type n_elem() const override final
virtual void update_parallel_id_counts() override
Updates parallel caches so that methods like n_elem() accurately reflect changes on other processors.
virtual SimpleRange< const_element_iterator > active_subdomain_set_elements_ptr_range(std::set< subdomain_id_type > ss) const override final
DECLARE_ELEM_ITERATORS(active_,,)
virtual void libmesh_assert_valid_parallel_ids() const override
Verify id and processor_id consistency of our elements and nodes containers.
virtual const Elem * query_elem_ptr(const dof_id_type i) const override final
unique_id_type _next_unpartitioned_unique_id
The next available unique id for assigning ids to unpartitioned DOF objects.
virtual void gather_to_zero() override
Gathers all elements and nodes of the mesh onto processor zero.
DECLARE_ELEM_ITERATORS(not_ancestor_,,)
dofobject_container< Node >::const_veclike_iterator const_node_iterator_imp
virtual void allgather() override
Gathers all elements and nodes of the mesh onto every processor.
DECLARE_ELEM_ITERATORS(not_level_, unsigned int level, level) DECLARE_ELEM_ITERATORS(active_local_
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 ...
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.
bool _is_serial_on_proc_0
A boolean remembering whether we're serialized to proc 0 or not.
virtual Node * add_node(Node *n) override final
Add Node n to the end of the vertex array.
dofobject_container< Node >::veclike_iterator node_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 const Node * node_ptr(const dof_id_type i) const override final
This class handles the numbering of degrees of freedom on a mesh.
Definition dof_map.h:181
static constexpr dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition dof_object.h:473
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
This is the base class from which all geometric element types are derived.
Definition elem.h:96
This is the MeshBase class.
Definition mesh_base.h:81
A Node is like a Point, but with more information.
Definition node.h:55
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
The SimpleRange templated class is intended to make it easy to construct ranges from pairs of iterato...
The UnstructuredMesh class is derived from the MeshBase class.
virtual void move_nodes_and_elements(MeshBase &&other_mesh)=0
Move node and elements from other_mesh to this mesh.
This chunked_mapvector templated class is intended to provide the asymptotic performance characterist...
This mapvector templated class is intended to provide the performance characteristics of a std::map w...
Definition mapvector.h:45
The libMesh namespace provides an interface to certain functionality in the library.
uint8_t unique_id_type
Definition id_types.h:86
ElemType
Defines an enum for geometric element types.
int8_t boundary_id_type
Definition id_types.h:51
libmesh_assert(ctx)
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:303
uint8_t dof_id_type
Definition id_types.h:67
uint8_t processor_id_type
Definition id_types.h:104
The definition of the element_iterator struct.
Definition mesh_base.h:2538