multi_predicates.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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
22 #include "libmesh/libmesh.h" // libMesh::invalid_uint
24 
25 // C++ includes
26 #include <vector>
27 
28 namespace libMesh {
29 class Elem;
30 }
31 
32 namespace libMesh
33 {
34 
35 // Forward declarations
36 class BoundaryInfo;
37 
46 namespace Predicates
47 {
48 
49 // Empty place-holder base class for multi_predicates
50 struct multi_predicate {};
51 
52 
53 // This class represents a generic combination of more than one predicate.
54 // It is meant to be derived from to actually be used.
55 template <typename T>
57 {
58  // virtual destructor.
60  {
61  // Clean-up vector
62  for (std::size_t i=0; i<_predicates.size(); ++i)
63  delete _predicates[i];
64  }
65 
66  // operator= (perform deep copy of entries in _predicates vector
68  {
69  // First clear out the predicates vector
70  for (std::size_t i=0; i<_predicates.size(); ++i)
71  delete _predicates[i];
72 
73  // Now copy over the information from the rhs.
74  this->deep_copy(rhs);
75 
76  return *this;
77  }
78 
79  // operator() checks all the predicates in the vector.
80  virtual bool operator()(const T & it) const
81  {
82  for (std::size_t i=0; i<_predicates.size(); ++i)
83  {
84  const predicate<T> * pred = _predicates[i];
85 
86  libmesh_assert (pred);
87 
88  if (!(*pred)(it))
89  return false;
90  }
91 
92  return true;
93  }
94 
95 protected:
96  // Do not instantiate the base class.
98 
99  // Copy constructor.
101  {
102  this->deep_copy(rhs);
103  }
104 
105  // The deep_copy function is used by both the op= and
106  // copy constructors. This function uses the default (empty)
107  // copy constructor for the predicate class.
109  {
110  for (std::size_t i=0; i<rhs._predicates.size(); ++i)
111  _predicates.push_back(rhs._predicates[i]->clone());
112  }
113 
114  // Predicates to be evaluated.
115  std::vector<predicate<T> *> _predicates;
116 };
117 
118 
119 
123 template <typename T>
125 {
126  // Constructor, pushes back a single predicate
128  {
129  this->_predicates.push_back(new is_null<T>);
130  }
131 };
132 
133 
134 
138 template <typename T>
140 {
141  // Constructor, pushes back a single predicate
143  {
144  this->_predicates.push_back(new not_null<T>);
145  }
146 };
147 
148 
149 
153 template <typename T>
155 {
156  // Constructor, pushes back two single predicates
158  {
159  this->_predicates.push_back(new not_null<T>);
160  this->_predicates.push_back(new active<T>);
161  }
162 };
163 
164 
165 
169 template <typename T>
171 {
172  // Constructor, pushes back two single predicates
174  {
175  this->_predicates.push_back(new not_null<T>);
176  this->_predicates.push_back(new not_active<T>);
177  }
178 };
179 
180 
181 
182 
187 template <typename T>
189 {
190  // Constructor, pushes back two single predicates
192  {
193  this->_predicates.push_back(new not_null<T>);
194  this->_predicates.push_back(new ancestor<T>);
195  }
196 };
197 
198 
199 
200 
205 template <typename T>
207 {
208  // Constructor, pushes back two single predicates
210  {
211  this->_predicates.push_back(new not_null<T>);
212  this->_predicates.push_back(new not_ancestor<T>);
213  }
214 };
215 
216 
217 
218 
223 template <typename T>
225 {
226  // Constructor, pushes back two single predicates
228  {
229  this->_predicates.push_back(new not_null<T>);
230  this->_predicates.push_back(new subactive<T>);
231  }
232 };
233 
234 
235 
236 
241 template <typename T>
243 {
244  // Constructor, pushes back two single predicates
246  {
247  this->_predicates.push_back(new not_null<T>);
248  this->_predicates.push_back(new not_subactive<T>);
249  }
250 };
251 
252 
253 
258 template <typename T>
260 {
261  // Constructor, pushes back two single predicates
263  {
264  this->_predicates.push_back(new not_null<T>);
265  this->_predicates.push_back(new pid<T>(my_pid));
266  }
267 };
268 
269 
279 // template <typename T>
280 // struct SemiLocal : abstract_multi_predicate<T>
281 // {
282 // // Constructor, pushes back two single predicates
283 // SemiLocal(processor_id_type my_pid)
284 // {
285 // this->_predicates.push_back(new not_null<T>);
286 // this->_predicates.push_back(new not_subactive<T>);
287 // this->_predicates.push_back(new semilocal_pid<T>(my_pid));
288 // }
289 // };
290 
291 
296 template <typename T>
298 {
299  // Constructor, pushes back two single predicates
301  {
302  this->_predicates.push_back(new not_null<T>);
303  this->_predicates.push_back(new active<T>);
304  this->_predicates.push_back(new not_subactive<T>);
305  this->_predicates.push_back(new semilocal_pid<T>(my_pid));
306  }
307 };
308 
309 
315 template <typename T>
317 {
318  // Constructor, pushes back two single predicates
320  {
321  this->_predicates.push_back(new not_null<T>);
322  this->_predicates.push_back(new not_subactive<T>);
323  this->_predicates.push_back(new facelocal_pid<T>(my_pid));
324  }
325 };
326 
327 
328 
333 template <typename T>
335 {
336  // Constructor, pushes back two single predicates
338  {
339  this->_predicates.push_back(new not_null<T>);
340  this->_predicates.push_back(new not_pid<T>(my_pid));
341  }
342 };
343 
344 
349 template <typename T>
351 {
352  // Constructor, pushes back two single predicates
354  {
355  this->_predicates.push_back(new not_null<T>);
356  this->_predicates.push_back(new active<T>);
357  this->_predicates.push_back(new not_pid<T>(my_pid));
358  }
359 };
360 
361 
365 template <typename T>
367 {
369  {
370  this->_predicates.push_back(new not_null<T>);
371  this->_predicates.push_back(new elem_type<T>(type));
372  }
373 };
374 
375 
376 
380 template <typename T>
382 {
384  {
385  this->_predicates.push_back(new not_null<T>);
386  this->_predicates.push_back(new active<T>);
387  this->_predicates.push_back(new elem_type<T>(type));
388  }
389 };
390 
391 
392 
393 #ifdef LIBMESH_ENABLE_AMR
394 
398 template <typename T>
400 {
401  Flagged(unsigned char rflag)
402  {
403  this->_predicates.push_back(new not_null<T>);
404  this->_predicates.push_back(new flagged<T>(rflag));
405  }
406 };
407 
408 
409 
414 template <typename T>
416 {
417  FlaggedPID(unsigned char rflag, processor_id_type proc_id)
418  {
419  this->_predicates.push_back(new not_null<T>);
420  this->_predicates.push_back(new flagged<T>(rflag));
421  this->_predicates.push_back(new pid<T>(proc_id));
422  }
423 };
424 
425 #endif // LIBMESH_ENABLE_AMR
426 
427 
428 
429 
434 template <typename T>
436 {
438  {
439  this->_predicates.push_back(new not_null<T>);
440  this->_predicates.push_back(new active<T>);
441  this->_predicates.push_back(new pid<T>(proc_id));
442  }
443 };
444 
445 
446 
447 
448 
453 template <typename T>
455 {
457  {
458  this->_predicates.push_back(new not_null<T>);
459  this->_predicates.push_back(new active<T>);
460  this->_predicates.push_back(new pid<T>(my_pid));
461  }
462 };
463 
464 
465 
466 
467 
471 template <typename T>
473 {
475  {
476  this->_predicates.push_back(new not_null<T>);
477  this->_predicates.push_back(new pid<T>(proc_id));
478  }
479 };
480 
481 
482 
487 template <typename T>
489 {
490  BID(boundary_id_type bndry_id, const BoundaryInfo & bndry_info)
491  {
492  this->_predicates.push_back(new not_null<T>);
493  this->_predicates.push_back(new bid<T>(bndry_id, bndry_info));
494  }
495 };
496 
497 
498 
502 template <typename T>
504 {
505  BND(const BoundaryInfo & bndry_info)
506  {
507  this->_predicates.push_back(new not_null<T>);
508  this->_predicates.push_back(new bnd<T>(bndry_info));
509  }
510 };
511 
512 
513 
518 template <typename T>
520 {
522  {
523  this->_predicates.push_back(new not_null<T>);
524  this->_predicates.push_back(new not_pid<T>(proc_id));
525  }
526 };
527 
528 
529 
533 template <typename T>
535 {
536  Level(unsigned int l)
537  {
538  this->_predicates.push_back(new not_null<T>);
539  this->_predicates.push_back(new level<T>(l));
540  }
541 };
542 
543 
544 
549 template <typename T>
551 {
552  NotLevel(unsigned int l)
553  {
554  this->_predicates.push_back(new not_null<T>);
555  this->_predicates.push_back(new not_level<T>(l));
556  }
557 };
558 
559 
560 
565 template <typename T>
567 {
569  unsigned int l)
570  {
571  this->_predicates.push_back(new not_null<T>);
572  this->_predicates.push_back(new pid<T>(my_pid));
573  this->_predicates.push_back(new level<T>(l));
574  }
575 };
576 
577 
578 
583 template <typename T>
585 {
587  unsigned int l)
588  {
589  this->_predicates.push_back(new not_null<T>);
590  this->_predicates.push_back(new pid<T>(my_pid));
591  this->_predicates.push_back(new not_level<T>(l));
592  }
593 };
594 
595 
596 
601 template <typename T>
603 {
605  {
606  this->_predicates.push_back(new not_null<T>);
607  this->_predicates.push_back(new active<T>);
608  this->_predicates.push_back(new null_neighbor<T>);
609  }
610 };
611 
612 
613 
618 template <typename T>
620 {
622  {
623  this->_predicates.push_back(new boundary_side<T>);
624  }
625 };
626 
627 
628 
633 template <typename T>
635 {
637  subdomain_id_type subdomain_id)
638  {
639  this->_predicates.push_back(new not_null<T>);
640  this->_predicates.push_back(new active<T>);
641  this->_predicates.push_back(new pid<T>(my_pid));
642  this->_predicates.push_back(new subdomain<T>(subdomain_id));
643  }
644 };
645 
646 
647 
652 template <typename T>
654 {
656  {
657  this->_predicates.push_back(new not_null<T>);
658  this->_predicates.push_back(new active<T>);
659  this->_predicates.push_back(new subdomain<T>(subdomain_id));
660  }
661 };
662 
663 
664 
669 template <typename T>
671 {
672  ActiveSubdomainSet(std::set<subdomain_id_type> sset)
673  {
674  this->_predicates.push_back(new not_null<T>);
675  this->_predicates.push_back(new active<T>);
676  this->_predicates.push_back(new subdomain_set<T>(sset));
677  }
678 };
679 
680 
681 
686 template <typename T>
688 {
690  {
691  this->_predicates.push_back(new not_null<T>);
692  this->_predicates.push_back(new active<T>);
693  this->_predicates.push_back(new not_pid<T>(my_pid));
694  this->_predicates.push_back(new semilocal_pid<T>(my_pid));
695  }
696 };
697 
698 
699 
704 template <typename T>
706 {
707  Evaluable(const DofMap & dof_map,
708  unsigned int var_num = libMesh::invalid_uint)
709  {
710  this->_predicates.push_back(new not_null<T>);
711  this->_predicates.push_back(new active<T>);
712  this->_predicates.push_back(new evaluable<T>(dof_map, var_num));
713  }
714 };
715 
716 }
717 
718 
719 } // namespace libMesh
720 
721 #endif // LIBMESH_MULTI_PREDICATES_H
Ghost(processor_id_type my_pid)
FlaggedPID(unsigned char rflag, processor_id_type proc_id)
NotLocal(processor_id_type my_pid)
const unsigned int invalid_uint
Definition: libmesh.h:245
BND(const BoundaryInfo &bndry_info)
ActiveLocalSubdomain(processor_id_type my_pid, subdomain_id_type subdomain_id)
ActiveSubdomainSet(std::set< subdomain_id_type > sset)
ActiveSemiLocal(processor_id_type my_pid)
uint8_t processor_id_type
Definition: id_types.h:99
Evaluable(const DofMap &dof_map, unsigned int var_num=libMesh::invalid_uint)
Manages the degrees of freedom (DOFs) in a simulation.
Definition: dof_map.h:176
ActivePID(processor_id_type proc_id)
int8_t boundary_id_type
Definition: id_types.h:51
abstract_multi_predicate & operator=(const abstract_multi_predicate &rhs)
PID(processor_id_type proc_id)
void deep_copy(const abstract_multi_predicate &rhs)
Used by the Mesh to keep track of boundary nodes and elements.
Definition: boundary_info.h:57
NotPID(processor_id_type proc_id)
std::vector< predicate< T > * > _predicates
PredBase * pred
LocalNotLevel(processor_id_type my_pid, unsigned int l)
ActiveLocal(processor_id_type my_pid)
abstract_multi_predicate(const abstract_multi_predicate &rhs)
Flagged(unsigned char rflag)
Local(processor_id_type my_pid)
FaceLocal(processor_id_type my_pid)
ActiveSubdomain(subdomain_id_type subdomain_id)
virtual bool operator()(const T &it) const
ActiveNotLocal(processor_id_type my_pid)
BID(boundary_id_type bndry_id, const BoundaryInfo &bndry_info)
LocalLevel(processor_id_type my_pid, unsigned int l)