libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
const_function.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 
19 #ifndef LIBMESH_CONST_FUNCTION_H
20 #define LIBMESH_CONST_FUNCTION_H
21 
22 // Local includes
23 #include "libmesh/dense_vector.h"
24 #include "libmesh/function_base.h"
25 #include "libmesh/point.h"
26 
27 // C++ includes
28 #include <memory>
29 #include <string>
30 
31 namespace libMesh
32 {
33 
40 template <typename Output=Number>
41 class ConstFunction : public FunctionBase<Output>
42 {
43 public:
48  explicit
49  ConstFunction (const Output & c) : _c(c)
50  {
51  // 将initialized标记为true,表示初始化完成
52  this->_initialized = true;
53  // 将is_time_dependent标记为false,表示该函数不依赖于时间
54  this->_is_time_dependent = false;
55  }
56 
60  ConstFunction (ConstFunction &&) = default;
61  ConstFunction (const ConstFunction &) = default;
62  ConstFunction & operator= (const ConstFunction &) = default;
63  ConstFunction & operator= (ConstFunction &&) = default;
64 
68  virtual ~ConstFunction () = default;
69 
76  virtual Output operator() (const Point &,
77  const Real = 0) override
78  { return _c; }
79 
86  virtual void operator() (const Point &,
87  const Real,
88  DenseVector<Output> & output) override
89  {
90  // 将输出矢量的每个分量设置为常量值
91  unsigned int size = output.size();
92  for (unsigned int i=0; i != size; ++i)
93  output(i) = _c;
94  }
95 
100  virtual std::unique_ptr<FunctionBase<Output>> clone() const override
101  {
102  return std::make_unique<ConstFunction<Output>>(_c);
103  }
104 
105 private:
106  Output _c; // 存储常量值
107 };
108 
109 } // namespace libMesh
110 
111 #endif // LIBMESH_CONST_FUNCTION_H
bool _initialized
当 init() 被调用以确保一切都准备好后,可以调用 operator() (...) 时为 true。
virtual Output operator()(const Point &, const Real=0) override
重载操作符,用于计算标量值。
virtual ~ConstFunction()=default
默认析构函数。
bool _is_time_dependent
成员变量用于缓存函数是否真正依赖于时间。
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual std::unique_ptr< FunctionBase< Output > > clone() const override
克隆函数。创建并返回一个与当前实例相同类型的新实例。
ConstFunction(const Output &c)
构造函数,用于初始化常量值。
由Roy Stogner创作 2012年
FunctionBase是一个函数对象的基类,可以在某一点(可选地包括时间)进行评估。
virtual unsigned int size() const overridefinal
Definition: dense_vector.h:111
ConstFunction & operator=(const ConstFunction &)=default