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...
 
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...
 
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 28 of file Vec3D.h.

Constructor & Destructor Documentation

◆ Vec3D() [1/3]

nnp::Vec3D::Vec3D ( )
inline

Constructor, initializes to zero.

Definition at line 152 of file Vec3D.h.

153{
154 r[0] = 0.0;
155 r[1] = 0.0;
156 r[2] = 0.0;
157}
double r[3]
cartesian coordinates.
Definition: Vec3D.h:31

References r.

◆ Vec3D() [2/3]

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

Constructor, with initialization of coordinates.

Definition at line 159 of file Vec3D.h.

160{
161 r[0] = x;
162 r[1] = y;
163 r[2] = z;
164}

References r.

◆ Vec3D() [3/3]

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

Copy constructor.

Definition at line 166 of file Vec3D.h.

167{
168 r[0] = source.r[0];
169 r[1] = source.r[1];
170 r[2] = source.r[2];
171}

References r.

Member Function Documentation

◆ operator=()

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

Overload = operator.

Returns
Vector with copied data.

Definition at line 173 of file Vec3D.h.

174{
175 r[0] = rhs.r[0];
176 r[1] = rhs.r[1];
177 r[2] = rhs.r[2];
178
179 return *this;
180}

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 182 of file Vec3D.h.

183{
184 r[0] += rhs.r[0];
185 r[1] += rhs.r[1];
186 r[2] += rhs.r[2];
187
188 return *this;
189}

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 191 of file Vec3D.h.

192{
193 r[0] -= rhs.r[0];
194 r[1] -= rhs.r[1];
195 r[2] -= rhs.r[2];
196
197 return *this;
198}

References r.

◆ operator*=()

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

Overload *= operator to implement multiplication with scalar.

Returns
Original vector multiplied with scalar.

Definition at line 200 of file Vec3D.h.

201{
202 r[0] *= a;
203 r[1] *= a;
204 r[2] *= a;
205
206 return *this;
207}

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 209 of file Vec3D.h.

210{
211 *this *= 1.0 / a;
212
213 return *this;
214}

◆ 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 216 of file Vec3D.h.

217{
218 return r[0] * v.r[0] + r[1] * v.r[1] + r[2] * v.r[2];
219}

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 222 of file Vec3D.h.

223{
224 if (index < 3) return r[index];
225 else
226 {
227 throw std::runtime_error("ERROR: 3D vector has only three"
228 " components.\n");
229 }
230}

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 233 of file Vec3D.h.

234{
235 if (index < 3) return r[index];
236 else
237 {
238 throw std::runtime_error("ERROR: 3D vector has only three"
239 " components.\n");
240 }
241}

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 243 of file Vec3D.h.

244{
245 if (r[0] != rhs.r[0]) return false;
246 if (r[1] != rhs.r[1]) return false;
247 if (r[2] != rhs.r[2]) return false;
248 return true;
249}

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 251 of file Vec3D.h.

252{
253 return !(*this == rhs);
254}

◆ norm()

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

Calculate norm of vector.

Returns
Norm of vector.

Definition at line 256 of file Vec3D.h.

257{
258 return sqrt(r[0] * r[0] + r[1] * r[1] + r[2] * r[2]);
259}

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 261 of file Vec3D.h.

262{
263 return r[0] * r[0] + r[1] * r[1] + r[2] * r[2];
264}

References r.

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

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 266 of file Vec3D.h.

267{
268 return fabs(r[0]) + fabs(r[1]) + fabs(r[2]);
269}

References r.

◆ normalize()

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

Normalize vector, norm equals 1.0 afterwards.

Definition at line 271 of file Vec3D.h.

272{
273 double n = norm();
274 r[0] /= n;
275 r[1] /= n;
276 r[2] /= n;
277
278 return *this;
279}
double norm() const
Calculate norm of vector.
Definition: Vec3D.h:256

References norm(), and r.

Referenced by nnp::Structure::calculatePbcCopies().

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 281 of file Vec3D.h.

282{
283 Vec3D w;
284
285 w.r[0] = r[1] * v.r[2] - r[2] * v.r[1];
286 w.r[1] = r[2] * v.r[0] - r[0] * v.r[2];
287 w.r[2] = r[0] * v.r[1] - r[1] * v.r[0];
288
289 return w;
290}
Vec3D()
Constructor, initializes to zero.
Definition: Vec3D.h:152

References r.

Referenced by nnp::Structure::calculatePbcCopies().

Here is the caller graph for this function:

Member Data Documentation

◆ r


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