libMesh
replicated_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_REPLICATED_MESH_H
21 #define LIBMESH_REPLICATED_MESH_H
22 
23 // Local Includes
24 #include "libmesh/unstructured_mesh.h"
25 
26 // C++ Includes
27 #include <cstddef>
28 #include <memory>
29 #include <unordered_map>
30 
31 namespace libMesh
32 {
33 
47 {
48 public:
49 
55  explicit
56  ReplicatedMesh (const Parallel::Communicator & comm_in,
57  unsigned char dim=1);
58 
63  ReplicatedMesh (const UnstructuredMesh & other_mesh);
64 
69  ReplicatedMesh (const ReplicatedMesh & other_mesh);
70 
74  ReplicatedMesh(ReplicatedMesh &&) = delete;
75 
79  ReplicatedMesh & operator= (const ReplicatedMesh &) = delete;
80 
84  ReplicatedMesh & operator= (ReplicatedMesh && other_mesh);
85 
89  virtual MeshBase & assign(MeshBase && other_mesh) override;
90 
94  virtual void move_nodes_and_elements(MeshBase && other_mesh) override;
95 
100  virtual bool subclass_locally_equals (const MeshBase & other_mesh) const override;
101 
105  virtual std::unique_ptr<MeshBase> clone () const override
106  { return std::make_unique<ReplicatedMesh>(*this); }
107 
111  virtual ~ReplicatedMesh();
112 
116  virtual void clear() override;
117 
121  virtual void clear_elems() override;
122 
126  virtual void renumber_nodes_and_elements () override;
127 
128  virtual dof_id_type n_nodes () const override final
129  { return _n_nodes; }
130 
131  virtual dof_id_type parallel_n_nodes () const override final
132  { return _n_nodes; }
133 
134  virtual dof_id_type max_node_id () const override final
135  { return cast_int<dof_id_type>(_nodes.size()); }
136 
137  virtual void reserve_nodes (const dof_id_type nn) override final
138  { _nodes.reserve (nn); }
139 
140  virtual dof_id_type n_elem () const override final
141  { return _n_elem; }
142 
143  virtual dof_id_type parallel_n_elem () const override final
144  { return _n_elem; }
145 
146  virtual dof_id_type n_active_elem () const override final;
147 
148  virtual dof_id_type max_elem_id () const override final
149  { return cast_int<dof_id_type>(_elements.size()); }
150 
151 #ifdef LIBMESH_ENABLE_UNIQUE_ID
152  virtual unique_id_type parallel_max_unique_id () const override final;
153  virtual void set_next_unique_id(unique_id_type id) override final;
154 #endif
155 
156  virtual void reserve_elem (const dof_id_type ne) override final
157  { _elements.reserve (ne); }
158 
159  virtual void update_parallel_id_counts () override;
160 
161  virtual const Point & point (const dof_id_type i) const override final;
162 
163  virtual const Node * node_ptr (const dof_id_type i) const override final;
164  virtual Node * node_ptr (const dof_id_type i) override final;
165 
166  virtual const Node * query_node_ptr (const dof_id_type i) const override final;
167  virtual Node * query_node_ptr (const dof_id_type i) override final;
168 
169  virtual const Elem * elem_ptr (const dof_id_type i) const override final;
170  virtual Elem * elem_ptr (const dof_id_type i) override final;
171 
172  virtual const Elem * query_elem_ptr (const dof_id_type i) const override final;
173  virtual Elem * query_elem_ptr (const dof_id_type i) override final;
174 
178  virtual Node * add_point (const Point & p,
180  const processor_id_type proc_id = DofObject::invalid_processor_id) override final;
181  virtual Node * add_node (Node * n) override final;
182  virtual Node * add_node (std::unique_ptr<Node> n) override final;
183 
184 #ifdef LIBMESH_ENABLE_DEPRECATED
185 
197  virtual Node * insert_node(Node * n) override final;
198  virtual Node * insert_node(std::unique_ptr<Node> n) override final;
199 #endif
200 
201  virtual void delete_node (Node * n) override final;
202  virtual void renumber_node (dof_id_type old_id, dof_id_type new_id) override final;
203  virtual Elem * add_elem (Elem * e) override final;
204  virtual Elem * add_elem (std::unique_ptr<Elem> e) override final;
205  virtual Elem * insert_elem (Elem * e) override final;
206  virtual Elem * insert_elem (std::unique_ptr<Elem> e) override final;
207  virtual void delete_elem (Elem * e) override final;
208  virtual void renumber_elem (dof_id_type old_id, dof_id_type new_id) override final;
209 
216  virtual void fix_broken_node_and_element_numbering () override;
217 
228  std::vector<dof_id_type> get_disconnected_subdomains(std::vector<subdomain_id_type> * subdomain_ids = nullptr) const;
229 
242  std::unordered_map<dof_id_type, std::vector<std::vector<Point>>> get_boundary_points() const;
243 
244 public:
250  DECLARE_ELEM_ITERATORS(active_,,);
251  DECLARE_ELEM_ITERATORS(ancestor_,,)
252  DECLARE_ELEM_ITERATORS(subactive_,,)
253  DECLARE_ELEM_ITERATORS(local_,,)
254  DECLARE_ELEM_ITERATORS(unpartitioned_,,)
255  DECLARE_ELEM_ITERATORS(facelocal_,,)
256  DECLARE_ELEM_ITERATORS(level_, unsigned int level, level)
259 
260  DECLARE_ELEM_ITERATORS(active_subdomain_, subdomain_id_type sid, sid)
261  DECLARE_ELEM_ITERATORS(active_subdomain_set_, std::set<subdomain_id_type> ss, ss)
262 
263  DECLARE_ELEM_ITERATORS(not_active_,,);
264  DECLARE_ELEM_ITERATORS(not_ancestor_,,);
265  DECLARE_ELEM_ITERATORS(not_subactive_,,);
266  DECLARE_ELEM_ITERATORS(not_local_,,);
267  DECLARE_ELEM_ITERATORS(not_level_, unsigned int level, level)
268 
269  DECLARE_ELEM_ITERATORS(active_local_,,)
270  DECLARE_ELEM_ITERATORS(active_not_local_,,)
271  DECLARE_ELEM_ITERATORS(active_unpartitioned_,,)
272  DECLARE_ELEM_ITERATORS(active_type_, ElemType type, type)
274  DECLARE_ELEM_ITERATORS(local_level_, unsigned int level, level)
275  DECLARE_ELEM_ITERATORS(local_not_level_, unsigned int level, level)
276  DECLARE_ELEM_ITERATORS(active_local_subdomain_, subdomain_id_type sid, sid)
277  DECLARE_ELEM_ITERATORS(active_local_subdomain_set_, std::set<subdomain_id_type> ss, ss)
278 
279  // Backwards compatibility
280  virtual SimpleRange<element_iterator> active_subdomain_elements_ptr_range(subdomain_id_type sid) override final { return active_subdomain_element_ptr_range(sid); }
281  virtual SimpleRange<const_element_iterator> active_subdomain_elements_ptr_range(subdomain_id_type sid) const override final { return active_subdomain_element_ptr_range(sid); }
282  virtual SimpleRange<element_iterator> active_local_subdomain_elements_ptr_range(subdomain_id_type sid) override final { return active_local_subdomain_element_ptr_range(sid); }
283  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); }
284  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); }
285  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); }
286 
287  DECLARE_ELEM_ITERATORS(semilocal_,,)
288  DECLARE_ELEM_ITERATORS(ghost_,,)
289  DECLARE_ELEM_ITERATORS(active_semilocal_,,)
290 
291  DECLARE_ELEM_ITERATORS(evaluable_, const DofMap & dof_map LIBMESH_COMMA unsigned int var_num = libMesh::invalid_uint, dof_map LIBMESH_COMMA var_num)
292  DECLARE_ELEM_ITERATORS(multi_evaluable_, std::vector<const DofMap *> dof_maps, dof_maps)
293 
294 #ifdef LIBMESH_ENABLE_AMR
295  DECLARE_ELEM_ITERATORS(flagged_, unsigned char rflag, rflag)
296 
297  // Elem::refinement_flag() == rflag && Elem::processor_id() == pid
298  DECLARE_ELEM_ITERATORS(flagged_pid_, unsigned char rflag LIBMESH_COMMA processor_id_type pid, rflag LIBMESH_COMMA pid)
299 #endif
300 
302  DECLARE_NODE_ITERATORS(active_,,)
303  DECLARE_NODE_ITERATORS(local_,,)
304  DECLARE_NODE_ITERATORS(bnd_,,)
307 
308  DECLARE_NODE_ITERATORS(evaluable_, const DofMap & dof_map LIBMESH_COMMA unsigned int var_num = libMesh::invalid_uint, dof_map LIBMESH_COMMA var_num)
309 
310  DECLARE_NODE_ITERATORS(multi_evaluable_, std::vector<const DofMap *> dof_maps, dof_maps)
311 
312 
313 protected:
314 
318  std::vector<Node *> _nodes;
319 
321 
325  std::vector<Elem *> _elements;
326 
328 
329 private:
330 
335  typedef std::vector<Elem *>::iterator elem_iterator_imp;
336  typedef std::vector<Elem *>::const_iterator const_elem_iterator_imp;
337 
342  typedef std::vector<Node *>::iterator node_iterator_imp;
343  typedef std::vector<Node *>::const_iterator const_node_iterator_imp;
344 };
345 
346 } // namespace libMesh
347 
348 
349 
350 #endif // LIBMESH_REPLICATED_MESH_H
virtual dof_id_type n_nodes() const override final
The definition of the element_iterator struct.
Definition: mesh_base.h:2103
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 dof_id_type max_node_id() 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...
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
A Node is like a Point, but with more information.
Definition: node.h:52
virtual dof_id_type n_elem() const override final
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 const Node * query_node_ptr(const dof_id_type i) const override final
std::vector< Elem * > _elements
The elements in the mesh.
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 ~ReplicatedMesh()
Destructor.
virtual void set_next_unique_id(unique_id_type id) override final
Sets the next available unique id to be used.
std::vector< Elem * >::const_iterator const_elem_iterator_imp
unsigned int dim
virtual void reserve_elem(const dof_id_type ne) override final
Reserves space for a known number of elements.
std::vector< Node * >::iterator node_iterator_imp
Typedefs for the container implementation.
virtual void reserve_nodes(const dof_id_type nn) override final
Reserves space for a known number of nodes.
virtual Node * insert_node(Node *n) override final
These methods are deprecated.
virtual SimpleRange< element_iterator > active_local_subdomain_elements_ptr_range(subdomain_id_type sid) override final
std::vector< dof_id_type > get_disconnected_subdomains(std::vector< subdomain_id_type > *subdomain_ids=nullptr) const
Return IDs of representative elements of all disconnected subdomains.
virtual dof_id_type max_elem_id() const override final
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
virtual dof_id_type parallel_n_elem() const override final
The libMesh namespace provides an interface to certain functionality in the library.
std::unordered_map< dof_id_type, std::vector< std::vector< Point > > > get_boundary_points() const
Return all points on boundary.
virtual void delete_elem(Elem *e) override final
Removes element e from the mesh.
virtual Node * add_node(Node *n) override final
Add Node n to the end of the vertex array.
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 MeshBase & assign(MeshBase &&other_mesh) override
Shim to call the move assignment operator for this class.
processor_id_type pid unsigned int level std::set< subdomain_id_type > virtual ss SimpleRange< element_iterator > active_subdomain_elements_ptr_range(subdomain_id_type sid) override final
uint8_t processor_id_type
Definition: id_types.h:104
This is the MeshBase class.
Definition: mesh_base.h:74
virtual const Elem * query_elem_ptr(const dof_id_type i) const override final
virtual unique_id_type parallel_max_unique_id() const override final
virtual void delete_node(Node *n) override final
Removes the Node n from the mesh.
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:169
virtual const Elem * elem_ptr(const dof_id_type i) const override final
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...
int8_t boundary_id_type
Definition: id_types.h:51
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
virtual void clear() override
Clear all internal data.
The UnstructuredMesh class is derived from the MeshBase class.
std::vector< Node * >::const_iterator const_node_iterator_imp
virtual void move_nodes_and_elements(MeshBase &&other_mesh) override
Move node and elements from a ReplicatedMesh.
void subdomain_ids(std::set< subdomain_id_type > &ids, const bool global=true) const
Constructs a list of all subdomain identifiers in the local mesh if global == false, and in the global mesh if global == true (default).
Definition: mesh_base.C:899
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:477
DECLARE_ELEM_ITERATORS(,,)
Elem and Node iterator accessor functions.
const DofMap &dof_map LIBMESH_COMMA unsigned int var_num
virtual Elem * add_elem(Elem *e) override final
Add elem e to the end of the element array.
virtual void renumber_nodes_and_elements() override
Remove nullptr elements from arrays.
unsigned int level ElemType type std::set< subdomain_id_type > ss
virtual const Point & point(const dof_id_type i) const override final
unsigned int level ElemType type
virtual SimpleRange< const_element_iterator > active_subdomain_elements_ptr_range(subdomain_id_type sid) const override final
virtual dof_id_type n_active_elem() const override final
ReplicatedMesh & operator=(const ReplicatedMesh &)=delete
Copy assignment is not allowed.
virtual void update_parallel_id_counts() override
Updates parallel caches so that methods like n_elem() accurately reflect changes on other processors...
virtual void clear_elems() override
Clear internal Elem data.
virtual void fix_broken_node_and_element_numbering() override
There is no reason for a user to ever call this function.
virtual std::unique_ptr< MeshBase > clone() const override
Virtual copy-constructor, creates a copy of this mesh.
virtual const Node * node_ptr(const dof_id_type i) const override final
virtual dof_id_type parallel_n_nodes() const override final
std::vector< Elem * >::iterator elem_iterator_imp
Typedefs for the container implementation.
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.
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 dof_id_typ _n_nodes)
The vertices (spatial coordinates) of the mesh.
processor_id_type pid
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...
ReplicatedMesh(const Parallel::Communicator &comm_in, unsigned char dim=1)
Constructor.
virtual SimpleRange< const_element_iterator > active_subdomain_set_elements_ptr_range(std::set< subdomain_id_type > ss) const override final
const DofMap &dof_map LIBMESH_COMMA unsigned int dof_map LIBMESH_COMMA var_num unsigned char rflag
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
virtual SimpleRange< element_iterator > active_subdomain_set_elements_ptr_range(std::set< subdomain_id_type > ss) override final
uint8_t unique_id_type
Definition: id_types.h:86
uint8_t dof_id_type
Definition: id_types.h:67
virtual SimpleRange< const_element_iterator > active_local_subdomain_elements_ptr_range(subdomain_id_type sid) const override final