libMesh
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
libMesh::TypeVector< T > Class Template Reference

This class defines a vector in LIBMESH_DIM dimensional space of type T. More...

#include <tensor_tools.h>

Inheritance diagram for libMesh::TypeVector< T >:
[legend]

Public Types

typedef T value_type
 Helper typedef for C++98 generic programming. More...
 
typedef unsigned int index_type
 Helper typedef for generic index programming. More...
 

Public Member Functions

 TypeVector ()
 Empty constructor. More...
 
template<typename T2 >
 TypeVector (const TypeVector< T2 > &p)
 Copy-constructor. More...
 
 ~TypeVector ()
 Destructor. More...
 
template<typename T2 >
void assign (const TypeVector< T2 > &)
 Assign to this vector without creating a temporary. More...
 
template<typename Scalar >
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeVector & >::type operator= (const Scalar &libmesh_dbg_var(p))
 Assignment-from-scalar operator. More...
 
const T & operator() (const unsigned int i) const
 
const T & slice (const unsigned int i) const
 
T & operator() (const unsigned int i)
 
T & slice (const unsigned int i)
 
template<typename T2 >
TypeVector< typename CompareTypes< T, T2 >::supertype > operator+ (const TypeVector< T2 > &) const
 Add two vectors. More...
 
template<typename T2 >
const TypeVector< T > & operator+= (const TypeVector< T2 > &)
 Add to this vector. More...
 
template<typename T2 >
void add (const TypeVector< T2 > &)
 Add to this vector without creating a temporary. More...
 
template<typename T2 >
void add_scaled (const TypeVector< T2 > &, const T &)
 Add a scaled value to this vector without creating a temporary. More...
 
template<typename T2 >
TypeVector< typename CompareTypes< T, T2 >::supertype > operator- (const TypeVector< T2 > &) const
 Subtract from this vector. More...
 
template<typename T2 >
const TypeVector< T > & operator-= (const TypeVector< T2 > &)
 Subtract from this vector. More...
 
template<typename T2 >
void subtract (const TypeVector< T2 > &)
 Subtract from this vector without creating a temporary. More...
 
template<typename T2 >
void subtract_scaled (const TypeVector< T2 > &, const T &)
 Subtract a scaled value from this vector without creating a temporary. More...
 
TypeVector< T > operator- () const
 
template<typename Scalar >
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. More...
 
const TypeVector< T > & operator*= (const T &)
 Multiply this vector by a scalar value. More...
 
template<typename Scalar >
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. More...
 
const TypeVector< T > & operator/= (const T &)
 Divide each entry of this vector by scalar value. More...
 
template<typename T2 >
CompareTypes< T, T2 >::supertype operator* (const TypeVector< T2 > &) const
 
template<typename T2 >
CompareTypes< T, T2 >::supertype contract (const TypeVector< T2 > &) const
 
template<typename T2 >
TypeVector< typename CompareTypes< T, T2 >::supertype > cross (const TypeVector< T2 > &v) const
 
TypeVector< T > unit () const
 
auto size () const -> decltype(std::norm(T()))
 
auto norm () const -> decltype(std::norm(T()))
 
auto size_sq () const -> decltype(std::norm(T()))
 
auto norm_sq () const -> decltype(std::norm(T()))
 
bool is_zero () const
 
void zero ()
 Set all entries of the vector to 0. More...
 
bool relative_fuzzy_equals (const TypeVector< T > &rhs, Real tol=TOLERANCE) const
 
bool absolute_fuzzy_equals (const TypeVector< T > &rhs, Real tol=TOLERANCE) const
 
bool operator== (const TypeVector< T > &rhs) const
 
bool operator!= (const TypeVector< T > &rhs) const
 
bool operator< (const TypeVector< T > &rhs) const
 
bool operator<= (const TypeVector< T > &rhs) const
 
bool operator> (const TypeVector< T > &rhs) const
 
bool operator>= (const TypeVector< T > &rhs) const
 
void print (std::ostream &os=libMesh::out) const
 Formatted print, by default to libMesh::out. More...
 
void write_unformatted (std::ostream &out, const bool newline=true) const
 Unformatted print to the stream out. More...
 

Protected Member Functions

 TypeVector (const T &x, const T &y=0, const T &z=0)
 Constructor-from-T. More...
 
template<typename Scalar1 , typename Scalar2 , typename Scalar3 >
 TypeVector (typename boostcopy::enable_if_c< ScalarTraits< Scalar1 >::value, const Scalar1 >::type &x, typename boostcopy::enable_if_c< ScalarTraits< Scalar2 >::value, const Scalar2 >::type &y=0, typename boostcopy::enable_if_c< ScalarTraits< Scalar3 >::value, const Scalar3 >::type &z=0)
 Constructor-from-scalars. More...
 
template<typename Scalar >
 TypeVector (const Scalar &x, typename boostcopy::enable_if_c< ScalarTraits< Scalar >::value, const Scalar >::type *sfinae=nullptr)
 Constructor-from-scalar. More...
 

Protected Attributes

_coords [LIBMESH_DIM]
 The coordinates of the TypeVector. More...
 

Friends

template<typename T2 >
class TypeVector
 
class TypeTensor< T >
 
std::ostream & operator<< (std::ostream &os, const TypeVector< T > &t)
 Formatted print as above but supports the syntax: More...
 

Detailed Description

template<typename T>
class libMesh::TypeVector< T >

This class defines a vector in LIBMESH_DIM dimensional space of type T.

T may either be Real or Complex. Instead use one of the derived types such as Point or Node.

Author
Benjamin S. Kirk
Date
2003

Definition at line 45 of file tensor_tools.h.

Member Typedef Documentation

◆ index_type

template<typename T>
typedef unsigned int libMesh::TypeVector< T >::index_type

Helper typedef for generic index programming.

Definition at line 141 of file type_vector.h.

◆ value_type

template<typename T>
typedef T libMesh::TypeVector< T >::value_type

Helper typedef for C++98 generic programming.

Definition at line 136 of file type_vector.h.

Constructor & Destructor Documentation

◆ TypeVector() [1/5]

template<typename T >
libMesh::TypeVector< T >::TypeVector ( )

Empty constructor.

Gives the vector 0 in LIBMESH_DIM dimensions.

Definition at line 457 of file type_vector.h.

458 {
459  _coords[0] = 0;
460 
461 #if LIBMESH_DIM > 1
462  _coords[1] = 0;
463 #endif
464 
465 #if LIBMESH_DIM > 2
466  _coords[2] = 0;
467 #endif
468 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ TypeVector() [2/5]

template<typename T>
libMesh::TypeVector< T >::TypeVector ( const T &  x,
const T &  y = 0,
const T &  z = 0 
)
protected

Constructor-from-T.

By default sets higher dimensional entries to 0.

Definition at line 474 of file type_vector.h.

477 {
478  _coords[0] = x;
479 
480 #if LIBMESH_DIM > 1
481  _coords[1] = y;
482 #else
483  libmesh_assert_equal_to (y, 0);
484 #endif
485 
486 #if LIBMESH_DIM > 2
487  _coords[2] = z;
488 #else
489  libmesh_assert_equal_to (z, 0);
490 #endif
491 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ TypeVector() [3/5]

template<typename T >
template<typename Scalar1 , typename Scalar2 , typename Scalar3 >
libMesh::TypeVector< T >::TypeVector ( typename boostcopy::enable_if_c< ScalarTraits< Scalar1 >::value, const Scalar1 >::type &  x,
typename boostcopy::enable_if_c< ScalarTraits< Scalar2 >::value, const Scalar2 >::type &  y = 0,
typename boostcopy::enable_if_c< ScalarTraits< Scalar3 >::value, const Scalar3 >::type &  z = 0 
)
protected

Constructor-from-scalars.

By default sets higher dimensional entries to 0.

Definition at line 497 of file type_vector.h.

506 {
507  _coords[0] = x;
508 
509 #if LIBMESH_DIM > 1
510  _coords[1] = y;
511 #else
512  libmesh_assert_equal_to (y, 0);
513 #endif
514 
515 #if LIBMESH_DIM > 2
516  _coords[2] = z;
517 #else
518  libmesh_assert_equal_to (z, 0);
519 #endif
520 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ TypeVector() [4/5]

template<typename T >
template<typename Scalar >
libMesh::TypeVector< T >::TypeVector ( const Scalar &  x,
typename boostcopy::enable_if_c< ScalarTraits< Scalar >::value, const Scalar >::type *  sfinae = nullptr 
)
protected

Constructor-from-scalar.

Sets higher dimensional entries to 0. Necessary because for some reason the constructor-from-scalars alone is insufficient to let the compiler figure out TypeVector<Complex> v = 0;

Definition at line 527 of file type_vector.h.

531 {
532  _coords[0] = x;
533 
534 #if LIBMESH_DIM > 1
535  _coords[1] = 0;
536 #endif
537 
538 #if LIBMESH_DIM > 2
539  _coords[2] = 0;
540 #endif
541 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ TypeVector() [5/5]

template<typename T >
template<typename T2 >
libMesh::TypeVector< T >::TypeVector ( const TypeVector< T2 > &  p)

Copy-constructor.

Definition at line 548 of file type_vector.h.

549 {
550  // copy the nodes from vector p to me
551  for (unsigned int i=0; i<LIBMESH_DIM; i++)
552  _coords[i] = p._coords[i];
553 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ ~TypeVector()

template<typename T >
libMesh::TypeVector< T >::~TypeVector ( )

Destructor.

Definition at line 559 of file type_vector.h.

560 {
561 }

Member Function Documentation

◆ absolute_fuzzy_equals()

template<typename T>
bool libMesh::TypeVector< T >::absolute_fuzzy_equals ( const TypeVector< T > &  rhs,
Real  tol = TOLERANCE 
) const
Returns
true if two vectors are equal to within an absolute tolerance of tol.

Definition at line 1010 of file type_vector.h.

1011 {
1012 #if LIBMESH_DIM == 1
1013  return (std::abs(_coords[0] - rhs._coords[0])
1014  <= tol);
1015 #endif
1016 
1017 #if LIBMESH_DIM == 2
1018  return (std::abs(_coords[0] - rhs._coords[0]) +
1019  std::abs(_coords[1] - rhs._coords[1])
1020  <= tol);
1021 #endif
1022 
1023 #if LIBMESH_DIM == 3
1024  return (std::abs(_coords[0] - rhs._coords[0]) +
1025  std::abs(_coords[1] - rhs._coords[1]) +
1026  std::abs(_coords[2] - rhs._coords[2])
1027  <= tol);
1028 #endif
1029 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445
double abs(double a)

◆ add()

template<typename T >
template<typename T2 >
void libMesh::TypeVector< T >::add ( const TypeVector< T2 > &  p)

Add to this vector without creating a temporary.

Definition at line 639 of file type_vector.h.

640 {
641 #if LIBMESH_DIM == 1
642  _coords[0] += p._coords[0];
643 #endif
644 
645 #if LIBMESH_DIM == 2
646  _coords[0] += p._coords[0];
647  _coords[1] += p._coords[1];
648 #endif
649 
650 #if LIBMESH_DIM == 3
651  _coords[0] += p._coords[0];
652  _coords[1] += p._coords[1];
653  _coords[2] += p._coords[2];
654 #endif
655 
656 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ add_scaled()

template<typename T>
template<typename T2 >
void libMesh::TypeVector< T >::add_scaled ( const TypeVector< T2 > &  p,
const T &  factor 
)

Add a scaled value to this vector without creating a temporary.

Definition at line 663 of file type_vector.h.

Referenced by TypeVectorTestBase< DerivedClass >::testVectorAddScaledBase().

664 {
665 #if LIBMESH_DIM == 1
666  _coords[0] += factor*p(0);
667 #endif
668 
669 #if LIBMESH_DIM == 2
670  _coords[0] += factor*p(0);
671  _coords[1] += factor*p(1);
672 #endif
673 
674 #if LIBMESH_DIM == 3
675  _coords[0] += factor*p(0);
676  _coords[1] += factor*p(1);
677  _coords[2] += factor*p(2);
678 #endif
679 
680 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ assign()

template<typename T >
template<typename T2 >
void libMesh::TypeVector< T >::assign ( const TypeVector< T2 > &  p)

Assign to this vector without creating a temporary.

Definition at line 568 of file type_vector.h.

569 {
570  for (unsigned int i=0; i<LIBMESH_DIM; i++)
571  _coords[i] = p._coords[i];
572 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ contract()

template<typename T >
template<typename T2 >
CompareTypes< T, T2 >::supertype libMesh::TypeVector< T >::contract ( const TypeVector< T2 > &  p) const
Returns
The result of TypeVector::operator*().

Definition at line 908 of file type_vector.h.

909 {
910  return (*this)*(p);
911 }

◆ cross()

template<typename T >
template<typename T2 >
TypeVector< typename CompareTypes< T, T2 >::supertype > libMesh::TypeVector< T >::cross ( const TypeVector< T2 > &  v) const
Returns
The cross product of this vector with v.

Definition at line 918 of file type_vector.h.

919 {
920  typedef typename CompareTypes<T, T2>::supertype TS;
921  libmesh_assert_equal_to (LIBMESH_DIM, 3);
922 
923  // | i j k |
924  // |(*this)(0) (*this)(1) (*this)(2)|
925  // | p(0) p(1) p(2) |
926 
927  return TypeVector<TS>( _coords[1]*p._coords[2] - _coords[2]*p._coords[1],
928  -_coords[0]*p._coords[2] + _coords[2]*p._coords[0],
929  _coords[0]*p._coords[1] - _coords[1]*p._coords[0]);
930 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ is_zero()

template<typename T >
bool libMesh::TypeVector< T >::is_zero ( ) const
Returns
True if all values in the vector are zero

Definition at line 1000 of file type_vector.h.

1001 {
1002  for (const auto & val : _coords)
1003  if (val != T(0))
1004  return false;
1005  return true;
1006 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ norm()

template<typename T>
auto libMesh::TypeVector< T >::norm ( ) const -> decltype(std::norm(T()))
Returns
The magnitude of the vector, i.e. the square-root of the sum of the elements squared.

Definition at line 948 of file type_vector.h.

Referenced by libMesh::Sphere::surface_coords(), and TypeVectorTestBase< DerivedClass >::testNormBase().

949 {
950  return std::sqrt(this->norm_sq());
951 }
MetaPhysicL::DualNumber< T, D > sqrt(const MetaPhysicL::DualNumber< T, D > &in)
auto norm_sq() const -> decltype(std::norm(T()))
Definition: type_vector.h:979

◆ norm_sq()

template<typename T>
auto libMesh::TypeVector< T >::norm_sq ( ) const -> decltype(std::norm(T()))
Returns
The magnitude of the vector squared, i.e. the sum of the element magnitudes squared.

Definition at line 979 of file type_vector.h.

Referenced by TypeVectorTestBase< DerivedClass >::testNormSqBase().

980 {
981 #if LIBMESH_DIM == 1
982  return (TensorTools::norm_sq(_coords[0]));
983 #endif
984 
985 #if LIBMESH_DIM == 2
986  return (TensorTools::norm_sq(_coords[0]) +
988 #endif
989 
990 #if LIBMESH_DIM == 3
991  return (TensorTools::norm_sq(_coords[0]) +
994 #endif
995 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445
T norm_sq(std::complex< T > a)
Definition: tensor_tools.h:85

◆ operator!=()

template<typename T>
bool libMesh::TypeVector< T >::operator!= ( const TypeVector< T > &  rhs) const
Returns
!(*this == rhs)

Definition at line 1082 of file type_vector.h.

1083 {
1084  return (!(*this == rhs));
1085 }

◆ operator()() [1/2]

template<typename T >
const T & libMesh::TypeVector< T >::operator() ( const unsigned int  i) const
Returns
A const reference to the $ i^{th} $ entry of the vector.

Definition at line 578 of file type_vector.h.

579 {
580  libmesh_assert_less (i, LIBMESH_DIM);
581 
582  return _coords[i];
583 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ operator()() [2/2]

template<typename T >
T & libMesh::TypeVector< T >::operator() ( const unsigned int  i)
Returns
A writable reference to the $ i^{th} $ entry of the vector.

Definition at line 589 of file type_vector.h.

590 {
591  libmesh_assert_less (i, LIBMESH_DIM);
592 
593  return _coords[i];
594 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ operator*() [1/2]

template<typename T >
template<typename Scalar >
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeVector< typename CompareTypes< T, Scalar >::supertype > >::type libMesh::TypeVector< T >::operator* ( const Scalar &  factor) const

Multiply this vector by a scalar value.

Returns
A copy of the result, this vector is unchanged.

Definition at line 775 of file type_vector.h.

776 {
777  typedef typename CompareTypes<T, Scalar>::supertype SuperType;
778 
779 #if LIBMESH_DIM == 1
780  return TypeVector<SuperType>(_coords[0]*factor);
781 #endif
782 
783 #if LIBMESH_DIM == 2
784  return TypeVector<SuperType>(_coords[0]*factor,
785  _coords[1]*factor);
786 #endif
787 
788 #if LIBMESH_DIM == 3
789  return TypeVector<SuperType>(_coords[0]*factor,
790  _coords[1]*factor,
791  _coords[2]*factor);
792 #endif
793 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ operator*() [2/2]

template<typename T >
template<typename T2 >
CompareTypes< T, T2 >::supertype libMesh::TypeVector< T >::operator* ( const TypeVector< T2 > &  p) const
Returns
The dot-product of this vector with another vector.
Note
The complex conjugate is not taken in the complex-valued case.
The vectors may contain different numeric types.

Definition at line 886 of file type_vector.h.

887 {
888 #if LIBMESH_DIM == 1
889  return _coords[0]*p._coords[0];
890 #endif
891 
892 #if LIBMESH_DIM == 2
893  return (_coords[0]*p._coords[0] +
894  _coords[1]*p._coords[1]);
895 #endif
896 
897 #if LIBMESH_DIM == 3
898  return (_coords[0]*p(0) +
899  _coords[1]*p(1) +
900  _coords[2]*p(2));
901 #endif
902 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ operator*=()

template<typename T>
const TypeVector< T > & libMesh::TypeVector< T >::operator*= ( const T &  factor)

Multiply this vector by a scalar value.

Returns
A reference to *this.

Definition at line 812 of file type_vector.h.

813 {
814 #if LIBMESH_DIM == 1
815  _coords[0] *= factor;
816 #endif
817 
818 #if LIBMESH_DIM == 2
819  _coords[0] *= factor;
820  _coords[1] *= factor;
821 #endif
822 
823 #if LIBMESH_DIM == 3
824  _coords[0] *= factor;
825  _coords[1] *= factor;
826  _coords[2] *= factor;
827 #endif
828 
829  return *this;
830 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ operator+()

template<typename T >
template<typename T2 >
TypeVector< typename CompareTypes< T, T2 >::supertype > libMesh::TypeVector< T >::operator+ ( const TypeVector< T2 > &  p) const

Add two vectors.

Returns
A copy of the result, this vector is unchanged.

Definition at line 602 of file type_vector.h.

603 {
604  typedef typename CompareTypes<T, T2>::supertype TS;
605 #if LIBMESH_DIM == 1
606  return TypeVector<TS> (_coords[0] + p._coords[0]);
607 #endif
608 
609 #if LIBMESH_DIM == 2
610  return TypeVector<TS> (_coords[0] + p._coords[0],
611  _coords[1] + p._coords[1]);
612 #endif
613 
614 #if LIBMESH_DIM == 3
615  return TypeVector<TS> (_coords[0] + p._coords[0],
616  _coords[1] + p._coords[1],
617  _coords[2] + p._coords[2]);
618 #endif
619 
620 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ operator+=()

template<typename T >
template<typename T2 >
const TypeVector< T > & libMesh::TypeVector< T >::operator+= ( const TypeVector< T2 > &  p)

Add to this vector.

Returns
A reference to *this.

Definition at line 627 of file type_vector.h.

628 {
629  this->add (p);
630 
631  return *this;
632 }
void add(const TypeVector< T2 > &)
Add to this vector without creating a temporary.
Definition: type_vector.h:639

◆ operator-() [1/2]

template<typename T >
template<typename T2 >
TypeVector< typename CompareTypes< T, T2 >::supertype > libMesh::TypeVector< T >::operator- ( const TypeVector< T2 > &  p) const

Subtract from this vector.

Returns
A copy of the result, this vector is unchanged.

Definition at line 688 of file type_vector.h.

689 {
690  typedef typename CompareTypes<T, T2>::supertype TS;
691 
692 #if LIBMESH_DIM == 1
693  return TypeVector<TS>(_coords[0] - p._coords[0]);
694 #endif
695 
696 #if LIBMESH_DIM == 2
697  return TypeVector<TS>(_coords[0] - p._coords[0],
698  _coords[1] - p._coords[1]);
699 #endif
700 
701 #if LIBMESH_DIM == 3
702  return TypeVector<TS>(_coords[0] - p._coords[0],
703  _coords[1] - p._coords[1],
704  _coords[2] - p._coords[2]);
705 #endif
706 
707 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ operator-() [2/2]

template<typename T >
TypeVector< T > libMesh::TypeVector< T >::operator- ( ) const
Returns
The negative of this vector in a separate copy.

Definition at line 747 of file type_vector.h.

748 {
749 
750 #if LIBMESH_DIM == 1
751  return TypeVector(-_coords[0]);
752 #endif
753 
754 #if LIBMESH_DIM == 2
755  return TypeVector(-_coords[0],
756  -_coords[1]);
757 #endif
758 
759 #if LIBMESH_DIM == 3
760  return TypeVector(-_coords[0],
761  -_coords[1],
762  -_coords[2]);
763 #endif
764 
765 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445
TypeVector()
Empty constructor.
Definition: type_vector.h:457

◆ operator-=()

template<typename T >
template<typename T2 >
const TypeVector< T > & libMesh::TypeVector< T >::operator-= ( const TypeVector< T2 > &  p)

Subtract from this vector.

Returns
A reference to *this.

Definition at line 714 of file type_vector.h.

715 {
716  this->subtract (p);
717 
718  return *this;
719 }
void subtract(const TypeVector< T2 > &)
Subtract from this vector without creating a temporary.
Definition: type_vector.h:726

◆ operator/()

template<typename T >
template<typename Scalar >
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeVector< typename CompareTypes< T, Scalar >::supertype > >::type libMesh::TypeVector< T >::operator/ ( const Scalar &  factor) const

Divide each entry of this vector by scalar value.

Returns
A copy of the result, this vector is unchanged.

Definition at line 840 of file type_vector.h.

841 {
842  libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
843 
844  typedef typename CompareTypes<T, Scalar>::supertype TS;
845 
846 #if LIBMESH_DIM == 1
847  return TypeVector<TS>(_coords[0]/factor);
848 #endif
849 
850 #if LIBMESH_DIM == 2
851  return TypeVector<TS>(_coords[0]/factor,
852  _coords[1]/factor);
853 #endif
854 
855 #if LIBMESH_DIM == 3
856  return TypeVector<TS>(_coords[0]/factor,
857  _coords[1]/factor,
858  _coords[2]/factor);
859 #endif
860 
861 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ operator/=()

template<typename T>
const TypeVector< T > & libMesh::TypeVector< T >::operator/= ( const T &  factor)

Divide each entry of this vector by scalar value.

Returns
A reference to *this.

Definition at line 869 of file type_vector.h.

870 {
871  libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
872 
873  for (unsigned int i=0; i<LIBMESH_DIM; i++)
874  _coords[i] /= factor;
875 
876  return *this;
877 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ operator<()

template<typename T>
bool libMesh::TypeVector< T >::operator< ( const TypeVector< T > &  rhs) const
Returns
true if this vector is "less" than rhs.

Useful for sorting. Also used for choosing some arbitrary basis function orientations.

◆ operator<=()

template<typename T>
bool libMesh::TypeVector< T >::operator<= ( const TypeVector< T > &  rhs) const
Returns
true if this vector is <= to rhs.

Useful for sorting. Also used for choosing some arbitrary constraint equation directions.

◆ operator=()

template<typename T>
template<typename Scalar >
boostcopy::enable_if_c< ScalarTraits<Scalar>::value, TypeVector &>::type libMesh::TypeVector< T >::operator= ( const Scalar &  libmesh_dbg_varp)

Assignment-from-scalar operator.

Used only to zero out vectors.

Definition at line 167 of file type_vector.h.

168  { libmesh_assert_equal_to (p, Scalar(0)); this->zero(); return *this; }
void zero()
Set all entries of the vector to 0.
Definition: type_vector.h:957

◆ operator==()

template<typename T>
bool libMesh::TypeVector< T >::operator== ( const TypeVector< T > &  rhs) const
Returns
true if this(i)==rhs(i) for each component of the vector.
Note
For floating point types T, the function absolute_fuzzy_equals() may be a more appropriate choice.

Definition at line 1060 of file type_vector.h.

1061 {
1062 #if LIBMESH_DIM == 1
1063  return (_coords[0] == rhs._coords[0]);
1064 #endif
1065 
1066 #if LIBMESH_DIM == 2
1067  return (_coords[0] == rhs._coords[0] &&
1068  _coords[1] == rhs._coords[1]);
1069 #endif
1070 
1071 #if LIBMESH_DIM == 3
1072  return (_coords[0] == rhs._coords[0] &&
1073  _coords[1] == rhs._coords[1] &&
1074  _coords[2] == rhs._coords[2]);
1075 #endif
1076 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ operator>()

template<typename T>
bool libMesh::TypeVector< T >::operator> ( const TypeVector< T > &  rhs) const
Returns
true if this vector is "greater" than rhs.

Useful for sorting. Also used for choosing some arbitrary basis function orientations.

◆ operator>=()

template<typename T>
bool libMesh::TypeVector< T >::operator>= ( const TypeVector< T > &  rhs) const
Returns
true if this vector is >= rhs.

Useful for sorting. Also used for choosing some arbitrary constraint equation directions.

◆ print()

template<typename T>
void libMesh::TypeVector< T >::print ( std::ostream &  os = libMesh::out) const

Formatted print, by default to libMesh::out.

◆ relative_fuzzy_equals()

template<typename T>
bool libMesh::TypeVector< T >::relative_fuzzy_equals ( const TypeVector< T > &  rhs,
Real  tol = TOLERANCE 
) const
Returns
true if two vectors are equal to within a relative tolerance of tol.

Definition at line 1035 of file type_vector.h.

1036 {
1037 #if LIBMESH_DIM == 1
1038  return this->absolute_fuzzy_equals(rhs, tol *
1039  (std::abs(_coords[0]) + std::abs(rhs._coords[0])));
1040 #endif
1041 
1042 #if LIBMESH_DIM == 2
1043  return this->absolute_fuzzy_equals(rhs, tol *
1044  (std::abs(_coords[0]) + std::abs(rhs._coords[0]) +
1045  std::abs(_coords[1]) + std::abs(rhs._coords[1])));
1046 #endif
1047 
1048 #if LIBMESH_DIM == 3
1049  return this->absolute_fuzzy_equals(rhs, tol *
1050  (std::abs(_coords[0]) + std::abs(rhs._coords[0]) +
1051  std::abs(_coords[1]) + std::abs(rhs._coords[1]) +
1052  std::abs(_coords[2]) + std::abs(rhs._coords[2])));
1053 #endif
1054 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445
double abs(double a)
bool absolute_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const
Definition: type_vector.h:1010

◆ size()

template<typename T>
auto libMesh::TypeVector< T >::size ( ) const -> decltype(std::norm(T()))
Returns
The magnitude of the vector, i.e. the square-root of the sum of the elements squared.
Deprecated:
Use the norm() function instead.

Definition at line 937 of file type_vector.h.

938 {
939  libmesh_deprecated();
940  return this->norm();
941 }
auto norm() const -> decltype(std::norm(T()))
Definition: type_vector.h:948

◆ size_sq()

template<typename T>
auto libMesh::TypeVector< T >::size_sq ( ) const -> decltype(std::norm(T()))
Returns
The magnitude of the vector squared, i.e. the sum of the element magnitudes squared.
Deprecated:
Use the norm_sq() function instead.

Definition at line 968 of file type_vector.h.

969 {
970  libmesh_deprecated();
971  return this->norm_sq();
972 }
auto norm_sq() const -> decltype(std::norm(T()))
Definition: type_vector.h:979

◆ slice() [1/2]

template<typename T>
const T& libMesh::TypeVector< T >::slice ( const unsigned int  i) const

Definition at line 174 of file type_vector.h.

174 { return (*this)(i); }

◆ slice() [2/2]

template<typename T>
T& libMesh::TypeVector< T >::slice ( const unsigned int  i)

Definition at line 180 of file type_vector.h.

180 { return (*this)(i); }

◆ subtract()

template<typename T >
template<typename T2 >
void libMesh::TypeVector< T >::subtract ( const TypeVector< T2 > &  p)

Subtract from this vector without creating a temporary.

Definition at line 726 of file type_vector.h.

727 {
728  for (unsigned int i=0; i<LIBMESH_DIM; i++)
729  _coords[i] -= p._coords[i];
730 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ subtract_scaled()

template<typename T>
template<typename T2 >
void libMesh::TypeVector< T >::subtract_scaled ( const TypeVector< T2 > &  p,
const T &  factor 
)

Subtract a scaled value from this vector without creating a temporary.

Definition at line 737 of file type_vector.h.

738 {
739  for (unsigned int i=0; i<LIBMESH_DIM; i++)
740  _coords[i] -= factor*p(i);
741 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

◆ unit()

template<typename T >
TypeVector< T > libMesh::TypeVector< T >::unit ( ) const
Returns
A unit vector in the direction of *this.

Definition at line 1150 of file type_vector.h.

1151 {
1152 
1153  auto && length = norm();
1154 
1155  libmesh_assert_not_equal_to (length, static_cast<Real>(0.));
1156 
1157 #if LIBMESH_DIM == 1
1158  return TypeVector<T>(_coords[0]/length);
1159 #endif
1160 
1161 #if LIBMESH_DIM == 2
1162  return TypeVector<T>(_coords[0]/length,
1163  _coords[1]/length);
1164 #endif
1165 
1166 #if LIBMESH_DIM == 3
1167  return TypeVector<T>(_coords[0]/length,
1168  _coords[1]/length,
1169  _coords[2]/length);
1170 #endif
1171 
1172 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445
auto norm() const -> decltype(std::norm(T()))
Definition: type_vector.h:948

◆ write_unformatted()

template<typename T>
void libMesh::TypeVector< T >::write_unformatted ( std::ostream &  out,
const bool  newline = true 
) const

Unformatted print to the stream out.

Simply prints the elements of the vector separated by spaces. Also prints a newline by default, however, this behavior can be controlled with the newline parameter.

◆ zero()

template<typename T >
void libMesh::TypeVector< T >::zero ( )

Set all entries of the vector to 0.

Definition at line 957 of file type_vector.h.

Referenced by libMesh::VectorValue< Real >::operator=(), libMesh::TypeVector< Real >::operator=(), and TypeVectorTestBase< DerivedClass >::testZeroBase().

958 {
959  for (unsigned int i=0; i<LIBMESH_DIM; i++)
960  _coords[i] = 0.;
961 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:445

Friends And Related Function Documentation

◆ operator<<

template<typename T>
std::ostream& operator<< ( std::ostream &  os,
const TypeVector< T > &  t 
)
friend

Formatted print as above but supports the syntax:

Point p(1,2,3);
std::cout << p << std::endl;

Definition at line 426 of file type_vector.h.

427  {
428  t.print(os);
429  return os;
430  }

◆ TypeTensor< T >

template<typename T>
friend class TypeTensor< T >
friend

Definition at line 86 of file type_vector.h.

◆ TypeVector

template<typename T>
template<typename T2 >
friend class TypeVector
friend

Definition at line 84 of file type_vector.h.

Member Data Documentation

◆ _coords

template<typename T>
T libMesh::TypeVector< T >::_coords[LIBMESH_DIM]
protected

The coordinates of the TypeVector.

Definition at line 445 of file type_vector.h.

Referenced by libMesh::TypeTensor< T >::row().


The documentation for this class was generated from the following files: