Simpatico
v1.10
|
A Vector is a Cartesian vector.
The Cartesian elements of a Vector can be accessed using array notation: The elements of a three dimensional Vector 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 a scalar.
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 Vector, 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 Vector valued operations avoids dynamic allocation of temporary Vector objects, by requiring that the invoking function provide an object to hold the result.
For efficiency, all methods in this class are declared inline.
#include <Vector.h>
Public Member Functions | |
Vector & | 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 | |
Vector () | |
Default constructor. More... | |
Vector (const Vector &v) | |
Copy constructor. More... | |
Vector (double scalar) | |
Constructor, initialize all elements to a scalar value. More... | |
Vector (const double *v) | |
Construct Vector from C double[3] array. More... | |
Vector (double x, double y, double z=0.0) | |
Construct Vector from its coordinates. More... | |
Assignment | |
Vector & | operator= (const Vector &v) |
Copy assignment. More... | |
Vector & | operator= (const double *v) |
Assignment from C double[3] array. More... | |
Arithmetic Assignment | |
void | operator+= (const Vector &dv) |
Add vector dv to this vector. More... | |
void | operator-= (const Vector &dv) |
Subtract vector dv from this vector. More... | |
void | operator*= (double s) |
Multiply this vector by scalar s. More... | |
void | operator/= (double s) |
Divide this vector by scalar s. More... | |
Array Subscript | |
const double & | operator[] (int i) const |
Return one Cartesian element by value. More... | |
double & | operator[] (int i) |
Return one element of the vector by references. More... | |
Scalar-valued functions | |
double | square () const |
Return square magnitude of this vector. More... | |
double | abs () const |
Return absolute magnitude of this vector. More... | |
double | dot (const Vector &v) const |
Return dot product of this vector and vector v. More... | |
double | projection (const Vector &p) const |
Return projection of this vector along vector p. More... | |
Vector valued functions (result assigned to invoking object) | |
Vector & | add (const Vector &v1, const Vector &v2) |
Add vectors v1 and v2. More... | |
Vector & | subtract (const Vector &v1, const Vector &v2) |
Subtract vector v2 from v1. More... | |
Vector & | multiply (const Vector &v, double s) |
Multiply a vector v by a scalar s. More... | |
Vector & | divide (const Vector &v, double s) |
Divide vector v by scalar s. More... | |
Vector & | cross (const Vector &v1, const Vector &v2) |
Calculate cross product of vectors v1 and v2. More... | |
Vector & | versor (const Vector &v) |
Calculate unit vector parallel to input vector v. More... | |
Vector & | parallel (const Vector &v, const Vector &p) |
Calculate component of vector v parallel to vector p. More... | |
Vector & | transverse (const Vector &v, const Vector &p) |
Calculate component of vector v transverse to vector p. More... | |
int | minId (const Vector &v) |
Computes the index corresponding to minimum element in a vector. More... | |
int | maxId (const Vector &v) |
Computes the index corresponding to maximum element in a vector. More... | |
Friends | |
bool | operator== (const Vector &v1, const Vector &v2) |
Equality for Vectors. More... | |
bool | operator== (const Vector &v1, const double *v2) |
Equality of Vector and C array. More... | |
std::istream & | operator>> (std::istream &in, Vector &vector) |
istream extractor for a Vector. More... | |
std::ostream & | operator<< (std::ostream &out, const Vector &vector) |
ostream inserter for a Vector. More... | |
Static Members | |
static const Vector | Zero = Vector(0.0) |
Zero Vector = {0.0, 0.0, 0.0}. More... | |
static void | initStatic () |
Initialize Zero Vector. More... | |
static void | commitMpiType () |
Commit MPI datatype MpiTraits<Vector>::type. More... | |
|
inline |
|
inlineexplicit |
|
inlineexplicit |
|
inline |
|
inline |
Set all elements of a 3D vector to zero.
Definition at line 514 of file Vector.h.
Referenced by McMd::MdEwaldPotential::addForces(), McMd::MdSpmePotential::addForces(), McMd::Atom::allocate(), McMd::Cluster::clusterCOM(), Simp::GeneralPeriodicExternal::energy(), Simp::HarmonicAngle::force(), Simp::CosineDihedral::force(), Simp::MultiHarmonicDihedral::force(), Simp::PeriodicExternal::getForce(), Simp::SimplePeriodicExternal::getForce(), Simp::GeneralPeriodicExternal::getForce(), Simp::NucleationExternal::getForce(), Simp::LocalLamellarOrderingExternal::getForce(), Simp::LamellarOrderingExternal::getForce(), Simp::OrthoBoxExternal::getForce(), McMd::NphIntegrator::NphIntegrator(), Tools::ChainMaker::readParam(), and Util::setToZero().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Return one Cartesian element by value.
i | element index |
Definition at line 594 of file Vector.h.
References Util::Dimension.
|
inline |
Return one element of the vector by references.
i | element index |
Definition at line 605 of file Vector.h.
References Util::Dimension.
|
inline |
Return square magnitude of this vector.
Definition at line 616 of file Vector.h.
Referenced by abs(), DdMd::PairList::build(), Simp::Bend::computeAngle(), Simp::Torsion::computeAngle(), Simp::TorsionForce::computeDerivatives(), DdMd::PairPotentialImpl< Interaction >::computeEnergy(), DdMd::PairPotentialImpl< Interaction >::computeForcesAndStress(), DdMd::PairPotentialImpl< Interaction >::computePairEnergies(), DdMd::PairPotentialImpl< Interaction >::computeStress(), McMd::MdEwaldPotential::makeWaves(), McMd::MdSpmePotential::makeWaves(), DdMd::AtomStorage::maxSqDisplacement(), DdMd::PairPotential::nPair(), parallel(), McMd::EndtoEnd::sample(), McMd::BlockRadiusGyration::sample(), McMd::RadiusGyration::sample(), Util::MeanSqDispArray< Data >::sample(), McMd::RingTetraRebridgeMove::scanBridge(), and transverse().
|
inline |
Return absolute magnitude of this vector.
Definition at line 625 of file Vector.h.
References square().
Referenced by McMd::GroupRebridgeBase::angleEnergy(), Simp::BendForce::computeDerivatives(), Simp::CosineSqAngle::force(), Simp::CosineAngle::force(), McMd::McNVTChemicalPotential::load(), McMd::MdEwaldPotential::makeWaves(), projection(), and versor().
|
inline |
Return dot product of this vector and vector v.
v | input vector |
Definition at line 632 of file Vector.h.
Referenced by McMd::CfbLinear::addAtom(), McMd::CfbEndBase::addEndAtom(), McMd::GroupRebridgeBase::angleEnergy(), McMd::AnglePotentialImpl< Interaction >::atomEnergy(), Simp::Bend::computeAngle(), Simp::Torsion::computeAngle(), Simp::BendForce::computeDerivatives(), Simp::TorsionForce::computeDerivatives(), DdMd::AnglePotentialImpl< Interaction >::computeEnergy(), McMd::AnglePotentialImpl< Interaction >::computeEnergy(), McMd::CfbLinear::deleteAtom(), McMd::CfbEndBase::deleteEndAtom(), Simp::NucleationExternal::energy(), Simp::PeriodicExternal::energy(), Simp::SimplePeriodicExternal::energy(), Simp::GeneralPeriodicExternal::energy(), Simp::CosineSqAngle::force(), Simp::CosineAngle::force(), Simp::NucleationExternal::getForce(), Simp::PeriodicExternal::getForce(), Simp::SimplePeriodicExternal::getForce(), Simp::GeneralPeriodicExternal::getForce(), DdMd::NptIntegrator::integrateStep2(), McMd::MdEwaldPotential::makeWaves(), parallel(), Util::product(), projection(), McMd::CompositionProfile::sample(), McMd::StructureFactor::sample(), DdMd::StructureFactor::sample(), DdMd::VanHove::sample(), McMd::VanHove::sample(), McMd::StructureFactorP::sample(), McMd::IntraStructureFactor::sample(), McMd::NvtDpdVvIntegrator::setup(), and transverse().
|
inline |
Add vectors v1 and v2.
Upon return, *this = v1 + v2.
v1 | vector (input) |
v2 | vector (input) |
Definition at line 657 of file Vector.h.
Referenced by McMd::CfbEndBase::addEndAtom(), McMd::CfbRebridgeBase::addMiddleAtom(), McMd::CfbEndBase::deleteEndAtom(), McMd::CfbRebridgeBase::deleteMiddleAtom(), McMd::McNVTChemicalPotential::load(), McMd::McNVTChemicalPotential::sample(), McMd::NvtDpdVvIntegrator::step(), and McMd::NphIntegrator::step().
Subtract vector v2 from v1.
Upon return, *this = v1 - v2.
v1 | vector (input) |
v2 | vector (input) |
Definition at line 672 of file Vector.h.
Referenced by McMd::CfbLinear::addAtom(), DdMd::PairList::build(), Simp::BendForce::computeDerivatives(), DdMd::PairPotentialImpl< Interaction >::computeEnergy(), DdMd::PairPotentialImpl< Interaction >::computeForcesAndStress(), DdMd::PairPotentialImpl< Interaction >::computePairEnergies(), DdMd::PairPotentialImpl< Interaction >::computeStress(), McMd::CfbLinear::deleteAtom(), DdMd::AtomStorage::maxSqDisplacement(), DdMd::PairPotential::nPair(), McMd::LammpsConfigIo::read(), DdMd::LammpsConfigIo::readConfig(), McMd::EndtoEndXYZ::sample(), McMd::EndtoEnd::sample(), McMd::BlockRadiusGyration::sample(), McMd::RadiusGyration::sample(), Util::MeanSqDispArray< Data >::sample(), McMd::RingTetraRebridgeMove::scanBridge(), and McMd::NvtDpdVvIntegrator::setup().
Multiply a vector v by a scalar s.
Upon return, *this = v*s.
v | vector input |
s | scalar input |
Definition at line 686 of file Vector.h.
Referenced by McMd::MdEwaldPotential::addForces(), Simp::BendForce::computeDerivatives(), Simp::TorsionForce::computeDerivatives(), McMd::MdEwaldPotential::computeStress(), Simp::CosineSqAngle::force(), Simp::HarmonicAngle::force(), Simp::CosineAngle::force(), Simp::CosineDihedral::force(), Simp::MultiHarmonicDihedral::force(), DdMd::NvtIntegrator::integrateStep1(), DdMd::NphIntegrator::integrateStep1(), DdMd::NveIntegrator::integrateStep1(), DdMd::NptIntegrator::integrateStep1(), DdMd::NvtLangevinIntegrator::integrateStep1(), DdMd::NvtIntegrator::integrateStep2(), DdMd::NphIntegrator::integrateStep2(), DdMd::NveIntegrator::integrateStep2(), DdMd::NptIntegrator::integrateStep2(), DdMd::NvtLangevinIntegrator::integrateStep2(), McMd::MdSystem::kineticEnergy(), McMd::McNVTChemicalPotential::load(), McMd::MdEwaldPotential::makeWaves(), McMd::MdSpmePotential::makeWaves(), McMd::RingRouseAutoCorr::sample(), McMd::LinearRouseAutoCorr::sample(), McMd::NvtDpdVvIntegrator::setup(), McMd::NveVvIntegrator::step(), McMd::NvtLangevinIntegrator::step(), McMd::NvtDpdVvIntegrator::step(), McMd::NvtNhIntegrator::step(), and McMd::NphIntegrator::step().
Divide vector v by scalar s.
Upon return, *this = v/s;
v | vector input |
s | scalar input |
Definition at line 700 of file Vector.h.
Referenced by Simp::BendForce::computeDerivatives(), and McMd::McNVTChemicalPotential::load().
Calculate cross product of vectors v1 and v2.
Upon return, *this = v1 x v2.
v1 | input vector |
v2 | input vector |
Definition at line 714 of file Vector.h.
Referenced by Simp::Torsion::computeAngle(), and Simp::TorsionForce::computeDerivatives().
Calculate unit vector parallel to input vector v.
Upon return *this = unit vector.
v | input vector |
Definition at line 726 of file Vector.h.
References abs().
Referenced by McMd::IntraBondTensorAutoCorr< SystemType >::sample().
Calculate component of vector v parallel to vector p.
Upon return, the invoking vector is equal to the vector projection of vector v along a direction parallel to vector p.
The vector projection of v along p is parallel to p and has an absolute magnitude equal to the scalar projection of v along p.
v | vector to project |
p | vector along which to project |
Calculate component of vector v transverse to vector p.
Upon return, the invoking vector is equal to the vector projection of vector v perpendicular to vector p.
v | input vector |
p | vector perpendicular to which to project. |
Definition at line 771 of file Vector.h.
References Util::DimensionSq, dot(), maxId(), minId(), and square().
int Util::Vector::minId | ( | const Vector & | v | ) |
Computes the index corresponding to minimum element in a vector.
v | input vector |
Referenced by transverse().
int Util::Vector::maxId | ( | const Vector & | v | ) |
Computes the index corresponding to maximum element in a vector.
v | input vector |
Referenced by transverse().
|
static |
Initialize Zero Vector.
Definition at line 119 of file Vector.cpp.
Referenced by Util::initStatic().
|
static |
Commit MPI datatype MpiTraits<Vector>::type.
Commit MPI Datatype.
Definition at line 97 of file Vector.cpp.
References Util::MpiStructBuilder::addMember(), Util::MpiStructBuilder::commit(), and Util::MpiStructBuilder::setBase().
Referenced by McMd::commitMpiTypes(), and DdMd::Simulation::Simulation().
Equality for Vectors.
Definition at line 26 of file Vector.cpp.
|
friend |
Equality of Vector and C array.
Definition at line 36 of file Vector.cpp.
|
friend |
istream extractor for a Vector.
Input elements of a vector from stream, without line breaks.
in | input stream |
vector | Vector to be read from stream |
Definition at line 65 of file Vector.cpp.
|
friend |
ostream inserter for a Vector.
Output elements of a vector to stream, without line breaks.
out | output stream |
vector | Vector to be written to stream |
Definition at line 76 of file Vector.cpp.
Zero Vector = {0.0, 0.0, 0.0}.
Definition at line 369 of file Vector.h.
Referenced by McMd::CompositionProfile::makeWaveVectors(), McMd::StructureFactor::makeWaveVectors(), DdMd::VanHove::makeWaveVectors(), DdMd::StructureFactor::makeWaveVectors(), McMd::StructureFactorP::makeWaveVectors(), Simp::MonoclinicBoundary::MonoclinicBoundary(), Simp::OrthorhombicBoundary::OrthorhombicBoundary(), McMd::VanHove::sample(), and McMd::IntraStructureFactor::sample().