eOn client
Long-timescale dynamics: aKMC, NEB, parallel replica
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
Vec.h
Go to the documentation of this file.
1
#ifndef __VEC_H__
2
#define __VEC_H__
3
4
#include <iostream>
5
using
std::istream;
6
using
std::ostream;
7
// class istream;
8
// class ostream;
9
11
17
18
class
Vec
{
19
public
:
21
Vec
() {};
23
Vec
(
double
x0,
double
x1,
double
x2);
25
double
operator*
(
const
Vec
&v)
const
;
27
Vec
operator*
(
const
double
&s)
const
;
29
Vec
operator+
(
const
Vec
&v)
const
;
31
Vec
operator-
(
const
Vec
&v)
const
;
33
Vec
operator-
()
const
;
35
Vec
&
operator+=
(
const
Vec
&v);
37
Vec
&
operator-=
(
const
Vec
&v);
39
Vec
&
operator*=
(
double
s);
41
Vec
&
operator/=
(
double
s);
43
double
operator[]
(
int
n)
const
;
45
double
&
operator[]
(
int
n);
47
friend
Vec
Cross
(
const
Vec
&v1,
const
Vec
&v2);
49
friend
double
Length2
(
const
Vec
&v);
51
friend
void
Vaxpy
(
double
a,
const
Vec
&
x
,
Vec
&y);
53
friend
ostream &
operator<<
(ostream &out,
const
Vec
&v);
55
friend
istream &
operator>>
(istream &in,
Vec
&v);
56
57
public
:
58
double
x
[3];
59
};
60
61
inline
Vec::Vec
(
double
x0,
double
x1,
double
x2) {
62
x
[0] = x0;
63
x
[1] = x1;
64
x
[2] = x2;
65
}
66
67
inline
double
Vec::operator*
(
const
Vec
&v)
const
{
68
return
x
[0] * v.
x
[0] +
x
[1] * v.
x
[1] +
x
[2] * v.
x
[2];
69
}
70
71
inline
Vec
Vec::operator*
(
const
double
&s)
const
{
72
return
Vec
(s *
x
[0], s *
x
[1], s *
x
[2]);
73
}
74
75
inline
Vec
Vec::operator+
(
const
Vec
&v)
const
{
76
return
Vec
(
x
[0] + v.
x
[0],
x
[1] + v.
x
[1],
x
[2] + v.
x
[2]);
77
}
78
79
inline
Vec
Vec::operator-
(
const
Vec
&v)
const
{
80
return
Vec
(
x
[0] - v.
x
[0],
x
[1] - v.
x
[1],
x
[2] - v.
x
[2]);
81
}
82
83
inline
Vec
Vec::operator-
()
const
{
return
Vec
(-
x
[0], -
x
[1], -
x
[2]); }
84
85
inline
Vec
&
Vec::operator+=
(
const
Vec
&v) {
86
x
[0] += v.
x
[0];
87
x
[1] += v.
x
[1];
88
x
[2] += v.
x
[2];
89
return
*
this
;
90
}
91
92
inline
Vec
&
Vec::operator-=
(
const
Vec
&v) {
93
x
[0] -= v.
x
[0];
94
x
[1] -= v.
x
[1];
95
x
[2] -= v.
x
[2];
96
return
*
this
;
97
}
98
99
inline
Vec
&
Vec::operator*=
(
double
s) {
100
x
[0] *= s;
101
x
[1] *= s;
102
x
[2] *= s;
103
return
*
this
;
104
}
105
106
inline
Vec
&
Vec::operator/=
(
double
s) {
107
x
[0] /= s;
108
x
[1] /= s;
109
x
[2] /= s;
110
return
*
this
;
111
}
112
113
inline
double
Vec::operator[]
(
int
n)
const
{
return
x
[n]; }
114
115
inline
double
&
Vec::operator[]
(
int
n) {
return
x
[n]; }
116
117
inline
Vec
Cross
(
const
Vec
&v1,
const
Vec
&v2) {
118
return
Vec
(v1.
x
[1] * v2.
x
[2] - v1.
x
[2] * v2.
x
[1],
119
v1.
x
[2] * v2.
x
[0] - v1.
x
[0] * v2.
x
[2],
120
v1.
x
[0] * v2.
x
[1] - v1.
x
[1] * v2.
x
[0]);
121
}
122
123
inline
void
Vaxpy
(
double
a,
const
Vec
&
x
,
Vec
&y) {
124
y.
x
[0] += a *
x
.x[0];
125
y.
x
[1] += a *
x
.x[1];
126
y.
x
[2] += a *
x
.x[2];
127
}
128
129
inline
double
Length2
(
const
Vec
&v) {
130
return
v.
x
[0] * v.
x
[0] + v.
x
[1] * v.
x
[1] + v.
x
[2] * v.
x
[2];
131
}
132
133
#endif
// __VEC_H__
Length2
double Length2(const Vec &v)
Definition
Vec.h:129
Vaxpy
void Vaxpy(double a, const Vec &x, Vec &y)
Definition
Vec.h:123
Cross
Vec Cross(const Vec &v1, const Vec &v2)
Definition
Vec.h:117
Vec
A 3-vector useful for postions etc.
Definition
Vec.h:18
Vec::Length2
friend double Length2(const Vec &v)
The length of a Vec.
Definition
Vec.h:129
Vec::operator-=
Vec & operator-=(const Vec &v)
Subtract a vec from this one.
Definition
Vec.h:92
Vec::operator+
Vec operator+(const Vec &v) const
Add two Vecs.
Definition
Vec.h:75
Vec::operator<<
friend ostream & operator<<(ostream &out, const Vec &v)
Print a Vec.
Vec::Vaxpy
friend void Vaxpy(double a, const Vec &x, Vec &y)
Increment y with a times x.
Definition
Vec.h:123
Vec::operator*=
Vec & operator*=(double s)
Multiply this vec with a scalar.
Definition
Vec.h:99
Vec::Cross
friend Vec Cross(const Vec &v1, const Vec &v2)
Cross product of two Vecs.
Definition
Vec.h:117
Vec::operator-
Vec operator-() const
Unary minus.
Definition
Vec.h:83
Vec::operator/=
Vec & operator/=(double s)
Divide this Vec with a scalar.
Definition
Vec.h:106
Vec::operator+=
Vec & operator+=(const Vec &v)
Add a Vec to this one.
Definition
Vec.h:85
Vec::operator>>
friend istream & operator>>(istream &in, Vec &v)
Read a Vec.
Vec::operator[]
double operator[](int n) const
const indexing
Definition
Vec.h:113
Vec::operator*
double operator*(const Vec &v) const
Dot product.
Definition
Vec.h:67
Vec::Vec
Vec()
Dummy constructor needed by STL containers.
Definition
Vec.h:21
Vec::x
double x[3]
The actual data.
Definition
Vec.h:58
include
eon
potentials
EMT
Asap
Vec.h
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf