libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
single_predicates.h
浏览该文件的文档.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2023 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 
31 namespace libMesh
32 {
33 
34 // Forward declarations
35 class BoundaryInfo;
36 class DofMap;
37 enum ElemType : int;
38 
50 namespace Predicates
51 {
52 // Forward declaration
53 template <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.
59 template <typename T>
60 struct predicate
61 {
62  virtual ~predicate() = default;
63  virtual bool operator()(const T & it) const = 0;
64 
65 protected:
66  friend struct abstract_multi_predicate<T>;
67  virtual std::unique_ptr<predicate> clone() const = 0;
68 };
69 
70 
74 template <typename T>
75 struct is_null : predicate<T>
76 {
77  virtual ~is_null() = default;
78  virtual bool operator()(const T & it) const override { return *it == nullptr; }
79 
80 protected:
81  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<is_null<T>>(*this); }
82 };
83 
87 template <typename T>
88 struct not_null : is_null<T>
89 {
90  virtual bool operator()(const T & it) const override { return !is_null<T>::operator()(it); }
91 
92 protected:
93  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<not_null<T>>(*this); }
94 };
95 
96 
100 template <typename T>
101 struct active : predicate<T>
102 {
103  virtual ~active() = default;
104  virtual bool operator()(const T & it) const override { return (*it)->active(); }
105 
106 protected:
107  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<active<T>>(*this); }
108 };
109 
113 template <typename T>
114 struct not_active : active<T>
115 {
116  virtual bool operator()(const T & it) const override { return !active<T>::operator()(it); }
117 
118 protected:
119  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<not_active<T>>(*this); }
120 };
121 
122 
126 template <typename T>
127 struct ancestor : predicate<T>
128 {
129  virtual ~ancestor() = default;
130  virtual bool operator()(const T & it) const override { return (*it)->ancestor(); }
131 
132 protected:
133  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<ancestor<T>>(*this); }
134 };
135 
139 template <typename T>
141 {
142  virtual bool operator()(const T & it) const override { return !ancestor<T>::operator()(it); }
143 
144 protected:
145  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<not_ancestor<T>>(*this); }
146 };
147 
148 
152 template <typename T>
153 struct subactive : predicate<T>
154 {
155  virtual ~subactive() = default;
156  virtual bool operator()(const T & it) const override { return (*it)->subactive(); }
157 
158 protected:
159  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<subactive<T>>(*this); }
160 };
161 
165 template <typename T>
167 {
168  virtual bool operator()(const T & it) const override { return !subactive<T>::operator()(it); }
169 
170 protected:
171  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<not_subactive<T>>(*this); }
172 };
173 
174 
175 
179 template <typename T>
180 struct 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 
188 protected:
189  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<pid<T>>(*this); }
191 };
192 
193 
194 
198 template <typename T>
199 struct 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 
211 protected:
212  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<bid<T>>(*this); }
214  const BoundaryInfo & _bndry_info;
215 };
216 
217 
218 
222 template <typename T>
223 struct 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 
233 protected:
234  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<bnd<T>>(*this); }
235  const BoundaryInfo & _bndry_info;
236 };
237 
238 
239 
244 template <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 
253 protected:
254  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<semilocal_pid<T>>(*this); }
256 };
257 
258 
259 
264 template <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 
281 protected:
282  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<facelocal_pid<T>>(*this); }
284 };
285 
286 
287 
291 template <typename T>
292 struct not_pid : pid<T>
293 {
295 
296  virtual bool operator()(const T & it) const override { return !pid<T>::operator()(it); }
297 
298 protected:
299  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<not_pid<T>>(*this); }
300 };
301 
302 
308 template <typename T>
309 struct elem_type : predicate<T>
310 {
311  elem_type (ElemType t) : _elem_type(t) {}
312  virtual ~elem_type() = default;
313 
314  virtual bool operator()(const T & it) const override { return (*it)->type() == _elem_type; }
315 
316 protected:
317  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<elem_type<T>>(*this); }
318  const ElemType _elem_type;
319 };
320 
321 
322 
323 #ifdef LIBMESH_ENABLE_AMR
324 
329 template <typename T>
330 struct flagged : predicate<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 
337 protected:
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 
351 template <typename T>
352 struct 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 
359 protected:
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 
370 template <typename T>
371 struct 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 
377 protected:
378  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<not_level<T>>(*this); }
379 };
380 
381 
382 
383 
387 template <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 
396 protected:
397  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<null_neighbor<T>>(*this); }
398 };
399 
400 
401 
409 template <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 
418 protected:
419  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<boundary_side<T>>(*this); }
420 };
421 
426 template <typename T>
427 struct subdomain : predicate<T>
428 {
430  virtual ~subdomain() = default;
431 
432  // op()
433  virtual bool operator()(const T & it) const override { return (*it)->subdomain_id() == _subdomain; }
434 
435 protected:
436  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<subdomain<T>>(*this); }
438 };
439 
440 
445 template <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 
454 protected:
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 
465 template <typename T>
466 struct evaluable : predicate<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 
476 protected:
477  virtual std::unique_ptr<predicate<T>> clone() const override { return std::make_unique<evaluable<T>>(*this); }
478  const DofMap & _dof_map;
479  unsigned int _var_num;
480 };
481 
487 template <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 
497 protected:
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
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
std::vector< const DofMap * > _dof_maps
const processor_id_type _pid
flagged(unsigned char rflag)
virtual ~elem_type()=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
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) 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
virtual bool operator()(const T &it) const override
virtual ~active()=default
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate< T > > clone() const override
bnd(const BoundaryInfo &bndry_info)
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
virtual ~bid()=default
virtual bool operator()(const T &it) const override
virtual bool operator()(const T &it) const override
uint8_t processor_id_type
Definition: id_types.h:104
const BoundaryInfo & _bndry_info
virtual std::unique_ptr< predicate< T > > clone() const override
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:169
const boundary_id_type _bid
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 bool operator()(const T &it) const override
int8_t boundary_id_type
Definition: id_types.h:51
virtual std::unique_ptr< predicate< T > > clone() const override
virtual std::unique_ptr< predicate< T > > clone() 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 =0
bid(boundary_id_type b_id, const BoundaryInfo &bndry_info)
not_pid(processor_id_type p)
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 ~pid()=default
multi_evaluable(std::vector< const DofMap * > dof_maps)
subdomain(subdomain_id_type sid)
virtual std::unique_ptr< predicate< T > > clone() const override
virtual ~bnd()=default
virtual std::unique_ptr< predicate< T > > clone() const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual std::unique_ptr< predicate< T > > clone() const override
virtual ~flagged()=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
virtual std::unique_ptr< predicate< T > > clone() const override
subdomain_set(std::set< subdomain_id_type > sset)
const BoundaryInfo & _bndry_info
virtual ~level()=default
virtual bool operator()(const T &it) const override
virtual ~is_null()=default
const subdomain_id_type _subdomain
virtual std::unique_ptr< predicate< T > > clone() const override
virtual ~ancestor()=default
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 std::unique_ptr< predicate< T > > clone() const override
virtual ~subactive()=default
virtual ~subdomain()=default
virtual std::unique_ptr< predicate< T > > clone() const override
pid(processor_id_type p)
virtual std::unique_ptr< predicate< T > > clone() const override
virtual bool operator()(const T &it) const override
virtual std::unique_ptr< predicate > clone() const =0
const std::set< subdomain_id_type > _subdomain_set
virtual bool operator()(const T &it) const override
virtual ~predicate()=default