$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 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_MULTI_PREDICATES_H 00019 #define LIBMESH_MULTI_PREDICATES_H 00020 00021 // Local includes 00022 #include "libmesh/single_predicates.h" 00023 00024 // C++ includes 00025 #include <vector> 00026 00027 namespace libMesh 00028 { 00029 00037 namespace Predicates 00038 { 00039 00040 // Empty place-holder base class for multi_predicates 00041 struct multi_predicate {}; 00042 00043 00044 // This class represents a generic combination of more than one predicate. 00045 // It is meant to be derived from to actually be used. 00046 template <typename T> 00047 struct abstract_multi_predicate : multi_predicate 00048 { 00049 // virtual destructor. 00050 virtual ~abstract_multi_predicate() 00051 { 00052 // Clean-up vector 00053 for (unsigned int i=0; i<_predicates.size(); ++i) 00054 delete _predicates[i]; 00055 } 00056 00057 // operator= (perform deep copy of entries in _predicates vector 00058 abstract_multi_predicate& operator=(const abstract_multi_predicate& rhs) 00059 { 00060 // First clear out the predicates vector 00061 for (unsigned int i=0; i<_predicates.size(); ++i) 00062 delete _predicates[i]; 00063 00064 // Now copy over the information from the rhs. 00065 this->deep_copy(rhs); 00066 00067 return *this; 00068 } 00069 00070 // operator() checks all the predicates in the vector. 00071 virtual bool operator()(const T& it) const 00072 { 00073 for (unsigned int i=0; i<_predicates.size(); ++i) 00074 { 00075 const predicate<T>* pred = _predicates[i]; 00076 00077 libmesh_assert (pred); 00078 00079 if ( ! (*pred)(it) ) 00080 return false; 00081 } 00082 00083 return true; 00084 } 00085 00086 protected: 00087 // Do not instantiate the base class. 00088 abstract_multi_predicate() {} 00089 00090 // Copy constructor. 00091 abstract_multi_predicate(const abstract_multi_predicate& rhs) 00092 { 00093 this->deep_copy(rhs); 00094 } 00095 00096 // The deep_copy function is used by both the op= and 00097 // copy constructors. This function uses the default (empty) 00098 // copy constructor for the predicate class. 00099 void deep_copy(const abstract_multi_predicate& rhs) 00100 { 00101 for (unsigned int i=0; i<rhs._predicates.size(); ++i) 00102 _predicates.push_back(rhs._predicates[i]->clone()); 00103 } 00104 00105 // Predicates to be evaluated. 00106 std::vector<predicate<T>*> _predicates; 00107 }; 00108 00109 00110 00111 // Instantiation of the IsNull abstract_multi_predicate. 00112 // This would be used to iterate over NULL entries in a container. 00113 template <typename T> 00114 struct IsNull : abstract_multi_predicate<T> 00115 { 00116 // Constructor, pushes back a single predicate 00117 IsNull() 00118 { 00119 this->_predicates.push_back(new is_null<T>); 00120 } 00121 }; 00122 00123 00124 00125 00126 00127 00128 // Instantiation for the NotNull abstract_multi_predicate 00129 template <typename T> 00130 struct NotNull : abstract_multi_predicate<T> 00131 { 00132 // Constructor, pushes back a single predicate 00133 NotNull() 00134 { 00135 this->_predicates.push_back(new not_null<T>); 00136 } 00137 }; 00138 00139 00140 00141 00142 00143 // Instantiation for the Active abstract_multi_predicate 00144 template <typename T> 00145 struct Active : abstract_multi_predicate<T> 00146 { 00147 // Constructor, pushes back two single predicates 00148 Active() 00149 { 00150 this->_predicates.push_back(new not_null<T>); 00151 this->_predicates.push_back(new active<T>); 00152 } 00153 }; 00154 00155 00156 00157 // Instantiation for the NotActive abstract_multi_predicate 00158 template <typename T> 00159 struct NotActive : abstract_multi_predicate<T> 00160 { 00161 // Constructor, pushes back two single predicates 00162 NotActive() 00163 { 00164 this->_predicates.push_back(new not_null<T>); 00165 this->_predicates.push_back(new not_active<T>); 00166 } 00167 }; 00168 00169 00170 00171 00172 // Instantiation for the Ancestor abstract_multi_predicate 00173 template <typename T> 00174 struct Ancestor : abstract_multi_predicate<T> 00175 { 00176 // Constructor, pushes back two single predicates 00177 Ancestor() 00178 { 00179 this->_predicates.push_back(new not_null<T>); 00180 this->_predicates.push_back(new ancestor<T>); 00181 } 00182 }; 00183 00184 00185 00186 00187 // Instantiation for the NotAncestor abstract_multi_predicate 00188 template <typename T> 00189 struct NotAncestor : abstract_multi_predicate<T> 00190 { 00191 // Constructor, pushes back two single predicates 00192 NotAncestor() 00193 { 00194 this->_predicates.push_back(new not_null<T>); 00195 this->_predicates.push_back(new not_ancestor<T>); 00196 } 00197 }; 00198 00199 00200 00201 00202 // Instantiation for the SubActive abstract_multi_predicate 00203 template <typename T> 00204 struct SubActive : abstract_multi_predicate<T> 00205 { 00206 // Constructor, pushes back two single predicates 00207 SubActive() 00208 { 00209 this->_predicates.push_back(new not_null<T>); 00210 this->_predicates.push_back(new subactive<T>); 00211 } 00212 }; 00213 00214 00215 00216 00217 // Instantiation for the NotSubActive abstract_multi_predicate 00218 template <typename T> 00219 struct NotSubActive : abstract_multi_predicate<T> 00220 { 00221 // Constructor, pushes back two single predicates 00222 NotSubActive() 00223 { 00224 this->_predicates.push_back(new not_null<T>); 00225 this->_predicates.push_back(new not_subactive<T>); 00226 } 00227 }; 00228 00229 00230 00231 // Instantiation for the Local abstract_multi_predicate 00232 template <typename T> 00233 struct Local : abstract_multi_predicate<T> 00234 { 00235 // Constructor, pushes back two single predicates 00236 Local(const processor_id_type my_pid) 00237 { 00238 this->_predicates.push_back(new not_null<T>); 00239 this->_predicates.push_back(new pid<T>(my_pid)); 00240 } 00241 00242 }; 00243 00244 00245 // Instantiation for the Local abstract_multi_predicate 00246 template <typename T> 00247 struct SemiLocal : abstract_multi_predicate<T> 00248 { 00249 // Constructor, pushes back two single predicates 00250 SemiLocal(const processor_id_type my_pid) 00251 { 00252 this->_predicates.push_back(new not_null<T>); 00253 this->_predicates.push_back(new not_subactive<T>); 00254 this->_predicates.push_back(new semilocal_pid<T>(my_pid)); 00255 } 00256 00257 }; 00258 00259 00260 // Instantiation for the Local abstract_multi_predicate 00261 template <typename T> 00262 struct FaceLocal : abstract_multi_predicate<T> 00263 { 00264 // Constructor, pushes back two single predicates 00265 FaceLocal(const processor_id_type my_pid) 00266 { 00267 this->_predicates.push_back(new not_null<T>); 00268 this->_predicates.push_back(new not_subactive<T>); 00269 this->_predicates.push_back(new facelocal_pid<T>(my_pid)); 00270 } 00271 00272 }; 00273 00274 00275 // Instantiation for the NotLocal abstract_multi_predicate 00276 template <typename T> 00277 struct NotLocal : abstract_multi_predicate<T> 00278 { 00279 // Constructor, pushes back two single predicates 00280 NotLocal(const processor_id_type my_pid) 00281 { 00282 this->_predicates.push_back(new not_null<T>); 00283 this->_predicates.push_back(new not_pid<T>(my_pid)); 00284 } 00285 00286 }; 00287 00288 00289 // Instantiation for the ActiveNotLocal abstract_multi_predicate 00290 template <typename T> 00291 struct ActiveNotLocal : abstract_multi_predicate<T> 00292 { 00293 // Constructor, pushes back two single predicates 00294 ActiveNotLocal(const processor_id_type my_pid) 00295 { 00296 this->_predicates.push_back(new not_null<T>); 00297 this->_predicates.push_back(new active<T>); 00298 this->_predicates.push_back(new not_pid<T>(my_pid)); 00299 } 00300 00301 }; 00302 00303 00304 // Instantiation for the Type abstract_multi_predicate 00305 template <typename T> 00306 struct Type : abstract_multi_predicate<T> 00307 { 00308 Type(const ElemType type) 00309 { 00310 this->_predicates.push_back(new not_null<T>); 00311 this->_predicates.push_back(new elem_type<T>(type)); 00312 } 00313 }; 00314 00315 00316 00317 // Instantiation for the ActiveType abstract_multi_predicate 00318 template <typename T> 00319 struct ActiveType : abstract_multi_predicate<T> 00320 { 00321 ActiveType(const ElemType type) 00322 { 00323 this->_predicates.push_back(new not_null<T>); 00324 this->_predicates.push_back(new active<T>); 00325 this->_predicates.push_back(new elem_type<T>(type)); 00326 } 00327 }; 00328 00329 00330 00331 // Instantiation for the ActivePID abstract_multi_predicate 00332 template <typename T> 00333 struct ActivePID : abstract_multi_predicate<T> 00334 { 00335 ActivePID(const processor_id_type proc_id) 00336 { 00337 this->_predicates.push_back(new not_null<T>); 00338 this->_predicates.push_back(new active<T>); 00339 this->_predicates.push_back(new pid<T>(proc_id)); 00340 } 00341 }; 00342 00343 00344 00345 00346 00347 // Instantiation for the ActiveLocal abstract_multi_predicate 00348 template <typename T> 00349 struct ActiveLocal : abstract_multi_predicate<T> 00350 { 00351 ActiveLocal(const processor_id_type my_pid) 00352 { 00353 this->_predicates.push_back(new not_null<T>); 00354 this->_predicates.push_back(new active<T>); 00355 this->_predicates.push_back(new pid<T>(my_pid)); 00356 } 00357 }; 00358 00359 00360 00361 00362 00363 // Instantiation for the PID abstract_multi_predicate 00364 template <typename T> 00365 struct PID : abstract_multi_predicate<T> 00366 { 00367 PID(const processor_id_type proc_id) 00368 { 00369 this->_predicates.push_back(new not_null<T>); 00370 this->_predicates.push_back(new pid<T>(proc_id)); 00371 } 00372 }; 00373 00374 00375 00376 // Instantiation for the NotPID abstract_multi_predicate 00377 template <typename T> 00378 struct NotPID : abstract_multi_predicate<T> 00379 { 00380 NotPID(const processor_id_type proc_id) 00381 { 00382 this->_predicates.push_back(new not_null<T>); 00383 this->_predicates.push_back(new not_pid<T>(proc_id)); 00384 } 00385 }; 00386 00387 00388 00389 00390 // Instantiation for the Level abstract_multi_predicate 00391 template <typename T> 00392 struct Level : abstract_multi_predicate<T> 00393 { 00394 Level(const unsigned int l) 00395 { 00396 this->_predicates.push_back(new not_null<T>); 00397 this->_predicates.push_back(new level<T>(l)); 00398 } 00399 }; 00400 00401 00402 00403 00404 // Instantiation for the NotLevel abstract_multi_predicate 00405 template <typename T> 00406 struct NotLevel : abstract_multi_predicate<T> 00407 { 00408 NotLevel(const unsigned int l) 00409 { 00410 this->_predicates.push_back(new not_null<T>); 00411 this->_predicates.push_back(new not_level<T>(l)); 00412 } 00413 }; 00414 00415 00416 00417 00418 // Instantiation for the LocalLevel abstract_multi_predicate 00419 template <typename T> 00420 struct LocalLevel : abstract_multi_predicate<T> 00421 { 00422 LocalLevel(const processor_id_type my_pid, 00423 const unsigned int l) 00424 { 00425 this->_predicates.push_back(new not_null<T>); 00426 this->_predicates.push_back(new pid<T>(my_pid)); 00427 this->_predicates.push_back(new level<T>(l)); 00428 } 00429 }; 00430 00431 00432 00433 00434 // Instantiation for the LocalNotLevel abstract_multi_predicate 00435 template <typename T> 00436 struct LocalNotLevel : abstract_multi_predicate<T> 00437 { 00438 LocalNotLevel(const processor_id_type my_pid, 00439 const unsigned int l) 00440 { 00441 this->_predicates.push_back(new not_null<T>); 00442 this->_predicates.push_back(new pid<T>(my_pid)); 00443 this->_predicates.push_back(new not_level<T>(l)); 00444 } 00445 }; 00446 00447 00448 00449 // Instantiation for the ActiveOnBoundary abstract_multi_predicate 00450 template <typename T> 00451 struct ActiveOnBoundary : abstract_multi_predicate<T> 00452 { 00453 ActiveOnBoundary() 00454 { 00455 this->_predicates.push_back(new not_null<T>); 00456 this->_predicates.push_back(new active<T>); 00457 this->_predicates.push_back(new null_neighbor<T>); 00458 } 00459 }; 00460 00461 00462 00463 // Instantiation for the BoundarySide abstract_multi_predicate 00464 template <typename T> 00465 struct BoundarySide : abstract_multi_predicate<T> 00466 { 00467 BoundarySide() 00468 { 00469 this->_predicates.push_back(new boundary_side<T>); 00470 } 00471 }; 00472 00473 00474 00475 // Instantiation for the ActiveLocalSubdomain abstract_multi_predicate 00476 template <typename T> 00477 struct ActiveLocalSubdomain : abstract_multi_predicate<T> 00478 { 00479 ActiveLocalSubdomain(const processor_id_type my_pid, 00480 const subdomain_id_type subdomain_id) 00481 { 00482 this->_predicates.push_back(new not_null<T>); 00483 this->_predicates.push_back(new active<T>); 00484 this->_predicates.push_back(new pid<T>(my_pid)); 00485 this->_predicates.push_back(new subdomain<T>(subdomain_id)); 00486 } 00487 }; 00488 00489 00490 00491 // Instantiation for the ActiveSubdomain abstract_multi_predicate 00492 template <typename T> 00493 struct ActiveSubdomain : abstract_multi_predicate<T> 00494 { 00495 ActiveSubdomain(const subdomain_id_type subdomain_id) 00496 { 00497 this->_predicates.push_back(new not_null<T>); 00498 this->_predicates.push_back(new active<T>); 00499 this->_predicates.push_back(new subdomain<T>(subdomain_id)); 00500 } 00501 }; 00502 00503 } 00504 00505 00506 } // namespace libMesh 00507 00508 #endif // LIBMESH_MULTI_PREDICATES_H