n2p2 - A neural network potential package
nnp::Vec3D Struct Reference

Vector in 3 dimensional real space. More...

#include <Vec3D.h>

Collaboration diagram for nnp::Vec3D:

Public Member Functions

 Vec3D ()
 Constructor, initializes to zero. More...
 
 Vec3D (double x, double y, double z)
 Constructor, with initialization of coordinates. More...
 
 Vec3D (Vec3D const &source)
 Copy constructor. More...
 
 Vec3D (Vec3D &&source)
 Move constructor. More...
 
Vec3Doperator= (Vec3D const &rhs)
 Overload = operator. More...
 
Vec3Doperator+= (Vec3D const &v)
 Overload += operator to implement in-place vector addition. More...
 
Vec3Doperator-= (Vec3D const &v)
 Overload -= operator to implement in-place vector subtraction. More...
 
Vec3Doperator*= (double const a)
 Overload *= operator to implement multiplication with scalar. More...
 
Vec3Doperator/= (double const a)
 Overload /= operator to implement division by scalar. More...
 
double operator* (Vec3D const &v) const
 Overload * operator to implement scalar product. More...
 
Vec3Doperator*= (Vec3D const (&A)[3])
 Overload * operator to implement (left) multiplication with a matrix defined as Vec3D A[3]. More...
 
double & operator[] (std::size_t const index)
 Overload [] operator to return coordinate by index. More...
 
double const & operator[] (std::size_t const index) const
 Overload [] operator to return coordinate by index (const version). More...
 
bool operator== (Vec3D const &rhs) const
 Compare if vectors are equal. More...
 
bool operator!= (Vec3D const &rhs) const
 Compare if vectors are not equal. More...
 
double norm () const
 Calculate norm of vector. More...
 
double norm2 () const
 Calculate square of norm of vector. More...
 
double l1norm () const
 Calculate l1 norm of vector (taxicab metric). More...
 
Vec3Dnormalize ()
 Normalize vector, norm equals 1.0 afterwards. More...
 
Vec3D cross (Vec3D const &v) const
 Cross product, argument vector is second in product. More...
 

Public Attributes

double r [3]
 cartesian coordinates. More...
 

Detailed Description

Vector in 3 dimensional real space.

Definition at line 29 of file Vec3D.h.

Constructor & Destructor Documentation

◆ Vec3D() [1/4]

nnp::Vec3D::Vec3D ( )
inline

Constructor, initializes to zero.

Definition at line 168 of file Vec3D.h.

169{
170 r[0] = 0.0;
171 r[1] = 0.0;
172 r[2] = 0.0;
173}
double r[3]
cartesian coordinates.
Definition: Vec3D.h:32

References r.

◆ Vec3D() [2/4]

nnp::Vec3D::Vec3D ( double  x,
double  y,
double  z 
)
inline

Constructor, with initialization of coordinates.

Definition at line 175 of file Vec3D.h.

176{
177 r[0] = x;
178 r[1] = y;
179 r[2] = z;
180}

References r.

◆ Vec3D() [3/4]

nnp::Vec3D::Vec3D ( Vec3D const &  source)
inline

Copy constructor.

Definition at line 182 of file Vec3D.h.

183{
184 r[0] = source.r[0];
185 r[1] = source.r[1];
186 r[2] = source.r[2];
187}

References r.

◆ Vec3D() [4/4]

nnp::Vec3D::Vec3D ( Vec3D &&  source)
inline

Move constructor.

Definition at line 189 of file Vec3D.h.

190{
191 r[0] = std::move(source.r[0]);
192 r[1] = std::move(source.r[1]);
193 r[2] = std::move(source.r[2]);
194}

References r.

Member Function Documentation

◆ operator=()

Vec3D & nnp::Vec3D::operator= ( Vec3D const &  rhs)
inline

Overload = operator.

Returns
Vector with copied data.

Definition at line 196 of file Vec3D.h.

197{
198 r[0] = rhs.r[0];
199 r[1] = rhs.r[1];
200 r[2] = rhs.r[2];
201
202 return *this;
203}

References r.

◆ operator+=()

Vec3D & nnp::Vec3D::operator+= ( Vec3D const &  v)
inline

Overload += operator to implement in-place vector addition.

Returns
Replace original vector with sum of two vectors.

Definition at line 205 of file Vec3D.h.

206{
207 r[0] += rhs.r[0];
208 r[1] += rhs.r[1];
209 r[2] += rhs.r[2];
210
211 return *this;
212}

References r.

◆ operator-=()

Vec3D & nnp::Vec3D::operator-= ( Vec3D const &  v)
inline

Overload -= operator to implement in-place vector subtraction.

Returns
Replace original vector with original minus given.

Definition at line 214 of file Vec3D.h.

215{
216 r[0] -= rhs.r[0];
217 r[1] -= rhs.r[1];
218 r[2] -= rhs.r[2];
219
220 return *this;
221}

References r.

◆ operator*=() [1/2]

Vec3D & nnp::Vec3D::operator*= ( double const  a)
inline

Overload *= operator to implement multiplication with scalar.

Returns
Original vector multiplied with scalar.

Definition at line 223 of file Vec3D.h.

224{
225 r[0] *= a;
226 r[1] *= a;
227 r[2] *= a;
228
229 return *this;
230}

References r.

◆ operator/=()

Vec3D & nnp::Vec3D::operator/= ( double const  a)
inline

Overload /= operator to implement division by scalar.

Returns
Original vector divided by scalar.

Definition at line 246 of file Vec3D.h.

247{
248 *this *= 1.0 / a;
249
250 return *this;
251}

◆ operator*()

double nnp::Vec3D::operator* ( Vec3D const &  v) const
inline

Overload * operator to implement scalar product.

Returns
Scalar product of two vectors.

Definition at line 253 of file Vec3D.h.

254{
255 return r[0] * v.r[0] + r[1] * v.r[1] + r[2] * v.r[2];
256}

References r.

◆ operator*=() [2/2]

Vec3D & nnp::Vec3D::operator*= ( Vec3D const (&)  A[3])
inline

Overload * operator to implement (left) multiplication with a matrix defined as Vec3D A[3].

By convention A[i][j] gives the element of j-th row and i-th column.

Returns
Original vector multiplied with a matrix.

Definition at line 232 of file Vec3D.h.

233{
234 Vec3D w;
235 for (size_t i=0; i<3; ++i)
236 {
237 for (size_t j=0; j<3; ++j)
238 {
239 w.r[i] += A[j][i] * r[j];
240 }
241 }
242 *this = w;
243 return *this;
244}
Vec3D()
Constructor, initializes to zero.
Definition: Vec3D.h:168

References r.

◆ operator[]() [1/2]

double & nnp::Vec3D::operator[] ( std::size_t const  index)
inline

Overload [] operator to return coordinate by index.

Returns
x,y or z when index is 0, 1 or 2, respectively.

Definition at line 260 of file Vec3D.h.

261{
262 if (index < 3) return r[index];
263 else
264 {
265 throw std::runtime_error("ERROR: 3D vector has only three"
266 " components.\n");
267 }
268}

References r.

◆ operator[]() [2/2]

double const & nnp::Vec3D::operator[] ( std::size_t const  index) const
inline

Overload [] operator to return coordinate by index (const version).

Returns
x,y or z when index is 0, 1 or 2, respectively.

Definition at line 271 of file Vec3D.h.

272{
273 if (index < 3) return r[index];
274 else
275 {
276 throw std::runtime_error("ERROR: 3D vector has only three"
277 " components.\n");
278 }
279}

References r.

◆ operator==()

bool nnp::Vec3D::operator== ( Vec3D const &  rhs) const
inline

Compare if vectors are equal.

Returns
True if all components are equal, false else.

Definition at line 281 of file Vec3D.h.

282{
283 if (r[0] != rhs.r[0]) return false;
284 if (r[1] != rhs.r[1]) return false;
285 if (r[2] != rhs.r[2]) return false;
286 return true;
287}

References r.

◆ operator!=()

bool nnp::Vec3D::operator!= ( Vec3D const &  rhs) const
inline

Compare if vectors are not equal.

Returns
False if all components are equal, false else.

Definition at line 289 of file Vec3D.h.

290{
291 return !(*this == rhs);
292}

◆ norm()

double nnp::Vec3D::norm ( ) const
inline

Calculate norm of vector.

Returns
Norm of vector.

Definition at line 294 of file Vec3D.h.

295{
296 return sqrt(r[0] * r[0] + r[1] * r[1] + r[2] * r[2]);
297}

References r.

Referenced by nnp::Structure::calculateNeighborList(), main(), and normalize().

Here is the caller graph for this function:

◆ norm2()

double nnp::Vec3D::norm2 ( ) const
inline

Calculate square of norm of vector.

Returns
Square of norm of vector.

Definition at line 299 of file Vec3D.h.

300{
301 return r[0] * r[0] + r[1] * r[1] + r[2] * r[2];
302}

References r.

Referenced by nnp::SymFncCompAngn::calculate(), nnp::SymFncCompAngnWeighted::calculate(), nnp::SymFncExpAngn::calculate(), nnp::SymFncExpAngnWeighted::calculate(), nnp::Structure::calculateNeighborList(), and nnp::KspaceGrid::setup().

Here is the caller graph for this function:

◆ l1norm()

double nnp::Vec3D::l1norm ( ) const
inline

Calculate l1 norm of vector (taxicab metric).

Returns
L1-norm of vector.

Definition at line 304 of file Vec3D.h.

305{
306 return fabs(r[0]) + fabs(r[1]) + fabs(r[2]);
307}

References r.

◆ normalize()

Vec3D & nnp::Vec3D::normalize ( )
inline

Normalize vector, norm equals 1.0 afterwards.

Definition at line 309 of file Vec3D.h.

310{
311 double n = norm();
312 r[0] /= n;
313 r[1] /= n;
314 r[2] /= n;
315
316 return *this;
317}
double norm() const
Calculate norm of vector.
Definition: Vec3D.h:294

References norm(), and r.

Referenced by nnp::KspaceGrid::calculatePbcCopies(), nnp::Structure::calculatePbcCopies(), and nnp::Structure::canMinimumImageConventionBeApplied().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cross()

Vec3D nnp::Vec3D::cross ( Vec3D const &  v) const
inline

Cross product, argument vector is second in product.

Returns
Cross product of two vectors.

Definition at line 319 of file Vec3D.h.

320{
321 Vec3D w;
322
323 w.r[0] = r[1] * v.r[2] - r[2] * v.r[1];
324 w.r[1] = r[2] * v.r[0] - r[0] * v.r[2];
325 w.r[2] = r[0] * v.r[1] - r[1] * v.r[0];
326
327 return w;
328}

References r.

Referenced by nnp::KspaceGrid::calculatePbcCopies(), nnp::Structure::calculatePbcCopies(), nnp::Structure::canMinimumImageConventionBeApplied(), and nnp::KspaceGrid::setup().

Here is the caller graph for this function:

Member Data Documentation

◆ r


The documentation for this struct was generated from the following file: