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
 
Real size () const
 
Real norm () const
 
Real size_sq () const
 
Real norm_sq () 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 30 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 110 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 105 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 421 of file type_vector.h.

422 {
423  _coords[0] = 0;
424 
425 #if LIBMESH_DIM > 1
426  _coords[1] = 0;
427 #endif
428 
429 #if LIBMESH_DIM > 2
430  _coords[2] = 0;
431 #endif
432 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 438 of file type_vector.h.

441 {
442  _coords[0] = x;
443 
444 #if LIBMESH_DIM > 1
445  _coords[1] = y;
446 #else
447  libmesh_assert_equal_to (y, 0);
448 #endif
449 
450 #if LIBMESH_DIM > 2
451  _coords[2] = z;
452 #else
453  libmesh_assert_equal_to (z, 0);
454 #endif
455 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 461 of file type_vector.h.

470 {
471  _coords[0] = x;
472 
473 #if LIBMESH_DIM > 1
474  _coords[1] = y;
475 #else
476  libmesh_assert_equal_to (y, 0);
477 #endif
478 
479 #if LIBMESH_DIM > 2
480  _coords[2] = z;
481 #else
482  libmesh_assert_equal_to (z, 0);
483 #endif
484 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 491 of file type_vector.h.

495 {
496  _coords[0] = x;
497 
498 #if LIBMESH_DIM > 1
499  _coords[1] = 0;
500 #endif
501 
502 #if LIBMESH_DIM > 2
503  _coords[2] = 0;
504 #endif
505 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ TypeVector() [5/5]

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

Copy-constructor.

Definition at line 512 of file type_vector.h.

513 {
514  // copy the nodes from vector p to me
515  for (unsigned int i=0; i<LIBMESH_DIM; i++)
516  _coords[i] = p._coords[i];
517 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ ~TypeVector()

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

Destructor.

Definition at line 523 of file type_vector.h.

524 {
525 }

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 965 of file type_vector.h.

966 {
967 #if LIBMESH_DIM == 1
968  return (std::abs(_coords[0] - rhs._coords[0])
969  <= tol);
970 #endif
971 
972 #if LIBMESH_DIM == 2
973  return (std::abs(_coords[0] - rhs._coords[0]) +
974  std::abs(_coords[1] - rhs._coords[1])
975  <= tol);
976 #endif
977 
978 #if LIBMESH_DIM == 3
979  return (std::abs(_coords[0] - rhs._coords[0]) +
980  std::abs(_coords[1] - rhs._coords[1]) +
981  std::abs(_coords[2] - rhs._coords[2])
982  <= tol);
983 #endif
984 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409
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 603 of file type_vector.h.

604 {
605 #if LIBMESH_DIM == 1
606  _coords[0] += p._coords[0];
607 #endif
608 
609 #if LIBMESH_DIM == 2
610  _coords[0] += p._coords[0];
611  _coords[1] += p._coords[1];
612 #endif
613 
614 #if LIBMESH_DIM == 3
615  _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:409

◆ 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 627 of file type_vector.h.

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

628 {
629 #if LIBMESH_DIM == 1
630  _coords[0] += factor*p(0);
631 #endif
632 
633 #if LIBMESH_DIM == 2
634  _coords[0] += factor*p(0);
635  _coords[1] += factor*p(1);
636 #endif
637 
638 #if LIBMESH_DIM == 3
639  _coords[0] += factor*p(0);
640  _coords[1] += factor*p(1);
641  _coords[2] += factor*p(2);
642 #endif
643 
644 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 532 of file type_vector.h.

533 {
534  for (unsigned int i=0; i<LIBMESH_DIM; i++)
535  _coords[i] = p._coords[i];
536 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 872 of file type_vector.h.

873 {
874  return (*this)*(p);
875 }

◆ 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 882 of file type_vector.h.

883 {
884  typedef typename CompareTypes<T, T2>::supertype TS;
885  libmesh_assert_equal_to (LIBMESH_DIM, 3);
886 
887  // | i j k |
888  // |(*this)(0) (*this)(1) (*this)(2)|
889  // | p(0) p(1) p(2) |
890 
891  return TypeVector<TS>( _coords[1]*p._coords[2] - _coords[2]*p._coords[1],
892  -_coords[0]*p._coords[2] + _coords[2]*p._coords[0],
893  _coords[0]*p._coords[1] - _coords[1]*p._coords[0]);
894 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ norm()

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

Definition at line 912 of file type_vector.h.

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

913 {
914  return std::sqrt(this->norm_sq());
915 }
Real norm_sq() const
Definition: type_vector.h:943

◆ norm_sq()

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

Definition at line 943 of file type_vector.h.

Referenced by libMesh::TensorTools::norm_sq(), and TypeVectorTestBase< DerivedClass >::testNormSqBase().

944 {
945 #if LIBMESH_DIM == 1
946  return (TensorTools::norm_sq(_coords[0]));
947 #endif
948 
949 #if LIBMESH_DIM == 2
950  return (TensorTools::norm_sq(_coords[0]) +
952 #endif
953 
954 #if LIBMESH_DIM == 3
955  return (TensorTools::norm_sq(_coords[0]) +
958 #endif
959 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ operator!=()

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

Definition at line 1037 of file type_vector.h.

1038 {
1039  return (!(*this == rhs));
1040 }

◆ 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 542 of file type_vector.h.

543 {
544  libmesh_assert_less (i, LIBMESH_DIM);
545 
546  return _coords[i];
547 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 553 of file type_vector.h.

554 {
555  libmesh_assert_less (i, LIBMESH_DIM);
556 
557  return _coords[i];
558 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 739 of file type_vector.h.

740 {
741  typedef typename CompareTypes<T, Scalar>::supertype SuperType;
742 
743 #if LIBMESH_DIM == 1
744  return TypeVector<SuperType>(_coords[0]*factor);
745 #endif
746 
747 #if LIBMESH_DIM == 2
748  return TypeVector<SuperType>(_coords[0]*factor,
749  _coords[1]*factor);
750 #endif
751 
752 #if LIBMESH_DIM == 3
753  return TypeVector<SuperType>(_coords[0]*factor,
754  _coords[1]*factor,
755  _coords[2]*factor);
756 #endif
757 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 850 of file type_vector.h.

851 {
852 #if LIBMESH_DIM == 1
853  return _coords[0]*p._coords[0];
854 #endif
855 
856 #if LIBMESH_DIM == 2
857  return (_coords[0]*p._coords[0] +
858  _coords[1]*p._coords[1]);
859 #endif
860 
861 #if LIBMESH_DIM == 3
862  return (_coords[0]*p(0) +
863  _coords[1]*p(1) +
864  _coords[2]*p(2));
865 #endif
866 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 776 of file type_vector.h.

777 {
778 #if LIBMESH_DIM == 1
779  _coords[0] *= factor;
780 #endif
781 
782 #if LIBMESH_DIM == 2
783  _coords[0] *= factor;
784  _coords[1] *= factor;
785 #endif
786 
787 #if LIBMESH_DIM == 3
788  _coords[0] *= factor;
789  _coords[1] *= factor;
790  _coords[2] *= factor;
791 #endif
792 
793  return *this;
794 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 566 of file type_vector.h.

567 {
568  typedef typename CompareTypes<T, T2>::supertype TS;
569 #if LIBMESH_DIM == 1
570  return TypeVector<TS> (_coords[0] + p._coords[0]);
571 #endif
572 
573 #if LIBMESH_DIM == 2
574  return TypeVector<TS> (_coords[0] + p._coords[0],
575  _coords[1] + p._coords[1]);
576 #endif
577 
578 #if LIBMESH_DIM == 3
579  return TypeVector<TS> (_coords[0] + p._coords[0],
580  _coords[1] + p._coords[1],
581  _coords[2] + p._coords[2]);
582 #endif
583 
584 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 591 of file type_vector.h.

592 {
593  this->add (p);
594 
595  return *this;
596 }
void add(const TypeVector< T2 > &)
Add to this vector without creating a temporary.
Definition: type_vector.h:603

◆ 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 652 of file type_vector.h.

653 {
654  typedef typename CompareTypes<T, T2>::supertype TS;
655 
656 #if LIBMESH_DIM == 1
657  return TypeVector<TS>(_coords[0] - p._coords[0]);
658 #endif
659 
660 #if LIBMESH_DIM == 2
661  return TypeVector<TS>(_coords[0] - p._coords[0],
662  _coords[1] - p._coords[1]);
663 #endif
664 
665 #if LIBMESH_DIM == 3
666  return TypeVector<TS>(_coords[0] - p._coords[0],
667  _coords[1] - p._coords[1],
668  _coords[2] - p._coords[2]);
669 #endif
670 
671 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 711 of file type_vector.h.

712 {
713 
714 #if LIBMESH_DIM == 1
715  return TypeVector(-_coords[0]);
716 #endif
717 
718 #if LIBMESH_DIM == 2
719  return TypeVector(-_coords[0],
720  -_coords[1]);
721 #endif
722 
723 #if LIBMESH_DIM == 3
724  return TypeVector(-_coords[0],
725  -_coords[1],
726  -_coords[2]);
727 #endif
728 
729 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409
TypeVector()
Empty constructor.
Definition: type_vector.h:421

◆ 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 678 of file type_vector.h.

679 {
680  this->subtract (p);
681 
682  return *this;
683 }
void subtract(const TypeVector< T2 > &)
Subtract from this vector without creating a temporary.
Definition: type_vector.h:690

◆ 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 804 of file type_vector.h.

805 {
806  libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
807 
808  typedef typename CompareTypes<T, Scalar>::supertype TS;
809 
810 #if LIBMESH_DIM == 1
811  return TypeVector<TS>(_coords[0]/factor);
812 #endif
813 
814 #if LIBMESH_DIM == 2
815  return TypeVector<TS>(_coords[0]/factor,
816  _coords[1]/factor);
817 #endif
818 
819 #if LIBMESH_DIM == 3
820  return TypeVector<TS>(_coords[0]/factor,
821  _coords[1]/factor,
822  _coords[2]/factor);
823 #endif
824 
825 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 833 of file type_vector.h.

834 {
835  libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
836 
837  for (unsigned int i=0; i<LIBMESH_DIM; i++)
838  _coords[i] /= factor;
839 
840  return *this;
841 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 136 of file type_vector.h.

137  { 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:921

◆ 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 1015 of file type_vector.h.

1016 {
1017 #if LIBMESH_DIM == 1
1018  return (_coords[0] == rhs._coords[0]);
1019 #endif
1020 
1021 #if LIBMESH_DIM == 2
1022  return (_coords[0] == rhs._coords[0] &&
1023  _coords[1] == rhs._coords[1]);
1024 #endif
1025 
1026 #if LIBMESH_DIM == 3
1027  return (_coords[0] == rhs._coords[0] &&
1028  _coords[1] == rhs._coords[1] &&
1029  _coords[2] == rhs._coords[2]);
1030 #endif
1031 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 990 of file type_vector.h.

991 {
992 #if LIBMESH_DIM == 1
993  return this->absolute_fuzzy_equals(rhs, tol *
994  (std::abs(_coords[0]) + std::abs(rhs._coords[0])));
995 #endif
996 
997 #if LIBMESH_DIM == 2
998  return this->absolute_fuzzy_equals(rhs, tol *
999  (std::abs(_coords[0]) + std::abs(rhs._coords[0]) +
1000  std::abs(_coords[1]) + std::abs(rhs._coords[1])));
1001 #endif
1002 
1003 #if LIBMESH_DIM == 3
1004  return this->absolute_fuzzy_equals(rhs, tol *
1005  (std::abs(_coords[0]) + std::abs(rhs._coords[0]) +
1006  std::abs(_coords[1]) + std::abs(rhs._coords[1]) +
1007  std::abs(_coords[2]) + std::abs(rhs._coords[2])));
1008 #endif
1009 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409
double abs(double a)
bool absolute_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const
Definition: type_vector.h:965

◆ size()

template<typename T >
Real libMesh::TypeVector< T >::size ( ) const
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 901 of file type_vector.h.

902 {
903  libmesh_deprecated();
904  return this->norm();
905 }
Real norm() const
Definition: type_vector.h:912

◆ size_sq()

template<typename T >
Real libMesh::TypeVector< T >::size_sq ( ) const
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 932 of file type_vector.h.

933 {
934  libmesh_deprecated();
935  return this->norm_sq();
936 }
Real norm_sq() const
Definition: type_vector.h:943

◆ slice() [1/2]

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

Definition at line 143 of file type_vector.h.

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

◆ slice() [2/2]

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

Definition at line 149 of file type_vector.h.

149 { 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 690 of file type_vector.h.

691 {
692  for (unsigned int i=0; i<LIBMESH_DIM; i++)
693  _coords[i] -= p._coords[i];
694 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ 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 701 of file type_vector.h.

702 {
703  for (unsigned int i=0; i<LIBMESH_DIM; i++)
704  _coords[i] -= factor*p(i);
705 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

◆ unit()

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

◆ 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 921 of file type_vector.h.

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

922 {
923  for (unsigned int i=0; i<LIBMESH_DIM; i++)
924  _coords[i] = 0.;
925 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:409

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 390 of file type_vector.h.

391  {
392  t.print(os);
393  return os;
394  }

◆ TypeTensor< T >

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

Definition at line 55 of file type_vector.h.

◆ TypeVector

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

Definition at line 53 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 409 of file type_vector.h.

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


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