Simpatico
v1.10
|
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,
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.
#include <IntVector.h>
Public Member Functions | |
IntVector & | zero () |
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... | |
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... | |
Assignment | |
IntVector & | operator= (const IntVector &v) |
Copy assignment. More... | |
IntVector & | operator= (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) | |
IntVector & | add (const IntVector &v1, const IntVector &v2) |
Add vectors v1 and v2. More... | |
IntVector & | subtract (const IntVector &v1, const IntVector &v2) |
Subtract vector v2 from v1. More... | |
IntVector & | multiply (const IntVector &v, int s) |
Multiply a vector v by a scalar s. More... | |
IntVector & | cross (const IntVector &v1, const IntVector &v2) |
Calculate cross product of vectors v1 and v2. More... | |
Friends | |
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... | |
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... | |
|
inline |
Default constructor.
Definition at line 84 of file IntVector.h.
|
inline |
Copy constructor.
Definition at line 90 of file IntVector.h.
|
inlineexplicit |
Constructor, initialize all elements to the same scalar.
scalar | initial value for all elements. |
Definition at line 102 of file IntVector.h.
|
inlineexplicit |
Construct IntVector from C int[3] array.
v | array of 3 coordinates |
Definition at line 114 of file IntVector.h.
|
inline |
Construct IntVector from its coordinates.
x | x-axis coordinate |
y | y-axis coordinate |
z | z-axis coordinate |
Definition at line 128 of file IntVector.h.
|
inline |
Set all elements of a 3D vector to zero.
Definition at line 140 of file IntVector.h.
References serialize().
Referenced by McMd::Atom::allocate().
|
inline |
Serialize to/from an archive.
Implementation uses syntax of Boost::serialize.
ar | archive |
version | archive version id |
Definition at line 456 of file IntVector.h.
Referenced by zero().
|
inline |
Assignment from C int[] array.
v | array of coordinates |
Definition at line 180 of file IntVector.h.
|
inline |
Add vector dv to this vector.
Upon return, *this = this + dv.
dv | vector increment (input) |
Definition at line 199 of file IntVector.h.
|
inline |
Subtract vector dv from this vector.
Upon return, *this = this + dv.
dv | vector increment (input) |
Definition at line 213 of file IntVector.h.
|
inline |
Multiply this vector by scalar s.
Upon return, *this = this*s.
s | scalar multiplier |
Definition at line 227 of file IntVector.h.
|
inline |
Return one Cartesian element by value.
i | element index |
Definition at line 244 of file IntVector.h.
References Util::Dimension.
|
inline |
Return a reference to one element of the vector.
i | element index |
Definition at line 257 of file IntVector.h.
References Util::Dimension.
|
inline |
Return square magnitude of this vector.
Definition at line 273 of file IntVector.h.
|
inline |
Return dot product of this vector and vector v.
v | input vector |
Definition at line 282 of file IntVector.h.
Add vectors v1 and v2.
Upon return, *this = v1 + v2.
v1 | vector (input) |
v2 | vector (input) |
Definition at line 299 of file IntVector.h.
Subtract vector v2 from v1.
Upon return, *this = v1 - v2.
v1 | vector (input) |
v2 | vector (input) |
Definition at line 316 of file IntVector.h.
Multiply a vector v by a scalar s.
Upon return, *this = v*s.
v | vector input |
s | scalar input |
Definition at line 333 of file IntVector.h.
Calculate cross product of vectors v1 and v2.
Upon return, *this = v1 x v2.
v1 | input vector |
v2 | input vector |
Definition at line 350 of file IntVector.h.
|
static |
Initialize static IntVector::Zero.
Definition at line 113 of file IntVector.cpp.
Referenced by Util::initStatic().
|
static |
Commit MPI datatype MpiTraits<IntVector>::type.
Definition at line 92 of file IntVector.cpp.
References Util::MpiStructBuilder::addMember(), Util::MpiStructBuilder::commit(), and Util::MpiStructBuilder::setBase().
Referenced by McMd::commitMpiTypes(), and DdMd::Simulation::Simulation().
Equality for IntVectors.
Definition at line 24 of file IntVector.cpp.
|
friend |
Equality of IntVector and C array.
Definition at line 35 of file IntVector.cpp.
|
friend |
istream extractor for a IntVector.
Input elements of a vector from stream, without line breaks.
in | input stream |
vector | IntVector to be read from stream |
Definition at line 64 of file IntVector.cpp.
|
friend |
ostream inserter for a IntVector.
Output elements of a vector to stream, without line breaks.
out | output stream |
vector | IntVector to be written to stream |
Definition at line 75 of file IntVector.cpp.
Zero IntVector.
Definition at line 364 of file IntVector.h.