libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
analytic_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 
20 #ifndef LIBMESH_ANALYTIC_FUNCTION_H
21 #define LIBMESH_ANALYTIC_FUNCTION_H
22 
23 // Local Includes
24 #include "libmesh/function_base.h"
25 
26 // C++ includes
27 #include <cstddef>
28 
29 namespace libMesh
30 {
31 
32 // Forward Declarations
33 template <typename T>
34 class DenseVector;
35 
47 template <typename Output=Number>
48 class AnalyticFunction : public FunctionBase<Output>
49 {
50 public:
51 
53  typedef Output (*OutputFunction)(const Point & p, const Real time);
54 
60 
62  typedef void (*OutputVectorFunction)(DenseVector<Output> & output,
63  const Point & p,
64  const Real time);
70 
74  AnalyticFunction(AnalyticFunction &&) = default;
75  AnalyticFunction(const AnalyticFunction &) = default;
76  AnalyticFunction &operator= (const AnalyticFunction &) = default;
78  virtual ~AnalyticFunction() = default;
79 
84 
89 
93  virtual void init() override;
94 
98  virtual void clear() override;
99 
103  virtual std::unique_ptr<FunctionBase<Output>> clone() const override;
104 
111  virtual Output operator()(const Point & p, const Real time=0.) override;
112 
119  virtual void operator()(const Point & p, const Real time, DenseVector<Output> & output) override;
120 };
121 
122 // ------------------------------------------------------------
123 // AnalyticFunction inline methods
130 template <typename Output>
131 inline
132 Output AnalyticFunction<Output>::operator()(const Point & p, const Real time)
133 {
134  libmesh_assert(this->initialized());
135  return (this->_number_fptr(p, time));
136 }
137 
144 template <typename Output>
145 inline
146 void AnalyticFunction<Output>::operator()(const Point & p, const Real time, DenseVector<Output> & output)
147 {
148  libmesh_assert(this->initialized());
149  this->_vector_fptr(output, p, time);
150  return;
151 }
152 
157 template <typename Output>
159  FunctionBase<Output>(),
160  _number_fptr(fptr),
161  _vector_fptr(nullptr)
162 {
163  libmesh_assert(fptr);
164  this->_initialized = true;
165 }
166 
171 template <typename Output>
172 inline
173 AnalyticFunction<Output>::AnalyticFunction(OutputVectorFunction fptr) :
174  FunctionBase<Output>(),
175  _number_fptr(nullptr),
176  _vector_fptr(fptr)
177 {
178  libmesh_assert(fptr);
179  this->_initialized = true;
180 }
181 
185 template <typename Output>
187 {
188  // 双重测试
189  libmesh_assert((_number_fptr != nullptr) || (_vector_fptr != nullptr));
190 
191  // 绝对准备好
192  this->_initialized = true;
193 }
194 
198 template <typename Output>
199 inline
201 {
202  // 我们可能需要一个方法来稍后重置这些...
203  _number_fptr = nullptr;
204  _vector_fptr = nullptr;
205 
206  // 绝对没准备好
207  this->_initialized = false;
208 }
209 
213 template <typename Output>
214 inline
215 std::unique_ptr<FunctionBase<Output>> AnalyticFunction<Output>::clone() const
216 {
217  return std::unique_ptr<FunctionBase<Output>>
218  (_number_fptr ?
219  new AnalyticFunction<Output>(_number_fptr) :
220  new AnalyticFunction<Output>(_vector_fptr));
221 }
222 
223 } // namespace libMesh
224 
225 #endif // LIBMESH_ANALYTIC_FUNCTION_H
OutputFunction _number_fptr
指向用户提供的函数的指针,该函数在有解析表达式时计算边界值。
virtual Output operator()(const Point &p, const Real time=0.) override
重载操作符,用于计算标量值。
bool _initialized
当 init() 被调用以确保一切都准备好后,可以调用 operator() (...) 时为 true。
void(* OutputVectorFunction)(DenseVector< Output > &output, const Point &p, const Real time)
矢量返回值函数指针类型。
OutputVectorFunction _vector_fptr
指向用户提供的矢量值函数的指针。
将函数指针封装成FunctionBase对象。
virtual std::unique_ptr< FunctionBase< Output > > clone() const override
克隆函数。创建并返回一个与当前实例相同类型的新实例。
virtual ~AnalyticFunction()=default
AnalyticFunction(OutputFunction fptr)
构造函数。接受标量返回值函数的函数指针。
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void init() override
初始化函数。检查是否已准备好使用。
Output(* OutputFunction)(const Point &p, const Real time)
标量返回值函数指针类型。
virtual void clear() override
清理函数。将函数指针重置为nullptr,并标记未准备好使用。
bool initialized()
Checks that library initialization has been done.
Definition: libmesh.C:261
FunctionBase是一个函数对象的基类,可以在某一点(可选地包括时间)进行评估。
AnalyticFunction & operator=(const AnalyticFunction &)=default