libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
wrapped_petsc.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_WRAPPED_PETSC_H
19 #define LIBMESH_WRAPPED_PETSC_H
20 
21 #include "libmesh/libmesh_config.h"
22 
23 #ifdef LIBMESH_HAVE_PETSC
24 
25 // C++ includes
26 #include <utility> // std::swap, std::move
27 
28 namespace libMesh
29 {
30 
31 // 该模板类包装了PETSc对象,并专门将析构函数定制为调用相应的 "XXXDestroy()" 程序。
32 template <typename T>
34 {
41  WrappedPetsc() : obj() {}
42 
50  WrappedPetsc(T obj_in) : obj(obj_in) {}
51 
56  {
57  destroy();
58  }
59 
67  {
68  destroy();
69  obj = nullptr;
70  }
71 
77  WrappedPetsc(const WrappedPetsc & other) = delete;
78  WrappedPetsc & operator= (const WrappedPetsc &) = delete;
79 
84  WrappedPetsc(WrappedPetsc && other) noexcept
85  : obj(other.obj)
86  {
87  other.obj = nullptr;
88  }
89 
94  WrappedPetsc & operator= (WrappedPetsc && other) noexcept
95  {
96  WrappedPetsc tmp(std::move(other));
97  std::swap(tmp, *this);
98  return *this;
99  }
100 
109  T * get() { return &obj; }
110 
116  operator T() const { return obj; }
117 
126  T & operator*() { return obj; }
127 
137  operator bool() const { return obj != nullptr; }
138 
155  void destroy();
156 private:
157  T obj;
158 };
159 
160 } // namespace libMesh
161 
162 #endif // LIBMESH_HAVE_PETSC
163 
164 #endif
void reset_to_zero()
调用destroy()并将托管对象设置为nullptr。据我所知,PETSc的各种 XXXDestroy()例程不会将obj设置为nullptr,因此我们在包装类的 析构函数中也不这样做,但有些情况下,...
Definition: wrapped_petsc.h:66
WrappedPetsc()
默认构造函数。这应该模拟我们通常编写的方式,例如: KSP ksp; 然后可以在不同的PETSc例程中使用ksp。也就是说, obj未初始化为任何特定值。
Definition: wrapped_petsc.h:41
~WrappedPetsc()
析构函数。只调用destroy()函数。
Definition: wrapped_petsc.h:55
WrappedPetsc & operator=(const WrappedPetsc &)=delete
T & operator*()
&quot;解引用&quot;运算符。返回对托管对象的引用。这在某些情况下是必需的,例如 使用C风格强制转换时: KSP ksp; ...
WrappedPetsc(WrappedPetsc &&other) noexcept
移动构造函数。我们几乎可以默认它,但我们需要将other.obj设置为nullptr, 以便在随后Destroy()时它仅仅是一个空操作,而不会破坏引用计数或尝试双重释放内存。 ...
Definition: wrapped_petsc.h:84
WrappedPetsc(T obj_in)
构造函数,用于将obj初始化为特定的传入值。这模拟了我们通过 IS is = NULL; 明确创建PETSc对象的代码。从技术上讲,可以在此处传递任何指针值, 但通常只有传递nullptr才有意义。 ...
Definition: wrapped_petsc.h:50
void destroy()
必须特例化以调用适当的XXXDestroy()例程,以便实例化WrappedPetsc&lt;T&gt;对象。