MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vec3D Class Reference

Implementation of a 3D vector (by Vitaliy). More...

#include <Vector.h>

Public Member Functions

 Vec3D ()
 constructor More...
 
 Vec3D (const Mdouble x, const Mdouble y, const Mdouble z)
 Alternative constructor, taking the three elements as arguments. More...
 
void setZero ()
 Sets all elements to zero. More...
 
bool isZero () const
 Checks if ALL elements are zero. More...
 
Vec3D operator+ (const Vec3D &a) const
 Adds another vector. More...
 
Vec3D operator- (const Vec3D &a) const
 Subtracts another vector. More...
 
Vec3D operator* (const Mdouble a) const
 Adds a scalar. More...
 
Vec3D operator/ (const Mdouble a) const
 Divides by a scalar. More...
 
Vec3Doperator+= (const Vec3D &a)
 Adds another vector. More...
 
Vec3Doperator-= (const Vec3D &a)
 Subtracts another vector. More...
 
Vec3Doperator*= (const Mdouble a)
 Multiplies by a scalar. More...
 
Vec3Doperator/= (const Mdouble a)
 Divides by a scalar. More...
 
void normalize ()
 Makes this Vec3D unit length. More...
 
void setLength (Mdouble length)
 Make this Vec3D a certain length. More...
 
Mdouble getLength () const
 Calculates the length of this Vec3D: $ \sqrt{a\cdot a} $. More...
 
Mdouble getLengthSquared () const
 Calculates the squared length of this Vec3D: $ a\cdot a $. More...
 
Mdouble getComponent (const int index) const
 Returns the requested component of this Vec3D. More...
 
void setComponent (const int index, const double val)
 Sets the requested component of this Vec3D to the requested value. More...
 
Vec3D getCylindricalCoordinates () const
 Returns the representation of this Vec3D in cylindrical coordinates. More...
 
Vec3D getFromCylindricalCoordinates () const
 Returns the representation of this Vec3D in cartesian coordinates. More...
 
bool isEqualTo (const Vec3D &other, const double tol) const
 Checks if the length this Vec3D is equal the length of other with a certain tolerance. More...
 

Static Public Member Functions

static Mdouble dot (const Vec3D &a, const Vec3D &b)
 Calculates the dot product of two Vec3D: $ a \cdot b$. More...
 
static Vec3D max (const Vec3D &a, const Vec3D &b)
 Calculates the pointwise maximum of two Vec3D. More...
 
static Vec3D min (const Vec3D &a, const Vec3D &b)
 Calculates the pointwise minimum of two Vec3D. More...
 
static Vec3D square (const Vec3D &a)
 Calculates the pointwise square of a Vec3D. More...
 
static Vec3D sqrt (const Vec3D &a)
 Calculates the pointwise square root of a Vec3D. More...
 
static Vec3D cross (const Vec3D &a, const Vec3D &b)
 Calculates the cross product of two Vec3D: $ a \times b$. More...
 
static Mdouble getDistance (const Vec3D &a, const Vec3D &b)
 Calculates the distance between two Vec3D: $ \sqrt{\left(a-b\right) \cdot \left(a-b\right)} $. More...
 
static Mdouble getDistanceSquared (const Vec3D &a, const Vec3D &b)
 Calculates the squared distance between two Vec3D: $ \left(a-b\right) \cdot \left(a-b\right) $. More...
 
static Mdouble getLength (const Vec3D &a)
 Calculates the length of a Vec3D: $ \sqrt{a\cdot a} $. More...
 
static Mdouble getLengthSquared (const Vec3D &a)
 Calculates the squared length of a Vec3D: $ a\cdot a $. More...
 
static Vec3D getUnitVector (const Vec3D &a)
 Returns a unit Vec3D based on a. More...
 

Public Attributes

Mdouble X
 the vector components More...
 
Mdouble Y
 
Mdouble Z
 

Friends

std::ostream & operator<< (std::ostream &os, const Vec3D &a)
 Adds elements to an output stream. More...
 
std::istream & operator>> (std::istream &is, Vec3D &a)
 Adds elements to an input stream. More...
 
Vec3D operator- (const Vec3D &a)
 Adds a scalar to a vector. More...
 
Vec3D operator* (const Mdouble a, const Vec3D &b)
 Multiplies all elements by a scalar. More...
 

Detailed Description

Implementation of a 3D vector (by Vitaliy).

Modifications 21:9:2009 - Added the inclusion guards and some include objects

Todo:
Need to generalize this to n-dimensional vectors of any type

Definition at line 45 of file Vector.h.

Constructor & Destructor Documentation

Vec3D::Vec3D ( )

constructor

Default constructor

Definition at line 31 of file Vector.cc.

References setZero().

Referenced by cross(), getCylindricalCoordinates(), getFromCylindricalCoordinates(), getUnitVector(), max(), min(), operator*(), operator+(), operator-(), operator/(), sqrt(), and square().

32 {
33  setZero();
34 }
void setZero()
Sets all elements to zero.
Definition: Vector.cc:52
Vec3D::Vec3D ( const Mdouble  x,
const Mdouble  y,
const Mdouble  z 
)

Alternative constructor, taking the three elements as arguments.

Alternative constructor, lets you define all three elements.

Parameters
[in]xthe x-component
[in]ythe y-component
[in]zthe z-component

Definition at line 42 of file Vector.cc.

References X, Y, and Z.

43 {
44  X = x;
45  Y = y;
46  Z = z;
47 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52

Member Function Documentation

Vec3D Vec3D::cross ( const Vec3D a,
const Vec3D b 
)
static

Calculates the cross product of two Vec3D: $ a \times b$.

Calculates the cross product of two vectors NB: this is a STATIC function!

Parameters
[in]athe first vector
[in]bthe second vector
Returns
the cross product of the arguments

Definition at line 255 of file Vector.cc.

References Vec3D(), X, Y, and Z.

Referenced by ChuteWithHopper::addHopper(), IntersectionOfWalls::addObject(), DPMBase::computeForcesDueToWalls(), FrictionInteraction::computeFrictionForce(), MindlinRollingTorsionInteraction::computeFrictionForce(), DPMBase::computeInternalForces(), IntersectionOfWalls::createOpenPrism(), IntersectionOfWalls::createPrism(), BaseInteractable::getVelocityAtContact(), TriangulatedWall::readVTK(), and AngledPeriodicBoundary::set().

256 {
257  return Vec3D(a.Y * b.Z - a.Z * b.Y, a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X);
258 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Mdouble Vec3D::dot ( const Vec3D a,
const Vec3D b 
)
static

Calculates the dot product of two Vec3D: $ a \cdot b$.

Calculates the dot product of two vectors. NB: this is a STATIC function!

Parameters
[in]athe first vector
[in]bthe second vector
Returns
the resulting scalar

Definition at line 167 of file Vector.cc.

References X, Y, and Z.

Referenced by IntersectionOfWalls::addObject(), SlidingFrictionInteraction::computeFrictionForce(), FrictionInteraction::computeFrictionForce(), MindlinInteraction::computeFrictionForce(), MindlinRollingTorsionInteraction::computeFrictionForce(), LinearPlasticViscoelasticInteraction::computeLinearPlasticViscoelasticForce(), HertzianViscoelasticInteraction::computeNormalForce(), SinterInteraction::computeNormalForce(), LinearViscoelasticInteraction::computeNormalForce(), HertzianSinterInteraction::computeSinterForce(), AxisymmetricIntersectionOfWalls::convertLimits(), AngledPeriodicBoundary::distance(), BaseInteraction::gatherContactStatistics(), DeletionBoundary::getDistance(), TriangulatedWall::Face::getDistance(), MaserBoundary::getDistance(), InfiniteWall::getDistance(), PeriodicBoundary::getDistance(), TriangulatedWall::Face::getDistanceAndNormal(), AxisymmetricIntersectionOfWalls::getDistanceAndNormal(), IntersectionOfWalls::getDistanceAndNormal(), DPMBase::getGravitationalEnergy(), InteractionHandler::getInteraction(), BaseWall::getLinePlaneIntersect(), AngledPeriodicBoundary::getOpeningAngle(), MindlinInteraction::getTangentialOverlap(), InfiniteWallWithHole::getWallDistance(), FrictionInteraction::integrate(), MindlinRollingTorsionInteraction::integrate(), PeriodicBoundary::isClosestToLeftBoundary(), BaseWall::isInsideWallVTK(), InfiniteWallWithHole::move_time(), BaseWall::projectOntoWallVTK(), DeletionBoundary::set(), AngledPeriodicBoundary::set(), PeriodicBoundary::set(), InfiniteWallWithHole::set(), AngledPeriodicBoundary::shiftPosition(), AngledPeriodicBoundary::shiftPositions(), MindlinInteraction::updateK_t(), DPMBase::writeEneTimestep(), and BaseInteraction::writeToFStat().

168 {
169  return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
170 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Mdouble Vec3D::getComponent ( const int  index) const

Returns the requested component of this Vec3D.

returns the vector element belonging to the given index.

Parameters
[in]indexthe index of interest (should be 0, 1 or 2)
Returns
the value of the vector element belonging to the given index

Definition at line 310 of file Vector.cc.

References ERROR, logger, X, Y, and Z.

311  {
312  switch (index)
313  {
314  case 0:
315  return X;
316  case 1:
317  return Y;
318  case 2:
319  return Z;
320  default:
321  logger(ERROR, "[Vector::getComponent] Index = %, which is too high for a 3D vector (should be 0-2).", index);
322  return 0;
323  }
324 }
Mdouble X
the vector components
Definition: Vector.h:52
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::getCylindricalCoordinates ( ) const

Returns the representation of this Vec3D in cylindrical coordinates.

Transforms the (Cartesian) vector to cylindrical coordinates

Returns
Transformed vector

Definition at line 354 of file Vector.cc.

References Vec3D(), X, Y, and Z.

355 {
356  return Vec3D(std::sqrt(X * X + Y * Y), std::atan2(Y, X), Z);
357 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Mdouble Vec3D::getDistance ( const Vec3D a,
const Vec3D b 
)
static

Calculates the distance between two Vec3D: $ \sqrt{\left(a-b\right) \cdot \left(a-b\right)} $.

Calculates the distance (i.e. the length of the difference) between two vectors NB: this is a STATIC function!

Parameters
[in]athe first vector
[in]bthe second vector
Returns
the distance between the two arguments.

Definition at line 267 of file Vector.cc.

References getDistanceSquared().

268 {
269  return std::sqrt(getDistanceSquared(a, b));
270 }
static Mdouble getDistanceSquared(const Vec3D &a, const Vec3D &b)
Calculates the squared distance between two Vec3D: .
Definition: Vector.cc:280
Mdouble Vec3D::getDistanceSquared ( const Vec3D a,
const Vec3D b 
)
static

Calculates the squared distance between two Vec3D: $ \left(a-b\right) \cdot \left(a-b\right) $.

Calculates the square of the distance (i.e. the length of the difference) between two vectors. NB: this is a STATIC function!

Parameters
[in]athe first vector
[in]bthe second vector
Returns
the square of the distance between the two arguments.

Definition at line 280 of file Vector.cc.

References X, Y, and Z.

Referenced by DPMBase::areInContact(), DPMBase::checkParticleForInteractionLocal(), and getDistance().

281 {
282  return ((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y) + (a.Z - b.Z) * (a.Z - b.Z));
283 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::getFromCylindricalCoordinates ( ) const

Returns the representation of this Vec3D in cartesian coordinates.

Transforms the (cylindrical) vector to cartesian coordinates

Returns
Transformed vector

Definition at line 363 of file Vector.cc.

References mathsFunc::cos(), mathsFunc::sin(), Vec3D(), X, Y, and Z.

364 {
365  return Vec3D(X * std::cos(Y), X * std::sin(Y), Z);
366 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble cos(Mdouble x)
Definition: ExtendedMath.cc:60
Mdouble sin(Mdouble x)
Definition: ExtendedMath.cc:42
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Mdouble Vec3D::getLength ( const Vec3D a)
static

Calculates the length of a Vec3D: $ \sqrt{a\cdot a} $.

Calculates the length of a given vector NB: this is a STATIC function!

Parameters
[in]avector to be measured.
Returns
length of the argument.

Definition at line 414 of file Vector.cc.

References getLength().

Referenced by MindlinInteraction::computeFrictionForce(), BaseInteraction::gatherContactStatistics(), CylindricalWall::getDistanceAndNormal(), Coil::getDistanceAndNormal(), AxisymmetricIntersectionOfWalls::getDistanceAndNormal(), InfiniteWallWithHole::getDistanceAndNormal(), getLength(), SlidingFrictionInteraction::getTangentialOverlap(), MindlinInteraction::getTangentialOverlap(), FileReader::read(), Chute::setChuteAngle(), MindlinInteraction::updateK_t(), and BaseInteraction::writeToFStat().

415 {
416  return a.getLength();
417 }
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:414
Mdouble Vec3D::getLength ( ) const

Calculates the length of this Vec3D: $ \sqrt{a\cdot a} $.

Calculates the length of this vector

Returns
the (scalar) length of this vector

Definition at line 403 of file Vector.cc.

References getLengthSquared().

Referenced by SphericalWall::getDistance(), TriangulatedWall::Face::getDistanceAndNormal(), SphericalWall::getDistanceAndNormal(), normalize(), AngledPeriodicBoundary::set(), and InfiniteWall::setNormal().

404 {
405  return std::sqrt(getLengthSquared());
406 }
Mdouble getLengthSquared() const
Calculates the squared length of this Vec3D: .
Definition: Vector.cc:300
Mdouble Vec3D::getLengthSquared ( const Vec3D a)
static

Calculates the squared length of a Vec3D: $ a\cdot a $.

Calculates the square of the length of a given vector. NB: this is a STATIC function!

Parameters
[in]athe vector.
Returns
the square of the length of the argument.

Definition at line 291 of file Vector.cc.

References X, Y, and Z.

Referenced by ChuteWithHopper::addHopper(), SlidingFrictionInteraction::computeFrictionForce(), FrictionInteraction::computeFrictionForce(), MindlinRollingTorsionInteraction::computeFrictionForce(), IntersectionOfWalls::getDistanceAndNormal(), SlidingFrictionInteraction::getElasticEnergy(), FrictionInteraction::getElasticEnergy(), MindlinInteraction::getElasticEnergy(), MindlinRollingTorsionInteraction::getElasticEnergy(), BaseParticle::getKineticEnergy(), getUnitVector(), and Quarternion::integrate().

292 {
293  return (a.X * a.X + a.Y * a.Y + a.Z * a.Z);
294 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Mdouble Vec3D::getLengthSquared ( ) const

Calculates the squared length of this Vec3D: $ a\cdot a $.

Calculates the square of the length of itself

Returns
the square of the length of this vector

Definition at line 300 of file Vector.cc.

References X, Y, and Z.

Referenced by AxisymmetricIntersectionOfWalls::convertLimits(), TriangulatedWall::Face::getDistanceAndNormal(), BaseParticle::getInteractionWith(), getLength(), and isEqualTo().

301 {
302  return (X * X + Y * Y + Z * Z);
303 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::getUnitVector ( const Vec3D a)
static

Returns a unit Vec3D based on a.

Calculates the unit vector of a given vector (unless it is a vector with zero length; in that case it returns a 3D vector with each element equal to zero). NB: this is a STATIC function!

Parameters
[in]athe vector of interest
Returns
unit vector in the direction of the argument (unless the argument has length zero; in that case a zero-vector).

Definition at line 428 of file Vector.cc.

References getLengthSquared(), and Vec3D().

Referenced by IntersectionOfWalls::createOpenPrism(), IntersectionOfWalls::createPrism(), MindlinInteraction::getTangentialOverlap(), TriangulatedWall::readVTK(), and MindlinInteraction::updateK_t().

429 {
430  Mdouble Length2 = a.getLengthSquared();
431  if (Length2 != 0.0)
432  return a / std::sqrt(Length2);
433  else
434  return Vec3D(0, 0, 0);
435 }
static Mdouble getLengthSquared(const Vec3D &a)
Calculates the squared length of a Vec3D: .
Definition: Vector.cc:291
Vec3D()
constructor
Definition: Vector.cc:31
double Mdouble
bool Vec3D::isEqualTo ( const Vec3D other,
const double  tol 
) const

Checks if the length this Vec3D is equal the length of other with a certain tolerance.

Checks if the length of the vector is equal to the one given in the first argument (other), with a tolerance given in the second argument (tol).

Parameters
[in]otherthe 3D vector to check against
[in]tolthe tolerance
Returns
returns TRUE if the difference between the lengths of this vector and that given in the first argument (other) is smaller than the given tolerance.

Definition at line 377 of file Vector.cc.

References getLengthSquared().

378  {
379  if ((Vec3D::getLengthSquared(*this - other)) <= tol * tol)
380  {
381  return true;
382  }
383  else
384  {
385  return false;
386  }
387 }
Mdouble getLengthSquared() const
Calculates the squared length of this Vec3D: .
Definition: Vector.cc:300
bool Vec3D::isZero ( ) const

Checks if ALL elements are zero.

Checks if ALL elements are zero

Returns
TRUE if ALL elements are zero

Definition at line 63 of file Vector.cc.

References X, Y, and Z.

64 {
65  return X == 0.0 && Y == 0.0 && Z == 0.0;
66 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::max ( const Vec3D a,
const Vec3D b 
)
static

Calculates the pointwise maximum of two Vec3D.

Calculates the pointwise maximum of two vectors. NB: this is a STATIC function!

Parameters
[in]athe first vector
[in]bthe second vector
Returns
The resulting vector, in which each element is the maximum of the equivalent elements of the arguments

Definition at line 180 of file Vector.cc.

References Vec3D(), X, Y, and Z.

Referenced by FileReader::read().

181 {
182  return Vec3D(std::max(a.X, b.X), std::max(a.Y, b.Y), std::max(a.Z, b.Z));
183 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::min ( const Vec3D a,
const Vec3D b 
)
static

Calculates the pointwise minimum of two Vec3D.

Calculates the pointwise minimum of two vectors. NB: this is a STATIC function!

Parameters
[in]athe first vector
[in]bthe second vector
Returns
The resulting vector, in which each element is the minimum of the equivalent elements of the arguments

Definition at line 193 of file Vector.cc.

References Vec3D(), X, Y, and Z.

Referenced by FileReader::read().

194 {
195  return Vec3D(std::min(a.X, b.X), std::min(a.Y, b.Y), std::min(a.Z, b.Z));
196 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
void Vec3D::normalize ( )

Makes this Vec3D unit length.

Normalises the vector, i.e. divides all elements by the vectors length (resulting in a vector in the same direction, but with unit length).

Definition at line 214 of file Vector.cc.

References getLength(), logger, and WARN.

Referenced by IntersectionOfWalls::addObject(), Screw::getDistanceAndNormal(), Quarternion::Quarternion(), and setLength().

215 {
216  Mdouble length = this->getLength();
217  if (length!=0)
218  {
219  *this /= this->getLength();
220  } else {
221  logger(WARN, "Normalizing a vector of length 0");
222  }
223 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Mdouble getLength() const
Calculates the length of this Vec3D: .
Definition: Vector.cc:403
Vec3D Vec3D::operator* ( const Mdouble  a) const

Adds a scalar.

Subtracts a scalar

Multiplies by a scalar

Multiplies each element with a scalar

Parameters
[in]athe scalar to be multiplied with
Returns
the resulting vector

Definition at line 93 of file Vector.cc.

References Vec3D(), X, Y, and Z.

94  {
95  return Vec3D(X * a, Y * a, Z * a);
96 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D & Vec3D::operator*= ( const Mdouble  a)

Multiplies by a scalar.

Multiplies each element by a scalar

Parameters
[in]ascalar to be multiplied by
Returns
(reference to) itself, i.e. resulting vector

Definition at line 139 of file Vector.cc.

References X, Y, and Z.

140 {
141  X *= a;
142  Y *= a;
143  Z *= a;
144  return *this;
145 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::operator+ ( const Vec3D a) const

Adds another vector.

Adds vector to itself

Parameters
[in]avector to be added
Returns
resulting 3D vector

Definition at line 73 of file Vector.cc.

References Vec3D(), X, Y, and Z.

74  {
75  return Vec3D(X + a.X, Y + a.Y, Z + a.Z);
76 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D & Vec3D::operator+= ( const Vec3D a)

Adds another vector.

Adds a vector to itself

Parameters
[in]avector to be added
Returns
(reference to) itself, i.e. resulting vector

Definition at line 113 of file Vector.cc.

References X, Y, and Z.

114 {
115  X += a.X;
116  Y += a.Y;
117  Z += a.Z;
118  return *this;
119 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::operator- ( const Vec3D a) const

Subtracts another vector.

Subtracts vector from itself

Parameters
[in]avector to be subtracted
Returns
resulting vector

Definition at line 83 of file Vector.cc.

References Vec3D(), X, Y, and Z.

84  {
85  return Vec3D(X - a.X, Y - a.Y, Z - a.Z);
86 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D & Vec3D::operator-= ( const Vec3D a)

Subtracts another vector.

Subtracts a vector from itself

Parameters
[in]avector to be subtracted
Returns
(reference to) itself, i.e. resulting vector

Definition at line 126 of file Vector.cc.

References X, Y, and Z.

127 {
128  X -= a.X;
129  Y -= a.Y;
130  Z -= a.Z;
131  return *this;
132 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::operator/ ( const Mdouble  a) const

Divides by a scalar.

Divides each element by a scalar

Parameters
[in]athe scalar to be divided by
Returns
resulting vector

Definition at line 103 of file Vector.cc.

References Vec3D(), X, Y, and Z.

104  {
105  return Vec3D(X / a, Y / a, Z / a);
106 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D & Vec3D::operator/= ( const Mdouble  a)

Divides by a scalar.

Divides each element by a scalar

Parameters
[in]ascalar to be divided by
Returns
(reference to) itself, i.e. resulting vector

Definition at line 152 of file Vector.cc.

References X, Y, and Z.

153 {
154  X /= a;
155  Y /= a;
156  Z /= a;
157  return *this;
158 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
void Vec3D::setComponent ( const int  index,
const double  val 
)

Sets the requested component of this Vec3D to the requested value.

Sets the element of the vector belonging to the first argument (index) to the value given in the second argument (val).

Parameters
[in]indexindex of element of interest,
[in]valvalue to be set

Definition at line 332 of file Vector.cc.

References ERROR, logger, X, Y, and Z.

333 {
334  switch (index)
335  {
336  case 0:
337  X = val;
338  break;
339  case 1:
340  Y = val;
341  break;
342  case 2:
343  Z = val;
344  break;
345  default:
346  logger(ERROR, "[Vector::setComponent] Index = %, which is too high for a 3D vector (should be 0-2).", index);
347  }
348 }
Mdouble X
the vector components
Definition: Vector.h:52
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
void Vec3D::setLength ( Mdouble  length)

Make this Vec3D a certain length.

Sets the length of the vector to a given scalar (while maintaining the direction).

Parameters
[in]lengththe length to be set

Definition at line 230 of file Vector.cc.

References normalize().

231 {
232  this->normalize();
233  *this *= length;
234 }
void normalize()
Makes this Vec3D unit length.
Definition: Vector.cc:214
void Vec3D::setZero ( )
Vec3D Vec3D::sqrt ( const Vec3D a)
static

Calculates the pointwise square root of a Vec3D.

Calculates the pointwise square root of a given vector. NB: this is a STATIC function!

Parameters
[in]athe vector to be pointwise square rooted
Returns
the resulting vector, of which each element is the square root of the equivalent element of the argument.

Definition at line 243 of file Vector.cc.

References Vec3D(), X, Y, and Z.

244 {
245  return Vec3D(std::sqrt(a.X), std::sqrt(a.Y), std::sqrt(a.Z));
246 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::square ( const Vec3D a)
static

Calculates the pointwise square of a Vec3D.

Calculates the pointwise square of the vector. NB: this is a STATIC function!

Parameters
[in]athe vector to be squared.
Returns
the resulting vector, of which each element is the square of the equivalent element of the argument.

Definition at line 205 of file Vector.cc.

References Vec3D(), X, Y, and Z.

206 {
207  return Vec3D(a.X * a.X, a.Y * a.Y, a.Z * a.Z);
208 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52

Friends And Related Function Documentation

Vec3D operator* ( const Mdouble  a,
const Vec3D b 
)
friend

Multiplies all elements by a scalar.

Multiplies each element of a given vector (b) by a given scalar (a). NB: this is a global function and a friend of the Vec3D class. Gets called when a scalar multiplication of the form (Mdouble) * (Vec3D) is performed.

Parameters
[in]athe scalar
[in]bthe vector
Returns
the resulting vector

Definition at line 483 of file Vector.cc.

484 {
485  return Vec3D(b.X * a, b.Y * a, b.Z * a);
486 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D operator- ( const Vec3D a)
friend

Adds a scalar to a vector.

Subtracts the elements of a vector from a scalar

Subtracts a vector

Returns the negative of a given vector. NB: this is a global function and a friend of the Vec3D class. Gets called when a negation operation of the form - (Vec3D) is performed.

Parameters
[in]athe vector to be negated
Returns
the negated vector

Definition at line 470 of file Vector.cc.

471 {
472  return Vec3D(-a.X, -a.Y, -a.Z);
473 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
std::ostream& operator<< ( std::ostream &  os,
const Vec3D a 
)
friend

Adds elements to an output stream.

Adds all elements of the vector to an output stream. NB: this is a global function and a friend of the Vec3D class!

Parameters
[in]osthe output stream,
[in]aThe vector of interest
Returns
the output stream with vector elements added

Definition at line 444 of file Vector.cc.

445 {
446  os << a.X << ' ' << a.Y << ' ' << a.Z;
447  return os;
448 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
std::istream& operator>> ( std::istream &  is,
Vec3D a 
)
friend

Adds elements to an input stream.

Reads all elements of a given vector from an input stream. NB: this is a global function and a friend of the Vec3D class!

Parameters
[in,out]isthe input stream
[in,out]athe vector to be read in
Returns
the input stream from which the vector elements were read

Definition at line 457 of file Vector.cc.

458 {
459  is >> a.X >> a.Y >> a.Z;
460  return is;
461 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52

Member Data Documentation

Mdouble Vec3D::X

the vector components

Definition at line 52 of file Vector.h.

Referenced by ChuteWithHopper::addHopper(), CircularPeriodicBoundary::checkBoundaryAfterParticleMoved(), Chute::cleanChute(), AxisymmetricIntersectionOfWalls::convertLimits(), Chute::createBottom(), CircularPeriodicBoundary::createPeriodicParticles(), InfiniteWall::createVTK(), Matrix3D::cross(), cross(), dot(), Matrix3D::dyadic(), ChuteInsertionBoundary::generateParticle(), CubeInsertionBoundary::generateParticle(), getComponent(), getCylindricalCoordinates(), BaseParticle::getDisplacement2(), Screw::getDistanceAndNormal(), CylindricalWall::getDistanceAndNormal(), Coil::getDistanceAndNormal(), AxisymmetricIntersectionOfWalls::getDistanceAndNormal(), InfiniteWallWithHole::getDistanceAndNormal(), getDistanceSquared(), getFromCylindricalCoordinates(), InfiniteWallWithHole::getHoleDistance(), ShearBoxBoundary::getHorizontalDistance(), LeesEdwardsBoundary::getHorizontalDistance(), getLengthSquared(), Screw::getTriangulation(), Mercury2D::hGridFindOneSidedContacts(), Mercury3D::hGridFindOneSidedContacts(), Mercury2D::hGridHasParticleContacts(), Mercury3D::hGridUpdateParticle(), Mercury2D::hGridUpdateParticle(), Quarternion::integrate(), mathsFunc::isEqual(), isZero(), max(), min(), Matrix3D::operator*(), operator*(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator/(), operator/=(), operator<<(), operator>>(), Quarternion::Quarternion(), DPMBase::readNextDataFile(), ParticleHandler::readOldObject(), TriangulatedWall::readVTK(), CircularPeriodicBoundary::rotateParticle(), MatrixSymmetric3D::selfDyadic(), AngledPeriodicBoundary::set(), setComponent(), DPMBase::setMax(), DPMBase::setMin(), ChuteBottom::setupInitialConditions(), setZero(), sqrt(), square(), MatrixSymmetric3D::symmetrisedDyadic(), Vec3D(), and AxisymmetricIntersectionOfWalls::writeVTK().

Mdouble Vec3D::Y

Definition at line 52 of file Vector.h.

Referenced by CircularPeriodicBoundary::checkBoundaryAfterParticleMoved(), AxisymmetricIntersectionOfWalls::convertLimits(), Chute::createBottom(), CircularPeriodicBoundary::createPeriodicParticles(), InfiniteWall::createVTK(), Matrix3D::cross(), cross(), dot(), Matrix3D::dyadic(), ChuteInsertionBoundary::generateParticle(), CubeInsertionBoundary::generateParticle(), getComponent(), getCylindricalCoordinates(), BaseParticle::getDisplacement2(), Screw::getDistanceAndNormal(), CylindricalWall::getDistanceAndNormal(), Coil::getDistanceAndNormal(), InfiniteWallWithHole::getDistanceAndNormal(), getDistanceSquared(), getFromCylindricalCoordinates(), InfiniteWallWithHole::getHoleDistance(), getLengthSquared(), Screw::getTriangulation(), LeesEdwardsBoundary::getVerticalDistance(), ShearBoxBoundary::getVerticalDistance(), Mercury2D::hGridFindOneSidedContacts(), Mercury3D::hGridFindOneSidedContacts(), Mercury2D::hGridHasParticleContacts(), Mercury2D::hGridUpdateParticle(), Mercury3D::hGridUpdateParticle(), Quarternion::integrate(), mathsFunc::isEqual(), isZero(), max(), min(), Matrix3D::operator*(), operator*(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator/(), operator/=(), operator<<(), operator>>(), Quarternion::Quarternion(), DPMBase::readNextDataFile(), ParticleHandler::readOldObject(), TriangulatedWall::readVTK(), CircularPeriodicBoundary::rotateParticle(), MatrixSymmetric3D::selfDyadic(), AngledPeriodicBoundary::set(), setComponent(), DPMBase::setMax(), DPMBase::setMin(), ChuteBottom::setupInitialConditions(), setZero(), sqrt(), square(), MatrixSymmetric3D::symmetrisedDyadic(), Vec3D(), and AxisymmetricIntersectionOfWalls::writeVTK().

Mdouble Vec3D::Z

Definition at line 52 of file Vector.h.

Referenced by ChuteWithHopper::addHopper(), AxisymmetricIntersectionOfWalls::convertLimits(), InfiniteWall::createVTK(), Matrix3D::cross(), cross(), dot(), Matrix3D::dyadic(), ChuteInsertionBoundary::generateParticle(), CubeInsertionBoundary::generateParticle(), getComponent(), getCylindricalCoordinates(), BaseParticle::getDisplacement2(), Screw::getDistanceAndNormal(), CylindricalWall::getDistanceAndNormal(), Coil::getDistanceAndNormal(), AxisymmetricIntersectionOfWalls::getDistanceAndNormal(), InfiniteWallWithHole::getDistanceAndNormal(), getDistanceSquared(), getFromCylindricalCoordinates(), getLengthSquared(), Screw::getTriangulation(), Mercury3D::hGridFindOneSidedContacts(), Mercury3D::hGridUpdateParticle(), Quarternion::integrate(), mathsFunc::isEqual(), isZero(), max(), min(), Matrix3D::operator*(), operator*(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator/(), operator/=(), operator<<(), operator>>(), Quarternion::Quarternion(), DPMBase::readNextDataFile(), ParticleHandler::readOldObject(), TriangulatedWall::readVTK(), CircularPeriodicBoundary::rotateParticle(), MatrixSymmetric3D::selfDyadic(), AngledPeriodicBoundary::set(), setComponent(), DPMBase::setMax(), DPMBase::setMin(), ChuteBottom::setupInitialConditions(), setZero(), ShearBoxBoundary::shiftHorizontalPosition(), sqrt(), square(), MatrixSymmetric3D::symmetrisedDyadic(), Vec3D(), and AxisymmetricIntersectionOfWalls::writeVTK().


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