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>
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>
255 template <
typename Scalar>
274 template <
typename T2>
281 template <
typename T2>
288 template <
typename T2>
345 bool operator == (const
TypeVector<T> & rhs) const;
350 bool operator != (const
TypeVector<T> & rhs) const;
358 bool operator < (const
TypeVector<T> & rhs) const;
366 bool operator <= (const
TypeVector<T> & rhs) const;
374 bool operator > (const
TypeVector<T> & rhs) const;
382 bool operator >= (const
TypeVector<T> & rhs) const;
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>
763 template <
typename T,
typename Scalar>
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>
808 libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
832 template <
typename T>
837 libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
839 for (
unsigned int i=0; i<LIBMESH_DIM; i++)
840 _coords[i] /= factor;
848 template <
typename T>
849 template <
typename T2>
855 return _coords[0]*p._coords[0];
859 return (_coords[0]*p._coords[0] +
860 _coords[1]*p._coords[1]);
864 return (_coords[0]*p(0) +
870 template <
typename T>
871 template <
typename T2>
881 template <
typename T>
882 template <
typename T2>
887 libmesh_assert_equal_to (LIBMESH_DIM, 3);
894 return TypeVector<TS>( _coords[1]*p._coords[2] - _coords[2]*p._coords[1],
895 -_coords[0]*p._coords[2] + _coords[2]*p._coords[0],
896 _coords[0]*p._coords[1] - _coords[1]*p._coords[0]);
905 template <
typename T>
909 return std::sqrt(this->
norm_sq());
914 template <
typename T>
918 for (
unsigned int i=0; i<LIBMESH_DIM; i++)
924 template <
typename T>
945 template <
typename T>
949 for (
const auto & val : _coords)
959 template <
typename T>
963 decltype(std::abs(T())) ret{};
965 ret += std::abs(_coords[i]);
970 template <
typename T>
979 template <
typename T>
988 template <
typename T>
993 return (_coords[0] == rhs._coords[0]);
997 return (_coords[0] == rhs._coords[0] &&
998 _coords[1] == rhs._coords[1]);
1001 #if LIBMESH_DIM == 3 1002 return (_coords[0] == rhs._coords[0] &&
1003 _coords[1] == rhs._coords[1] &&
1004 _coords[2] == rhs._coords[2]);
1010 template <
typename T>
1014 return (!(*
this == rhs));
1027 template <
typename T>
1033 #if LIBMESH_DIM == 3 1035 a(0)*(b(1)*c(2) - b(2)*c(1)) -
1036 a(1)*(b(0)*c(2) - b(2)*c(0)) +
1037 a(2)*(b(0)*c(1) - b(1)*c(0));
1049 template <
typename T>
1055 const Real norm01 = v01.norm(),
1056 norm02 = v02.norm(),
1057 norm03 = v03.norm();
1058 const T tan_half_angle =
1060 ((v01*v02)*norm03 + (v01*v03)*norm02 + (v02*v03)*norm01 +
1061 norm01*norm02*norm03);
1063 return Real(2)*std::atan(tan_half_angle);
1073 template <
typename T>
1078 T z = b(0)*c(1) - b(1)*c(0);
1080 #if LIBMESH_DIM == 3 1081 T x = b(1)*c(2) - b(2)*c(1),
1082 y = b(0)*c(2) - b(2)*c(0);
1083 return x*x + y*y + z*z;
1094 template <
typename T>
1102 template <
typename T>
1107 auto && length =
norm();
1109 libmesh_assert_not_equal_to (length, static_cast<Real>(0.));
1111 #if LIBMESH_DIM == 1 1115 #if LIBMESH_DIM == 2 1120 #if LIBMESH_DIM == 3 1128 template <
typename T>
1131 #if LIBMESH_DIM == 1 1133 os <<
"x=" << (*this)(0);
1136 #if LIBMESH_DIM == 2 1139 << std::setw(8) << (*this)(0) <<
", " 1140 << std::setw(8) << (*this)(1) <<
")";
1143 #if LIBMESH_DIM == 3 1146 << std::setw(8) << (*this)(0) <<
", " 1147 << std::setw(8) << (*this)(1) <<
", " 1148 << std::setw(8) << (*this)(2) <<
")";
1152 template <
typename T>
1158 template <
typename T,
typename T2>
1169 for (
unsigned int i = 0; i < LIBMESH_DIM; i++)
1176 TypeVector<typename CompareTypes<T, T2>::supertype>
1181 for (
unsigned int i = 0; i < LIBMESH_DIM; i++)
1182 ret(i) = a(i) * conj_b;
1187 template <
typename T>
1191 return var.l1_norm();
1194 template <
typename T,
typename T2>
1205 template <
typename T>
1209 return vector.norm_sq();
1213 #ifdef LIBMESH_HAVE_METAPHYSICL 1216 template <
typename T>
1224 for (
unsigned int i = 0; i < LIBMESH_DIM; ++i)
1225 ret(i) = raw_value(in(i));
1231 template <
typename T,
typename U>
1232 struct ReplaceAlgebraicType<
libMesh::TypeVector<T>, U>
1239 #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)
auto norm() const -> decltype(std::norm(T()))
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
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.
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().
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 &...)
auto norm_sq() const -> decltype(std::norm(T()))
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.
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< Scalar, T >::supertype > >::type operator*(const Scalar &, const TypeNTensor< N, T > &)
T value_type
Helper typedef for C++98 generic programming.
auto l1_norm_diff(const NumericVector< T > &vec1, const NumericVector< T > &vec2)
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.
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.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeVector< typename CompareTypes< T, Scalar >::supertype > >::type operator*(const Scalar &) const
Multiply this vector by a scalar value.
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.
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeVector< typename CompareTypes< T, Scalar >::supertype > >::type operator/(const Scalar &) const
Divide each entry of this vector by scalar value.
bool relative_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeVector & >::type operator=(const Scalar &libmesh_dbg_var(p))
Assignment-from-scalar operator.
bool operator!=(const TypeVector< T > &rhs) const
const T & slice(const unsigned int i) const
~TypeVector()=default
Destructor.