single_predicates.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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/enum_elem_type.h"
24 #include "libmesh/id_types.h"
25 
26 // C++ includes
27 #include <cstddef>
28 #include <vector>
29 
30 namespace libMesh
31 {
32 
43 namespace Predicates
44 {
45  // Forward declaration
46  template <typename T> struct abstract_multi_predicate;
47 
48  // abstract single predicate. Derived classes must implement the clone()
49  // function. Be careful using it since it allocates memory! The clone()
50  // function is necessary since the predicate class has pure virtual
51  // functions.
52  template <typename T>
53  struct predicate
54  {
55  virtual ~predicate() {}
56  virtual bool operator()(const T& it) const = 0;
57 
58 
59  protected:
60  friend struct abstract_multi_predicate<T>;
61  virtual predicate* clone() const = 0;
62 
63  };
64 
65 
66  // The is_null predicate returns true if the underlying pointer is NULL.
67  template <typename T>
68  struct is_null : predicate<T>
69  {
70  virtual ~is_null() {}
71  virtual bool operator()(const T& it) const { return *it == NULL; }
72 
73  protected:
74  virtual predicate<T>* clone() const { return new is_null<T>(*this); }
75  };
76 
77  // The not_null predicate simply returns true if the pointer is not NULL.
78  template <typename T>
79  struct not_null : is_null<T>
80  {
81  virtual bool operator()(const T& it) const { return !is_null<T>::operator()(it); }
82 
83  protected:
84  virtual predicate<T>* clone() const { return new not_null<T>(*this); }
85  };
86 
87 
88  // The active predicate returns true if the pointer is active.
89  template <typename T>
90  struct active : predicate<T>
91  {
92  virtual ~active() {}
93  virtual bool operator()(const T& it) const { return (*it)->active(); }
94 
95  protected:
96  virtual predicate<T>* clone() const { return new active<T>(*this); }
97  };
98 
99  // The not active predicate returns true when the pointer is inactive
100  template <typename T>
101  struct not_active : active<T>
102  {
103  virtual bool operator()(const T& it) const { return !active<T>::operator()(it); }
104 
105  protected:
106  virtual predicate<T>* clone() const { return new not_active<T>(*this); }
107  };
108 
109 
110  // The ancestor predicate returns true if the pointer is ancestor.
111  template <typename T>
112  struct ancestor : predicate<T>
113  {
114  virtual ~ancestor() {}
115  virtual bool operator()(const T& it) const { return (*it)->ancestor(); }
116 
117  protected:
118  virtual predicate<T>* clone() const { return new ancestor<T>(*this); }
119  };
120 
121  // The not_ancestor predicate returns true when the pointer is not ancestor
122  template <typename T>
123  struct not_ancestor : ancestor<T>
124  {
125  virtual bool operator()(const T& it) const { return !ancestor<T>::operator()(it); }
126 
127  protected:
128  virtual predicate<T>* clone() const { return new not_ancestor<T>(*this); }
129  };
130 
131 
132  // The subactive predicate returns true if the pointer is subactive.
133  template <typename T>
134  struct subactive : predicate<T>
135  {
136  virtual ~subactive() {}
137  virtual bool operator()(const T& it) const { return (*it)->subactive(); }
138 
139  protected:
140  virtual predicate<T>* clone() const { return new subactive<T>(*this); }
141  };
142 
143  // The not_subactive predicate returns true when the pointer is not subactive
144  template <typename T>
146  {
147  virtual bool operator()(const T& it) const { return !subactive<T>::operator()(it); }
148 
149  protected:
150  virtual predicate<T>* clone() const { return new not_subactive<T>(*this); }
151  };
152 
153 
154 
155  // The pid predicate returns true if the pointers
156  // processor id matches a given processor id.
157  template <typename T>
158  struct pid : predicate<T>
159  {
160  // Constructor
161  pid(const processor_id_type p) : _pid(p) {}
162  virtual ~pid() {}
163 
164  // op()
165  virtual bool operator()(const T& it) const { return (*it)->processor_id() == _pid; }
166 
167  protected:
168  virtual predicate<T>* clone() const { return new pid<T>(*this); }
170  };
171 
172 
173 
174  // The not_pid predicate returns ture if the pointers
175  // processor id does _not_ match p.
176  template <typename T>
177  struct not_pid : pid<T>
178  {
179  not_pid(const processor_id_type p) : pid<T>(p) {}
180 
181  virtual bool operator()(const T& it) const { return !pid<T>::operator()(it); }
182 
183  protected:
184  virtual predicate<T>* clone() const { return new not_pid<T>(*this); }
185  };
186 
187 
188  // The elem_type predicate returns true if the pointers
189  // type matches the given type. Of course, this one can only
190  // be instantiated for objects which return Elem*s when dereferened.
191  template <typename T>
192  struct elem_type : predicate<T>
193  {
194  // Constructor
195  elem_type (const ElemType t) : _elem_type(t) {}
196  virtual ~elem_type() {}
197 
198  virtual bool operator()(const T& it) const { return (*it)->type() == _elem_type; }
199 
200  protected:
201  virtual predicate<T>* clone() const { return new elem_type<T>(*this); }
203  };
204 
205 
206 
207 
208 
209  // The level predicate returns true if the pointers level
210  // matches the given level.
211  template <typename T>
212  struct level : predicate<T>
213  {
214  // Constructor
215  level (const unsigned int l) : _level(l) {}
216  virtual ~level() {}
217 
218  virtual bool operator()(const T& it) const { return (*it)->level() == _level; }
219 
220  protected:
221  virtual predicate<T>* clone() const { return new level<T>(*this); }
222  const unsigned int _level;
223  };
224 
225 
226 
227  // The not_level predicate returns true if the pointers level
228  // _does not_ match the given level.
229  template <typename T>
230  struct not_level : level<T>
231  {
232  // Constructor
233  not_level(const unsigned int l) : level<T>(l) {}
234 
235  virtual bool operator()(const T& it) const { return !level<T>::operator()(it); }
236 
237  protected:
238  virtual predicate<T>* clone() const { return new not_level<T>(*this); }
239  };
240 
241 
242 
243 
244  // The null_neighbor predicate returns true if the pointer has any
245  // NULL neigbors.
246  template <typename T>
248  {
249  virtual ~null_neighbor() {}
250  virtual bool operator()(const T& it) const
251  {
252  return (*it)->on_boundary();
253  }
254 
255  protected:
256  virtual predicate<T>* clone() const { return new null_neighbor<T>(*this); }
257  };
258 
259 
260 
261  // This predicate simply forwards the work of determining whether
262  // a particular side is on the boundary to the iterator itself, which
263  // has more information.
264  template <typename T>
266  {
267  virtual ~boundary_side() {}
268  virtual bool operator()(const T& it) const
269  {
270  return it.side_on_boundary();
271  }
272 
273  protected:
274  virtual predicate<T>* clone() const { return new boundary_side<T>(*this); }
275  };
276 
277  // The subdomain predicate returns true if the pointers
278  // subdimain id matches a given subdomain id.
279  template <typename T>
280  struct subdomain : predicate<T>
281  {
282  // Constructor
284  virtual ~subdomain() {}
285 
286  // op()
287  virtual bool operator()(const T& it) const { return (*it)->subdomain_id() == _subdomain; }
288 
289  protected:
290  virtual predicate<T>* clone() const { return new subdomain<T>(*this); }
292  };
293 
294 }
295 
296 
297 } // namespace libMesh
298 
299 #endif // LIBMESH_SINGLE_PREDICATES_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:07 UTC

Hosted By:
SourceForge.net Logo