libMesh
Loading...
Searching...
No Matches
single_predicates.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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 "libmesh/libmesh_common.h"
23#include "libmesh/id_types.h"
24
25// C++ includes
26#include <cstddef>
27#include <vector>
28#include <set>
29#include <memory>
30
31namespace libMesh
32{
33
34// Forward declarations
35class BoundaryInfo;
36class DofMap;
37enum ElemType : int;
38
50namespace Predicates
51{
52// Forward declaration
53template <typename T> struct abstract_multi_predicate;
54
55// abstract single predicate. Derived classes must implement the clone()
56// function. Be careful using it since it allocates memory! The clone()
57// function is necessary since the predicate class has pure virtual
58// functions.
59template <typename T>
61{
62 virtual ~predicate() = default;
63 virtual bool operator()(const T & it) const = 0;
64
65protected:
66 friend struct abstract_multi_predicate<T>;
67 virtual std::unique_ptr<predicate> clone() const = 0;
68};
69
70
74template <typename T>
75struct is_null : predicate<T>
76{
77 virtual ~is_null() = default;
78 virtual bool operator()(const T & it) const override { return *it == nullptr; }
79
80protected:
81 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<is_null<T>>(*this); }
82};
83
87template <typename T>
88struct not_null : is_null<T>
89{
90 virtual bool operator()(const T & it) const override { return !is_null<T>::operator()(it); }
91
92protected:
93 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<not_null<T>>(*this); }
94};
95
96
100template <typename T>
101struct active : predicate<T>
102{
103 virtual ~active() = default;
104 virtual bool operator()(const T & it) const override { return (*it)->active(); }
105
106protected:
107 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<active<T>>(*this); }
108};
109
113template <typename T>
115{
116 virtual bool operator()(const T & it) const override { return !active<T>::operator()(it); }
117
118protected:
119 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<not_active<T>>(*this); }
120};
121
122
126template <typename T>
128{
129 virtual ~ancestor() = default;
130 virtual bool operator()(const T & it) const override { return (*it)->ancestor(); }
131
132protected:
133 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<ancestor<T>>(*this); }
134};
135
139template <typename T>
141{
142 virtual bool operator()(const T & it) const override { return !ancestor<T>::operator()(it); }
143
144protected:
145 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<not_ancestor<T>>(*this); }
146};
147
148
152template <typename T>
154{
155 virtual ~subactive() = default;
156 virtual bool operator()(const T & it) const override { return (*it)->subactive(); }
157
158protected:
159 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<subactive<T>>(*this); }
160};
161
165template <typename T>
167{
168 virtual bool operator()(const T & it) const override { return !subactive<T>::operator()(it); }
169
170protected:
171 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<not_subactive<T>>(*this); }
172};
173
174
175
179template <typename T>
180struct pid : predicate<T>
181{
183 virtual ~pid() = default;
184
185 // op()
186 virtual bool operator()(const T & it) const override { return (*it)->processor_id() == _pid; }
187
188protected:
189 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<pid<T>>(*this); }
191};
192
193
194
198template <typename T>
199struct bid : predicate<T>
200{
202 const BoundaryInfo & bndry_info) :
203 _bid(b_id),
204 _bndry_info(bndry_info)
205 {}
206 virtual ~bid() = default;
207
208 // op()
209 virtual bool operator()(const T & it) const override;
210
211protected:
212 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<bid<T>>(*this); }
215};
216
217
218
222template <typename T>
223struct bnd : predicate<T>
224{
225 bnd(const BoundaryInfo & bndry_info) :
226 _bndry_info(bndry_info)
227 {}
228 virtual ~bnd() = default;
229
230 // op()
231 virtual bool operator()(const T & it) const override;
232
233protected:
234 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<bnd<T>>(*this); }
236};
237
238
239
244template <typename T>
246{
248 virtual ~semilocal_pid() = default;
249
250 // op()
251 virtual bool operator()(const T & it) const override { return (*it)->is_semilocal(_pid); }
252
253protected:
254 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<semilocal_pid<T>>(*this); }
256};
257
258
259
264template <typename T>
266{
268 virtual ~facelocal_pid() = default;
269
270 // op()
271 virtual bool operator()(const T & it) const override
272 {
273 if ((*it)->processor_id() == _pid)
274 return true;
275 for (auto n : (*it)->neighbor_ptr_range())
276 if (n && n->processor_id() == _pid)
277 return true;
278 return false;
279 }
280
281protected:
282 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<facelocal_pid<T>>(*this); }
284};
285
286
287
291template <typename T>
292struct not_pid : pid<T>
293{
295
296 virtual bool operator()(const T & it) const override { return !pid<T>::operator()(it); }
297
298protected:
299 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<not_pid<T>>(*this); }
300};
301
302
308template <typename T>
310{
312 virtual ~elem_type() = default;
313
314 virtual bool operator()(const T & it) const override { return (*it)->type() == _elem_type; }
315
316protected:
317 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<elem_type<T>>(*this); }
319};
320
321
322
323#ifdef LIBMESH_ENABLE_AMR
329template <typename T>
331{
332 flagged (unsigned char rflag) : _rflag(rflag) {}
333 virtual ~flagged() = default;
334
335 virtual bool operator()(const T & it) const override { return (*it)->refinement_flag() == _rflag; }
336
337protected:
338 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<flagged<T>>(*this); }
339 const unsigned char _rflag;
340};
341#endif // LIBMESH_ENABLE_AMR
342
343
344
345
346
347
351template <typename T>
352struct level : predicate<T>
353{
354 level (unsigned int l) : _level(l) {}
355 virtual ~level() = default;
356
357 virtual bool operator()(const T & it) const override { return (*it)->level() == _level; }
358
359protected:
360 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<level<T>>(*this); }
361 const unsigned int _level;
362};
363
364
365
370template <typename T>
371struct not_level : level<T>
372{
373 not_level(unsigned int l) : level<T>(l) {}
374
375 virtual bool operator()(const T & it) const override { return !level<T>::operator()(it); }
376
377protected:
378 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<not_level<T>>(*this); }
379};
380
381
382
383
387template <typename T>
389{
390 virtual ~null_neighbor() = default;
391 virtual bool operator()(const T & it) const override
392 {
393 return (*it)->on_boundary();
394 }
395
396protected:
397 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<null_neighbor<T>>(*this); }
398};
399
400
401
409template <typename T>
411{
412 virtual ~boundary_side() = default;
413 virtual bool operator()(const T & it) const override
414 {
415 return it.side_on_boundary();
416 }
417
418protected:
419 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<boundary_side<T>>(*this); }
420};
421
426template <typename T>
428{
430 virtual ~subdomain() = default;
431
432 // op()
433 virtual bool operator()(const T & it) const override { return (*it)->subdomain_id() == _subdomain; }
434
435protected:
436 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<subdomain<T>>(*this); }
438};
439
440
445template <typename T>
447{
448 subdomain_set(std::set<subdomain_id_type> sset) : _subdomain_set(sset) {}
449 virtual ~subdomain_set() = default;
450
451 // op()
452 virtual bool operator()(const T & it) const override { return _subdomain_set.count((*it)->subdomain_id()); }
453
454protected:
455 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<subdomain_set<T>>(*this); }
456 const std::set<subdomain_id_type> _subdomain_set;
457};
458
459
465template <typename T>
467{
468 evaluable(const DofMap & dof_map,
469 unsigned int var_num) :
470 _dof_map(dof_map), _var_num(var_num) {}
471 virtual ~evaluable() = default;
472
473 // op()
474 virtual bool operator()(const T & it) const override;
475
476protected:
477 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<evaluable<T>>(*this); }
479 unsigned int _var_num;
480};
481
487template <typename T>
489{
490 multi_evaluable(std::vector<const DofMap *> dof_maps) :
491 _dof_maps(dof_maps) {}
492 virtual ~multi_evaluable() = default;
493
494 // op()
495 virtual bool operator()(const T & it) const override;
496
497protected:
498 virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<multi_evaluable<T>>(*this); }
499 std::vector<const DofMap *> _dof_maps;
500};
501
502
503} // namespace Predicates
504
505
506} // namespace libMesh
507
508#endif // LIBMESH_SINGLE_PREDICATES_H
void ErrorVector unsigned int
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
This class handles the numbering of degrees of freedom on a mesh.
Definition dof_map.h:181
The libMesh namespace provides an interface to certain functionality in the library.
ElemType
Defines an enum for geometric element types.
int8_t boundary_id_type
Definition id_types.h:51
uint8_t processor_id_type
Definition id_types.h:104
virtual ~active()=default
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
virtual ~ancestor()=default
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
const BoundaryInfo & _bndry_info
virtual std::unique_ptr< predicate< T > > clone() const override
bid(boundary_id_type b_id, const BoundaryInfo &bndry_info)
const boundary_id_type _bid
virtual ~bid()=default
virtual ~bnd()=default
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
bnd(const BoundaryInfo &bndry_info)
const BoundaryInfo & _bndry_info
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
virtual ~elem_type()=default
virtual std::unique_ptr< predicate< T > > clone() const override
virtual ~evaluable()=default
evaluable(const DofMap &dof_map, unsigned int var_num)
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
virtual ~flagged()=default
virtual ~is_null()=default
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
virtual ~level()=default
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate< T > > clone() const override
multi_evaluable(std::vector< const DofMap * > dof_maps)
std::vector< const DofMap * > _dof_maps
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate< T > > clone() const override
const processor_id_type _pid
virtual bool operator()(const T &it) const override
virtual ~pid()=default
virtual std::unique_ptr< predicate< T > > clone() const override
pid(processor_id_type p)
virtual ~predicate()=default
virtual bool operator()(const T &it) const =0
virtual std::unique_ptr< predicate > clone() const =0
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
virtual ~subactive()=default
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
const std::set< subdomain_id_type > _subdomain_set
subdomain_set(std::set< subdomain_id_type > sset)
virtual std::unique_ptr< predicate< T > > clone() const override
const subdomain_id_type _subdomain
virtual ~subdomain()=default
virtual std::unique_ptr< predicate< T > > clone() const override
subdomain(subdomain_id_type sid)
virtual bool operator()(const T &it) const override