single_predicates.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 #ifndef LIBMESH_SINGLE_PREDICATES_H 00019 #define LIBMESH_SINGLE_PREDICATES_H 00020 00021 // Local includes 00022 #include <cstddef> // for NULL with gcc 4.6.2 - I'm serious! 00023 #include "libmesh/enum_elem_type.h" 00024 #include "libmesh/id_types.h" 00025 00026 // C++ includes 00027 #include <cstddef> 00028 #include <vector> 00029 00030 namespace libMesh 00031 { 00032 00043 namespace Predicates 00044 { 00045 // Forward declaration 00046 template <typename T> struct abstract_multi_predicate; 00047 00048 // abstract single predicate. Derived classes must implement the clone() 00049 // function. Be careful using it since it allocates memory! The clone() 00050 // function is necessary since the predicate class has pure virtual 00051 // functions. 00052 template <typename T> 00053 struct predicate 00054 { 00055 virtual ~predicate() {} 00056 virtual bool operator()(const T& it) const = 0; 00057 00058 00059 protected: 00060 friend struct abstract_multi_predicate<T>; 00061 virtual predicate* clone() const = 0; 00062 00063 }; 00064 00065 00066 // The is_null predicate returns true if the underlying pointer is NULL. 00067 template <typename T> 00068 struct is_null : predicate<T> 00069 { 00070 virtual ~is_null() {} 00071 virtual bool operator()(const T& it) const { return *it == NULL; } 00072 00073 protected: 00074 virtual predicate<T>* clone() const { return new is_null<T>(*this); } 00075 }; 00076 00077 // The not_null predicate simply returns true if the pointer is not NULL. 00078 template <typename T> 00079 struct not_null : is_null<T> 00080 { 00081 virtual bool operator()(const T& it) const { return !is_null<T>::operator()(it); } 00082 00083 protected: 00084 virtual predicate<T>* clone() const { return new not_null<T>(*this); } 00085 }; 00086 00087 00088 // The active predicate returns true if the pointer is active. 00089 template <typename T> 00090 struct active : predicate<T> 00091 { 00092 virtual ~active() {} 00093 virtual bool operator()(const T& it) const { return (*it)->active(); } 00094 00095 protected: 00096 virtual predicate<T>* clone() const { return new active<T>(*this); } 00097 }; 00098 00099 // The not active predicate returns true when the pointer is inactive 00100 template <typename T> 00101 struct not_active : active<T> 00102 { 00103 virtual bool operator()(const T& it) const { return !active<T>::operator()(it); } 00104 00105 protected: 00106 virtual predicate<T>* clone() const { return new not_active<T>(*this); } 00107 }; 00108 00109 00110 // The ancestor predicate returns true if the pointer is ancestor. 00111 template <typename T> 00112 struct ancestor : predicate<T> 00113 { 00114 virtual ~ancestor() {} 00115 virtual bool operator()(const T& it) const { return (*it)->ancestor(); } 00116 00117 protected: 00118 virtual predicate<T>* clone() const { return new ancestor<T>(*this); } 00119 }; 00120 00121 // The not_ancestor predicate returns true when the pointer is not ancestor 00122 template <typename T> 00123 struct not_ancestor : ancestor<T> 00124 { 00125 virtual bool operator()(const T& it) const { return !ancestor<T>::operator()(it); } 00126 00127 protected: 00128 virtual predicate<T>* clone() const { return new not_ancestor<T>(*this); } 00129 }; 00130 00131 00132 // The subactive predicate returns true if the pointer is subactive. 00133 template <typename T> 00134 struct subactive : predicate<T> 00135 { 00136 virtual ~subactive() {} 00137 virtual bool operator()(const T& it) const { return (*it)->subactive(); } 00138 00139 protected: 00140 virtual predicate<T>* clone() const { return new subactive<T>(*this); } 00141 }; 00142 00143 // The not_subactive predicate returns true when the pointer is not subactive 00144 template <typename T> 00145 struct not_subactive : subactive<T> 00146 { 00147 virtual bool operator()(const T& it) const { return !subactive<T>::operator()(it); } 00148 00149 protected: 00150 virtual predicate<T>* clone() const { return new not_subactive<T>(*this); } 00151 }; 00152 00153 00154 00155 // The pid predicate returns true if the pointers 00156 // processor id matches a given processor id. 00157 template <typename T> 00158 struct pid : predicate<T> 00159 { 00160 // Constructor 00161 pid(const unsigned int p) : _pid(p) {} 00162 virtual ~pid() {} 00163 00164 // op() 00165 virtual bool operator()(const T& it) const { return (*it)->processor_id() == _pid; } 00166 00167 protected: 00168 virtual predicate<T>* clone() const { return new pid<T>(*this); } 00169 const unsigned int _pid; 00170 }; 00171 00172 00173 00174 // The not_pid predicate returns ture if the pointers 00175 // processor id does _not_ match p. 00176 template <typename T> 00177 struct not_pid : pid<T> 00178 { 00179 not_pid(const unsigned int p) : pid<T>(p) {} 00180 00181 virtual bool operator()(const T& it) const { return !pid<T>::operator()(it); } 00182 00183 protected: 00184 virtual predicate<T>* clone() const { return new not_pid<T>(*this); } 00185 }; 00186 00187 00188 // The elem_type predicate returns true if the pointers 00189 // type matches the given type. Of course, this one can only 00190 // be instantiated for objects which return Elem*s when dereferened. 00191 template <typename T> 00192 struct elem_type : predicate<T> 00193 { 00194 // Constructor 00195 elem_type (const ElemType t) : _elem_type(t) {} 00196 virtual ~elem_type() {} 00197 00198 virtual bool operator()(const T& it) const { return (*it)->type() == _elem_type; } 00199 00200 protected: 00201 virtual predicate<T>* clone() const { return new elem_type<T>(*this); } 00202 const ElemType _elem_type; 00203 }; 00204 00205 00206 00207 00208 00209 // The level predicate returns true if the pointers level 00210 // matches the given level. 00211 template <typename T> 00212 struct level : predicate<T> 00213 { 00214 // Constructor 00215 level (const unsigned int l) : _level(l) {} 00216 virtual ~level() {} 00217 00218 virtual bool operator()(const T& it) const { return (*it)->level() == _level; } 00219 00220 protected: 00221 virtual predicate<T>* clone() const { return new level<T>(*this); } 00222 const unsigned int _level; 00223 }; 00224 00225 00226 00227 // The not_level predicate returns true if the pointers level 00228 // _does not_ match the given level. 00229 template <typename T> 00230 struct not_level : level<T> 00231 { 00232 // Constructor 00233 not_level(const unsigned int l) : level<T>(l) {} 00234 00235 virtual bool operator()(const T& it) const { return !level<T>::operator()(it); } 00236 00237 protected: 00238 virtual predicate<T>* clone() const { return new not_level<T>(*this); } 00239 }; 00240 00241 00242 00243 00244 // The null_neighbor predicate returns true if the pointer has any 00245 // NULL neigbors. 00246 template <typename T> 00247 struct null_neighbor : predicate<T> 00248 { 00249 virtual ~null_neighbor() {} 00250 virtual bool operator()(const T& it) const 00251 { 00252 return (*it)->on_boundary(); 00253 } 00254 00255 protected: 00256 virtual predicate<T>* clone() const { return new null_neighbor<T>(*this); } 00257 }; 00258 00259 00260 00261 // This predicate simply forwards the work of determining whether 00262 // a particular side is on the boundary to the iterator itself, which 00263 // has more information. 00264 template <typename T> 00265 struct boundary_side : predicate<T> 00266 { 00267 virtual ~boundary_side() {} 00268 virtual bool operator()(const T& it) const 00269 { 00270 return it.side_on_boundary(); 00271 } 00272 00273 protected: 00274 virtual predicate<T>* clone() const { return new boundary_side<T>(*this); } 00275 }; 00276 00277 // The subdomain predicate returns true if the pointers 00278 // subdimain id matches a given subdomain id. 00279 template <typename T> 00280 struct subdomain : predicate<T> 00281 { 00282 // Constructor 00283 subdomain(const subdomain_id_type sid) : _subdomain(sid) {} 00284 virtual ~subdomain() {} 00285 00286 // op() 00287 virtual bool operator()(const T& it) const { return (*it)->subdomain_id() == _subdomain; } 00288 00289 protected: 00290 virtual predicate<T>* clone() const { return new subdomain<T>(*this); } 00291 const subdomain_id_type _subdomain; 00292 }; 00293 00294 } 00295 00296 00297 } // namespace libMesh 00298 00299 #endif // LIBMESH_SINGLE_PREDICATES_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:48 UTC
Hosted By: