libMesh
Loading...
Searching...
No Matches
replicated_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_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
31namespace libMesh
32{
33
47{
48public:
49
55 explicit
57 unsigned char dim=1);
58
63 ReplicatedMesh (const MeshBase & other_mesh);
64
69 ReplicatedMesh (const ReplicatedMesh & other_mesh);
70
75
80
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 {
107 auto returnval = std::make_unique<ReplicatedMesh>(*this);
108#ifdef DEBUG
109 libmesh_assert(*returnval == *this);
110#endif
111 return returnval;
112 }
113
117 virtual ~ReplicatedMesh();
118
122 virtual void clear() override;
123
127 virtual void clear_elems() override;
128
137 virtual void renumber_nodes_and_elements () override;
138
139 virtual dof_id_type n_nodes () const override final
140 { return _n_nodes; }
141
142 virtual dof_id_type parallel_n_nodes () const override final
143 { return _n_nodes; }
144
145 virtual dof_id_type max_node_id () const override final
146 { return cast_int<dof_id_type>(_nodes.size()); }
147
148 virtual void reserve_nodes (const dof_id_type nn) override final
149 { _nodes.reserve (nn); }
150
151 virtual dof_id_type n_elem () const override final
152 { return _n_elem; }
153
154 virtual dof_id_type parallel_n_elem () const override final
155 { return _n_elem; }
156
157 virtual dof_id_type n_active_elem () const override final;
158
159 virtual dof_id_type max_elem_id () const override final
160 { return cast_int<dof_id_type>(_elements.size()); }
161
162#ifdef LIBMESH_ENABLE_UNIQUE_ID
163 virtual unique_id_type parallel_max_unique_id () const override final;
164 virtual void set_next_unique_id(unique_id_type id) override final;
165#endif
166
167 virtual void reserve_elem (const dof_id_type ne) override final
168 { _elements.reserve (ne); }
169
170 virtual void update_parallel_id_counts () override;
171
172 virtual const Point & point (const dof_id_type i) const override final;
173
174 virtual const Node * node_ptr (const dof_id_type i) const override final;
175 virtual Node * node_ptr (const dof_id_type i) override final;
176
177 virtual const Node * query_node_ptr (const dof_id_type i) const override final;
178 virtual Node * query_node_ptr (const dof_id_type i) override final;
179
180 virtual const Elem * elem_ptr (const dof_id_type i) const override final;
181 virtual Elem * elem_ptr (const dof_id_type i) override final;
182
183 virtual const Elem * query_elem_ptr (const dof_id_type i) const override final;
184 virtual Elem * query_elem_ptr (const dof_id_type i) override final;
185
189 virtual Node * add_point (const Point & p,
191 const processor_id_type proc_id = DofObject::invalid_processor_id) override final;
192 virtual Node * add_node (Node * n) override final;
193 virtual Node * add_node (std::unique_ptr<Node> n) override final;
194 virtual void delete_node (Node * n) override final;
195 virtual void renumber_node (dof_id_type old_id, dof_id_type new_id) override final;
196 virtual Elem * add_elem (Elem * e) override final;
197 virtual Elem * add_elem (std::unique_ptr<Elem> e) override final;
198 virtual Elem * insert_elem (Elem * e) override final;
199 virtual Elem * insert_elem (std::unique_ptr<Elem> e) override final;
200 virtual void delete_elem (Elem * e) override final;
201 virtual void renumber_elem (dof_id_type old_id, dof_id_type new_id) override final;
202
209 virtual void fix_broken_node_and_element_numbering () override;
210
221 std::vector<dof_id_type> get_disconnected_subdomains(std::vector<subdomain_id_type> * subdomain_ids = nullptr) const;
222
235 std::unordered_map<dof_id_type, std::vector<std::vector<Point>>> get_boundary_points() const;
236
237public:
245 DECLARE_ELEM_ITERATORS(subactive_,,)
247 DECLARE_ELEM_ITERATORS(unpartitioned_,,)
249 DECLARE_ELEM_ITERATORS(level_, unsigned int level, level)
252
253 DECLARE_ELEM_ITERATORS(active_subdomain_, subdomain_id_type sid, sid)
254 DECLARE_ELEM_ITERATORS(active_subdomain_set_, std::set<subdomain_id_type> ss, ss)
255
257 DECLARE_ELEM_ITERATORS(not_ancestor_,,);
258 DECLARE_ELEM_ITERATORS(not_subactive_,,);
260 DECLARE_ELEM_ITERATORS(not_level_, unsigned int level, level)
261
262 DECLARE_ELEM_ITERATORS(active_local_,,)
263 DECLARE_ELEM_ITERATORS(active_not_local_,,)
264 DECLARE_ELEM_ITERATORS(active_unpartitioned_,,)
267 DECLARE_ELEM_ITERATORS(local_level_, unsigned int level, level)
268 DECLARE_ELEM_ITERATORS(local_not_level_, unsigned int level, level)
269 DECLARE_ELEM_ITERATORS(active_local_subdomain_, subdomain_id_type sid, sid)
270 DECLARE_ELEM_ITERATORS(active_local_subdomain_set_, std::set<subdomain_id_type> ss, ss)
271
272 // Backwards compatibility
273 virtual SimpleRange<element_iterator> active_subdomain_elements_ptr_range(subdomain_id_type sid) override final { return active_subdomain_element_ptr_range(sid); }
274 virtual SimpleRange<const_element_iterator> active_subdomain_elements_ptr_range(subdomain_id_type sid) const override final { return active_subdomain_element_ptr_range(sid); }
275 virtual SimpleRange<element_iterator> active_local_subdomain_elements_ptr_range(subdomain_id_type sid) override final { return active_local_subdomain_element_ptr_range(sid); }
276 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); }
277 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); }
278 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); }
279
281 DECLARE_ELEM_ITERATORS(ghost_,,)
282 DECLARE_ELEM_ITERATORS(active_semilocal_,,)
283
284 DECLARE_ELEM_ITERATORS(evaluable_, const DofMap & dof_map LIBMESH_COMMA unsigned int var_num = libMesh::invalid_uint, dof_map LIBMESH_COMMA var_num)
285 DECLARE_ELEM_ITERATORS(multi_evaluable_, std::vector<const DofMap *> dof_maps, dof_maps)
286
287#ifdef LIBMESH_ENABLE_AMR
288 DECLARE_ELEM_ITERATORS(flagged_, unsigned char rflag, rflag)
289
290 // Elem::refinement_flag() == rflag && Elem::processor_id() == pid
291 DECLARE_ELEM_ITERATORS(flagged_pid_, unsigned char rflag LIBMESH_COMMA processor_id_type pid, rflag LIBMESH_COMMA pid)
292#endif
293
296 DECLARE_NODE_ITERATORS(local_,,)
300
301 DECLARE_NODE_ITERATORS(evaluable_, const DofMap & dof_map LIBMESH_COMMA unsigned int var_num = libMesh::invalid_uint, dof_map LIBMESH_COMMA var_num)
302
303 DECLARE_NODE_ITERATORS(multi_evaluable_, std::vector<const DofMap *> dof_maps, dof_maps)
304
305
306protected:
307
311 std::vector<Node *> _nodes;
312
314
318 std::vector<Elem *> _elements;
319
321
322private:
323
328 typedef std::vector<Elem *>::iterator elem_iterator_imp;
329 typedef std::vector<Elem *>::const_iterator const_elem_iterator_imp;
330
335 typedef std::vector<Node *>::iterator node_iterator_imp;
336 typedef std::vector<Node *>::const_iterator const_node_iterator_imp;
337};
338
339} // namespace libMesh
340
341
342
343#endif // LIBMESH_REPLICATED_MESH_H
unsigned int dim
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
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,...
Definition mesh_base.C:1126
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 ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
DECLARE_ELEM_ITERATORS(,,)
Elem and Node iterator accessor functions.
virtual void clear() override
Clear all internal data.
virtual SimpleRange< const_element_iterator > active_subdomain_elements_ptr_range(subdomain_id_type sid) 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.
std::vector< Elem * > _elements
The elements in the mesh.
virtual Node * add_node(Node *n) override final
Add Node n to the end of the vertex array.
virtual void update_parallel_id_counts() override
Updates parallel caches so that methods like n_elem() accurately reflect changes on other processors.
unsigned int level ElemType type
virtual void move_nodes_and_elements(MeshBase &&other_mesh) override
Move node and elements from a ReplicatedMesh.
ReplicatedMesh(ReplicatedMesh &&)=delete
Move-constructor deleted in MeshBase.
std::vector< Node * >::iterator node_iterator_imp
Typedefs for the container implementation.
virtual SimpleRange< element_iterator > active_local_subdomain_elements_ptr_range(subdomain_id_type sid) override final
std::vector< Node * >::const_iterator const_node_iterator_imp
virtual void delete_node(Node *n) override final
Removes the Node n from the mesh.
DECLARE_ELEM_ITERATORS(semilocal_,,) DECLARE_ELEM_ITERATORS(ghost_
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 dof_id_type max_node_id() const override final
virtual dof_id_type max_elem_id() const override final
virtual const Node * 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.
DECLARE_ELEM_ITERATORS(ancestor_,,) DECLARE_ELEM_ITERATORS(subactive_
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...
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_
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.
virtual dof_id_type n_active_elem() const override final
virtual void reserve_nodes(const dof_id_type nn) override final
Reserves space for a known number of nodes.
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 SimpleRange< const_element_iterator > active_local_subdomain_elements_ptr_range(subdomain_id_type sid) const override final
virtual SimpleRange< element_iterator > active_subdomain_set_elements_ptr_range(std::set< subdomain_id_type > ss) override final
virtual void reserve_elem(const dof_id_type ne) override final
Reserves space for a known number of elements.
virtual dof_id_type n_elem() const override final
virtual void delete_elem(Elem *e) override final
Removes element e from the mesh.
virtual const Elem * query_elem_ptr(const dof_id_type i) const override final
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
std::unordered_map< dof_id_type, std::vector< std::vector< Point > > > get_boundary_points() const
Return all points on boundary.
virtual const Elem * elem_ptr(const dof_id_type i) const override final
virtual Elem * add_elem(Elem *e) override final
Add elem e to the end of the element array.
ReplicatedMesh & operator=(const ReplicatedMesh &)=delete
Copy assignment is not allowed.
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 var_num
virtual dof_id_type n_nodes() const override final
std::vector< Elem * >::const_iterator const_elem_iterator_imp
unsigned int level ElemType type std::set< subdomain_id_type > ss
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 MeshBase & assign(MeshBase &&other_mesh) override
Shim to call the move assignment operator for this class.
DECLARE_ELEM_ITERATORS(active_,,)
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.
const DofMap &dof_map LIBMESH_COMMA unsigned int dof_map LIBMESH_COMMA var_num unsigned char rflag
std::vector< Elem * >::iterator elem_iterator_imp
Typedefs for the container implementation.
virtual const Point & point(const dof_id_type i) const override final
virtual void set_next_unique_id(unique_id_type id) override final
Sets the next available unique id to be used.
virtual unique_id_type parallel_max_unique_id() const override final
virtual std::unique_ptr< MeshBase > clone() const override
Virtual copy-constructor, creates a copy of this mesh.
virtual const Node * query_node_ptr(const dof_id_type i) const override final
virtual void renumber_nodes_and_elements() override
After partitioning a mesh it is useful to renumber the nodes and elements so that they lie in contigu...
virtual ~ReplicatedMesh()
Destructor.
virtual dof_id_type parallel_n_nodes() const override final
virtual dof_id_type parallel_n_elem() const override final
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.
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