libMesh
mesh_iterators.C
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 // C++ includes
21 
22 // Local includes
23 #include "libmesh/distributed_mesh.h"
24 #include "libmesh/elem.h"
25 #include "libmesh/replicated_mesh.h"
26 
27 #include "libmesh/ignore_warnings.h" // Ignore warnings about variadic macros
28 
29 namespace libMesh
30 {
31 
32 // This file contains the implementation of all the different iterator
33 // functions for the mesh class.
34 
35 // This macro generates four iterator accessor function definitions
36 // (const/non-const and begin/end) for both Replicated and DistributedMesh
37 // given the Predicate PRED, which may be passed an arbitrary number
38 // of arguments.
39 #define INSTANTIATE_ELEM_ACCESSORS(FUNC_PREFIX, PRED, FUNC_ARG, ...) \
40  ReplicatedMesh::element_iterator \
41  ReplicatedMesh::FUNC_PREFIX##_begin (FUNC_ARG) \
42  { \
43  return element_iterator(_elements.begin(), _elements.end(), Predicates::PRED<elem_iterator_imp>(__VA_ARGS__)); \
44  } \
45  ReplicatedMesh::const_element_iterator \
46  ReplicatedMesh::FUNC_PREFIX##_begin (FUNC_ARG) const \
47  { \
48  return const_element_iterator(_elements.begin(), _elements.end(), Predicates::PRED<const_elem_iterator_imp>(__VA_ARGS__)); \
49  } \
50  ReplicatedMesh::element_iterator \
51  ReplicatedMesh::FUNC_PREFIX##_end (FUNC_ARG) \
52  { \
53  return element_iterator(_elements.end(), _elements.end(), Predicates::PRED<elem_iterator_imp>(__VA_ARGS__)); \
54  } \
55  ReplicatedMesh::const_element_iterator \
56  ReplicatedMesh::FUNC_PREFIX##_end (FUNC_ARG) const \
57  { \
58  return const_element_iterator(_elements.end(), _elements.end(), Predicates::PRED<const_elem_iterator_imp>(__VA_ARGS__)); \
59  } \
60  DistributedMesh::element_iterator \
61  DistributedMesh::FUNC_PREFIX##_begin (FUNC_ARG) \
62  { \
63  return element_iterator(_elements.begin(), _elements.end(), Predicates::PRED<elem_iterator_imp>(__VA_ARGS__)); \
64  } \
65  DistributedMesh::const_element_iterator \
66  DistributedMesh::FUNC_PREFIX##_begin (FUNC_ARG) const \
67  { \
68  return const_element_iterator(_elements.begin(), _elements.end(), Predicates::PRED<const_elem_iterator_imp>(__VA_ARGS__)); \
69  } \
70  DistributedMesh::element_iterator \
71  DistributedMesh::FUNC_PREFIX##_end (FUNC_ARG) \
72  { \
73  return element_iterator(_elements.end(), _elements.end(), Predicates::PRED<elem_iterator_imp>(__VA_ARGS__)); \
74  } \
75  DistributedMesh::const_element_iterator \
76  DistributedMesh::FUNC_PREFIX##_end (FUNC_ARG) const \
77  { \
78  return const_element_iterator(_elements.end(), _elements.end(), Predicates::PRED<const_elem_iterator_imp>(__VA_ARGS__)); \
79  }
80 
81 
82 
83 // This macro is similar to the one above except that it generates
84 // node iterator accessor functions.
85 #define INSTANTIATE_NODE_ACCESSORS(FUNC_PREFIX, PRED, FUNC_ARG, ...) \
86  ReplicatedMesh::node_iterator \
87  ReplicatedMesh::FUNC_PREFIX##_begin (FUNC_ARG) \
88  { \
89  return node_iterator(_nodes.begin(), _nodes.end(), Predicates::PRED<node_iterator_imp>(__VA_ARGS__)); \
90  } \
91  ReplicatedMesh::const_node_iterator \
92  ReplicatedMesh::FUNC_PREFIX##_begin (FUNC_ARG) const \
93  { \
94  return const_node_iterator(_nodes.begin(), _nodes.end(), Predicates::PRED<const_node_iterator_imp>(__VA_ARGS__)); \
95  } \
96  ReplicatedMesh::node_iterator \
97  ReplicatedMesh::FUNC_PREFIX##_end (FUNC_ARG) \
98  { \
99  return node_iterator(_nodes.end(), _nodes.end(), Predicates::PRED<node_iterator_imp>(__VA_ARGS__)); \
100  } \
101  ReplicatedMesh::const_node_iterator \
102  ReplicatedMesh::FUNC_PREFIX##_end (FUNC_ARG) const \
103  { \
104  return const_node_iterator(_nodes.end(), _nodes.end(), Predicates::PRED<const_node_iterator_imp>(__VA_ARGS__)); \
105  } \
106  DistributedMesh::node_iterator \
107  DistributedMesh::FUNC_PREFIX##_begin (FUNC_ARG) \
108  { \
109  return node_iterator(_nodes.begin(), _nodes.end(), Predicates::PRED<node_iterator_imp>(__VA_ARGS__)); \
110  } \
111  DistributedMesh::const_node_iterator \
112  DistributedMesh::FUNC_PREFIX##_begin (FUNC_ARG) const \
113  { \
114  return const_node_iterator(_nodes.begin(), _nodes.end(), Predicates::PRED<const_node_iterator_imp>(__VA_ARGS__)); \
115  } \
116  DistributedMesh::node_iterator \
117  DistributedMesh::FUNC_PREFIX##_end (FUNC_ARG) \
118  { \
119  return node_iterator(_nodes.end(), _nodes.end(), Predicates::PRED<node_iterator_imp>(__VA_ARGS__)); \
120  } \
121  DistributedMesh::const_node_iterator \
122  DistributedMesh::FUNC_PREFIX##_end (FUNC_ARG) const \
123  { \
124  return const_node_iterator(_nodes.end(), _nodes.end(), Predicates::PRED<const_node_iterator_imp>(__VA_ARGS__)); \
125  }
126 
127 // Use an empty preprocessor token to silence older compilers that
128 // still warn about empty macro arguments.
129 #define EMPTY
130 
131 // Use a second macro layer to allow us to pass commas into a macro
132 // argument
133 #define LIBMESH_COMMA ,
134 
135 // Instantiate various element iterator accessor functions.
136 INSTANTIATE_ELEM_ACCESSORS(elements, NotNull, EMPTY, EMPTY)
137 INSTANTIATE_ELEM_ACCESSORS(active_elements, Active, EMPTY, EMPTY)
138 INSTANTIATE_ELEM_ACCESSORS(not_active_elements, NotActive, EMPTY, EMPTY)
139 INSTANTIATE_ELEM_ACCESSORS(ancestor_elements, Ancestor, EMPTY, EMPTY)
140 INSTANTIATE_ELEM_ACCESSORS(not_ancestor_elements, NotAncestor, EMPTY, EMPTY)
141 INSTANTIATE_ELEM_ACCESSORS(subactive_elements, SubActive, EMPTY, EMPTY)
142 INSTANTIATE_ELEM_ACCESSORS(not_subactive_elements, NotSubActive, EMPTY, EMPTY)
143 INSTANTIATE_ELEM_ACCESSORS(local_elements, Local, EMPTY, this->processor_id())
144 INSTANTIATE_ELEM_ACCESSORS(semilocal_elements, ActiveSemiLocal, EMPTY, this->processor_id())
145 INSTANTIATE_ELEM_ACCESSORS(active_semilocal_elements, ActiveSemiLocal, EMPTY, this->processor_id())
146 INSTANTIATE_ELEM_ACCESSORS(facelocal_elements, FaceLocal, EMPTY, this->processor_id())
147 INSTANTIATE_ELEM_ACCESSORS(not_local_elements, NotLocal, EMPTY, this->processor_id())
148 INSTANTIATE_ELEM_ACCESSORS(active_local_elements, ActiveLocal, EMPTY, this->processor_id())
149 INSTANTIATE_ELEM_ACCESSORS(active_not_local_elements, ActiveNotLocal, EMPTY, this->processor_id())
150 INSTANTIATE_ELEM_ACCESSORS(level_elements, Level, unsigned int level, level)
151 INSTANTIATE_ELEM_ACCESSORS(not_level_elements, NotLevel, unsigned int level, level)
152 INSTANTIATE_ELEM_ACCESSORS(pid_elements, PID, processor_id_type proc_id, proc_id)
153 INSTANTIATE_ELEM_ACCESSORS(type_elements, Type, ElemType type, type)
154 INSTANTIATE_ELEM_ACCESSORS(active_type_elements, ActiveType, ElemType type, type)
155 INSTANTIATE_ELEM_ACCESSORS(active_pid_elements, ActivePID, processor_id_type proc_id, proc_id)
156 INSTANTIATE_ELEM_ACCESSORS(active_subdomain_elements, ActiveSubdomain, subdomain_id_type subdomain_id, subdomain_id)
157 INSTANTIATE_ELEM_ACCESSORS(active_subdomain_set_elements, ActiveSubdomainSet, std::set<subdomain_id_type> ss, ss)
158 INSTANTIATE_ELEM_ACCESSORS(ghost_elements, Ghost, EMPTY, this->processor_id())
159 INSTANTIATE_ELEM_ACCESSORS(evaluable_elements, Evaluable, const DofMap & dof_map LIBMESH_COMMA unsigned int var_num, dof_map, var_num)
160 INSTANTIATE_ELEM_ACCESSORS(multi_evaluable_elements, MultiEvaluable, std::vector<const DofMap *> dof_maps, dof_maps)
161 INSTANTIATE_ELEM_ACCESSORS(unpartitioned_elements, PID, EMPTY, DofObject::invalid_processor_id)
162 INSTANTIATE_ELEM_ACCESSORS(active_unpartitioned_elements, ActivePID, EMPTY, DofObject::invalid_processor_id)
163 
164 #ifdef LIBMESH_ENABLE_AMR
165 INSTANTIATE_ELEM_ACCESSORS(flagged_elements, Flagged, unsigned char rflag, rflag)
166 INSTANTIATE_ELEM_ACCESSORS(flagged_pid_elements, FlaggedPID, unsigned char rflag LIBMESH_COMMA processor_id_type pid, rflag, pid)
167 #endif
168 
169 INSTANTIATE_ELEM_ACCESSORS(local_level_elements, LocalLevel, unsigned int level, this->processor_id(), level)
170 INSTANTIATE_ELEM_ACCESSORS(local_not_level_elements, LocalNotLevel, unsigned int level, this->processor_id(), level)
171 INSTANTIATE_ELEM_ACCESSORS(active_local_subdomain_elements, ActiveLocalSubdomain, subdomain_id_type subdomain_id, this->processor_id(), subdomain_id)
172 INSTANTIATE_ELEM_ACCESSORS(active_local_subdomain_set_elements, ActiveLocalSubdomainSet, std::set<subdomain_id_type> ss, this->processor_id(), ss)
173 
174 // Instantiate various node iterator accessor functions.
175 INSTANTIATE_NODE_ACCESSORS(nodes, NotNull, EMPTY, EMPTY)
176 INSTANTIATE_NODE_ACCESSORS(active_nodes, Active, EMPTY, EMPTY)
177 INSTANTIATE_NODE_ACCESSORS(local_nodes, Local, EMPTY, this->processor_id())
178 INSTANTIATE_NODE_ACCESSORS(pid_nodes, PID, processor_id_type proc_id, proc_id)
179 INSTANTIATE_NODE_ACCESSORS(bnd_nodes, BND, EMPTY, this->get_boundary_info())
180 INSTANTIATE_NODE_ACCESSORS(bid_nodes, BID, boundary_id_type bndry_id, bndry_id, this->get_boundary_info())
181 INSTANTIATE_NODE_ACCESSORS(evaluable_nodes, Evaluable, const DofMap & dof_map LIBMESH_COMMA unsigned int var_num, dof_map, var_num)
182 INSTANTIATE_NODE_ACCESSORS(multi_evaluable_nodes, MultiEvaluable, std::vector<const DofMap *> dof_maps, dof_maps)
183 
184 } // namespace libMesh
ElemType
Defines an enum for geometric element types.
TestClass subdomain_id_type
Based on the 4-byte comment warning above, this probably doesn&#39;t work with exodusII at all...
Definition: id_types.h:43
The libMesh namespace provides an interface to certain functionality in the library.
uint8_t processor_id_type
int8_t boundary_id_type
Definition: id_types.h:51