PSCF v1.1
List of all members
Util::IntVector Class Reference

An IntVector is an integer Cartesian vector. More...

#include <IntVector.h>

Public Member Functions

Constructors
 IntVector ()
 Default constructor. More...
 
 IntVector (const IntVector &v)
 Copy constructor. More...
 
 IntVector (int scalar)
 Constructor, initialize all elements to the same scalar. More...
 
 IntVector (const int *v)
 Construct IntVector from C int[3] array. More...
 
 IntVector (int x, int y, int z=0)
 Construct IntVector from its coordinates. More...
 
IntVectorzero ()
 Set all elements of a 3D vector to zero. More...
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 Serialize to/from an archive. More...
 
Assignment
IntVectoroperator= (const IntVector &v)
 Copy assignment. More...
 
IntVectoroperator= (const int *v)
 Assignment from C int[] array. More...
 
Arithmetic Assignment
void operator+= (const IntVector &dv)
 Add vector dv to this vector. More...
 
void operator-= (const IntVector &dv)
 Subtract vector dv from this vector. More...
 
void operator*= (int s)
 Multiply this vector by scalar s. More...
 
Array Subscript
const int & operator[] (int i) const
 Return one Cartesian element by value. More...
 
int & operator[] (int i)
 Return a reference to one element of the vector. More...
 
Scalar valued functions
int square () const
 Return square magnitude of this vector. More...
 
int dot (const IntVector &v) const
 Return dot product of this vector and vector v. More...
 
IntVector valued functions (result assigned to invoking object)
IntVectoradd (const IntVector &v1, const IntVector &v2)
 Add vectors v1 and v2. More...
 
IntVectorsubtract (const IntVector &v1, const IntVector &v2)
 Subtract vector v2 from v1. More...
 
IntVectormultiply (const IntVector &v, int s)
 Multiply a vector v by a scalar s. More...
 
IntVectorcross (const IntVector &v1, const IntVector &v2)
 Calculate cross product of vectors v1 and v2. More...
 

Static Members

static const IntVector Zero = IntVector(0)
 Zero IntVector. More...
 
static void initStatic ()
 Initialize static IntVector::Zero. More...
 
static void commitMpiType ()
 Commit MPI datatype MpiTraits<IntVector>::type. More...
 
bool operator== (const IntVector &v1, const IntVector &v2)
 Equality for IntVectors. More...
 
bool operator== (const IntVector &v1, const int *v2)
 Equality of IntVector and C array. More...
 
std::istream & operator>> (std::istream &in, IntVector &vector)
 istream extractor for a IntVector. More...
 
std::ostream & operator<< (std::ostream &out, const IntVector &vector)
 ostream inserter for a IntVector. More...
 

Detailed Description

An IntVector is an integer Cartesian vector.

The Cartesian elements of a IntVector can be accessed using array notation: The elements of a three dimensional IntVector v are v[0], v[1], and v[2]. The subscript operator [] returns elements as references, which can be used on either the left or right side of an assignment operator.

The arithmetic assignment operators +=, -=, *=, and /= are overloaded. The operators += and -= represent increment or decrement by a vector, while *= and /= represent multiplication or division by an integer.

All other unary and binary mathematical operations are implemented as methods. Operations that yield a scalar result, such as a dot product, are implemented as methods that return the resulting value. Operations that yield a IntVector, such as vector addition, are implemented by methods that assign the result to the invoking vector, and return a reference to the invoking vector. For example,

IntVector a, b, c;
int s;
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 s = a.b
s = dot(a, b)
// Set c = a + b
c.add(a, b)
// Set a = a + b
a += b
// Set b = b*2
b *= 2
An IntVector is an integer Cartesian vector.
Definition: IntVector.h:74
int dot(const IntVector &v) const
Return dot product of this vector and vector v.
Definition: IntVector.h:282
IntVector & add(const IntVector &v1, const IntVector &v2)
Add vectors v1 and v2.
Definition: IntVector.h:299

This syntax for IntVector valued operations avoids dynamic allocation of temporary IntVector objects, by requiring that the invoking function provide an object to hold the result.

For efficiency, all methods in this class are inlined.

Definition at line 73 of file IntVector.h.

Constructor & Destructor Documentation

◆ IntVector() [1/5]

Util::IntVector::IntVector ( )
inline

Default constructor.

Definition at line 84 of file IntVector.h.

◆ IntVector() [2/5]

Util::IntVector::IntVector ( const IntVector v)
inline

Copy constructor.

Definition at line 90 of file IntVector.h.

◆ IntVector() [3/5]

Util::IntVector::IntVector ( int  scalar)
inlineexplicit

Constructor, initialize all elements to the same scalar.

Parameters
scalarinitial value for all elements.

Definition at line 102 of file IntVector.h.

◆ IntVector() [4/5]

Util::IntVector::IntVector ( const int *  v)
inlineexplicit

Construct IntVector from C int[3] array.

Parameters
varray of 3 coordinates

Definition at line 114 of file IntVector.h.

◆ IntVector() [5/5]

Util::IntVector::IntVector ( int  x,
int  y,
int  z = 0 
)
inline

Construct IntVector from its coordinates.

Parameters
xx-axis coordinate
yy-axis coordinate
zz-axis coordinate

Definition at line 128 of file IntVector.h.

Member Function Documentation

◆ zero()

IntVector & Util::IntVector::zero ( )
inline

Set all elements of a 3D vector to zero.

Definition at line 140 of file IntVector.h.

◆ serialize()

template<class Archive >
void Util::IntVector::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 456 of file IntVector.h.

◆ operator=() [1/2]

IntVector & Util::IntVector::operator= ( const IntVector v)
inline

Copy assignment.

Parameters
vIntVector to assign.

Definition at line 167 of file IntVector.h.

◆ operator=() [2/2]

IntVector & Util::IntVector::operator= ( const int *  v)
inline

Assignment from C int[] array.

Parameters
varray of coordinates

Definition at line 180 of file IntVector.h.

◆ operator+=()

void Util::IntVector::operator+= ( const IntVector dv)
inline

Add vector dv to this vector.

Upon return, *this = this + dv.

Parameters
dvvector increment (input)

Definition at line 199 of file IntVector.h.

◆ operator-=()

void Util::IntVector::operator-= ( const IntVector dv)
inline

Subtract vector dv from this vector.

Upon return, *this = this + dv.

Parameters
dvvector increment (input)

Definition at line 213 of file IntVector.h.

◆ operator*=()

void Util::IntVector::operator*= ( int  s)
inline

Multiply this vector by scalar s.

Upon return, *this = this*s.

Parameters
sscalar multiplier

Definition at line 227 of file IntVector.h.

◆ operator[]() [1/2]

const int & Util::IntVector::operator[] ( int  i) const
inline

Return one Cartesian element by value.

Parameters
ielement index
Returns
element i of the vector

Definition at line 244 of file IntVector.h.

References Util::Dimension.

◆ operator[]() [2/2]

int & Util::IntVector::operator[] ( int  i)
inline

Return a reference to one element of the vector.

Parameters
ielement index
Returns
element i of the vector

Definition at line 257 of file IntVector.h.

References Util::Dimension.

◆ square()

int Util::IntVector::square ( ) const
inline

Return square magnitude of this vector.

Returns
square magnitude of this vector

Definition at line 273 of file IntVector.h.

◆ dot()

int Util::IntVector::dot ( const IntVector v) const
inline

Return dot product of this vector and vector v.

Parameters
vinput vector
Returns
dot product of this vector and vector v

Definition at line 282 of file IntVector.h.

◆ add()

IntVector & Util::IntVector::add ( const IntVector v1,
const IntVector v2 
)
inline

Add vectors v1 and v2.

Upon return, *this = v1 + v2.

Parameters
v1vector (input)
v2vector (input)

Definition at line 299 of file IntVector.h.

◆ subtract()

IntVector & Util::IntVector::subtract ( const IntVector v1,
const IntVector v2 
)
inline

Subtract vector v2 from v1.

Upon return, *this = v1 - v2.

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

Definition at line 316 of file IntVector.h.

◆ multiply()

IntVector & Util::IntVector::multiply ( const IntVector v,
int  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 333 of file IntVector.h.

◆ cross()

IntVector & Util::IntVector::cross ( const IntVector v1,
const IntVector v2 
)
inline

Calculate cross product of vectors v1 and v2.

Upon return, *this = v1 x v2.

Parameters
v1input vector
v2input vector
Returns
modified invoking vector

Definition at line 350 of file IntVector.h.

◆ initStatic()

void Util::IntVector::initStatic ( )
static

Initialize static IntVector::Zero.

Definition at line 113 of file IntVector.cpp.

Referenced by Util::initStatic().

◆ commitMpiType()

void Util::IntVector::commitMpiType ( )
static

Friends And Related Function Documentation

◆ operator== [1/2]

bool operator== ( const IntVector v1,
const IntVector v2 
)
friend

Equality for IntVectors.

Definition at line 24 of file IntVector.cpp.

◆ operator== [2/2]

bool operator== ( const IntVector v1,
const int *  v2 
)
friend

Equality of IntVector and C array.

Definition at line 35 of file IntVector.cpp.

◆ operator>>

std::istream & operator>> ( std::istream &  in,
IntVector vector 
)
friend

istream extractor for a IntVector.

Input elements of a vector from stream, without line breaks.

Parameters
ininput stream
vectorIntVector to be read from stream
Returns
modified input stream

Definition at line 64 of file IntVector.cpp.

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
const IntVector vector 
)
friend

ostream inserter for a IntVector.

Output elements of a vector to stream, without line breaks.

Parameters
outoutput stream
vectorIntVector to be written to stream
Returns
modified output stream

Definition at line 75 of file IntVector.cpp.

Member Data Documentation

◆ Zero

const IntVector Util::IntVector::Zero = IntVector(0)
static

Zero IntVector.

Definition at line 364 of file IntVector.h.


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