libMesh
type_vector.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 <type_traits> // std::is_trivially_copyable
26 
27 
28 // Boost doesn't satisfy `is_trivially_copyable` for its float128
29 // wrapper, but surely it's memcpyable anyway?
30 #if !LIBMESH_DEFAULT_QUADRUPLE_PRECISION
31 static_assert(std::is_trivially_copyable<libMesh::TypeVector<libMesh::Real>>::value,
32  "Someone made TypeVector non-TriviallyCopyable");
33 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
34 static_assert(std::is_trivially_copyable<libMesh::TypeVector<libMesh::Complex>>::value,
35  "Someone made TypeVector non-TriviallyCopyable");
36 #endif
37 #endif // LIBMESH_DEFAULT_QUADRUPLE_PRECISION
38 
39 
40 namespace libMesh
41 {
42 
43 
44 
45 
46 // ------------------------------------------------------------
47 // TypeVector<T> class member functions
48 
49 
50 template <typename T>
51 void TypeVector<T>::write_unformatted (std::ostream & os,
52  const bool newline) const
53 {
54  os << std::setiosflags(std::ios::showpoint)
55  << (*this)(0) << " "
56  << (*this)(1) << " "
57  << (*this)(2) << " ";
58 
59  if (newline)
60  os << '\n';
61 }
62 
63 
64 
65 template <typename T>
67 {
68  for (unsigned int i=0; i<LIBMESH_DIM; i++)
69  {
70  if ((*this)(i) < rhs(i))
71  return true;
72  if ((*this)(i) > rhs(i))
73  return false;
74  }
75  return false;
76 }
77 
78 
79 template <typename T>
81 {
82  for (unsigned int i=0; i<LIBMESH_DIM; i++)
83  {
84  if ((*this)(i) < rhs(i))
85  return true;
86  if ((*this)(i) > rhs(i))
87  return false;
88  }
89  return true;
90 }
91 
92 
93 
94 template <typename T>
96 {
97  for (unsigned int i=0; i<LIBMESH_DIM; i++)
98  {
99  if ((*this)(i) > rhs(i))
100  return true;
101  if ((*this)(i) < rhs(i))
102  return false;
103  }
104  return false;
105 }
106 
107 
108 template <typename T>
110 {
111  for (unsigned int i=0; i<LIBMESH_DIM; i++)
112  {
113  if ((*this)(i) > rhs(i))
114  return true;
115  if ((*this)(i) < rhs(i))
116  return false;
117  }
118  return true;
119 }
120 
121 
122 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
123 template <>
125 {
126  for (unsigned int i=0; i<LIBMESH_DIM; i++)
127  {
128  if ((*this)(i).real() < rhs(i).real())
129  return true;
130  if ((*this)(i).real() > rhs(i).real())
131  return false;
132  if ((*this)(i).imag() < rhs(i).imag())
133  return true;
134  if ((*this)(i).imag() > rhs(i).imag())
135  return false;
136  }
137  return false;
138 }
139 
140 
141 
142 template <>
144 {
145  for (unsigned int i=0; i<LIBMESH_DIM; i++)
146  {
147  if ((*this)(i).real() < rhs(i).real())
148  return true;
149  if ((*this)(i).real() > rhs(i).real())
150  return false;
151  if ((*this)(i).imag() < rhs(i).imag())
152  return true;
153  if ((*this)(i).imag() > rhs(i).imag())
154  return false;
155  }
156  return true;
157 }
158 
159 
160 
161 template <>
163 {
164  for (unsigned int i=0; i<LIBMESH_DIM; i++)
165  {
166  if ((*this)(i).real() > rhs(i).real())
167  return true;
168  if ((*this)(i).real() < rhs(i).real())
169  return false;
170  if ((*this)(i).imag() > rhs(i).imag())
171  return true;
172  if ((*this)(i).imag() < rhs(i).imag())
173  return false;
174  }
175  return false;
176 }
177 
178 
179 
180 template <>
182 {
183  for (unsigned int i=0; i<LIBMESH_DIM; i++)
184  {
185  if ((*this)(i).real() > rhs(i).real())
186  return true;
187  if ((*this)(i).real() < rhs(i).real())
188  return false;
189  if ((*this)(i).imag() > rhs(i).imag())
190  return true;
191  if ((*this)(i).imag() < rhs(i).imag())
192  return false;
193  }
194  return true;
195 }
196 
197 #endif
198 
199 
200 
201 template <>
202 auto
204 {
205  bool ret{};
206  for (const auto i : make_range(libmesh_dim))
207  ret += _coords[i];
208 
209  return ret;
210 }
211 
212 
213 
214 // ------------------------------------------------------------
215 // Explicit instantiations
216 template class LIBMESH_EXPORT TypeVector<Real>;
217 
218 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
219 template class LIBMESH_EXPORT TypeVector<Complex>;
220 #endif
221 
222 } // namespace libMesh
static constexpr std::size_t libmesh_dim
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
bool operator>(const TypeVector< T > &rhs) const
Definition: type_vector.C:95
The libMesh namespace provides an interface to certain functionality in the library.
bool operator>=(const TypeVector< T > &rhs) const
Definition: type_vector.C:109
bool operator<=(const TypeVector< T > &rhs) const
Definition: type_vector.C:80
This class defines a vector in LIBMESH_DIM dimensional space of type T.
Definition: tensor_tools.h:34
bool operator<(const TypeVector< T > &rhs) const
Definition: type_vector.C:66
static const bool value
Definition: xdr_io.C:54
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140
boost::multiprecision::float128 imag(const boost::multiprecision::float128)
void write_unformatted(std::ostream &out_stream, const bool newline=true) const
Unformatted print to the stream out.
Definition: type_vector.C:51
auto l1_norm() const
Definition: type_vector.h:961