libMesh
single_predicates.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 <cstddef> // for NULL with gcc 4.6.2 - I'm serious!
23 #include "libmesh/libmesh_common.h"
24 #include "libmesh/enum_elem_type.h"
25 #include "libmesh/id_types.h"
26 
27 // C++ includes
28 #include <vector>
29 #include <set>
30 
31 namespace libMesh
32 {
33 
34 // Forward declarations
35 class BoundaryInfo;
36 class DofMap;
37 
38 
50 namespace Predicates
51 {
52 // Forward declaration
53 template <typename T> struct abstract_multi_predicate;
54 
55 // abstract single predicate. Derived classes must implement the clone()
56 // function. Be careful using it since it allocates memory! The clone()
57 // function is necessary since the predicate class has pure virtual
58 // functions.
59 template <typename T>
60 struct predicate
61 {
62  virtual ~predicate() {}
63  virtual bool operator()(const T & it) const = 0;
64 
65 protected:
66  friend struct abstract_multi_predicate<T>;
67  virtual predicate * clone() const = 0;
68 };
69 
70 
74 template <typename T>
75 struct is_null : predicate<T>
76 {
77  virtual ~is_null() {}
78  virtual bool operator()(const T & it) const libmesh_override { return *it == libmesh_nullptr; }
79 
80 protected:
81  virtual predicate<T> * clone() const libmesh_override { return new is_null<T>(*this); }
82 };
83 
87 template <typename T>
88 struct not_null : is_null<T>
89 {
90  virtual bool operator()(const T & it) const libmesh_override { return !is_null<T>::operator()(it); }
91 
92 protected:
93  virtual predicate<T> * clone() const libmesh_override { return new not_null<T>(*this); }
94 };
95 
96 
100 template <typename T>
101 struct active : predicate<T>
102 {
103  virtual ~active() {}
104  virtual bool operator()(const T & it) const libmesh_override { return (*it)->active(); }
105 
106 protected:
107  virtual predicate<T> * clone() const libmesh_override { return new active<T>(*this); }
108 };
109 
113 template <typename T>
114 struct not_active : active<T>
115 {
116  virtual bool operator()(const T & it) const libmesh_override { return !active<T>::operator()(it); }
117 
118 protected:
119  virtual predicate<T> * clone() const libmesh_override { return new not_active<T>(*this); }
120 };
121 
122 
126 template <typename T>
127 struct ancestor : predicate<T>
128 {
129  virtual ~ancestor() {}
130  virtual bool operator()(const T & it) const libmesh_override { return (*it)->ancestor(); }
131 
132 protected:
133  virtual predicate<T> * clone() const libmesh_override { return new ancestor<T>(*this); }
134 };
135 
139 template <typename T>
141 {
142  virtual bool operator()(const T & it) const libmesh_override { return !ancestor<T>::operator()(it); }
143 
144 protected:
145  virtual predicate<T> * clone() const libmesh_override { return new not_ancestor<T>(*this); }
146 };
147 
148 
152 template <typename T>
153 struct subactive : predicate<T>
154 {
155  virtual ~subactive() {}
156  virtual bool operator()(const T & it) const libmesh_override { return (*it)->subactive(); }
157 
158 protected:
159  virtual predicate<T> * clone() const libmesh_override { return new subactive<T>(*this); }
160 };
161 
165 template <typename T>
167 {
168  virtual bool operator()(const T & it) const libmesh_override { return !subactive<T>::operator()(it); }
169 
170 protected:
171  virtual predicate<T> * clone() const libmesh_override { return new not_subactive<T>(*this); }
172 };
173 
174 
175 
179 template <typename T>
180 struct pid : predicate<T>
181 {
182  pid(processor_id_type p) : _pid(p) {}
183  virtual ~pid() {}
184 
185  // op()
186  virtual bool operator()(const T & it) const libmesh_override { return (*it)->processor_id() == _pid; }
187 
188 protected:
189  virtual predicate<T> * clone() const libmesh_override { return new pid<T>(*this); }
191 };
192 
193 
194 
198 template <typename T>
199 struct bid : predicate<T>
200 {
202  const BoundaryInfo & bndry_info) :
203  _bid(bid),
204  _bndry_info(bndry_info)
205  {}
206  virtual ~bid() {}
207 
208  // op()
209  virtual bool operator()(const T & it) const libmesh_override;
210 
211 protected:
212  virtual predicate<T> * clone() const libmesh_override { return new bid<T>(*this); }
215 };
216 
217 
218 
222 template <typename T>
223 struct bnd : predicate<T>
224 {
225  bnd(const BoundaryInfo & bndry_info) :
226  _bndry_info(bndry_info)
227  {}
228  virtual ~bnd() {}
229 
230  // op()
231  virtual bool operator()(const T & it) const libmesh_override;
232 
233 protected:
234  virtual predicate<T> * clone() const libmesh_override { return new bnd<T>(*this); }
236 };
237 
238 
239 
244 template <typename T>
246 {
248  virtual ~semilocal_pid() {}
249 
250  // op()
251  virtual bool operator()(const T & it) const libmesh_override { return (*it)->is_semilocal(_pid); }
252 
253 protected:
254  virtual predicate<T> * clone() const libmesh_override { return new semilocal_pid<T>(*this); }
256 };
257 
258 
259 
264 template <typename T>
266 {
268  virtual ~facelocal_pid() {}
269 
270  // op()
271  virtual bool operator()(const T & it) const libmesh_override
272  {
273  if ((*it)->processor_id() == _pid)
274  return true;
275  for (auto n : (*it)->neighbor_ptr_range())
276  if (n && n->processor_id() == _pid)
277  return true;
278  return false;
279  }
280 
281 protected:
282  virtual predicate<T> * clone() const libmesh_override { return new facelocal_pid<T>(*this); }
284 };
285 
286 
287 
291 template <typename T>
292 struct not_pid : pid<T>
293 {
295 
296  virtual bool operator()(const T & it) const libmesh_override { return !pid<T>::operator()(it); }
297 
298 protected:
299  virtual predicate<T> * clone() const libmesh_override { return new not_pid<T>(*this); }
300 };
301 
302 
308 template <typename T>
309 struct elem_type : predicate<T>
310 {
311  elem_type (ElemType t) : _elem_type(t) {}
312  virtual ~elem_type() {}
313 
314  virtual bool operator()(const T & it) const libmesh_override { return (*it)->type() == _elem_type; }
315 
316 protected:
317  virtual predicate<T> * clone() const libmesh_override { return new elem_type<T>(*this); }
319 };
320 
321 
322 
323 #ifdef LIBMESH_ENABLE_AMR
324 
329 template <typename T>
330 struct flagged : predicate<T>
331 {
332  flagged (unsigned char rflag) : _rflag(rflag) {}
333  virtual ~flagged() {}
334 
335  virtual bool operator()(const T & it) const libmesh_override { return (*it)->refinement_flag() == _rflag; }
336 
337 protected:
338  virtual predicate<T> * clone() const libmesh_override { return new flagged<T>(*this); }
339  const unsigned char _rflag;
340 };
341 #endif // LIBMESH_ENABLE_AMR
342 
343 
344 
345 
346 
347 
351 template <typename T>
352 struct level : predicate<T>
353 {
354  level (unsigned int l) : _level(l) {}
355  virtual ~level() {}
356 
357  virtual bool operator()(const T & it) const libmesh_override { return (*it)->level() == _level; }
358 
359 protected:
360  virtual predicate<T> * clone() const libmesh_override { return new level<T>(*this); }
361  const unsigned int _level;
362 };
363 
364 
365 
370 template <typename T>
371 struct not_level : level<T>
372 {
373  not_level(unsigned int l) : level<T>(l) {}
374 
375  virtual bool operator()(const T & it) const libmesh_override { return !level<T>::operator()(it); }
376 
377 protected:
378  virtual predicate<T> * clone() const libmesh_override { return new not_level<T>(*this); }
379 };
380 
381 
382 
383 
387 template <typename T>
389 {
390  virtual ~null_neighbor() {}
391  virtual bool operator()(const T & it) const libmesh_override
392  {
393  return (*it)->on_boundary();
394  }
395 
396 protected:
397  virtual predicate<T> * clone() const libmesh_override { return new null_neighbor<T>(*this); }
398 };
399 
400 
401 
409 template <typename T>
411 {
412  virtual ~boundary_side() {}
413  virtual bool operator()(const T & it) const libmesh_override
414  {
415  return it.side_on_boundary();
416  }
417 
418 protected:
419  virtual predicate<T> * clone() const libmesh_override { return new boundary_side<T>(*this); }
420 };
421 
426 template <typename T>
427 struct subdomain : predicate<T>
428 {
429  subdomain(subdomain_id_type sid) : _subdomain(sid) {}
430  virtual ~subdomain() {}
431 
432  // op()
433  virtual bool operator()(const T & it) const libmesh_override { return (*it)->subdomain_id() == _subdomain; }
434 
435 protected:
436  virtual predicate<T> * clone() const libmesh_override { return new subdomain<T>(*this); }
438 };
439 
440 
445 template <typename T>
447 {
448  subdomain_set(std::set<subdomain_id_type> sset) : _subdomain_set(sset) {}
449  virtual ~subdomain_set() {}
450 
451  // op()
452  virtual bool operator()(const T & it) const libmesh_override { return _subdomain_set.count((*it)->subdomain_id()); }
453 
454 protected:
455  virtual predicate<T> * clone() const libmesh_override { return new subdomain_set<T>(*this); }
456  const std::set<subdomain_id_type> _subdomain_set;
457 };
458 
459 
465 template <typename T>
466 struct evaluable : predicate<T>
467 {
468  evaluable(const DofMap & dof_map,
469  unsigned int var_num) :
470  _dof_map(dof_map), _var_num(var_num) {}
471  virtual ~evaluable() {}
472 
473  // op()
474  virtual bool operator()(const T & it) const libmesh_override;
475 
476 protected:
477  virtual predicate<T> * clone() const libmesh_override { return new evaluable<T>(*this); }
478  const DofMap & _dof_map;
479  unsigned int _var_num;
480 };
481 
482 
483 } // namespace Predicates
484 
485 
486 } // namespace libMesh
487 
488 #endif // LIBMESH_SINGLE_PREDICATES_H
virtual predicate< T > * clone() const libmesh_override
const processor_id_type _pid
flagged(unsigned char rflag)
virtual predicate< T > * clone() const libmesh_override
virtual predicate< T > * clone() const libmesh_override
virtual predicate< T > * clone() const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
virtual predicate< T > * clone() const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
ElemType
Defines an enum for geometric element types.
virtual predicate< T > * clone() const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
virtual predicate< T > * clone() const libmesh_override
uint8_t processor_id_type
Definition: id_types.h:99
const class libmesh_nullptr_t libmesh_nullptr
virtual bool operator()(const T &it) const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
virtual predicate< T > * clone() const libmesh_override
bnd(const BoundaryInfo &bndry_info)
The libMesh namespace provides an interface to certain functionality in the library.
bid(boundary_id_type bid, const BoundaryInfo &bndry_info)
virtual bool operator()(const T &it) const libmesh_override
virtual predicate< T > * clone() const libmesh_override
virtual predicate * clone() const =0
virtual predicate< T > * clone() const libmesh_override
const BoundaryInfo & _bndry_info
virtual bool operator()(const T &it) const libmesh_override
virtual predicate< T > * clone() const libmesh_override
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:167
const boundary_id_type _bid
virtual predicate< T > * clone() const libmesh_override
evaluable(const DofMap &dof_map, unsigned int var_num)
virtual predicate< T > * clone() const libmesh_override
int8_t boundary_id_type
Definition: id_types.h:51
virtual predicate< T > * clone() const libmesh_override
virtual predicate< T > * clone() const libmesh_override
virtual predicate< T > * clone() const libmesh_override
not_pid(processor_id_type p)
virtual bool operator()(const T &it) const =0
The BoundaryInfo class contains information relevant to boundary conditions including storing faces...
Definition: boundary_info.h:56
virtual predicate< T > * clone() const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
subdomain(subdomain_id_type sid)
virtual bool operator()(const T &it) const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
virtual predicate< T > * clone() const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
virtual predicate< T > * clone() const libmesh_override
virtual predicate< T > * clone() const libmesh_override
virtual predicate< T > * clone() const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
subdomain_set(std::set< subdomain_id_type > sset)
virtual bool operator()(const T &it) const libmesh_override
const BoundaryInfo & _bndry_info
const subdomain_id_type _subdomain
virtual bool operator()(const T &it) const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
virtual bool operator()(const T &it) const libmesh_override
virtual predicate< T > * clone() const libmesh_override
pid(processor_id_type p)
virtual predicate< T > * clone() const libmesh_override
const std::set< subdomain_id_type > _subdomain_set