1 |
gezelter |
2 |
#include <iostream> |
2 |
|
|
|
3 |
|
|
using namespace std; |
4 |
|
|
|
5 |
tim |
3 |
#include "utils/simError.h" |
6 |
|
|
#include "primitives/Atom.hpp" |
7 |
gezelter |
2 |
|
8 |
|
|
Atom::Atom(int theIndex, SimState* theConfig) { |
9 |
|
|
|
10 |
|
|
objType = OT_ATOM; |
11 |
|
|
myConfig = theConfig; |
12 |
|
|
hasCoords = false; |
13 |
|
|
|
14 |
|
|
has_dipole = 0; |
15 |
|
|
has_charge = 0; |
16 |
|
|
|
17 |
|
|
index = theIndex; |
18 |
|
|
offset = 0; |
19 |
|
|
offsetX = offset; |
20 |
|
|
offsetY = offset+1; |
21 |
|
|
offsetZ = offset+2; |
22 |
|
|
|
23 |
|
|
Axx = 0; |
24 |
|
|
Axy = Axx+1; |
25 |
|
|
Axz = Axx+2; |
26 |
|
|
|
27 |
|
|
Ayx = Axx+3; |
28 |
|
|
Ayy = Axx+4; |
29 |
|
|
Ayz = Axx+5; |
30 |
|
|
|
31 |
|
|
Azx = Axx+6; |
32 |
|
|
Azy = Axx+7; |
33 |
|
|
Azz = Axx+8; |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
void Atom::setIndex(int theIndex) { |
37 |
|
|
index = theIndex; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
void Atom::setCoords(void){ |
41 |
|
|
|
42 |
|
|
if( myConfig->isAllocated() ){ |
43 |
|
|
|
44 |
|
|
myConfig->getAtomPointers( index, |
45 |
|
|
&pos, |
46 |
|
|
&vel, |
47 |
|
|
&frc, |
48 |
|
|
&trq, |
49 |
|
|
&Amat, |
50 |
|
|
&mu, |
51 |
|
|
&ul); |
52 |
|
|
} |
53 |
|
|
else{ |
54 |
|
|
sprintf( painCave.errMsg, |
55 |
|
|
"Attempted to set Atom %d coordinates with an unallocated " |
56 |
|
|
"SimState object.\n", index ); |
57 |
|
|
painCave.isFatal = 1; |
58 |
|
|
simError(); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
hasCoords = true; |
62 |
|
|
|
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
void Atom::getPos( double theP[3] ){ |
66 |
|
|
|
67 |
|
|
if( hasCoords ){ |
68 |
|
|
theP[0] = pos[offsetX]; |
69 |
|
|
theP[1] = pos[offsetY]; |
70 |
|
|
theP[2] = pos[offsetZ]; |
71 |
|
|
} |
72 |
|
|
else{ |
73 |
|
|
|
74 |
|
|
sprintf( painCave.errMsg, |
75 |
|
|
"Attempt to get Pos for atom %d before coords set.\n", |
76 |
|
|
index ); |
77 |
|
|
painCave.isFatal = 1; |
78 |
|
|
simError(); |
79 |
|
|
} |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
void Atom::setPos( double theP[3] ){ |
83 |
|
|
|
84 |
|
|
if( hasCoords ){ |
85 |
|
|
pos[offsetX] = theP[0]; |
86 |
|
|
pos[offsetY] = theP[1]; |
87 |
|
|
pos[offsetZ] = theP[2]; |
88 |
|
|
} |
89 |
|
|
else{ |
90 |
|
|
|
91 |
|
|
sprintf( painCave.errMsg, |
92 |
|
|
"Attempt to set Pos for atom %d before coords set.\n", |
93 |
|
|
index ); |
94 |
|
|
painCave.isFatal = 1; |
95 |
|
|
simError(); |
96 |
|
|
} |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
void Atom::getVel( double theV[3] ){ |
100 |
|
|
|
101 |
|
|
if( hasCoords ){ |
102 |
|
|
theV[0] = vel[offsetX]; |
103 |
|
|
theV[1] = vel[offsetY]; |
104 |
|
|
theV[2] = vel[offsetZ]; |
105 |
|
|
} |
106 |
|
|
else{ |
107 |
|
|
|
108 |
|
|
sprintf( painCave.errMsg, |
109 |
|
|
"Attempt to get vel for atom %d before coords set.\n", |
110 |
|
|
index ); |
111 |
|
|
painCave.isFatal = 1; |
112 |
|
|
simError(); |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
void Atom::setVel( double theV[3] ){ |
118 |
|
|
|
119 |
|
|
if( hasCoords ){ |
120 |
|
|
vel[offsetX] = theV[0]; |
121 |
|
|
vel[offsetY] = theV[1]; |
122 |
|
|
vel[offsetZ] = theV[2]; |
123 |
|
|
} |
124 |
|
|
else{ |
125 |
|
|
|
126 |
|
|
sprintf( painCave.errMsg, |
127 |
|
|
"Attempt to set vel for atom %d before coords set.\n", |
128 |
|
|
index ); |
129 |
|
|
painCave.isFatal = 1; |
130 |
|
|
simError(); |
131 |
|
|
} |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
void Atom::getFrc( double theF[3] ){ |
135 |
|
|
|
136 |
|
|
if( hasCoords ){ |
137 |
|
|
theF[0] = frc[offsetX]; |
138 |
|
|
theF[1] = frc[offsetY]; |
139 |
|
|
theF[2] = frc[offsetZ]; |
140 |
|
|
} |
141 |
|
|
else{ |
142 |
|
|
|
143 |
|
|
sprintf( painCave.errMsg, |
144 |
|
|
"Attempt to get frc for atom %d before coords set.\n", |
145 |
|
|
index ); |
146 |
|
|
painCave.isFatal = 1; |
147 |
|
|
simError(); |
148 |
|
|
} |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
void Atom::addFrc( double theF[3] ){ |
152 |
|
|
|
153 |
|
|
if( hasCoords ){ |
154 |
|
|
frc[offsetX] += theF[0]; |
155 |
|
|
frc[offsetY] += theF[1]; |
156 |
|
|
frc[offsetZ] += theF[2]; |
157 |
|
|
} |
158 |
|
|
else{ |
159 |
|
|
|
160 |
|
|
sprintf( painCave.errMsg, |
161 |
|
|
"Attempt to add frc for atom %d before coords set.\n", |
162 |
|
|
index ); |
163 |
|
|
painCave.isFatal = 1; |
164 |
|
|
simError(); |
165 |
|
|
} |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
|
169 |
|
|
void Atom::zeroForces( void ){ |
170 |
|
|
|
171 |
|
|
if( hasCoords ){ |
172 |
|
|
frc[offsetX] = 0.0; |
173 |
|
|
frc[offsetY] = 0.0; |
174 |
|
|
frc[offsetZ] = 0.0; |
175 |
|
|
} |
176 |
|
|
else{ |
177 |
|
|
|
178 |
|
|
sprintf( painCave.errMsg, |
179 |
|
|
"Attempt to zero frc for atom %d before coords set.\n", |
180 |
|
|
index ); |
181 |
|
|
painCave.isFatal = 1; |
182 |
|
|
simError(); |
183 |
|
|
} |
184 |
|
|
} |
185 |
|
|
|