multi_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_MULTI_PREDICATES_H
19 #define LIBMESH_MULTI_PREDICATES_H
20 
21 // Local includes
23 
24 // C++ includes
25 #include <vector>
26 
27 namespace libMesh
28 {
29 
37 namespace Predicates
38 {
39 
40  // Empty place-holder base class for multi_predicates
41  struct multi_predicate {};
42 
43 
44  // This class represents a generic combination of more than one predicate.
45  // It is meant to be derived from to actually be used.
46  template <typename T>
48  {
49  // virtual destructor.
51  {
52  // Clean-up vector
53  for (unsigned int i=0; i<_predicates.size(); ++i)
54  delete _predicates[i];
55  }
56 
57  // operator= (perform deep copy of entries in _predicates vector
59  {
60  // First clear out the predicates vector
61  for (unsigned int i=0; i<_predicates.size(); ++i)
62  delete _predicates[i];
63 
64  // Now copy over the information from the rhs.
65  this->deep_copy(rhs);
66 
67  return *this;
68  }
69 
70  // operator() checks all the predicates in the vector.
71  virtual bool operator()(const T& it) const
72  {
73  for (unsigned int i=0; i<_predicates.size(); ++i)
74  {
75  const predicate<T>* pred = _predicates[i];
76 
77  libmesh_assert (pred);
78 
79  if ( ! (*pred)(it) )
80  return false;
81  }
82 
83  return true;
84  }
85 
86  protected:
87  // Do not instantiate the base class.
89 
90  // Copy constructor.
92  {
93  this->deep_copy(rhs);
94  }
95 
96  // The deep_copy function is used by both the op= and
97  // copy constructors. This function uses the default (empty)
98  // copy constructor for the predicate class.
100  {
101  for (unsigned int i=0; i<rhs._predicates.size(); ++i)
102  _predicates.push_back(rhs._predicates[i]->clone());
103  }
104 
105  // Predicates to be evaluated.
106  std::vector<predicate<T>*> _predicates;
107  };
108 
109 
110 
111  // Instantiation of the IsNull abstract_multi_predicate.
112  // This would be used to iterate over NULL entries in a container.
113  template <typename T>
115  {
116  // Constructor, pushes back a single predicate
118  {
119  this->_predicates.push_back(new is_null<T>);
120  }
121  };
122 
123 
124 
125 
126 
127 
128  // Instantiation for the NotNull abstract_multi_predicate
129  template <typename T>
131  {
132  // Constructor, pushes back a single predicate
134  {
135  this->_predicates.push_back(new not_null<T>);
136  }
137  };
138 
139 
140 
141 
142 
143  // Instantiation for the Active abstract_multi_predicate
144  template <typename T>
146  {
147  // Constructor, pushes back two single predicates
149  {
150  this->_predicates.push_back(new not_null<T>);
151  this->_predicates.push_back(new active<T>);
152  }
153  };
154 
155 
156 
157  // Instantiation for the NotActive abstract_multi_predicate
158  template <typename T>
160  {
161  // Constructor, pushes back two single predicates
163  {
164  this->_predicates.push_back(new not_null<T>);
165  this->_predicates.push_back(new not_active<T>);
166  }
167  };
168 
169 
170 
171 
172  // Instantiation for the Ancestor abstract_multi_predicate
173  template <typename T>
175  {
176  // Constructor, pushes back two single predicates
178  {
179  this->_predicates.push_back(new not_null<T>);
180  this->_predicates.push_back(new ancestor<T>);
181  }
182  };
183 
184 
185 
186 
187  // Instantiation for the NotAncestor abstract_multi_predicate
188  template <typename T>
190  {
191  // Constructor, pushes back two single predicates
193  {
194  this->_predicates.push_back(new not_null<T>);
195  this->_predicates.push_back(new not_ancestor<T>);
196  }
197  };
198 
199 
200 
201 
202  // Instantiation for the SubActive abstract_multi_predicate
203  template <typename T>
205  {
206  // Constructor, pushes back two single predicates
208  {
209  this->_predicates.push_back(new not_null<T>);
210  this->_predicates.push_back(new subactive<T>);
211  }
212  };
213 
214 
215 
216 
217  // Instantiation for the NotSubActive abstract_multi_predicate
218  template <typename T>
220  {
221  // Constructor, pushes back two single predicates
223  {
224  this->_predicates.push_back(new not_null<T>);
225  this->_predicates.push_back(new not_subactive<T>);
226  }
227  };
228 
229 
230 
231  // Instantiation for the Local abstract_multi_predicate
232  template <typename T>
234  {
235  // Constructor, pushes back two single predicates
236  Local(const processor_id_type my_pid)
237  {
238  this->_predicates.push_back(new not_null<T>);
239  this->_predicates.push_back(new pid<T>(my_pid));
240  }
241 
242  };
243 
244 
245  // Instantiation for the NotLocal abstract_multi_predicate
246  template <typename T>
248  {
249  // Constructor, pushes back two single predicates
251  {
252  this->_predicates.push_back(new not_null<T>);
253  this->_predicates.push_back(new not_pid<T>(my_pid));
254  }
255 
256  };
257 
258 
259  // Instantiation for the ActiveNotLocal abstract_multi_predicate
260  template <typename T>
262  {
263  // Constructor, pushes back two single predicates
265  {
266  this->_predicates.push_back(new not_null<T>);
267  this->_predicates.push_back(new active<T>);
268  this->_predicates.push_back(new not_pid<T>(my_pid));
269  }
270 
271  };
272 
273 
274  // Instantiation for the Type abstract_multi_predicate
275  template <typename T>
277  {
278  Type(const ElemType type)
279  {
280  this->_predicates.push_back(new not_null<T>);
281  this->_predicates.push_back(new elem_type<T>(type));
282  }
283  };
284 
285 
286 
287  // Instantiation for the ActiveType abstract_multi_predicate
288  template <typename T>
290  {
291  ActiveType(const ElemType type)
292  {
293  this->_predicates.push_back(new not_null<T>);
294  this->_predicates.push_back(new active<T>);
295  this->_predicates.push_back(new elem_type<T>(type));
296  }
297  };
298 
299 
300 
301  // Instantiation for the ActivePID abstract_multi_predicate
302  template <typename T>
304  {
306  {
307  this->_predicates.push_back(new not_null<T>);
308  this->_predicates.push_back(new active<T>);
309  this->_predicates.push_back(new pid<T>(proc_id));
310  }
311  };
312 
313 
314 
315 
316 
317  // Instantiation for the ActiveLocal abstract_multi_predicate
318  template <typename T>
320  {
322  {
323  this->_predicates.push_back(new not_null<T>);
324  this->_predicates.push_back(new active<T>);
325  this->_predicates.push_back(new pid<T>(my_pid));
326  }
327  };
328 
329 
330 
331 
332 
333  // Instantiation for the PID abstract_multi_predicate
334  template <typename T>
336  {
337  PID(const processor_id_type proc_id)
338  {
339  this->_predicates.push_back(new not_null<T>);
340  this->_predicates.push_back(new pid<T>(proc_id));
341  }
342  };
343 
344 
345 
346  // Instantiation for the NotPID abstract_multi_predicate
347  template <typename T>
349  {
350  NotPID(const processor_id_type proc_id)
351  {
352  this->_predicates.push_back(new not_null<T>);
353  this->_predicates.push_back(new not_pid<T>(proc_id));
354  }
355  };
356 
357 
358 
359 
360  // Instantiation for the Level abstract_multi_predicate
361  template <typename T>
363  {
364  Level(const unsigned int l)
365  {
366  this->_predicates.push_back(new not_null<T>);
367  this->_predicates.push_back(new level<T>(l));
368  }
369  };
370 
371 
372 
373 
374  // Instantiation for the NotLevel abstract_multi_predicate
375  template <typename T>
377  {
378  NotLevel(const unsigned int l)
379  {
380  this->_predicates.push_back(new not_null<T>);
381  this->_predicates.push_back(new not_level<T>(l));
382  }
383  };
384 
385 
386 
387 
388  // Instantiation for the LocalLevel abstract_multi_predicate
389  template <typename T>
391  {
393  const unsigned int l)
394  {
395  this->_predicates.push_back(new not_null<T>);
396  this->_predicates.push_back(new pid<T>(my_pid));
397  this->_predicates.push_back(new level<T>(l));
398  }
399  };
400 
401 
402 
403 
404  // Instantiation for the LocalNotLevel abstract_multi_predicate
405  template <typename T>
407  {
409  const unsigned int l)
410  {
411  this->_predicates.push_back(new not_null<T>);
412  this->_predicates.push_back(new pid<T>(my_pid));
413  this->_predicates.push_back(new not_level<T>(l));
414  }
415  };
416 
417 
418 
419  // Instantiation for the ActiveOnBoundary abstract_multi_predicate
420  template <typename T>
422  {
424  {
425  this->_predicates.push_back(new not_null<T>);
426  this->_predicates.push_back(new active<T>);
427  this->_predicates.push_back(new null_neighbor<T>);
428  }
429  };
430 
431 
432 
433  // Instantiation for the BoundarySide abstract_multi_predicate
434  template <typename T>
436  {
438  {
439  this->_predicates.push_back(new boundary_side<T>);
440  }
441  };
442 
443 
444 
445  // Instantiation for the ActiveLocalSubdomain abstract_multi_predicate
446  template <typename T>
448  {
450  const subdomain_id_type subdomain_id)
451  {
452  this->_predicates.push_back(new not_null<T>);
453  this->_predicates.push_back(new active<T>);
454  this->_predicates.push_back(new pid<T>(my_pid));
455  this->_predicates.push_back(new subdomain<T>(subdomain_id));
456  }
457  };
458 
459 
460 
461  // Instantiation for the ActiveSubdomain abstract_multi_predicate
462  template <typename T>
464  {
465  ActiveSubdomain(const subdomain_id_type subdomain_id)
466  {
467  this->_predicates.push_back(new not_null<T>);
468  this->_predicates.push_back(new active<T>);
469  this->_predicates.push_back(new subdomain<T>(subdomain_id));
470  }
471  };
472 
473 }
474 
475 
476 } // namespace libMesh
477 
478 #endif // LIBMESH_MULTI_PREDICATES_H

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

Hosted By:
SourceForge.net Logo