libMesh
Loading...
Searching...
No Matches
vector_value.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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_VECTOR_VALUE_H
21#define LIBMESH_VECTOR_VALUE_H
22
23// Local includes
24#include "libmesh/type_vector.h"
25#include "libmesh/compare_types.h"
26
27#ifdef LIBMESH_HAVE_METAPHYSICL
28#include "metaphysicl/raw_type.h"
29#include "metaphysicl/ct_types.h"
30#endif
31
32// C++ includes
33
34namespace libMesh
35{
36
46template <typename T>
47class VectorValue : public TypeVector<T>
48{
49public:
50 typedef T value_type;
51
52 template <typename T2>
53 struct rebind
54 {
56 };
57
63
68 VectorValue (const T & x,
69 const T & y=0,
70 const T & z=0);
71
76 template <typename Scalar1, typename Scalar2, typename Scalar3>
77 VectorValue (typename
78 std::enable_if<ScalarTraits<Scalar1>::value,
79 const Scalar1>::type & x,
80 typename
81 std::enable_if<ScalarTraits<Scalar2>::value,
82 const Scalar2>::type & y = 0,
83 typename
84 std::enable_if<ScalarTraits<Scalar3>::value,
85 const Scalar3>::type & z = 0);
86
87
94 template <typename Scalar>
95 VectorValue (const Scalar & x,
96 typename
97 std::enable_if<ScalarTraits<Scalar>::value,
98 const Scalar>::type * sfinae = nullptr);
99
100
104 template <typename T2>
106
110 template <typename T2>
112
113#ifdef LIBMESH_USE_COMPLEX_NUMBERS
120 const TypeVector<Real> & p_im);
121#endif
122
126 template <typename Scalar>
127 typename std::enable_if<
129 VectorValue &>::type
130 operator = (const Scalar & libmesh_dbg_var(p))
131 { libmesh_assert_equal_to (p, Scalar(0)); this->zero(); return *this; }
132};
133
138typedef VectorValue<Real> RealVectorValue;
139typedef VectorValue<Number> NumberVectorValue;
142
143
144
145//------------------------------------------------------
146// Inline functions
147
148template <typename T>
149inline
154
155
156template <typename T>
157inline
159 const T & y,
160 const T & z) :
161 TypeVector<T> (x,y,z)
162{
163}
164
165
166
167template <typename T>
168template <typename Scalar1, typename Scalar2, typename Scalar3>
169inline
171 std::enable_if<ScalarTraits<Scalar1>::value,
172 const Scalar1>::type & x,
173 typename
174 std::enable_if<ScalarTraits<Scalar2>::value,
175 const Scalar2>::type & y,
176 typename
177 std::enable_if<ScalarTraits<Scalar3>::value,
178 const Scalar3>::type & z) :
179 TypeVector<T> (x,y,z)
180{
181}
182
183
184template <typename T>
185template <typename Scalar>
186inline
188 typename
189 std::enable_if<ScalarTraits<Scalar>::value,
190 const Scalar>::type * /*sfinae*/) :
191 TypeVector<T> (x)
192{
193}
194
195template <typename T>
196template <typename T2>
197inline
199 TypeVector<T> (p)
200{
201}
202
203
204
205template <typename T>
206template <typename T2>
207inline
209 TypeVector<T> (p)
210{
211}
212
213#ifdef LIBMESH_USE_COMPLEX_NUMBERS
214template <typename T>
215inline
217 const TypeVector<Real> & p_im) :
218 TypeVector<T> (Complex (p_re(0), p_im(0)),
219 Complex (p_re(1), p_im(1)),
220 Complex (p_re(2), p_im(2)))
221{
222}
223#endif
224
225template <typename T>
230
231template <typename T, typename T2>
236
237template <typename T, typename T2>
242
243template <typename T, typename T2>
248
249} // namespace libMesh
250
251#ifdef LIBMESH_HAVE_METAPHYSICL
252namespace MetaPhysicL
253{
254template <typename T>
255struct RawType<libMesh::VectorValue<T>>
256{
258
260 {
261 value_type ret;
262 for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
263 ret(i) = raw_value(in(i));
264
265 return ret;
266 }
267};
268
269template <typename T, typename U>
270struct ReplaceAlgebraicType<libMesh::VectorValue<T>, U>
271{
272 typedef U type;
273};
274}
275#endif
276
277#endif // LIBMESH_VECTOR_VALUE_H
This class defines a vector in LIBMESH_DIM dimensional space of type T.
Definition type_vector.h:63
void zero()
Set all entries of the vector to 0.
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
VectorValue()
Empty constructor.
VectorValue(typename std::enable_if< ScalarTraits< Scalar1 >::value, const Scalar1 >::type &x, typename std::enable_if< ScalarTraits< Scalar2 >::value, const Scalar2 >::type &y=0, typename std::enable_if< ScalarTraits< Scalar3 >::value, const Scalar3 >::type &z=0)
Constructor-from-scalars.
VectorValue(const Scalar &x, typename std::enable_if< ScalarTraits< Scalar >::value, const Scalar >::type *sfinae=nullptr)
Constructor-from-scalar.
VectorValue(const TypeVector< T2 > &p)
Copy-constructor.
VectorValue(const TypeVector< Real > &p_re, const TypeVector< Real > &p_im)
Constructor that takes two TypeVector<Real> representing the real and imaginary part as arguments.
std::enable_if< ScalarTraits< Scalar >::value, VectorValue & >::type operator=(const Scalar &libmesh_dbg_var(p))
Assignment-from-scalar operator.
VectorValue(const VectorValue< T2 > &p)
Copy-constructor.
VectorValue(const T &x, const T &y=0, const T &z=0)
Constructor-from-T.
The libMesh namespace provides an interface to certain functionality in the library.
std::complex< Real > Complex
NumberVectorValue Gradient
VectorValue< Real > RealVectorValue
Useful typedefs to allow transparent switching between Real and Complex data types.
RealVectorValue RealGradient
VectorValue< Number > NumberVectorValue
static value_type value(const libMesh::VectorValue< T > &in)
libMesh::VectorValue< typename RawType< T >::value_type > value_type
VectorValue< typename CompareTypes< T, T2 >::supertype > supertype
VectorValue< typename CompareTypes< T, T2 >::supertype > supertype
VectorValue< typename CompareTypes< T, T2 >::supertype > supertype