libMesh
vector_value.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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 
34 namespace libMesh
35 {
36 
46 template <typename T>
47 class VectorValue : public TypeVector<T>
48 {
49 public:
50  typedef T value_type;
51 
52  template <typename T2>
53  struct rebind
54  {
56  };
57 
62  VectorValue ();
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
79  const Scalar1>::type & x,
80  typename
82  const Scalar2>::type & y = 0,
83  typename
85  const Scalar3>::type & z = 0);
86 
87 
94  template <typename Scalar>
95  VectorValue (const Scalar & x,
96  typename
98  const Scalar>::type * sfinae = nullptr);
99 
100 
104  template <typename T2>
105  VectorValue (const VectorValue<T2> & p);
106 
110  template <typename T2>
111  VectorValue (const TypeVector<T2> & p);
112 
113 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
114 
119  VectorValue (const TypeVector<Real> & p_re,
120  const TypeVector<Real> & p_im);
121 #endif
122 
126  template <typename Scalar>
127  typename boostcopy::enable_if_c<
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 
138 typedef VectorValue<Real> RealVectorValue;
139 typedef VectorValue<Number> NumberVectorValue;
142 
143 
144 
145 //------------------------------------------------------
146 // Inline functions
147 
148 template <typename T>
149 inline
151  TypeVector<T> ()
152 {
153 }
154 
155 
156 template <typename T>
157 inline
159  const T & y,
160  const T & z) :
161  TypeVector<T> (x,y,z)
162 {
163 }
164 
165 
166 
167 template <typename T>
168 template <typename Scalar1, typename Scalar2, typename Scalar3>
169 inline
172  const Scalar1>::type & x,
173  typename
175  const Scalar2>::type & y,
176  typename
178  const Scalar3>::type & z) :
179  TypeVector<T> (x,y,z)
180 {
181 }
182 
183 
184 template <typename T>
185 template <typename Scalar>
186 inline
187 VectorValue<T>::VectorValue (const Scalar & x,
188  typename
190  const Scalar>::type * /*sfinae*/) :
191  TypeVector<T> (x)
192 {
193 }
194 
195 template <typename T>
196 template <typename T2>
197 inline
199  TypeVector<T> (p)
200 {
201 }
202 
203 
204 
205 template <typename T>
206 template <typename T2>
207 inline
209  TypeVector<T> (p)
210 {
211 }
212 
213 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
214 template <typename T>
215 inline
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 
225 template <typename T>
227 {
229 };
230 
231 template <typename T, typename T2>
233 {
235 };
236 
237 template <typename T, typename T2>
239 {
241 };
242 
243 template <typename T, typename T2>
245 {
247 };
248 
249 } // namespace libMesh
250 
251 #ifdef LIBMESH_HAVE_METAPHYSICL
252 namespace MetaPhysicL
253 {
254 template <typename T>
255 struct 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 
269 template <typename T, typename U>
270 struct ReplaceAlgebraicType<libMesh::VectorValue<T>, U>
271 {
272  typedef U type;
273 };
274 }
275 #endif
276 
277 #endif // LIBMESH_VECTOR_VALUE_H
VectorValue()
Empty constructor.
Definition: vector_value.h:150
RealVectorValue RealGradient
VectorValue< typename CompareTypes< T, T2 >::supertype > supertype
Definition: vector_value.h:246
VectorValue< Real > RealVectorValue
Useful typedefs to allow transparent switching between Real and Complex data types.
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, VectorValue & >::type operator=(const Scalar &libmesh_dbg_var(p))
Assignment-from-scalar operator.
Definition: vector_value.h:130
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
The libMesh namespace provides an interface to certain functionality in the library.
static value_type value(const libMesh::VectorValue< T > &in)
Definition: vector_value.h:259
void zero()
Set all entries of the vector to 0.
Definition: type_vector.h:938
NumberVectorValue Gradient
VectorValue< typename CompareTypes< T, T2 >::supertype > supertype
Definition: vector_value.h:234
libMesh::VectorValue< typename RawType< T >::value_type > value_type
Definition: vector_value.h:257
This class defines a vector in LIBMESH_DIM dimensional space of type T.
Definition: tensor_tools.h:34
VectorValue< typename CompareTypes< T, T2 >::supertype > supertype
Definition: vector_value.h:240
std::complex< Real > Complex
VectorValue< T2 > other
Definition: vector_value.h:55
VectorValue< Number > NumberVectorValue