libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
type_vector.C
浏览该文件的文档.
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 
21 // Local includes
22 #include "libmesh/type_vector.h"
23 
24 // C++ includes
25 #include <iostream>
26 #include <iomanip> // for std::setw, std::setiosflags
27 #include <type_traits> // std::is_trivially_copyable
28 
29 
30 static_assert(std::is_trivially_copyable<libMesh::TypeVector<libMesh::Real>>::value,
31  "Someone made TypeVector non-TriviallyCopyable");
32 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
33 static_assert(std::is_trivially_copyable<libMesh::TypeVector<libMesh::Complex>>::value,
34  "Someone made TypeVector non-TriviallyCopyable");
35 #endif
36 
37 
38 namespace libMesh
39 {
40 
41 
42 
43 
44 // ------------------------------------------------------------
45 // TypeVector<T> class member functions
46 template <typename T>
47 void TypeVector<T>::print(std::ostream & os) const
48 {
49 #if LIBMESH_DIM == 1
50 
51  os << "x=" << (*this)(0);
52 
53 #endif
54 #if LIBMESH_DIM == 2
55 
56  os << "(x,y)=("
57  << std::setw(8) << (*this)(0) << ", "
58  << std::setw(8) << (*this)(1) << ")";
59 
60 #endif
61 #if LIBMESH_DIM == 3
62 
63  os << "(x,y,z)=("
64  << std::setw(8) << (*this)(0) << ", "
65  << std::setw(8) << (*this)(1) << ", "
66  << std::setw(8) << (*this)(2) << ")";
67 #endif
68 }
69 
70 
71 
72 
73 
74 template <typename T>
75 void TypeVector<T>::write_unformatted (std::ostream & os,
76  const bool newline) const
77 {
78  os << std::setiosflags(std::ios::showpoint)
79  << (*this)(0) << " "
80  << (*this)(1) << " "
81  << (*this)(2) << " ";
82 
83  if (newline)
84  os << '\n';
85 }
86 
87 
88 
89 template <typename T>
91 {
92  for (unsigned int i=0; i<LIBMESH_DIM; i++)
93  {
94  if ((*this)(i) < rhs(i))
95  return true;
96  if ((*this)(i) > rhs(i))
97  return false;
98  }
99  return false;
100 }
101 
102 
103 template <typename T>
105 {
106  for (unsigned int i=0; i<LIBMESH_DIM; i++)
107  {
108  if ((*this)(i) < rhs(i))
109  return true;
110  if ((*this)(i) > rhs(i))
111  return false;
112  }
113  return true;
114 }
115 
116 
117 
118 template <typename T>
120 {
121  for (unsigned int i=0; i<LIBMESH_DIM; i++)
122  {
123  if ((*this)(i) > rhs(i))
124  return true;
125  if ((*this)(i) < rhs(i))
126  return false;
127  }
128  return false;
129 }
130 
131 
132 template <typename T>
134 {
135  for (unsigned int i=0; i<LIBMESH_DIM; i++)
136  {
137  if ((*this)(i) > rhs(i))
138  return true;
139  if ((*this)(i) < rhs(i))
140  return false;
141  }
142  return true;
143 }
144 
145 
146 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
147 template <>
149 {
150  for (unsigned int i=0; i<LIBMESH_DIM; i++)
151  {
152  if ((*this)(i).real() < rhs(i).real())
153  return true;
154  if ((*this)(i).real() > rhs(i).real())
155  return false;
156  if ((*this)(i).imag() < rhs(i).imag())
157  return true;
158  if ((*this)(i).imag() > rhs(i).imag())
159  return false;
160  }
161  return false;
162 }
163 
164 
165 
166 template <>
168 {
169  for (unsigned int i=0; i<LIBMESH_DIM; i++)
170  {
171  if ((*this)(i).real() < rhs(i).real())
172  return true;
173  if ((*this)(i).real() > rhs(i).real())
174  return false;
175  if ((*this)(i).imag() < rhs(i).imag())
176  return true;
177  if ((*this)(i).imag() > rhs(i).imag())
178  return false;
179  }
180  return true;
181 }
182 
183 
184 
185 template <>
187 {
188  for (unsigned int i=0; i<LIBMESH_DIM; i++)
189  {
190  if ((*this)(i).real() > rhs(i).real())
191  return true;
192  if ((*this)(i).real() < rhs(i).real())
193  return false;
194  if ((*this)(i).imag() > rhs(i).imag())
195  return true;
196  if ((*this)(i).imag() < rhs(i).imag())
197  return false;
198  }
199  return false;
200 }
201 
202 
203 
204 template <>
206 {
207  for (unsigned int i=0; i<LIBMESH_DIM; i++)
208  {
209  if ((*this)(i).real() > rhs(i).real())
210  return true;
211  if ((*this)(i).real() < rhs(i).real())
212  return false;
213  if ((*this)(i).imag() > rhs(i).imag())
214  return true;
215  if ((*this)(i).imag() < rhs(i).imag())
216  return false;
217  }
218  return true;
219 }
220 
221 #endif
222 
223 
224 
225 // ------------------------------------------------------------
226 // Explicit instantiations
227 template class LIBMESH_EXPORT TypeVector<Real>;
228 
229 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
230 template class LIBMESH_EXPORT TypeVector<Complex>;
231 #endif
232 
233 } // namespace libMesh
bool operator>=(const TypeVector< T > &rhs) const
判断该向量是否大于等于另一个向量。
Definition: type_vector.C:133
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
bool operator>(const TypeVector< T > &rhs) const
判断该向量是否大于另一个向量。
Definition: type_vector.C:119
void write_unformatted(std::ostream &out_stream, const bool newline=true) const
无格式输出到流 out。只是将向量的元素用空格分隔打印出来。 默认情况下,还会打印一个换行符,但可以通过 newline 参数来控制这个行为。
Definition: type_vector.C:75
bool operator<=(const TypeVector< T > &rhs) const
判断该向量是否小于等于另一个向量。
Definition: type_vector.C:104
void print(std::ostream &os=libMesh::out) const
格式化输出,默认输出到 libMesh::out 流。
Definition: type_vector.C:47
该类定义了一个在 LIBMESH_DIM 维度空间中类型为 T 的向量。
Definition: tensor_tools.h:34
bool operator<(const TypeVector< T > &rhs) const
判断该向量是否小于另一个向量。
Definition: type_vector.C:90
boost::multiprecision::float128 imag(const boost::multiprecision::float128)