libMesh
single_predicates.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 #ifndef LIBMESH_SINGLE_PREDICATES_H
19 #define LIBMESH_SINGLE_PREDICATES_H
20 
21 // Local includes
22 #include "libmesh/libmesh_common.h"
23 #include "libmesh/id_types.h"
24 
25 // C++ includes
26 #include <cstddef>
27 
28 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
29 namespace libMesh
30 {
31 enum ElemType : int;
32 }
33 #else
34 #include "libmesh/enum_elem_type.h"
35 #endif
36 
37 // C++ includes
38 #include <vector>
39 #include <set>
40 
41 namespace libMesh
42 {
43 
44 // Forward declarations
45 class BoundaryInfo;
46 class DofMap;
47 
59 namespace Predicates
60 {
61 // Forward declaration
62 template <typename T> struct abstract_multi_predicate;
63 
64 // abstract single predicate. Derived classes must implement the clone()
65 // function. Be careful using it since it allocates memory! The clone()
66 // function is necessary since the predicate class has pure virtual
67 // functions.
68 template <typename T>
69 struct predicate
70 {
71  virtual ~predicate() {}
72  virtual bool operator()(const T & it) const = 0;
73 
74 protected:
75  friend struct abstract_multi_predicate<T>;
76  virtual predicate * clone() const = 0;
77 };
78 
79 
83 template <typename T>
84 struct is_null : predicate<T>
85 {
86  virtual ~is_null() {}
87  virtual bool operator()(const T & it) const override { return *it == nullptr; }
88 
89 protected:
90  virtual predicate<T> * clone() const override { return new is_null<T>(*this); }
91 };
92 
96 template <typename T>
97 struct not_null : is_null<T>
98 {
99  virtual bool operator()(const T & it) const override { return !is_null<T>::operator()(it); }
100 
101 protected:
102  virtual predicate<T> * clone() const override { return new not_null<T>(*this); }
103 };
104 
105 
109 template <typename T>
110 struct active : predicate<T>
111 {
112  virtual ~active() {}
113  virtual bool operator()(const T & it) const override { return (*it)->active(); }
114 
115 protected:
116  virtual predicate<T> * clone() const override { return new active<T>(*this); }
117 };
118 
122 template <typename T>
123 struct not_active : active<T>
124 {
125  virtual bool operator()(const T & it) const override { return !active<T>::operator()(it); }
126 
127 protected:
128  virtual predicate<T> * clone() const override { return new not_active<T>(*this); }
129 };
130 
131 
135 template <typename T>
136 struct ancestor : predicate<T>
137 {
138  virtual ~ancestor() {}
139  virtual bool operator()(const T & it) const override { return (*it)->ancestor(); }
140 
141 protected:
142  virtual predicate<T> * clone() const override { return new ancestor<T>(*this); }
143 };
144 
148 template <typename T>
150 {
151  virtual bool operator()(const T & it) const override { return !ancestor<T>::operator()(it); }
152 
153 protected:
154  virtual predicate<T> * clone() const override { return new not_ancestor<T>(*this); }
155 };
156 
157 
161 template <typename T>
162 struct subactive : predicate<T>
163 {
164  virtual ~subactive() {}
165  virtual bool operator()(const T & it) const override { return (*it)->subactive(); }
166 
167 protected:
168  virtual predicate<T> * clone() const override { return new subactive<T>(*this); }
169 };
170 
174 template <typename T>
176 {
177  virtual bool operator()(const T & it) const override { return !subactive<T>::operator()(it); }
178 
179 protected:
180  virtual predicate<T> * clone() const override { return new not_subactive<T>(*this); }
181 };
182 
183 
184 
188 template <typename T>
189 struct pid : predicate<T>
190 {
192  virtual ~pid() {}
193 
194  // op()
195  virtual bool operator()(const T & it) const override { return (*it)->processor_id() == _pid; }
196 
197 protected:
198  virtual predicate<T> * clone() const override { return new pid<T>(*this); }
200 };
201 
202 
203 
207 template <typename T>
208 struct bid : predicate<T>
209 {
211  const BoundaryInfo & bndry_info) :
212  _bid(b_id),
213  _bndry_info(bndry_info)
214  {}
215  virtual ~bid() {}
216 
217  // op()
218  virtual bool operator()(const T & it) const override;
219 
220 protected:
221  virtual predicate<T> * clone() const override { return new bid<T>(*this); }
224 };
225 
226 
227 
231 template <typename T>
232 struct bnd : predicate<T>
233 {
234  bnd(const BoundaryInfo & bndry_info) :
235  _bndry_info(bndry_info)
236  {}
237  virtual ~bnd() {}
238 
239  // op()
240  virtual bool operator()(const T & it) const override;
241 
242 protected:
243  virtual predicate<T> * clone() const override { return new bnd<T>(*this); }
245 };
246 
247 
248 
253 template <typename T>
255 {
257  virtual ~semilocal_pid() {}
258 
259  // op()
260  virtual bool operator()(const T & it) const override { return (*it)->is_semilocal(_pid); }
261 
262 protected:
263  virtual predicate<T> * clone() const override { return new semilocal_pid<T>(*this); }
265 };
266 
267 
268 
273 template <typename T>
275 {
277  virtual ~facelocal_pid() {}
278 
279  // op()
280  virtual bool operator()(const T & it) const override
281  {
282  if ((*it)->processor_id() == _pid)
283  return true;
284  for (auto n : (*it)->neighbor_ptr_range())
285  if (n && n->processor_id() == _pid)
286  return true;
287  return false;
288  }
289 
290 protected:
291  virtual predicate<T> * clone() const override { return new facelocal_pid<T>(*this); }
293 };
294 
295 
296 
300 template <typename T>
301 struct not_pid : pid<T>
302 {
304 
305  virtual bool operator()(const T & it) const override { return !pid<T>::operator()(it); }
306 
307 protected:
308  virtual predicate<T> * clone() const override { return new not_pid<T>(*this); }
309 };
310 
311 
317 template <typename T>
318 struct elem_type : predicate<T>
319 {
321  virtual ~elem_type() {}
322 
323  virtual bool operator()(const T & it) const override { return (*it)->type() == _elem_type; }
324 
325 protected:
326  virtual predicate<T> * clone() const override { return new elem_type<T>(*this); }
328 };
329 
330 
331 
332 #ifdef LIBMESH_ENABLE_AMR
333 
338 template <typename T>
339 struct flagged : predicate<T>
340 {
341  flagged (unsigned char rflag) : _rflag(rflag) {}
342  virtual ~flagged() {}
343 
344  virtual bool operator()(const T & it) const override { return (*it)->refinement_flag() == _rflag; }
345 
346 protected:
347  virtual predicate<T> * clone() const override { return new flagged<T>(*this); }
348  const unsigned char _rflag;
349 };
350 #endif // LIBMESH_ENABLE_AMR
351 
352 
353 
354 
355 
356 
360 template <typename T>
361 struct level : predicate<T>
362 {
363  level (unsigned int l) : _level(l) {}
364  virtual ~level() {}
365 
366  virtual bool operator()(const T & it) const override { return (*it)->level() == _level; }
367 
368 protected:
369  virtual predicate<T> * clone() const override { return new level<T>(*this); }
370  const unsigned int _level;
371 };
372 
373 
374 
379 template <typename T>
380 struct not_level : level<T>
381 {
382  not_level(unsigned int l) : level<T>(l) {}
383 
384  virtual bool operator()(const T & it) const override { return !level<T>::operator()(it); }
385 
386 protected:
387  virtual predicate<T> * clone() const override { return new not_level<T>(*this); }
388 };
389 
390 
391 
392 
396 template <typename T>
398 {
399  virtual ~null_neighbor() {}
400  virtual bool operator()(const T & it) const override
401  {
402  return (*it)->on_boundary();
403  }
404 
405 protected:
406  virtual predicate<T> * clone() const override { return new null_neighbor<T>(*this); }
407 };
408 
409 
410 
418 template <typename T>
420 {
421  virtual ~boundary_side() {}
422  virtual bool operator()(const T & it) const override
423  {
424  return it.side_on_boundary();
425  }
426 
427 protected:
428  virtual predicate<T> * clone() const override { return new boundary_side<T>(*this); }
429 };
430 
435 template <typename T>
436 struct subdomain : predicate<T>
437 {
439  virtual ~subdomain() {}
440 
441  // op()
442  virtual bool operator()(const T & it) const override { return (*it)->subdomain_id() == _subdomain; }
443 
444 protected:
445  virtual predicate<T> * clone() const override { return new subdomain<T>(*this); }
447 };
448 
449 
454 template <typename T>
456 {
457  subdomain_set(std::set<subdomain_id_type> sset) : _subdomain_set(sset) {}
458  virtual ~subdomain_set() {}
459 
460  // op()
461  virtual bool operator()(const T & it) const override { return _subdomain_set.count((*it)->subdomain_id()); }
462 
463 protected:
464  virtual predicate<T> * clone() const override { return new subdomain_set<T>(*this); }
465  const std::set<subdomain_id_type> _subdomain_set;
466 };
467 
468 
474 template <typename T>
475 struct evaluable : predicate<T>
476 {
477  evaluable(const DofMap & dof_map,
478  unsigned int var_num) :
479  _dof_map(dof_map), _var_num(var_num) {}
480  virtual ~evaluable() {}
481 
482  // op()
483  virtual bool operator()(const T & it) const override;
484 
485 protected:
486  virtual predicate<T> * clone() const override { return new evaluable<T>(*this); }
487  const DofMap & _dof_map;
488  unsigned int _var_num;
489 };
490 
491 
492 } // namespace Predicates
493 
494 
495 } // namespace libMesh
496 
497 #endif // LIBMESH_SINGLE_PREDICATES_H
virtual predicate< T > * clone() const override
virtual bool operator()(const T &it) const override
ElemType
Defines an enum for geometric element types.
const processor_id_type _pid
flagged(unsigned char rflag)
virtual predicate< T > * clone() const override
virtual predicate< T > * clone() const override
virtual predicate< T > * clone() const override
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
virtual predicate< T > * clone() const override
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
virtual predicate< T > * clone() const override
virtual predicate< T > * clone() const override
virtual bool operator()(const T &it) const override
virtual predicate< T > * clone() const override
virtual bool operator()(const T &it) const override
bnd(const BoundaryInfo &bndry_info)
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
The libMesh namespace provides an interface to certain functionality in the library.
virtual predicate< T > * clone() const override
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
virtual predicate< T > * clone() const override
virtual predicate * clone() const =0
virtual predicate< T > * clone() const override
uint8_t processor_id_type
Definition: id_types.h:104
const BoundaryInfo & _bndry_info
virtual predicate< T > * clone() const override
virtual predicate< T > * clone() const override
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:177
const boundary_id_type _bid
evaluable(const DofMap &dof_map, unsigned int var_num)
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
int8_t boundary_id_type
Definition: id_types.h:51
virtual predicate< T > * clone() const override
virtual bool operator()(const T &it) const =0
bid(boundary_id_type b_id, const BoundaryInfo &bndry_info)
not_pid(processor_id_type p)
The BoundaryInfo class contains information relevant to boundary conditions including storing faces...
Definition: boundary_info.h:57
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
subdomain(subdomain_id_type sid)
virtual predicate< T > * clone() const override
virtual predicate< T > * clone() const override
virtual predicate< T > * clone() const override
virtual predicate< T > * clone() const override
virtual bool operator()(const T &it) const override
virtual predicate< T > * clone() const override
virtual predicate< T > * clone() const override
virtual bool operator()(const T &it) const override
virtual predicate< T > * clone() const override
subdomain_set(std::set< subdomain_id_type > sset)
const BoundaryInfo & _bndry_info
virtual bool operator()(const T &it) const override
virtual predicate< T > * clone() const override
const subdomain_id_type _subdomain
virtual bool operator()(const T &it) const override
virtual predicate< T > * clone() const override
pid(processor_id_type p)
const std::set< subdomain_id_type > _subdomain_set
virtual bool operator()(const T &it) const override