SCOREC core
Parallel unstructured mesh tools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
apf::Vector< N > Class Template Reference

template-generic vector of N doubles More...

Inherits Array< double, N >.

Public Member Functions

 Vector ()
 mandatory
 
 Vector (double const *v)
 construct from array
 
Vector< N > operator+ (Vector< N > const &b) const
 add two vectors
 
Vector< N > & operator+= (Vector< N > const &b)
 add a vector to this vector
 
Vector< N > operator- (Vector< N > const &b) const
 subtract two vectors
 
Vector< N > operator* (double s) const
 multiply a vector times a scalar More...
 
Vector< N > operator/ (double s) const
 divide a vector by a scalar More...
 
double operator* (Vector< N > const &b) const
 vector dot product More...
 
double getLength () const
 get the vector magnitude
 
Vector< N > normalize () const
 divide the vector by its magnitude
 
void zero ()
 zero the vector
 

Detailed Description

template<std::size_t N>
class apf::Vector< N >

template-generic vector of N doubles

this class implements a linear algebra vector whose size is known at compile time. It is intended to be used for small, dense vectors whose operations benefit from the optimization offered by templates and inline methods because they are so small that the overhead of function calls and conditionals is high.

For vectors sized at runtime, see apf::DynamicVector. For sparse structures or parallel vectors, look outside of APF.

apf::Vector objects should be used in a functional programming style, i.e. treated as immutable values for the most part, then we expect the compiler to optimize the assignments into faster code.

Definition at line 26 of file apfVector.h.

Member Function Documentation

template<std::size_t N>
Vector<N> apf::Vector< N >::operator* ( double  s) const
inline

multiply a vector times a scalar

currently there is no scalar-times-vector operator, so do be sure to put scalar on the right hand side.

Definition at line 83 of file apfVector.h.

84  {
85  Vector<N> c;
86  for (std::size_t i=0; i < N; ++i)
87  c[i] = (*this)[i] * s;
88  return c;
89  }
template<std::size_t N>
double apf::Vector< N >::operator* ( Vector< N > const &  b) const
inline

vector dot product

We chose the default vector-vector multiplication operator to be the dot product. So far this seems to have been a good choice

Definition at line 103 of file apfVector.h.

104  {
105  double r=0;
106  for (std::size_t i=0; i < N; ++i)
107  r += (*this)[i] * b[i];
108  return r;
109  }
template<std::size_t N>
Vector<N> apf::Vector< N >::operator/ ( double  s) const
inline

divide a vector by a scalar

equivalent to scaling by 1/s

Definition at line 92 of file apfVector.h.

93  {
94  Vector<N> c;
95  for (std::size_t i=0; i < N; ++i)
96  c[i] = (*this)[i] / s;
97  return c;
98  }

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