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()))
 
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 452 of file type_vector.h.

453 {
454  _coords[0] = 0;
455 
456 #if LIBMESH_DIM > 1
457  _coords[1] = 0;
458 #endif
459 
460 #if LIBMESH_DIM > 2
461  _coords[2] = 0;
462 #endif
463 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

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

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

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

501 {
502  _coords[0] = x;
503 
504 #if LIBMESH_DIM > 1
505  _coords[1] = y;
506 #else
507  libmesh_assert_equal_to (y, 0);
508 #endif
509 
510 #if LIBMESH_DIM > 2
511  _coords[2] = z;
512 #else
513  libmesh_assert_equal_to (z, 0);
514 #endif
515 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

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

526 {
527  _coords[0] = x;
528 
529 #if LIBMESH_DIM > 1
530  _coords[1] = 0;
531 #endif
532 
533 #if LIBMESH_DIM > 2
534  _coords[2] = 0;
535 #endif
536 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

◆ TypeVector() [5/5]

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

Copy-constructor.

Definition at line 543 of file type_vector.h.

544 {
545  // copy the nodes from vector p to me
546  for (unsigned int i=0; i<LIBMESH_DIM; i++)
547  _coords[i] = p._coords[i];
548 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

◆ ~TypeVector()

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

Destructor.

Definition at line 554 of file type_vector.h.

555 {
556 }

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

997 {
998 #if LIBMESH_DIM == 1
999  return (std::abs(_coords[0] - rhs._coords[0])
1000  <= tol);
1001 #endif
1002 
1003 #if LIBMESH_DIM == 2
1004  return (std::abs(_coords[0] - rhs._coords[0]) +
1005  std::abs(_coords[1] - rhs._coords[1])
1006  <= tol);
1007 #endif
1008 
1009 #if LIBMESH_DIM == 3
1010  return (std::abs(_coords[0] - rhs._coords[0]) +
1011  std::abs(_coords[1] - rhs._coords[1]) +
1012  std::abs(_coords[2] - rhs._coords[2])
1013  <= tol);
1014 #endif
1015 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440
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 634 of file type_vector.h.

635 {
636 #if LIBMESH_DIM == 1
637  _coords[0] += p._coords[0];
638 #endif
639 
640 #if LIBMESH_DIM == 2
641  _coords[0] += p._coords[0];
642  _coords[1] += p._coords[1];
643 #endif
644 
645 #if LIBMESH_DIM == 3
646  _coords[0] += p._coords[0];
647  _coords[1] += p._coords[1];
648  _coords[2] += p._coords[2];
649 #endif
650 
651 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

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

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

659 {
660 #if LIBMESH_DIM == 1
661  _coords[0] += factor*p(0);
662 #endif
663 
664 #if LIBMESH_DIM == 2
665  _coords[0] += factor*p(0);
666  _coords[1] += factor*p(1);
667 #endif
668 
669 #if LIBMESH_DIM == 3
670  _coords[0] += factor*p(0);
671  _coords[1] += factor*p(1);
672  _coords[2] += factor*p(2);
673 #endif
674 
675 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

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

564 {
565  for (unsigned int i=0; i<LIBMESH_DIM; i++)
566  _coords[i] = p._coords[i];
567 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

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

904 {
905  return (*this)*(p);
906 }

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

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

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

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

944 {
945  return std::sqrt(this->norm_sq());
946 }
MetaPhysicL::DualNumber< T, D > sqrt(const MetaPhysicL::DualNumber< T, D > &in)
auto norm_sq() const -> decltype(std::norm(T()))
Definition: type_vector.h:974

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

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

975 {
976 #if LIBMESH_DIM == 1
977  return (TensorTools::norm_sq(_coords[0]));
978 #endif
979 
980 #if LIBMESH_DIM == 2
981  return (TensorTools::norm_sq(_coords[0]) +
983 #endif
984 
985 #if LIBMESH_DIM == 3
986  return (TensorTools::norm_sq(_coords[0]) +
989 #endif
990 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440
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 1068 of file type_vector.h.

1069 {
1070  return (!(*this == rhs));
1071 }

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

574 {
575  libmesh_assert_less (i, LIBMESH_DIM);
576 
577  return _coords[i];
578 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

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

585 {
586  libmesh_assert_less (i, LIBMESH_DIM);
587 
588  return _coords[i];
589 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

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

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

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

882 {
883 #if LIBMESH_DIM == 1
884  return _coords[0]*p._coords[0];
885 #endif
886 
887 #if LIBMESH_DIM == 2
888  return (_coords[0]*p._coords[0] +
889  _coords[1]*p._coords[1]);
890 #endif
891 
892 #if LIBMESH_DIM == 3
893  return (_coords[0]*p(0) +
894  _coords[1]*p(1) +
895  _coords[2]*p(2));
896 #endif
897 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

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

808 {
809 #if LIBMESH_DIM == 1
810  _coords[0] *= factor;
811 #endif
812 
813 #if LIBMESH_DIM == 2
814  _coords[0] *= factor;
815  _coords[1] *= factor;
816 #endif
817 
818 #if LIBMESH_DIM == 3
819  _coords[0] *= factor;
820  _coords[1] *= factor;
821  _coords[2] *= factor;
822 #endif
823 
824  return *this;
825 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

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

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

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

623 {
624  this->add (p);
625 
626  return *this;
627 }
void add(const TypeVector< T2 > &)
Add to this vector without creating a temporary.
Definition: type_vector.h:634

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

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

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

743 {
744 
745 #if LIBMESH_DIM == 1
746  return TypeVector(-_coords[0]);
747 #endif
748 
749 #if LIBMESH_DIM == 2
750  return TypeVector(-_coords[0],
751  -_coords[1]);
752 #endif
753 
754 #if LIBMESH_DIM == 3
755  return TypeVector(-_coords[0],
756  -_coords[1],
757  -_coords[2]);
758 #endif
759 
760 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440
TypeVector()
Empty constructor.
Definition: type_vector.h:452

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

710 {
711  this->subtract (p);
712 
713  return *this;
714 }
void subtract(const TypeVector< T2 > &)
Subtract from this vector without creating a temporary.
Definition: type_vector.h:721

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

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

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

865 {
866  libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
867 
868  for (unsigned int i=0; i<LIBMESH_DIM; i++)
869  _coords[i] /= factor;
870 
871  return *this;
872 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

◆ 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:952

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

1047 {
1048 #if LIBMESH_DIM == 1
1049  return (_coords[0] == rhs._coords[0]);
1050 #endif
1051 
1052 #if LIBMESH_DIM == 2
1053  return (_coords[0] == rhs._coords[0] &&
1054  _coords[1] == rhs._coords[1]);
1055 #endif
1056 
1057 #if LIBMESH_DIM == 3
1058  return (_coords[0] == rhs._coords[0] &&
1059  _coords[1] == rhs._coords[1] &&
1060  _coords[2] == rhs._coords[2]);
1061 #endif
1062 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

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

1022 {
1023 #if LIBMESH_DIM == 1
1024  return this->absolute_fuzzy_equals(rhs, tol *
1025  (std::abs(_coords[0]) + std::abs(rhs._coords[0])));
1026 #endif
1027 
1028 #if LIBMESH_DIM == 2
1029  return this->absolute_fuzzy_equals(rhs, tol *
1030  (std::abs(_coords[0]) + std::abs(rhs._coords[0]) +
1031  std::abs(_coords[1]) + std::abs(rhs._coords[1])));
1032 #endif
1033 
1034 #if LIBMESH_DIM == 3
1035  return this->absolute_fuzzy_equals(rhs, tol *
1036  (std::abs(_coords[0]) + std::abs(rhs._coords[0]) +
1037  std::abs(_coords[1]) + std::abs(rhs._coords[1]) +
1038  std::abs(_coords[2]) + std::abs(rhs._coords[2])));
1039 #endif
1040 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440
double abs(double a)
bool absolute_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const
Definition: type_vector.h:996

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

933 {
934  libmesh_deprecated();
935  return this->norm();
936 }
auto norm() const -> decltype(std::norm(T()))
Definition: type_vector.h:943

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

964 {
965  libmesh_deprecated();
966  return this->norm_sq();
967 }
auto norm_sq() const -> decltype(std::norm(T()))
Definition: type_vector.h:974

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

722 {
723  for (unsigned int i=0; i<LIBMESH_DIM; i++)
724  _coords[i] -= p._coords[i];
725 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

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

733 {
734  for (unsigned int i=0; i<LIBMESH_DIM; i++)
735  _coords[i] -= factor*p(i);
736 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

◆ unit()

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

Definition at line 1136 of file type_vector.h.

1137 {
1138 
1139  auto && length = norm();
1140 
1141  libmesh_assert_not_equal_to (length, static_cast<Real>(0.));
1142 
1143 #if LIBMESH_DIM == 1
1144  return TypeVector<T>(_coords[0]/length);
1145 #endif
1146 
1147 #if LIBMESH_DIM == 2
1148  return TypeVector<T>(_coords[0]/length,
1149  _coords[1]/length);
1150 #endif
1151 
1152 #if LIBMESH_DIM == 3
1153  return TypeVector<T>(_coords[0]/length,
1154  _coords[1]/length,
1155  _coords[2]/length);
1156 #endif
1157 
1158 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440
auto norm() const -> decltype(std::norm(T()))
Definition: type_vector.h:943

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

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

953 {
954  for (unsigned int i=0; i<LIBMESH_DIM; i++)
955  _coords[i] = 0.;
956 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:440

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

422  {
423  t.print(os);
424  return os;
425  }

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

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


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