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 (const TypeVector &p)=default
 Copy-constructor for the trivial case. More...
 
 ~TypeVector ()=default
 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 norm () 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_stream, const bool newline=true) const
 Unformatted print to the stream out. More...
 
template<>
bool operator< (const TypeVector< Complex > &rhs) const
 
template<>
bool operator<= (const TypeVector< Complex > &rhs) const
 
template<>
bool operator> (const TypeVector< Complex > &rhs) const
 
template<>
bool operator>= (const TypeVector< Complex > &rhs) const
 

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 34 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 149 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 144 of file type_vector.h.

Constructor & Destructor Documentation

◆ TypeVector() [1/6]

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

Empty constructor.

Gives the vector 0 in LIBMESH_DIM dimensions.

Definition at line 451 of file type_vector.h.

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

◆ TypeVector() [2/6]

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

Constructor-from-T.

By default sets higher dimensional entries to 0.

Definition at line 468 of file type_vector.h.

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

◆ TypeVector() [3/6]

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 
)
inlineprotected

Constructor-from-scalars.

By default sets higher dimensional entries to 0.

Definition at line 493 of file type_vector.h.

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

◆ TypeVector() [4/6]

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 
)
inlineprotected

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

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

◆ TypeVector() [5/6]

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

Copy-constructor.

Definition at line 544 of file type_vector.h.

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

◆ TypeVector() [6/6]

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

Copy-constructor for the trivial case.

◆ ~TypeVector()

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

Destructor.

Member Function Documentation

◆ absolute_fuzzy_equals()

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

Definition at line 979 of file type_vector.h.

Referenced by libMesh::FEGenericBase< FEOutputType< T >::type >::compute_periodic_constraints(), libMesh::LocationMap< T >::find(), libMesh::Pyramid::local_singular_node(), libMesh::Elem::parent_bracketing_nodes(), VolumeTest::test_true_centroid_and_volume(), MeshTriangulationTest::testFoundCenters(), and VolumeTest::testQuad4TrueCentroid().

980 {
981 #if LIBMESH_DIM == 1
982  return (std::abs(_coords[0] - rhs._coords[0])
983  <= tol);
984 #endif
985 
986 #if LIBMESH_DIM == 2
987  return (std::abs(_coords[0] - rhs._coords[0]) +
988  std::abs(_coords[1] - rhs._coords[1])
989  <= tol);
990 #endif
991 
992 #if LIBMESH_DIM == 3
993  return (std::abs(_coords[0] - rhs._coords[0]) +
994  std::abs(_coords[1] - rhs._coords[1]) +
995  std::abs(_coords[2] - rhs._coords[2])
996  <= tol);
997 #endif
998 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:57

◆ add()

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

Add to this vector without creating a temporary.

Definition at line 627 of file type_vector.h.

Referenced by libMesh::FEMap::inverse_map(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::MeshTools::Modification::smooth(), and libMesh::Elem::vertex_average().

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

◆ add_scaled()

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

◆ assign()

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

Assign to this vector without creating a temporary.

Definition at line 556 of file type_vector.h.

557 {
558  for (unsigned int i=0; i<LIBMESH_DIM; i++)
559  _coords[i] = p._coords[i];
560 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439

◆ contract()

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

Definition at line 896 of file type_vector.h.

897 {
898  return (*this)*(p);
899 }

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

Referenced by libMesh::TriangulatorInterface::Hole::areavec(), assemble_shell(), libMesh::InfFE< Dim, T_radial, T_map >::compute_face_functions(), libMesh::FEMap::compute_face_map(), libMesh::InfFE< Dim, T_radial, T_map >::compute_shape_functions(), ContainsPointTest::containsPointTri3Helper(), libMesh::Plane::create_from_three_points(), libMesh::Quad4::has_invertible_map(), libMesh::TriangulatorInterface::MeshedHole::MeshedHole(), libMesh::Quad::quality(), libMesh::Face::quasicircumcenter(), and libMesh::Quad4::volume().

907 {
908  typedef typename CompareTypes<T, T2>::supertype TS;
909  libmesh_assert_equal_to (LIBMESH_DIM, 3);
910 
911  // | i j k |
912  // |(*this)(0) (*this)(1) (*this)(2)|
913  // | p(0) p(1) p(2) |
914 
915 #if LIBMESH_DIM == 3
916  return TypeVector<TS>( _coords[1]*p._coords[2] - _coords[2]*p._coords[1],
917  -_coords[0]*p._coords[2] + _coords[2]*p._coords[0],
918  _coords[0]*p._coords[1] - _coords[1]*p._coords[0]);
919 #else
920  libmesh_ignore(p);
921  return TypeVector<TS>(0);
922 #endif
923 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439
void libmesh_ignore(const Args &...)

◆ is_zero()

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

Definition at line 969 of file type_vector.h.

970 {
971  for (const auto & val : _coords)
972  if (val != T(0))
973  return false;
974  return true;
975 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439

◆ norm()

template<typename T>
auto libMesh::TypeVector< T >::norm ( ) const -> decltype(std::norm(T()))
inline

◆ norm_sq()

template<typename T>
auto libMesh::TypeVector< T >::norm_sq ( ) const -> decltype(std::norm(T()))
inline

◆ operator!=()

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

Definition at line 1051 of file type_vector.h.

1052 {
1053  return (!(*this == rhs));
1054 }

◆ operator()() [1/2]

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

Definition at line 566 of file type_vector.h.

567 {
568  libmesh_assert_less (i, LIBMESH_DIM);
569 
570  return _coords[i];
571 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439

◆ operator()() [2/2]

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

Definition at line 577 of file type_vector.h.

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

◆ 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
inline

Multiply this vector by a scalar value.

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

Definition at line 763 of file type_vector.h.

764 {
765  typedef typename CompareTypes<T, Scalar>::supertype SuperType;
766 
767 #if LIBMESH_DIM == 1
768  return TypeVector<SuperType>(_coords[0]*factor);
769 #endif
770 
771 #if LIBMESH_DIM == 2
772  return TypeVector<SuperType>(_coords[0]*factor,
773  _coords[1]*factor);
774 #endif
775 
776 #if LIBMESH_DIM == 3
777  return TypeVector<SuperType>(_coords[0]*factor,
778  _coords[1]*factor,
779  _coords[2]*factor);
780 #endif
781 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439

◆ operator*() [2/2]

template<typename T >
template<typename T2 >
CompareTypes< T, T2 >::supertype libMesh::TypeVector< T >::operator* ( const TypeVector< T2 > &  p) const
inline
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 874 of file type_vector.h.

875 {
876 #if LIBMESH_DIM == 1
877  return _coords[0]*p._coords[0];
878 #endif
879 
880 #if LIBMESH_DIM == 2
881  return (_coords[0]*p._coords[0] +
882  _coords[1]*p._coords[1]);
883 #endif
884 
885 #if LIBMESH_DIM == 3
886  return (_coords[0]*p(0) +
887  _coords[1]*p(1) +
888  _coords[2]*p(2));
889 #endif
890 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439

◆ operator*=()

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

Multiply this vector by a scalar value.

Returns
A reference to *this.

Definition at line 800 of file type_vector.h.

801 {
802 #if LIBMESH_DIM == 1
803  _coords[0] *= factor;
804 #endif
805 
806 #if LIBMESH_DIM == 2
807  _coords[0] *= factor;
808  _coords[1] *= factor;
809 #endif
810 
811 #if LIBMESH_DIM == 3
812  _coords[0] *= factor;
813  _coords[1] *= factor;
814  _coords[2] *= factor;
815 #endif
816 
817  return *this;
818 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439

◆ operator+()

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

Add two vectors.

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

Definition at line 590 of file type_vector.h.

591 {
592  typedef typename CompareTypes<T, T2>::supertype TS;
593 #if LIBMESH_DIM == 1
594  return TypeVector<TS> (_coords[0] + p._coords[0]);
595 #endif
596 
597 #if LIBMESH_DIM == 2
598  return TypeVector<TS> (_coords[0] + p._coords[0],
599  _coords[1] + p._coords[1]);
600 #endif
601 
602 #if LIBMESH_DIM == 3
603  return TypeVector<TS> (_coords[0] + p._coords[0],
604  _coords[1] + p._coords[1],
605  _coords[2] + p._coords[2]);
606 #endif
607 
608 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439

◆ operator+=()

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

Add to this vector.

Returns
A reference to *this.

Definition at line 615 of file type_vector.h.

616 {
617  this->add (p);
618 
619  return *this;
620 }
void add(const TypeVector< T2 > &)
Add to this vector without creating a temporary.
Definition: type_vector.h:627

◆ operator-() [1/2]

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

Subtract from this vector.

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

Definition at line 676 of file type_vector.h.

677 {
678  typedef typename CompareTypes<T, T2>::supertype TS;
679 
680 #if LIBMESH_DIM == 1
681  return TypeVector<TS>(_coords[0] - p._coords[0]);
682 #endif
683 
684 #if LIBMESH_DIM == 2
685  return TypeVector<TS>(_coords[0] - p._coords[0],
686  _coords[1] - p._coords[1]);
687 #endif
688 
689 #if LIBMESH_DIM == 3
690  return TypeVector<TS>(_coords[0] - p._coords[0],
691  _coords[1] - p._coords[1],
692  _coords[2] - p._coords[2]);
693 #endif
694 
695 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439

◆ operator-() [2/2]

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

Definition at line 735 of file type_vector.h.

736 {
737 
738 #if LIBMESH_DIM == 1
739  return TypeVector(-_coords[0]);
740 #endif
741 
742 #if LIBMESH_DIM == 2
743  return TypeVector(-_coords[0],
744  -_coords[1]);
745 #endif
746 
747 #if LIBMESH_DIM == 3
748  return TypeVector(-_coords[0],
749  -_coords[1],
750  -_coords[2]);
751 #endif
752 
753 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439
TypeVector()
Empty constructor.
Definition: type_vector.h:451

◆ operator-=()

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

Subtract from this vector.

Returns
A reference to *this.

Definition at line 702 of file type_vector.h.

703 {
704  this->subtract (p);
705 
706  return *this;
707 }
void subtract(const TypeVector< T2 > &)
Subtract from this vector without creating a temporary.
Definition: type_vector.h:714

◆ 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
inline

Divide each entry of this vector by scalar value.

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

Definition at line 828 of file type_vector.h.

829 {
830  libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
831 
832  typedef typename CompareTypes<T, Scalar>::supertype TS;
833 
834 #if LIBMESH_DIM == 1
835  return TypeVector<TS>(_coords[0]/factor);
836 #endif
837 
838 #if LIBMESH_DIM == 2
839  return TypeVector<TS>(_coords[0]/factor,
840  _coords[1]/factor);
841 #endif
842 
843 #if LIBMESH_DIM == 3
844  return TypeVector<TS>(_coords[0]/factor,
845  _coords[1]/factor,
846  _coords[2]/factor);
847 #endif
848 
849 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439

◆ operator/=()

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

Divide each entry of this vector by scalar value.

Returns
A reference to *this.

Definition at line 857 of file type_vector.h.

858 {
859  libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
860 
861  for (unsigned int i=0; i<LIBMESH_DIM; i++)
862  _coords[i] /= factor;
863 
864  return *this;
865 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439

◆ operator<() [1/2]

template<>
bool libMesh::TypeVector< Complex >::operator< ( const TypeVector< Complex > &  rhs) const

Definition at line 148 of file type_vector.C.

149 {
150  for (unsigned int i=0; i<LIBMESH_DIM; i++)
151  {
152  if ((*this)(i).real() < rhs(i).real())
153  return true;
154  if ((*this)(i).real() > rhs(i).real())
155  return false;
156  if ((*this)(i).imag() < rhs(i).imag())
157  return true;
158  if ((*this)(i).imag() > rhs(i).imag())
159  return false;
160  }
161  return false;
162 }
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
boost::multiprecision::float128 imag(const boost::multiprecision::float128)

◆ operator<() [2/2]

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.

Definition at line 90 of file type_vector.C.

91 {
92  for (unsigned int i=0; i<LIBMESH_DIM; i++)
93  {
94  if ((*this)(i) < rhs(i))
95  return true;
96  if ((*this)(i) > rhs(i))
97  return false;
98  }
99  return false;
100 }

◆ operator<=() [1/2]

template<>
bool libMesh::TypeVector< Complex >::operator<= ( const TypeVector< Complex > &  rhs) const

Definition at line 167 of file type_vector.C.

168 {
169  for (unsigned int i=0; i<LIBMESH_DIM; i++)
170  {
171  if ((*this)(i).real() < rhs(i).real())
172  return true;
173  if ((*this)(i).real() > rhs(i).real())
174  return false;
175  if ((*this)(i).imag() < rhs(i).imag())
176  return true;
177  if ((*this)(i).imag() > rhs(i).imag())
178  return false;
179  }
180  return true;
181 }
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
boost::multiprecision::float128 imag(const boost::multiprecision::float128)

◆ operator<=() [2/2]

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.

Definition at line 104 of file type_vector.C.

105 {
106  for (unsigned int i=0; i<LIBMESH_DIM; i++)
107  {
108  if ((*this)(i) < rhs(i))
109  return true;
110  if ((*this)(i) > rhs(i))
111  return false;
112  }
113  return true;
114 }

◆ 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)
inline

Assignment-from-scalar operator.

Used only to zero out vectors.

Definition at line 180 of file type_vector.h.

181  { 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:938

◆ operator==()

template<typename T>
bool libMesh::TypeVector< T >::operator== ( const TypeVector< T > &  rhs) const
inline
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 1029 of file type_vector.h.

1030 {
1031 #if LIBMESH_DIM == 1
1032  return (_coords[0] == rhs._coords[0]);
1033 #endif
1034 
1035 #if LIBMESH_DIM == 2
1036  return (_coords[0] == rhs._coords[0] &&
1037  _coords[1] == rhs._coords[1]);
1038 #endif
1039 
1040 #if LIBMESH_DIM == 3
1041  return (_coords[0] == rhs._coords[0] &&
1042  _coords[1] == rhs._coords[1] &&
1043  _coords[2] == rhs._coords[2]);
1044 #endif
1045 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439

◆ operator>() [1/2]

template<>
bool libMesh::TypeVector< Complex >::operator> ( const TypeVector< Complex > &  rhs) const

Definition at line 186 of file type_vector.C.

187 {
188  for (unsigned int i=0; i<LIBMESH_DIM; i++)
189  {
190  if ((*this)(i).real() > rhs(i).real())
191  return true;
192  if ((*this)(i).real() < rhs(i).real())
193  return false;
194  if ((*this)(i).imag() > rhs(i).imag())
195  return true;
196  if ((*this)(i).imag() < rhs(i).imag())
197  return false;
198  }
199  return false;
200 }
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
boost::multiprecision::float128 imag(const boost::multiprecision::float128)

◆ operator>() [2/2]

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.

Definition at line 119 of file type_vector.C.

120 {
121  for (unsigned int i=0; i<LIBMESH_DIM; i++)
122  {
123  if ((*this)(i) > rhs(i))
124  return true;
125  if ((*this)(i) < rhs(i))
126  return false;
127  }
128  return false;
129 }

◆ operator>=() [1/2]

template<>
bool libMesh::TypeVector< Complex >::operator>= ( const TypeVector< Complex > &  rhs) const

Definition at line 205 of file type_vector.C.

206 {
207  for (unsigned int i=0; i<LIBMESH_DIM; i++)
208  {
209  if ((*this)(i).real() > rhs(i).real())
210  return true;
211  if ((*this)(i).real() < rhs(i).real())
212  return false;
213  if ((*this)(i).imag() > rhs(i).imag())
214  return true;
215  if ((*this)(i).imag() < rhs(i).imag())
216  return false;
217  }
218  return true;
219 }
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
boost::multiprecision::float128 imag(const boost::multiprecision::float128)

◆ operator>=() [2/2]

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.

Definition at line 133 of file type_vector.C.

134 {
135  for (unsigned int i=0; i<LIBMESH_DIM; i++)
136  {
137  if ((*this)(i) > rhs(i))
138  return true;
139  if ((*this)(i) < rhs(i))
140  return false;
141  }
142  return true;
143 }

◆ print()

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

Formatted print, by default to libMesh::out.

Definition at line 47 of file type_vector.C.

48 {
49 #if LIBMESH_DIM == 1
50 
51  os << "x=" << (*this)(0);
52 
53 #endif
54 #if LIBMESH_DIM == 2
55 
56  os << "(x,y)=("
57  << std::setw(8) << (*this)(0) << ", "
58  << std::setw(8) << (*this)(1) << ")";
59 
60 #endif
61 #if LIBMESH_DIM == 3
62 
63  os << "(x,y,z)=("
64  << std::setw(8) << (*this)(0) << ", "
65  << std::setw(8) << (*this)(1) << ", "
66  << std::setw(8) << (*this)(2) << ")";
67 #endif
68 }

◆ relative_fuzzy_equals()

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

Definition at line 1004 of file type_vector.h.

Referenced by libMesh::Edge3::has_affine_map(), libMesh::Quad4::has_affine_map(), libMesh::Edge4::has_affine_map(), libMesh::Quad9::has_affine_map(), libMesh::Quad8::has_affine_map(), libMesh::Prism6::has_affine_map(), libMesh::Hex8::has_affine_map(), libMesh::Tri6::has_affine_map(), libMesh::Tri7::has_affine_map(), libMesh::Hex27::has_affine_map(), libMesh::Hex20::has_affine_map(), libMesh::Tet10::has_affine_map(), libMesh::Prism15::has_affine_map(), libMesh::Prism18::has_affine_map(), libMesh::Tet14::has_affine_map(), libMesh::Prism20::has_affine_map(), libMesh::Prism21::has_affine_map(), libMesh::Quad4::volume(), and libMesh::Tri6::volume().

1005 {
1006 #if LIBMESH_DIM == 1
1007  return this->absolute_fuzzy_equals(rhs, tol *
1008  (std::abs(_coords[0]) + std::abs(rhs._coords[0])));
1009 #endif
1010 
1011 #if LIBMESH_DIM == 2
1012  return this->absolute_fuzzy_equals(rhs, tol *
1013  (std::abs(_coords[0]) + std::abs(rhs._coords[0]) +
1014  std::abs(_coords[1]) + std::abs(rhs._coords[1])));
1015 #endif
1016 
1017 #if LIBMESH_DIM == 3
1018  return this->absolute_fuzzy_equals(rhs, tol *
1019  (std::abs(_coords[0]) + std::abs(rhs._coords[0]) +
1020  std::abs(_coords[1]) + std::abs(rhs._coords[1]) +
1021  std::abs(_coords[2]) + std::abs(rhs._coords[2])));
1022 #endif
1023 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:57
bool absolute_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const
Definition: type_vector.h:979

◆ slice() [1/2]

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

Definition at line 187 of file type_vector.h.

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

◆ slice() [2/2]

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

Definition at line 193 of file type_vector.h.

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

◆ subtract()

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

Subtract from this vector without creating a temporary.

Definition at line 714 of file type_vector.h.

715 {
716  for (unsigned int i=0; i<LIBMESH_DIM; i++)
717  _coords[i] -= p._coords[i];
718 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439

◆ subtract_scaled()

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

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

Definition at line 725 of file type_vector.h.

Referenced by libMesh::HPCoarsenTest::select_refinement().

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

◆ unit()

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

Definition at line 1120 of file type_vector.h.

Referenced by libMesh::InfFE< Dim, T_radial, T_map >::compute_face_functions(), libMesh::FEMap::compute_face_map(), ContainsPointTest::containsPointTri3Helper(), libMesh::Plane::create_from_point_normal(), libMesh::Plane::create_from_three_points(), libMesh::MeshTools::Modification::distort(), AzimuthalPeriodicBoundary::set_up_rotation_matrix(), and libMesh::Sphere::unit_normal().

1121 {
1122 
1123  auto && length = norm();
1124 
1125  libmesh_assert_not_equal_to (length, static_cast<Real>(0.));
1126 
1127 #if LIBMESH_DIM == 1
1128  return TypeVector<T>(_coords[0]/length);
1129 #endif
1130 
1131 #if LIBMESH_DIM == 2
1132  return TypeVector<T>(_coords[0]/length,
1133  _coords[1]/length);
1134 #endif
1135 
1136 #if LIBMESH_DIM == 3
1137  return TypeVector<T>(_coords[0]/length,
1138  _coords[1]/length,
1139  _coords[2]/length);
1140 #endif
1141 
1142 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439
auto norm() const -> decltype(std::norm(T()))
Definition: type_vector.h:929

◆ write_unformatted()

template<typename T >
void libMesh::TypeVector< T >::write_unformatted ( std::ostream &  out_stream,
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.

Definition at line 75 of file type_vector.C.

Referenced by libMesh::InfElemBuilder::build_inf_elem(), and libMesh::TecplotIO::write_ascii().

77 {
78  os << std::setiosflags(std::ios::showpoint)
79  << (*this)(0) << " "
80  << (*this)(1) << " "
81  << (*this)(2) << " ";
82 
83  if (newline)
84  os << '\n';
85 }

◆ zero()

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

Set all entries of the vector to 0.

Definition at line 938 of file type_vector.h.

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

939 {
940  for (unsigned int i=0; i<LIBMESH_DIM; i++)
941  _coords[i] = 0.;
942 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:439

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

420  {
421  t.print(os);
422  return os;
423  }

◆ TypeTensor< T >

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

Definition at line 94 of file type_vector.h.

◆ TypeVector

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

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

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


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