PSCF v1.1
List of all members
Pscf::Vec< D, T > Class Template Reference

A Vec<D, T><D,T> is a D-component vector with elements of type T. More...

#include <Vec.h>

Inheritance diagram for Pscf::Vec< D, T >:
Pscf::IntVec< D, T > Pscf::RealVec< D, T >

Public Member Functions

Constructors
 Vec ()
 Default constructor. More...
 
 Vec (const Vec< D, T > &v)
 Copy constructor. More...
 
 Vec (T const *v)
 Constructor from a C-array. More...
 
 Vec (T s)
 Constructor, initialize all elements to a common scalar value. More...
 
Assignment and Initialization
Vec< D, T > & operator= (const Vec< D, T > &v)
 Copy assignment. More...
 
Vec< D, T > & operator= (T s)
 Assignment all elements to the same scalar T value. More...
 
Vec< D, T > & setToZero ()
 Set all elements to zero. More...
 
Arithmetic Assignment
void operator+= (const Vec< D, T > &dv)
 Add vector dv to this vector. More...
 
void operator-= (const Vec< D, T > &dv)
 Subtract vector dv from this vector. More...
 
void operator+= (T s)
 Add a common scalar to all components. More...
 
void operator-= (T s)
 Subtract a common scalar from all components. More...
 
void operator*= (T s)
 Multiply this vector by scalar s. More...
 
Array Subscript
const T & operator[] (int i) const
 Return one Cartesian element by value. More...
 
T & operator[] (int i)
 Return one element of the vector by references. More...
 

Vec<D, T> valued functions (assigned to invoking object)

Vec< D, T > & add (const Vec< D, T > &v1, const Vec< D, T > &v2)
 Add vectors v1 and v2. More...
 
Vec< D, T > & subtract (const Vec< D, T > &v1, const Vec< D, T > &v2)
 Subtract vector v2 from v1. More...
 
Vec< D, T > & multiply (const Vec< D, T > &v, T s)
 Multiply a vector v by a scalar s. More...
 
Vec< D, T > & negate (const Vec< D, T > &v)
 Return negative of vector v. More...
 
Vec< D, T > & negate ()
 Negate all elements of this vector. More...
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 Serialize to/from an archive. More...
 

Detailed Description

template<int D, typename T>
class Pscf::Vec< D, T >

A Vec<D, T><D,T> is a D-component vector with elements of type T.

The elements of a Vec<D, T> can be accessed using subscript operator, as for a built in array.

The arithmetic assignment operators +=, -=, and *= are overloaded to allow vector-vector addition and subtraction and vector-scalar multiplication.

All other unary and binary mathematical operations are implemented as methods or free functions. Operations that yield a Vec<D, T>, such as addition, are implemented by methods that assign the result to the invoking Vec object, and return this object by reference. For example,

a[0] = 0.0
a[1] = 1.0
a[2] = 2.0
b[0] = 0.5
b[1] = -0.5
b[2] = -1.5
// Set a = a + b
a += b
// Set b = b*2
b *= 2.0;
// Set c = a + b
c.add(a, b);
A Vec<D, T><D,T> is a D-component vector with elements of type T.
Definition: Vec.h:66
Vec< D, T > & add(const Vec< D, T > &v1, const Vec< D, T > &v2)
Add vectors v1 and v2.
Definition: Vec.h:473

This syntax for functions that yield a vector makes the allocation of a temporary Vec<D, T> object explicit, by requiring that the invoking function be a member of an object that will hold the result.

For efficiency, all member functions are declared inline.

Definition at line 65 of file Vec.h.

Constructor & Destructor Documentation

◆ Vec() [1/4]

template<int D, typename T >
Pscf::Vec< D, T >::Vec
inline

Default constructor.

Definition at line 317 of file Vec.h.

◆ Vec() [2/4]

template<int D, typename T >
Pscf::Vec< D, T >::Vec ( const Vec< D, T > &  v)
inline

Copy constructor.

Parameters
vVec<D, T> to be copied

Definition at line 324 of file Vec.h.

◆ Vec() [3/4]

template<int D, typename T >
Pscf::Vec< D, T >::Vec ( T const *  v)
inlineexplicit

Constructor from a C-array.

Parameters
varray to be copied

Definition at line 335 of file Vec.h.

◆ Vec() [4/4]

template<int D, typename T >
Pscf::Vec< D, T >::Vec ( s)
inlineexplicit

Constructor, initialize all elements to a common scalar value.

Parameters
sinitial value for all elements.

Definition at line 346 of file Vec.h.

Member Function Documentation

◆ operator=() [1/2]

template<int D, typename T >
Vec< D, T > & Pscf::Vec< D, T >::operator= ( const Vec< D, T > &  v)
inline

Copy assignment.

Parameters
vVec<D, T> to assign.
Returns
this object, after modification

Definition at line 357 of file Vec.h.

◆ operator=() [2/2]

template<int D, typename T >
Vec< D, T > & Pscf::Vec< D, T >::operator= ( s)
inline

Assignment all elements to the same scalar T value.

Parameters
sscalar value
Returns
this object, after modification

Definition at line 369 of file Vec.h.

◆ setToZero()

template<int D, typename T >
Vec< D, T > & Pscf::Vec< D, T >::setToZero
inline

Set all elements to zero.

Returns
this object, after modification

Definition at line 381 of file Vec.h.

References Util::setToZero().

◆ operator+=() [1/2]

template<int D, typename T >
void Pscf::Vec< D, T >::operator+= ( const Vec< D, T > &  dv)
inline

Add vector dv to this vector.

Upon return, *this = this + dv.

Parameters
dvvector increment (input)

Definition at line 393 of file Vec.h.

◆ operator-=() [1/2]

template<int D, typename T >
void Pscf::Vec< D, T >::operator-= ( const Vec< D, T > &  dv)
inline

Subtract vector dv from this vector.

Upon return, *this = this + dv.

Parameters
dvvector increment (input)

Definition at line 404 of file Vec.h.

◆ operator+=() [2/2]

template<int D, typename T >
void Pscf::Vec< D, T >::operator+= ( s)
inline

Add a common scalar to all components.

Parameters
sscalar additive constant (input)

Definition at line 415 of file Vec.h.

◆ operator-=() [2/2]

template<int D, typename T >
void Pscf::Vec< D, T >::operator-= ( s)
inline

Subtract a common scalar from all components.

Parameters
sscalar subtractive constant (input)

Definition at line 426 of file Vec.h.

◆ operator*=()

template<int D, typename T >
void Pscf::Vec< D, T >::operator*= ( s)
inline

Multiply this vector by scalar s.

Upon return, *this = (*this)*s.

Parameters
sscalar multiplier

Definition at line 437 of file Vec.h.

◆ operator[]() [1/2]

template<int D, typename T >
const T & Pscf::Vec< D, T >::operator[] ( int  i) const
inline

Return one Cartesian element by value.

Parameters
ielement index
Returns
element i of the vector

Definition at line 448 of file Vec.h.

◆ operator[]() [2/2]

template<int D, typename T >
T & Pscf::Vec< D, T >::operator[] ( int  i)
inline

Return one element of the vector by references.

Parameters
ielement index
Returns
element i of this vector

Definition at line 459 of file Vec.h.

◆ add()

template<int D, typename T >
Vec< D, T > & Pscf::Vec< D, T >::add ( const Vec< D, T > &  v1,
const Vec< D, T > &  v2 
)
inline

Add vectors v1 and v2.

Upon return, *this = v1 + v2.

Parameters
v1vector (input)
v2vector (input)
Returns
modified invoking vector

Definition at line 473 of file Vec.h.

Referenced by Pscf::operator+().

◆ subtract()

template<int D, typename T >
Vec< D, T > & Pscf::Vec< D, T >::subtract ( const Vec< D, T > &  v1,
const Vec< D, T > &  v2 
)
inline

Subtract vector v2 from v1.

Upon return, *this = v1 - v2.

Parameters
v1vector (input)
v2vector (input)
Returns
modified invoking vector

Definition at line 490 of file Vec.h.

◆ multiply()

template<int D, typename T >
Vec< D, T > & Pscf::Vec< D, T >::multiply ( const Vec< D, T > &  v,
s 
)
inline

Multiply a vector v by a scalar s.

Upon return, *this = v*s.

Parameters
vvector input
sscalar input
Returns
modified invoking vector

Definition at line 505 of file Vec.h.

Referenced by Pscf::UnitCellBase< D >::ksq().

◆ negate() [1/2]

template<int D, typename T >
Vec< D, T > & Pscf::Vec< D, T >::negate ( const Vec< D, T > &  v)
inline

Return negative of vector v.

Upon return, *this = -v;

Parameters
vvector input
Returns
modified invoking vector

Definition at line 520 of file Vec.h.

Referenced by Pscf::Basis< D >::isValid(), Pscf::Pspc::FieldIo< D >::readFieldsBasis(), and Pscf::Pspg::FieldIo< D >::readFieldsBasis().

◆ negate() [2/2]

template<int D, typename T >
Vec< D, T > & Pscf::Vec< D, T >::negate
inline

Negate all elements of this vector.

Upon return, all elements of this have been negated (reversed)

Returns
this object, after modification

Definition at line 535 of file Vec.h.

◆ serialize()

template<int D, typename T >
template<class Archive >
void Pscf::Vec< D, T >::serialize ( Archive &  ar,
const unsigned int  version 
)
inline

Serialize to/from an archive.

Implementation uses syntax of Boost::serialize.

Parameters
ararchive
versionarchive version id

Definition at line 549 of file Vec.h.


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