libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
function_base.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 
20 #ifndef LIBMESH_FUNCTION_BASE_H
21 #define LIBMESH_FUNCTION_BASE_H
22 
23 // Local Includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/dense_vector.h" // required to instantiate a DenseVector<> below
26 
27 // C++ includes
28 #include <cstddef>
29 #include <memory>
30 
31 namespace libMesh
32 {
33 
34 // Forward Declarations
35 class Point;
36 
60 template <typename Output=Number>
61 class FunctionBase
62 {
63 protected:
64 
70  explicit
71  FunctionBase (const FunctionBase * master = nullptr);
72 
73 public:
74 
78  FunctionBase (FunctionBase &&) = default;
79  FunctionBase (const FunctionBase &) = default;
80  FunctionBase & operator= (const FunctionBase &) = default;
81  FunctionBase & operator= (FunctionBase &&) = default;
82  virtual ~FunctionBase () = default;
83 
89  virtual void init () {}
95  virtual void clear () {}
96 
102  virtual std::unique_ptr<FunctionBase<Output>> clone () const = 0;
103 
109  virtual Output operator() (const Point & p,
110  const Real time = 0.) = 0;
111 
116  void operator() (const Point & p,
117  DenseVector<Output> & output);
118 
126  virtual void operator() (const Point & p,
127  const Real time,
128  DenseVector<Output> & output) = 0;
129 
130 
142  virtual Output component(unsigned int i,
143  const Point & p,
144  Real time=0.);
145 
146 
159  bool initialized () const;
160 
167 
173  bool is_time_dependent() const;
174 
175  protected:
176 
185 
192 
198 
199 };
200 
201 // ------------------------------------------------------------
202 // FunctionBase 内联函数
203 
204 template<typename Output>
205 inline
207  _master (master),
208  _initialized (false),
209  _is_time_dependent (true) // 假设我们是时间相关的,直到用户说不是为止
210 {
211 }
212 
213 // 判断函数是否已经初始化
214 template <typename Output>
215 inline
217 {
218  return (this->_initialized);
219 }
220 
221 // 设置函数是否依赖时间
222 template <typename Output>
223 inline
224 void FunctionBase<Output>::set_is_time_dependent( bool is_time_dependent )
225 {
226  this->_is_time_dependent = is_time_dependent;
227 }
228 
229 // 查询函数是否依赖时间
230 template <typename Output>
231 inline
233 {
234  return (this->_is_time_dependent);
235 }
236 
237 // 获取向量的分量值
238 template <typename Output>
239 inline
240 Output FunctionBase<Output>::component (unsigned int i,
241  const Point & p,
242  Real time)
243 {
244  DenseVector<Output> outvec(i+1);
245  (*this)(p, time, outvec);
246  return outvec(i);
247 }
248 
249 // 评估函数对象在给定点的值
250 template <typename Output>
251 inline
253  DenseVector<Output> & output)
254 {
255  // 调用时间相关的函数,时间设为0。
256  this->operator()(p, 0., output);
257 }
258 
259 } // namespace libMesh
260 
261 #endif // LIBMESH_FUNCTION_BASE_H
FunctionBase(const FunctionBase *master=nullptr)
构造函数。可选地接受一个master。
virtual Output component(unsigned int i, const Point &p, Real time=0.)
bool initialized() const
const FunctionBase * _master
指向我们的主函数对象的const指针,初始化为 nullptr。 可能存在需要多个函数的情况,但为了节省内存,一个主函数对象可以处理一些集中的数据。
bool _initialized
当 init() 被调用以确保一切都准备好后,可以调用 operator() (...) 时为 true。
virtual Output operator()(const Point &p, const Real time=0.)=0
virtual void init()
实际的初始化过程。
Definition: function_base.h:89
void set_is_time_dependent(bool is_time_dependent)
设置函数是否依赖时间的函数。 这仅应该由无法本地确定时间依赖性的子类使用。 在这种情况下,应在构造之后立即使用这个函数。
bool is_time_dependent() const
virtual ~FunctionBase()=default
bool _is_time_dependent
成员变量用于缓存函数是否真正依赖于时间。
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual std::unique_ptr< FunctionBase< Output > > clone() const =0
FunctionBase是一个函数对象的基类,可以在某一点(可选地包括时间)进行评估。
FunctionBase & operator=(const FunctionBase &)=default
virtual void clear()
清除函数。
Definition: function_base.h:95