PSCF v1.3
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>

Public Member Functions

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

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

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);
Vec()
Default constructor.
Definition Vec.h:317
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.

Referenced by add(), multiply(), negate(), negate(), operator+=(), operator-=(), operator=(), operator=(), setToZero(), subtract(), and Vec().

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

References Vec().

◆ 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 ( T 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.

References Vec().

◆ operator=() [2/2]

template<int D, typename T>
Vec< D, T > & Pscf::Vec< D, T >::operator= ( T 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.

References Vec().

◆ 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(), and Vec().

Referenced by Pscf::Prdc::FilmFieldGenMaskBase< D >::needsUpdate().

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

References Vec().

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

References Vec().

◆ operator+=() [2/2]

template<int D, typename T>
void Pscf::Vec< D, T >::operator+= ( T 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-= ( T 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*= ( T 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.

References Vec().

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.

References Vec().

◆ multiply()

template<int D, typename T>
Vec< D, T > & Pscf::Vec< D, T >::multiply ( const Vec< D, T > & v,
T 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.

References Vec().

Referenced by Pscf::Prdc::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.

References Vec().

Referenced by Pscf::Rpc::FourthOrderParameter< D >::computePrefactor(), Pscf::Rpg::FourthOrderParameter< D >::computePrefactor(), Pscf::Prdc::Basis< D >::isValid(), and Pscf::Prdc::readBasisData().

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

References Vec().

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