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()))
 
auto l1_norm () const
 
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<>
auto l1_norm () 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
 
template<>
bool operator>= (const TypeVector< Complex > &rhs) const
 
template<>
auto l1_norm () 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 122 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 117 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 429 of file type_vector.h.

430 {
431  _coords[0] = {};
432 
433 #if LIBMESH_DIM > 1
434  _coords[1] = {};
435 #endif
436 
437 #if LIBMESH_DIM > 2
438  _coords[2] = {};
439 #endif
440 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:417

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

449 {
450  _coords[0] = x;
451 
452 #if LIBMESH_DIM > 1
453  _coords[1] = y;
454 #else
455  libmesh_ignore(y);
456  libmesh_assert_equal_to (y, 0);
457 #endif
458 
459 #if LIBMESH_DIM > 2
460  _coords[2] = z;
461 #else
462  libmesh_ignore(z);
463  libmesh_assert_equal_to (z, 0);
464 #endif
465 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:417
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 471 of file type_vector.h.

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

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

505 {
506  _coords[0] = x;
507 
508 #if LIBMESH_DIM > 1
509  _coords[1] = 0;
510 #endif
511 
512 #if LIBMESH_DIM > 2
513  _coords[2] = 0;
514 #endif
515 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:417

◆ TypeVector() [5/6]

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

Copy-constructor.

Definition at line 522 of file type_vector.h.

523 {
524  // copy the nodes from vector p to me
525  for (unsigned int i=0; i<LIBMESH_DIM; i++)
526  _coords[i] = p._coords[i];
527 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:417

◆ 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 972 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().

973 {
974  return libMesh::absolute_fuzzy_equals(*this, rhs, tol);
975 }
bool absolute_fuzzy_equals(const T &var1, const T2 &var2, const Real tol=TOLERANCE *TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
Definition: fuzzy_equals.h:64

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

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

606 {
607 #if LIBMESH_DIM == 1
608  _coords[0] += p._coords[0];
609 #endif
610 
611 #if LIBMESH_DIM == 2
612  _coords[0] += p._coords[0];
613  _coords[1] += p._coords[1];
614 #endif
615 
616 #if LIBMESH_DIM == 3
617  _coords[0] += p._coords[0];
618  _coords[1] += p._coords[1];
619  _coords[2] += p._coords[2];
620 #endif
621 
622 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:417

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

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

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

875 {
876  return (*this)*(p);
877 }

◆ 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 884 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(), libMesh::C0Polygon::retriangulate(), and libMesh::Quad4::volume().

885 {
886  typedef typename CompareTypes<T, T2>::supertype TS;
887  libmesh_assert_equal_to (LIBMESH_DIM, 3);
888 
889  // | i j k |
890  // |(*this)(0) (*this)(1) (*this)(2)|
891  // | p(0) p(1) p(2) |
892 
893 #if LIBMESH_DIM == 3
894  return TypeVector<TS>( _coords[1]*p._coords[2] - _coords[2]*p._coords[1],
895  -_coords[0]*p._coords[2] + _coords[2]*p._coords[0],
896  _coords[0]*p._coords[1] - _coords[1]*p._coords[0]);
897 #else
898  libmesh_ignore(p);
899  return TypeVector<TS>(0);
900 #endif
901 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:417
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 947 of file type_vector.h.

948 {
949  for (const auto & val : _coords)
950  if (val != T(0))
951  return false;
952  return true;
953 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:417

◆ l1_norm() [1/3]

template<>
auto libMesh::TypeVector< bool >::l1_norm ( ) const

Definition at line 203 of file type_vector.C.

204 {
205  bool ret{};
206  for (const auto i : make_range(libmesh_dim))
207  ret += _coords[i];
208 
209  return ret;
210 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:417
static constexpr std::size_t libmesh_dim
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140

◆ l1_norm() [2/3]

template<typename T >
auto libMesh::TypeVector< T >::l1_norm ( ) const
Returns
The L1 norm of the vector

Definition at line 961 of file type_vector.h.

962 {
963  decltype(std::abs(T())) ret{};
964  for (const auto i : make_range(libmesh_dim))
965  ret += std::abs(_coords[i]);
966 
967  return ret;
968 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:417
static constexpr std::size_t libmesh_dim
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140

◆ l1_norm() [3/3]

template<>
auto libMesh::TypeVector< bool >::l1_norm ( ) const

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

1013 {
1014  return (!(*this == rhs));
1015 }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

◆ operator<() [1/2]

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

Definition at line 124 of file type_vector.C.

125 {
126  for (unsigned int i=0; i<LIBMESH_DIM; i++)
127  {
128  if ((*this)(i).real() < rhs(i).real())
129  return true;
130  if ((*this)(i).real() > rhs(i).real())
131  return false;
132  if ((*this)(i).imag() < rhs(i).imag())
133  return true;
134  if ((*this)(i).imag() > rhs(i).imag())
135  return false;
136  }
137  return false;
138 }
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 66 of file type_vector.C.

67 {
68  for (unsigned int i=0; i<LIBMESH_DIM; i++)
69  {
70  if ((*this)(i) < rhs(i))
71  return true;
72  if ((*this)(i) > rhs(i))
73  return false;
74  }
75  return false;
76 }

◆ operator<=() [1/2]

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

Definition at line 143 of file type_vector.C.

144 {
145  for (unsigned int i=0; i<LIBMESH_DIM; i++)
146  {
147  if ((*this)(i).real() < rhs(i).real())
148  return true;
149  if ((*this)(i).real() > rhs(i).real())
150  return false;
151  if ((*this)(i).imag() < rhs(i).imag())
152  return true;
153  if ((*this)(i).imag() > rhs(i).imag())
154  return false;
155  }
156  return true;
157 }
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 80 of file type_vector.C.

81 {
82  for (unsigned int i=0; i<LIBMESH_DIM; i++)
83  {
84  if ((*this)(i) < rhs(i))
85  return true;
86  if ((*this)(i) > rhs(i))
87  return false;
88  }
89  return true;
90 }

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

154  { 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:916

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

991 {
992 #if LIBMESH_DIM == 1
993  return (_coords[0] == rhs._coords[0]);
994 #endif
995 
996 #if LIBMESH_DIM == 2
997  return (_coords[0] == rhs._coords[0] &&
998  _coords[1] == rhs._coords[1]);
999 #endif
1000 
1001 #if LIBMESH_DIM == 3
1002  return (_coords[0] == rhs._coords[0] &&
1003  _coords[1] == rhs._coords[1] &&
1004  _coords[2] == rhs._coords[2]);
1005 #endif
1006 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:417

◆ operator>() [1/2]

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

Definition at line 162 of file type_vector.C.

163 {
164  for (unsigned int i=0; i<LIBMESH_DIM; i++)
165  {
166  if ((*this)(i).real() > rhs(i).real())
167  return true;
168  if ((*this)(i).real() < rhs(i).real())
169  return false;
170  if ((*this)(i).imag() > rhs(i).imag())
171  return true;
172  if ((*this)(i).imag() < rhs(i).imag())
173  return false;
174  }
175  return false;
176 }
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 95 of file type_vector.C.

96 {
97  for (unsigned int i=0; i<LIBMESH_DIM; i++)
98  {
99  if ((*this)(i) > rhs(i))
100  return true;
101  if ((*this)(i) < rhs(i))
102  return false;
103  }
104  return false;
105 }

◆ operator>=() [1/2]

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

Definition at line 181 of file type_vector.C.

182 {
183  for (unsigned int i=0; i<LIBMESH_DIM; i++)
184  {
185  if ((*this)(i).real() > rhs(i).real())
186  return true;
187  if ((*this)(i).real() < rhs(i).real())
188  return false;
189  if ((*this)(i).imag() > rhs(i).imag())
190  return true;
191  if ((*this)(i).imag() < rhs(i).imag())
192  return false;
193  }
194  return true;
195 }
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 109 of file type_vector.C.

110 {
111  for (unsigned int i=0; i<LIBMESH_DIM; i++)
112  {
113  if ((*this)(i) > rhs(i))
114  return true;
115  if ((*this)(i) < rhs(i))
116  return false;
117  }
118  return true;
119 }

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

1130 {
1131 #if LIBMESH_DIM == 1
1132 
1133  os << "x=" << (*this)(0);
1134 
1135 #endif
1136 #if LIBMESH_DIM == 2
1137 
1138  os << "(x,y)=("
1139  << std::setw(8) << (*this)(0) << ", "
1140  << std::setw(8) << (*this)(1) << ")";
1141 
1142 #endif
1143 #if LIBMESH_DIM == 3
1144 
1145  os << "(x,y,z)=("
1146  << std::setw(8) << (*this)(0) << ", "
1147  << std::setw(8) << (*this)(1) << ", "
1148  << std::setw(8) << (*this)(2) << ")";
1149 #endif
1150 }

◆ relative_fuzzy_equals()

template<typename T>
bool libMesh::TypeVector< T >::relative_fuzzy_equals ( const TypeVector< T > &  rhs,
Real  tol = TOLERANCE 
) const
inline

◆ slice() [1/2]

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

Definition at line 160 of file type_vector.h.

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

◆ slice() [2/2]

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

Definition at line 166 of file type_vector.h.

166 { 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 692 of file type_vector.h.

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

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

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

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

◆ unit()

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

Definition at line 1104 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::Polyhedron::convex(), libMesh::Plane::create_from_point_normal(), libMesh::Plane::create_from_three_points(), libMesh::MeshTools::Modification::distort(), libMesh::Polyhedron::on_reference_element(), libMesh::Polyhedron::Polyhedron(), libMesh::Elem::quality(), libMesh::C0Polygon::retriangulate(), AzimuthalPeriodicBoundary::set_up_rotation_matrix(), and libMesh::Sphere::unit_normal().

1105 {
1106 
1107  auto && length = norm();
1108 
1109  libmesh_assert_not_equal_to (length, static_cast<Real>(0.));
1110 
1111 #if LIBMESH_DIM == 1
1112  return TypeVector<T>(_coords[0]/length);
1113 #endif
1114 
1115 #if LIBMESH_DIM == 2
1116  return TypeVector<T>(_coords[0]/length,
1117  _coords[1]/length);
1118 #endif
1119 
1120 #if LIBMESH_DIM == 3
1121  return TypeVector<T>(_coords[0]/length,
1122  _coords[1]/length,
1123  _coords[2]/length);
1124 #endif
1125 
1126 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:417
auto norm() const -> decltype(std::norm(T()))
Definition: type_vector.h:907

◆ 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 51 of file type_vector.C.

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

53 {
54  os << std::setiosflags(std::ios::showpoint)
55  << (*this)(0) << " "
56  << (*this)(1) << " "
57  << (*this)(2) << " ";
58 
59  if (newline)
60  os << '\n';
61 }

◆ zero()

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

Set all entries of the vector to 0.

Definition at line 916 of file type_vector.h.

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

917 {
918  for (unsigned int i=0; i<LIBMESH_DIM; i++)
919  _coords[i] = 0.;
920 }
T _coords[LIBMESH_DIM]
The coordinates of the TypeVector.
Definition: type_vector.h:417

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

398  {
399  t.print(os);
400  return os;
401  }

◆ TypeTensor< T >

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

Definition at line 67 of file type_vector.h.

◆ TypeVector

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

Definition at line 65 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 417 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: