1 |
#include <iostream> |
2 |
|
3 |
using namespace std; |
4 |
|
5 |
#include "simError.h" |
6 |
#include "Atom.hpp" |
7 |
|
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 |
&rc, |
53 |
&massRatio); |
54 |
} |
55 |
else{ |
56 |
sprintf( painCave.errMsg, |
57 |
"Attempted to set Atom %d coordinates with an unallocated " |
58 |
"SimState object.\n", index ); |
59 |
painCave.isFatal = 1; |
60 |
simError(); |
61 |
} |
62 |
|
63 |
hasCoords = true; |
64 |
|
65 |
} |
66 |
|
67 |
void Atom::getPos( double theP[3] ){ |
68 |
|
69 |
if( hasCoords ){ |
70 |
theP[0] = pos[offsetX]; |
71 |
theP[1] = pos[offsetY]; |
72 |
theP[2] = pos[offsetZ]; |
73 |
} |
74 |
else{ |
75 |
|
76 |
sprintf( painCave.errMsg, |
77 |
"Attempt to get Pos for atom %d before coords set.\n", |
78 |
index ); |
79 |
painCave.isFatal = 1; |
80 |
simError(); |
81 |
} |
82 |
} |
83 |
|
84 |
void Atom::setPos( double theP[3] ){ |
85 |
|
86 |
if( hasCoords ){ |
87 |
pos[offsetX] = theP[0]; |
88 |
pos[offsetY] = theP[1]; |
89 |
pos[offsetZ] = theP[2]; |
90 |
} |
91 |
else{ |
92 |
|
93 |
sprintf( painCave.errMsg, |
94 |
"Attempt to set Pos for atom %d before coords set.\n", |
95 |
index ); |
96 |
painCave.isFatal = 1; |
97 |
simError(); |
98 |
} |
99 |
} |
100 |
|
101 |
void Atom::getVel( double theV[3] ){ |
102 |
|
103 |
if( hasCoords ){ |
104 |
theV[0] = vel[offsetX]; |
105 |
theV[1] = vel[offsetY]; |
106 |
theV[2] = vel[offsetZ]; |
107 |
} |
108 |
else{ |
109 |
|
110 |
sprintf( painCave.errMsg, |
111 |
"Attempt to get vel for atom %d before coords set.\n", |
112 |
index ); |
113 |
painCave.isFatal = 1; |
114 |
simError(); |
115 |
} |
116 |
|
117 |
} |
118 |
|
119 |
void Atom::setVel( double theV[3] ){ |
120 |
|
121 |
if( hasCoords ){ |
122 |
vel[offsetX] = theV[0]; |
123 |
vel[offsetY] = theV[1]; |
124 |
vel[offsetZ] = theV[2]; |
125 |
} |
126 |
else{ |
127 |
|
128 |
sprintf( painCave.errMsg, |
129 |
"Attempt to set vel for atom %d before coords set.\n", |
130 |
index ); |
131 |
painCave.isFatal = 1; |
132 |
simError(); |
133 |
} |
134 |
} |
135 |
|
136 |
void Atom::getFrc( double theF[3] ){ |
137 |
|
138 |
if( hasCoords ){ |
139 |
theF[0] = frc[offsetX]; |
140 |
theF[1] = frc[offsetY]; |
141 |
theF[2] = frc[offsetZ]; |
142 |
} |
143 |
else{ |
144 |
|
145 |
sprintf( painCave.errMsg, |
146 |
"Attempt to get frc for atom %d before coords set.\n", |
147 |
index ); |
148 |
painCave.isFatal = 1; |
149 |
simError(); |
150 |
} |
151 |
} |
152 |
|
153 |
void Atom::addFrc( double theF[3] ){ |
154 |
|
155 |
if( hasCoords ){ |
156 |
frc[offsetX] += theF[0]; |
157 |
frc[offsetY] += theF[1]; |
158 |
frc[offsetZ] += theF[2]; |
159 |
} |
160 |
else{ |
161 |
|
162 |
sprintf( painCave.errMsg, |
163 |
"Attempt to add frc for atom %d before coords set.\n", |
164 |
index ); |
165 |
painCave.isFatal = 1; |
166 |
simError(); |
167 |
} |
168 |
} |
169 |
|
170 |
|
171 |
void Atom::zeroForces( void ){ |
172 |
|
173 |
if( hasCoords ){ |
174 |
frc[offsetX] = 0.0; |
175 |
frc[offsetY] = 0.0; |
176 |
frc[offsetZ] = 0.0; |
177 |
} |
178 |
else{ |
179 |
|
180 |
sprintf( painCave.errMsg, |
181 |
"Attempt to zero frc for atom %d before coords set.\n", |
182 |
index ); |
183 |
painCave.isFatal = 1; |
184 |
simError(); |
185 |
} |
186 |
} |
187 |
|
188 |
void Atom::getRc(double theRc[3]){ |
189 |
|
190 |
if( hasCoords ){ |
191 |
theRc[0] = rc[offsetX]; |
192 |
theRc[1] = rc[offsetY]; |
193 |
theRc[2] = rc[offsetZ]; |
194 |
} |
195 |
else{ |
196 |
|
197 |
sprintf( painCave.errMsg, |
198 |
"Attempt to get rc for atom %d before coords set.\n", |
199 |
index ); |
200 |
painCave.isFatal = 1; |
201 |
simError(); |
202 |
} |
203 |
|
204 |
} |
205 |
|
206 |
void Atom::setRc(double theRc[3]){ |
207 |
if( hasCoords ){ |
208 |
rc[offsetX] = theRc[0] ; |
209 |
rc[offsetY] = theRc[1]; |
210 |
rc[offsetZ] = theRc[2]; |
211 |
} |
212 |
else{ |
213 |
|
214 |
sprintf( painCave.errMsg, |
215 |
"Attempt to set rc for atom %d before coords set.\n", |
216 |
index ); |
217 |
painCave.isFatal = 1; |
218 |
} |
219 |
} |