libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
dense_subvector.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_DENSE_SUBVECTOR_H
21 #define LIBMESH_DENSE_SUBVECTOR_H
22 
23 // Local Includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/dense_vector.h"
26 #include "libmesh/int_range.h"
27 
28 // C++ includes
29 
30 namespace libMesh
31 {
32 
41 template<typename T>
43 {
44 public:
53  DenseSubVector(DenseVector<T> & new_parent,
54  const unsigned int ioff = 0,
55  const unsigned int n = 0);
56 
60  DenseSubVector (DenseSubVector &&) = default;
61  DenseSubVector (const DenseSubVector &) = default;
62  DenseSubVector & operator= (const DenseSubVector &) = default;
64  virtual ~DenseSubVector() = default;
65 
70 
74  virtual void zero() override final;
75 
79  const T & operator() (const unsigned int i) const;
80 
84  T & operator() (const unsigned int i);
85 
89  virtual T el(const unsigned int i) const override final
90  { return (*this)(i); }
91 
92  virtual T & el(const unsigned int i) override final
93  { return (*this)(i); }
94 
98  virtual unsigned int size() const override final
99  { return _n; }
100 
104  virtual bool empty() const override final
105  { return (_n == 0); }
106 
110  unsigned int i_off() const { return _i_off; }
111 
118  void reposition(const unsigned int ioff,
119  const unsigned int n);
120 
124  Real min () const;
125 
129  Real max () const;
130 
134  Real l1_norm () const;
135 
139  Real l2_norm () const;
140 
144  Real linfty_norm () const;
145 
146 private:
151 
155  unsigned int _n;
156 
160  unsigned int _i_off;
161 };
162 
163 
164 // ------------------------------------------------------------
165 // Dense Vector member functions
166 template<typename T>
167 inline
169  const unsigned int ioff,
170  const unsigned int n) :
171  _parent_vector(new_parent)
172 {
173  reposition (ioff, n);
174 }
175 
176 
177 
178 template<typename T>
179 inline
180 void DenseSubVector<T>::reposition(const unsigned int ioff,
181  const unsigned int n)
182 {
183  _i_off = ioff;
184  _n = n;
185 
186  // Make sure we still fit in the parent vector.
187  libmesh_assert_less_equal ((this->i_off() + this->size()), _parent_vector.size());
188 }
189 
190 
191 
192 template<typename T>
193 inline
195 {
196  for (auto i : index_range(*this))
197  _parent_vector (i + this->i_off()) = 0.;
198 }
199 
200 
201 
202 template<typename T>
203 inline
204 const T & DenseSubVector<T>::operator () (const unsigned int i) const
205 {
206  libmesh_assert_less (i, this->size());
207  libmesh_assert_less (i + this->i_off(), _parent_vector.size());
208 
209  return _parent_vector (i + this->i_off());
210 }
211 
212 
213 template<typename T>
214 inline
215 T & DenseSubVector<T>::operator () (const unsigned int i)
216 {
217  libmesh_assert_less (i, this->size());
218  libmesh_assert_less (i + this->i_off(), _parent_vector.size());
219 
220  return _parent_vector (i + this->i_off());
221 }
222 
223 template<typename T>
224 inline
226 {
227  libmesh_assert (this->size());
228  Real my_min = libmesh_real(_parent_vector (this->i_off()));
229 
230  for (auto i : make_range(1u, this->size()))
231  {
232  Real current = libmesh_real(_parent_vector (i + this->i_off()));
233  my_min = (my_min < current? my_min : current);
234  }
235  return my_min;
236 }
237 
238 
239 
240 template<typename T>
241 inline
243 {
244  libmesh_assert (this->size());
245  Real my_max = libmesh_real(_parent_vector (this->i_off()));
246 
247  for (auto i : make_range(1u, this->size()))
248  {
249  Real current = libmesh_real(_parent_vector (i + this->i_off()));
250  my_max = (my_max > current? my_max : current);
251  }
252  return my_max;
253 }
254 
255 
256 
257 template<typename T>
258 inline
260 {
261  Real my_norm = 0.;
262  for (auto i : index_range(*this))
263  {
264  my_norm += std::abs(_parent_vector (i + this->i_off()));
265  }
266  return my_norm;
267 }
268 
269 
270 
271 template<typename T>
272 inline
274 {
275  Real my_norm = 0.;
276  for (auto i : index_range(*this))
277  {
278  my_norm += TensorTools::norm_sq(_parent_vector (i + this->i_off()));
279  }
280  return sqrt(my_norm);
281 }
282 
283 
284 
285 template<typename T>
286 inline
288 {
289  if (!this->size())
290  return 0.;
291  Real my_norm = TensorTools::norm_sq(_parent_vector (this->i_off()));
292 
293  for (auto i : make_range(1u, this->size()))
294  {
295  Real current = TensorTools::norm_sq(_parent_vector (i + this->i_off()));
296  my_norm = (my_norm > current? my_norm : current);
297  }
298  return sqrt(my_norm);
299 }
300 
301 } // namespace libMesh
302 
303 
304 #endif // LIBMESH_DENSE_SUBVECTOR_H
T libmesh_real(T a)
DenseSubVector(DenseVector< T > &new_parent, const unsigned int ioff=0, const unsigned int n=0)
构造函数。创建一个向量 parent 的稠密子向量。 子向量的维度为 ,并且子向量的 元素位于父向量的 位置。
virtual bool empty() const overridefinal
const T & operator()(const unsigned int i) const
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的平方根。
Definition: type_vector.h:88
virtual T el(const unsigned int i) const overridefinal
重写基类函数,返回索引为 i 的元素的常量引用和可写引用。
DenseVector< T > & parent()
unsigned int _n
该子向量的长度。
定义了一个用于有限元计算的稠密子向量。 在将元素载荷向量累加到全局向量之前存储这些载荷向量时特别有用,尤其是在存在方程组的情况下。 所有重写的虚拟函数在 dense_vector_base.h 中有文档说明。
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的绝对值。
Definition: type_vector.h:112
T norm_sq(std::complex< T > a)
Definition: tensor_tools.h:74
void reposition(const unsigned int ioff, const unsigned int n)
更改子向量在父向量中的位置和长度。
unsigned int i_off() const
virtual unsigned int size() const overridefinal
virtual T & el(const unsigned int i) overridefinal
virtual ~DenseSubVector()=default
DenseVector< T > & _parent_vector
包含该子向量的父向量。
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
定义用于有限元计算的抽象稠密向量基类。 可以从这个类派生出特定的稠密向量,例如 DenseSubVectors。
Definition: dof_map.h:63
定义用于有限元计算的稠密向量类。该类基本上是为了补充 DenseMatrix 类而设计的。 它相对于 std::vector 具有额外的功能,使其在有限元中特别有用,特别是对于方程组。 所有重写的虚拟函...
Definition: dof_map.h:64
unsigned int _i_off
在父向量中的偏移。
virtual void zero() overridefinal
重写基类的 zero 函数,将子向量中的所有元素置零。
DenseSubVector & operator=(const DenseSubVector &)=default