20 #ifndef LIBMESH_TYPE_VECTOR_H 21 #define LIBMESH_TYPE_VECTOR_H 24 #include "libmesh/libmesh_common.h" 25 #include "libmesh/compare_types.h" 26 #include "libmesh/tensor_tools.h" 27 #include "libmesh/int_range.h" 28 #include "libmesh/fuzzy_equals.h" 40 template <
typename T>
class TypeTensor;
41 template <
typename T>
class VectorValue;
42 template <
typename T>
class TensorValue;
64 template <
typename T2>
89 template <
typename Scalar1,
typename Scalar2,
typename Scalar3>
92 const Scalar1>::type & x,
95 const Scalar2>::type & y=0,
98 const Scalar3>::type & z=0);
106 template <
typename Scalar>
110 const Scalar>::type * sfinae =
nullptr);
127 template <
typename T2>
143 template <
typename T2>
149 template <
typename Scalar>
150 typename std::enable_if<
154 { libmesh_assert_equal_to (p, Scalar(0)); this->
zero();
return *
this; }
159 const T &
operator () (
const unsigned int i)
const;
160 const T &
slice (
const unsigned int i)
const {
return (*
this)(i); }
166 T &
slice (
const unsigned int i) {
return (*
this)(i); }
173 template <
typename T2>
182 template <
typename T2>
188 template <
typename T2>
194 template <
typename T2>
202 template <
typename T2>
211 template <
typename T2>
217 template <
typename T2>
224 template <
typename T2>
237 template <
typename Scalar>
238 typename std::enable_if<
255 template <
typename Scalar>
256 typename std::enable_if<
274 template <
typename T2>
281 template <
typename T2>
288 template <
typename T2>
358 bool operator < (const TypeVector<T> & rhs)
const;
366 bool operator <= (const TypeVector<T> & rhs)
const;
397 friend std::ostream & operator << (std::ostream & os, const TypeVector<T> & t)
410 const bool newline =
true)
const;
427 template <
typename T>
444 template <
typename T>
456 libmesh_assert_equal_to (y, 0);
463 libmesh_assert_equal_to (z, 0);
468 template <
typename T>
469 template <
typename Scalar1,
typename Scalar2,
typename Scalar3>
473 const Scalar1>::type & x,
476 const Scalar2>::type & y,
479 const Scalar3>::type & z)
486 libmesh_assert_equal_to (y, 0);
492 libmesh_assert_equal_to (z, 0);
498 template <
typename T>
499 template <
typename Scalar>
504 const Scalar>::type * )
519 template <
typename T>
520 template <
typename T2>
525 for (
unsigned int i=0; i<LIBMESH_DIM; i++)
526 _coords[i] = p._coords[i];
531 template <
typename T>
532 template <
typename T2>
536 for (
unsigned int i=0; i<LIBMESH_DIM; i++)
537 _coords[i] = p._coords[i];
542 template <
typename T>
546 libmesh_assert_less (i, LIBMESH_DIM);
553 template <
typename T>
557 libmesh_assert_less (i, LIBMESH_DIM);
564 template <
typename T>
565 template <
typename T2>
577 _coords[1] + p._coords[1]);
582 _coords[1] + p._coords[1],
583 _coords[2] + p._coords[2]);
590 template <
typename T>
591 template <
typename T2>
602 template <
typename T>
603 template <
typename T2>
608 _coords[0] += p._coords[0];
612 _coords[0] += p._coords[0];
613 _coords[1] += p._coords[1];
617 _coords[0] += p._coords[0];
618 _coords[1] += p._coords[1];
619 _coords[2] += p._coords[2];
626 template <
typename T>
627 template <
typename T2>
632 _coords[0] += factor*p(0);
636 _coords[0] += factor*p(0);
637 _coords[1] += factor*p(1);
641 _coords[0] += factor*p(0);
642 _coords[1] += factor*p(1);
643 _coords[2] += factor*p(2);
650 template <
typename T>
651 template <
typename T2>
664 _coords[1] - p._coords[1]);
669 _coords[1] - p._coords[1],
670 _coords[2] - p._coords[2]);
677 template <
typename T>
678 template <
typename T2>
689 template <
typename T>
690 template <
typename T2>
694 for (
unsigned int i=0; i<LIBMESH_DIM; i++)
695 _coords[i] -= p._coords[i];
700 template <
typename T>
701 template <
typename T2>
705 for (
unsigned int i=0; i<LIBMESH_DIM; i++)
706 _coords[i] -= factor*p(i);
711 template <
typename T>
735 template <
typename T>
736 template <
typename Scalar>
738 typename std::enable_if<
763 template <
typename T,
typename Scalar>
765 typename std::enable_if<
776 template <
typename T>
781 _coords[0] *= factor;
785 _coords[0] *= factor;
786 _coords[1] *= factor;
790 _coords[0] *= factor;
791 _coords[1] *= factor;
792 _coords[2] *= factor;
800 template <
typename T>
801 template <
typename Scalar>
803 typename std::enable_if<
810 libmesh_assert_not_equal_to (static_cast<TS>(factor),
811 static_cast<TS>(0.));
833 template <
typename T>
838 libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
840 for (
unsigned int i=0; i<LIBMESH_DIM; i++)
841 _coords[i] /= factor;
849 template <
typename T>
850 template <
typename T2>
856 return _coords[0]*p._coords[0];
860 return (_coords[0]*p._coords[0] +
861 _coords[1]*p._coords[1]);
865 return (_coords[0]*p(0) +
871 template <
typename T>
872 template <
typename T2>
882 template <
typename T>
883 template <
typename T2>
888 libmesh_assert_equal_to (LIBMESH_DIM, 3);
895 return TypeVector<TS>( _coords[1]*p._coords[2] - _coords[2]*p._coords[1],
896 -_coords[0]*p._coords[2] + _coords[2]*p._coords[0],
897 _coords[0]*p._coords[1] - _coords[1]*p._coords[0]);
906 template <
typename T>
916 template <
typename T>
920 for (
unsigned int i=0; i<LIBMESH_DIM; i++)
926 template <
typename T>
947 template <
typename T>
951 for (
const auto & val : _coords)
961 template <
typename T>
966 decltype(abs(T())) ret{};
968 ret += abs(_coords[i]);
973 template <
typename T>
982 template <
typename T>
991 template <
typename T>
996 return (_coords[0] == rhs._coords[0]);
1000 return (_coords[0] == rhs._coords[0] &&
1001 _coords[1] == rhs._coords[1]);
1004 #if LIBMESH_DIM == 3 1005 return (_coords[0] == rhs._coords[0] &&
1006 _coords[1] == rhs._coords[1] &&
1007 _coords[2] == rhs._coords[2]);
1013 template <
typename T>
1017 return (!(*
this == rhs));
1030 template <
typename T>
1036 #if LIBMESH_DIM == 3 1038 a(0)*(
b(1)*c(2) -
b(2)*c(1)) -
1039 a(1)*(
b(0)*c(2) -
b(2)*c(0)) +
1040 a(2)*(
b(0)*c(1) -
b(1)*c(0));
1052 template <
typename T>
1060 const Real norm01 = v01.norm(),
1061 norm02 = v02.norm(),
1062 norm03 = v03.norm();
1063 const T tan_half_angle =
1065 ((v01*v02)*norm03 + (v01*v03)*norm02 + (v02*v03)*norm01 +
1066 norm01*norm02*norm03);
1068 return Real(2)*atan(tan_half_angle);
1078 template <
typename T>
1088 const TypeVector<T> scaled_vec = e02.norm_sq()*e21 + e21.norm_sq()*e02;
1089 #if LIBMESH_DIM == 3 1091 (e02.cross(e21)).cross(scaled_vec);
1093 const T e02_cross_e21_z = e02(0)*e21(1)-e02(1)*e21(0);
1094 const TypeVector<T> numerator {-e02_cross_e21_z*scaled_vec(1),
1095 e02_cross_e21_z*scaled_vec(0)};
1109 template <
typename T>
1114 T z =
b(0)*c(1) -
b(1)*c(0);
1116 #if LIBMESH_DIM == 3 1117 T x =
b(1)*c(2) -
b(2)*c(1),
1118 y =
b(0)*c(2) -
b(2)*c(0);
1119 return x*x + y*y + z*z;
1130 template <
typename T>
1139 template <
typename T>
1144 auto && length =
norm();
1146 libmesh_assert_not_equal_to (length, static_cast<Real>(0.));
1148 #if LIBMESH_DIM == 1 1152 #if LIBMESH_DIM == 2 1157 #if LIBMESH_DIM == 3 1165 template <
typename T>
1168 #if LIBMESH_DIM == 1 1170 os <<
"x=" << (*this)(0);
1173 #if LIBMESH_DIM == 2 1176 << std::setw(8) << (*this)(0) <<
", " 1177 << std::setw(8) << (*this)(1) <<
")";
1180 #if LIBMESH_DIM == 3 1183 << std::setw(8) << (*this)(0) <<
", " 1184 << std::setw(8) << (*this)(1) <<
", " 1185 << std::setw(8) << (*this)(2) <<
")";
1189 template <
typename T>
1195 template <
typename T,
typename T2>
1206 for (
unsigned int i = 0; i < LIBMESH_DIM; i++)
1213 TypeVector<typename CompareTypes<T, T2>::supertype>
1218 for (
unsigned int i = 0; i < LIBMESH_DIM; i++)
1219 ret(i) = a(i) * conj_b;
1224 template <
typename T>
1228 return var.l1_norm();
1231 template <
typename T,
typename T2>
1242 template <
typename T>
1246 return vector.norm_sq();
1250 #ifdef LIBMESH_HAVE_METAPHYSICL 1253 template <
typename T>
1261 for (
unsigned int i = 0; i < LIBMESH_DIM; ++i)
1262 ret(i) = raw_value(in(i));
1268 template <
typename T,
typename U>
1269 struct ReplaceAlgebraicType<
libMesh::TypeVector<T>, U>
1276 #endif // LIBMESH_TYPE_VECTOR_H
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
static constexpr std::size_t libmesh_dim
const TypeVector< T > & operator*=(const T &)
Multiply this vector by a scalar value.
T solid_angle(const TypeVector< T > &v01, const TypeVector< T > &v02, const TypeVector< T > &v03)
void add_scaled(const TypeVector< T2 > &, const T &)
Add a scaled value to this vector without creating a temporary.
TypeTensor< typename CompareTypes< T, T2 >::supertype > outer_product(const TypeVector< T > &a, const TypeVector< T2 > &b)
TypeVector< typename CompareTypes< T, T2 >::supertype > operator+(const TypeVector< T2 > &) const
Add two vectors.
void subtract_scaled(const TypeVector< T2 > &, const T &)
Subtract a scaled value from this vector without creating a temporary.
CompareTypes< T, T2 >::supertype contract(const TypeVector< T2 > &) const
static constexpr Real TOLERANCE
T cross_norm(const TypeVector< T > &b, const TypeVector< T > &c)
Calls cross_norm_sq() and takes the square root of the result.
TypeVector< typename CompareTypes< T, T2 >::supertype > supertype
bool operator>(const TypeVector< T > &rhs) const
unsigned int index_type
Helper typedef for generic index programming.
TypeVector< T > supertype
The libMesh namespace provides an interface to certain functionality in the library.
const TypeVector< T > & operator+=(const TypeVector< T2 > &)
Add to this vector.
std::enable_if< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< Scalar, T >::supertype > >::type operator*(const Scalar &, const TypeNTensor< N, T > &)
void add(const TypeVector< T2 > &)
Add to this vector without creating a temporary.
This class defines a tensor in LIBMESH_DIM dimensional space of type T.
T cross_norm_sq(const TypeVector< T > &b, const TypeVector< T > &c)
Compute |b x c|^2 without creating the extra temporary produced by calling b.cross(c).norm_sq().
bool operator>=(const TypeVector< T > &rhs) const
void print(std::ostream &os=libMesh::out) const
Formatted print, by default to libMesh::out.
T triple_product(const TypeVector< T > &a, const TypeVector< T > &b, const TypeVector< T > &c)
TypeVector< T > unit() const
void libmesh_ignore(const Args &...)
TypeVector< T > operator-() const
void zero()
Set all entries of the vector to 0.
auto l1_norm(const NumericVector< T > &vec)
void subtract(const TypeVector< T2 > &)
Subtract from this vector without creating a temporary.
std::enable_if< ScalarTraits< Scalar >::value, TypeVector & >::type operator=(const Scalar &libmesh_dbg_var(p))
Assignment-from-scalar operator.
T value_type
Helper typedef for C++98 generic programming.
auto l1_norm_diff(const NumericVector< T > &vec1, const NumericVector< T > &vec2)
std::enable_if< ScalarTraits< Scalar >::value, TypeVector< typename CompareTypes< T, Scalar >::supertype > >::type operator*(const Scalar &) const
Multiply this vector by a scalar value.
This class defines a vector in LIBMESH_DIM dimensional space of type T.
TypeVector< typename CompareTypes< T, T2 >::supertype > cross(const TypeVector< T2 > &v) const
bool absolute_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const
const TypeVector< T > & operator/=(const T &)
Divide each entry of this vector by scalar value.
std::enable_if< ScalarTraits< Scalar >::value, TypeVector< typename CompareTypes< T, Scalar >::supertype > >::type operator/(const Scalar &) const
Divide each entry of this vector by scalar value.
bool absolute_fuzzy_equals(const T &var1, const T2 &var2, const Real tol=TOLERANCE *TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
TypeVector()
Empty constructor.
const TypeVector< T > & operator-=(const TypeVector< T2 > &)
Subtract from this vector.
TypeVector< T > circumcenter(const TypeVector< T > &p0, const TypeVector< T > &p1, const TypeVector< T > &p2)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void assign(const TypeVector< T2 > &)
Assign to this vector without creating a temporary.
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...
T & slice(const unsigned int i)
const T & operator()(const unsigned int i) const
bool operator==(const TypeVector< T > &rhs) const
bool relative_fuzzy_equals(const T &var1, const T2 &var2, const Real tol=TOLERANCE *TOLERANCE)
Function to check whether two variables are equal within a relative tolerance.
auto norm(const libMesh::TypeVector< T > &vector) -> decltype(std::norm(T()))
void write_unformatted(std::ostream &out_stream, const bool newline=true) const
Unformatted print to the stream out.
bool relative_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const
bool operator!=(const TypeVector< T > &rhs) const
const T & slice(const unsigned int i) const
~TypeVector()=default
Destructor.