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/libmesh_device.h"
26#include "libmesh/compare_types.h"
27
28#ifdef LIBMESH_HAVE_METAPHYSICL
29#include "metaphysicl/raw_type.h"
30#include "metaphysicl/ct_types.h"
31#endif
32
33// C++ includes
34
35namespace libMesh
36{
37
47template <typename T>
48class VectorValue : public TypeVector<T>
49{
50public:
51 typedef T value_type;
52
53 template <typename T2>
54 struct rebind
55 {
57 };
58
64
69 VectorValue (const T & x,
70 const T & y=0,
71 const T & z=0);
72
77 template <typename Scalar1, typename Scalar2, typename Scalar3>
78 VectorValue (typename
79 std::enable_if<ScalarTraits<Scalar1>::value,
80 const Scalar1>::type & x,
81 typename
82 std::enable_if<ScalarTraits<Scalar2>::value,
83 const Scalar2>::type & y = 0,
84 typename
85 std::enable_if<ScalarTraits<Scalar3>::value,
86 const Scalar3>::type & z = 0);
87
88
95 template <typename Scalar>
96 VectorValue (const Scalar & x,
97 typename
98 std::enable_if<ScalarTraits<Scalar>::value,
99 const Scalar>::type * sfinae = nullptr);
100
101
105 template <typename T2>
107
111 template <typename T2>
113
114#ifdef LIBMESH_USE_COMPLEX_NUMBERS
121 const TypeVector<Real> & p_im);
122#endif
123
127 template <typename Scalar>
128 LIBMESH_DEVICE_INLINE
129 typename std::enable_if<
131 VectorValue &>::type
132 operator = (const Scalar & libmesh_dbg_var(p))
133 { libmesh_assert_equal_to (p, Scalar(0)); this->zero(); return *this; }
134};
135
140typedef VectorValue<Real> RealVectorValue;
141typedef VectorValue<Number> NumberVectorValue;
144
145
146
147//------------------------------------------------------
148// Inline functions
149
150template <typename T>
151LIBMESH_DEVICE_INLINE
156
157
158template <typename T>
159LIBMESH_DEVICE_INLINE
161 const T & y,
162 const T & z) :
163 TypeVector<T> (x,y,z)
164{
165}
166
167
168
169template <typename T>
170template <typename Scalar1, typename Scalar2, typename Scalar3>
171LIBMESH_DEVICE_INLINE
173 std::enable_if<ScalarTraits<Scalar1>::value,
174 const Scalar1>::type & x,
175 typename
176 std::enable_if<ScalarTraits<Scalar2>::value,
177 const Scalar2>::type & y,
178 typename
179 std::enable_if<ScalarTraits<Scalar3>::value,
180 const Scalar3>::type & z) :
181 TypeVector<T> (x,y,z)
182{
183}
184
185
186template <typename T>
187template <typename Scalar>
188LIBMESH_DEVICE_INLINE
190 typename
191 std::enable_if<ScalarTraits<Scalar>::value,
192 const Scalar>::type * /*sfinae*/) :
193 TypeVector<T> (x)
194{
195}
196
197template <typename T>
198template <typename T2>
199LIBMESH_DEVICE_INLINE
201 TypeVector<T> (p)
202{
203}
204
205
206
207template <typename T>
208template <typename T2>
209LIBMESH_DEVICE_INLINE
211 TypeVector<T> (p)
212{
213}
214
215#ifdef LIBMESH_USE_COMPLEX_NUMBERS
216template <typename T>
217LIBMESH_DEVICE_INLINE
219 const TypeVector<Real> & p_im) :
220 TypeVector<T> (Complex (p_re(0), p_im(0)),
221 Complex (p_re(1), p_im(1)),
222 Complex (p_re(2), p_im(2)))
223{
224}
225#endif
226
227template <typename T>
232
233template <typename T, typename T2>
238
239template <typename T, typename T2>
244
245template <typename T, typename T2>
250
251} // namespace libMesh
252
253#ifdef LIBMESH_HAVE_METAPHYSICL
254namespace MetaPhysicL
255{
256template <typename T>
257struct RawType<libMesh::VectorValue<T>>
258{
260
262 {
263 value_type ret;
264 for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
265 ret(i) = raw_value(in(i));
266
267 return ret;
268 }
269};
270
271template <typename T, typename U>
272struct ReplaceAlgebraicType<libMesh::VectorValue<T>, U>
273{
274 typedef U type;
275};
276}
277#endif
278
279#endif // LIBMESH_VECTOR_VALUE_H
This class defines a vector in LIBMESH_DIM dimensional space of type T.
Definition type_vector.h:64
LIBMESH_DEVICE_INLINE void zero()
Set all entries of the vector to 0.
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
VectorValue(const T &x, const T &y=0, const T &z=0)
Constructor-from-T.
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()
Empty constructor.
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.
LIBMESH_DEVICE_INLINE 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.
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