ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Atom.cpp
Revision: 999
Committed: Fri Jan 30 15:01:09 2004 UTC (20 years, 5 months ago) by chrisfen
File size: 6369 byte(s)
Log Message:
Substantial changes. OOPSE now has a working WATER.cpp forcefield and parser.
This involved changes to WATER.cpp and ForceFields amoung other files. One important
note: a hardwiring of LJ_rcut was made in calc_LJ_FF.F90. This will be removed on
the next commit...

File Contents

# Content
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 myConfig = theConfig;
11 hasCoords = false;
12
13 c_n_hyd = 0;
14 has_dipole = 0;
15 is_VDW = 0;
16 is_LJ = 0;
17 is_charged = 0;
18
19 index = theIndex;
20 offset = 0;
21 offsetX = offset;
22 offsetY = offset+1;
23 offsetZ = offset+2;
24
25 Axx = 0;
26 Axy = Axx+1;
27 Axz = Axx+2;
28
29 Ayx = Axx+3;
30 Ayy = Axx+4;
31 Ayz = Axx+5;
32
33 Azx = Axx+6;
34 Azy = Axx+7;
35 Azz = Axx+8;
36 }
37
38 void Atom::setIndex(int theIndex) {
39 index = theIndex;
40 }
41
42 void Atom::setCoords(void){
43
44 if( myConfig->isAllocated() ){
45
46
47 myConfig->getAtomPointers( index,
48 &pos,
49 &vel,
50 &frc,
51 &trq,
52 &Amat,
53 &mu,
54 &ul );
55 }
56 else{
57 sprintf( painCave.errMsg,
58 "Attempted to set Atom %d coordinates with an unallocated "
59 "SimState object.\n", index );
60 painCave.isFatal = 1;
61 simError();
62 }
63
64 hasCoords = true;
65
66 }
67
68 // void Atom::addAtoms(int nAdded, double* Apos, double* Avel, double* Afrc,
69 // double* Atrq, double* AAmat, double* Amu,
70 // double* Aul) {
71
72 // int nNew = nElements+nAdded;
73
74 // double* new_pos = new double[nNew*3];
75 // double* new_vel = new double[nNew*3];
76 // double* new_frc = new double[nNew*3];
77 // double* new_trq = new double[nNew*3];
78 // double* new_Amat = new double[nNew*9];
79 // double* new_mu = new double[nNew];
80 // double* new_ul = new double[nNew*3];
81 // int i, j;
82
83 // for (i = 0; i < 3*nElements; i++) {
84 // new_pos[i] = pos[i];
85 // new_vel[i] = vel[i];
86 // new_frc[i] = frc[i];
87 // new_trq[i] = trq[i];
88 // new_ul[i] = ul[i];
89 // }
90
91 // for(i = 0; i < 3*nAdded; i++) {
92 // j = i + 3*nElements;
93 // new_pos[j] = Apos[i];
94 // new_vel[j] = Avel[i];
95 // new_frc[j] = Afrc[i];
96 // new_trq[j] = Atrq[i];
97 // new_ul[j] = Aul[i];
98 // }
99
100 // for (i = 0; i < 9*nElements; i++) {
101 // new_Amat[i] = Amat[i];
102 // }
103
104 // for(i = 0; i < 9*nAdded; i++) {
105 // j = i + 9*nElements;
106 // new_Amat[j] = AAmat[i];
107 // }
108
109 // for (i = 0; i < nElements; i++) {
110 // new_mu[i] = mu[i];
111 // }
112
113 // for(i = 0; i < nAdded; i++) {
114 // j = i + nElements;
115 // new_mu[j] = Amu[i];
116 // }
117
118 // delete[] pos;
119 // delete[] vel;
120 // delete[] frc;
121 // delete[] trq;
122 // delete[] Amat;
123 // delete[] mu;
124
125 // pos = new_pos;
126 // vel = new_vel;
127 // frc = new_frc;
128 // trq = new_trq;
129 // ul = new_ul;
130 // Amat = new_Amat;
131 // mu = new_mu;
132
133 // nElements = nNew;
134 // }
135
136 // void Atom::deleteAtom(int theIndex) {
137 // deleteRange(theIndex, theIndex);
138 // }
139
140 // void Atom::deleteRange(int startIndex, int stopIndex) {
141
142 // int nNew = nElements-(stopIndex-startIndex+1);
143
144 // double* new_pos = new double[nNew*3];
145 // double* new_vel = new double[nNew*3];
146 // double* new_frc = new double[nNew*3];
147 // double* new_trq = new double[nNew*3];
148 // double* new_Amat = new double[nNew*9];
149 // double* new_mu = new double[nNew];
150 // double* new_ul = new double[nNew*3];
151 // int i, j;
152
153 // for (i = 0; i < 3*startIndex; i++) {
154 // new_pos[i] = pos[i];
155 // new_vel[i] = vel[i];
156 // new_frc[i] = frc[i];
157 // new_trq[i] = trq[i];
158 // new_ul[i] = ul[i];
159 // }
160
161 // for(i = 3*(stopIndex + 1); i < 3*nElements; i++) {
162 // j = i - 3*startIndex + 1;
163 // new_pos[j] = pos[i];
164 // new_vel[j] = vel[i];
165 // new_frc[j] = frc[i];
166 // new_trq[j] = trq[i];
167 // new_ul[j] = ul[i];
168 // }
169
170 // for (i = 0; i < 9*startIndex; i++) {
171 // new_Amat[i] = Amat[i];
172 // }
173
174 // for(i = 9*(stopIndex + 1); i < 9*nElements; i++) {
175 // j = i - 9*startIndex + 1;
176 // new_Amat[j] = Amat[i];
177 // }
178
179 // for (i = 0; i < startIndex; i++) {
180 // new_mu[i] = mu[i];
181 // }
182
183 // for(i = (stopIndex+1); i < nElements; i++) {
184 // j = i - startIndex + 1;
185 // new_mu[j] = mu[i];
186 // }
187
188 // delete[] pos;
189 // delete[] vel;
190 // delete[] frc;
191 // delete[] trq;
192 // delete[] Amat;
193 // delete[] mu;
194
195 // pos = new_pos;
196 // vel = new_vel;
197 // frc = new_frc;
198 // trq = new_trq;
199 // ul = new_ul;
200 // Amat = new_Amat;
201 // mu = new_mu;
202
203 // nElements = nNew;
204 // }
205
206
207 void Atom::getPos( double theP[3] ){
208
209 if( hasCoords ){
210 theP[0] = pos[offsetX];
211 theP[1] = pos[offsetY];
212 theP[2] = pos[offsetZ];
213 }
214 else{
215
216 sprintf( painCave.errMsg,
217 "Attempt to get Pos for atom %d before coords set.\n",
218 index );
219 painCave.isFatal = 1;
220 simError();
221 }
222 }
223
224 void Atom::setPos( double theP[3] ){
225
226 if( hasCoords ){
227 pos[offsetX] = theP[0];
228 pos[offsetY] = theP[1];
229 pos[offsetZ] = theP[2];
230 }
231 else{
232
233 sprintf( painCave.errMsg,
234 "Attempt to set Pos for atom %d before coords set.\n",
235 index );
236 painCave.isFatal = 1;
237 simError();
238 }
239 }
240
241 void Atom::getVel( double theV[3] ){
242
243 if( hasCoords ){
244 theV[0] = vel[offsetX];
245 theV[1] = vel[offsetY];
246 theV[2] = vel[offsetZ];
247 }
248 else{
249
250 sprintf( painCave.errMsg,
251 "Attempt to get vel for atom %d before coords set.\n",
252 index );
253 painCave.isFatal = 1;
254 simError();
255 }
256
257 }
258
259 void Atom::setVel( double theV[3] ){
260
261 if( hasCoords ){
262 vel[offsetX] = theV[0];
263 vel[offsetY] = theV[1];
264 vel[offsetZ] = theV[2];
265 }
266 else{
267
268 sprintf( painCave.errMsg,
269 "Attempt to set vel for atom %d before coords set.\n",
270 index );
271 painCave.isFatal = 1;
272 simError();
273 }
274 }
275
276 void Atom::getFrc( double theF[3] ){
277
278 if( hasCoords ){
279 theF[0] = frc[offsetX];
280 theF[1] = frc[offsetY];
281 theF[2] = frc[offsetZ];
282 }
283 else{
284
285 sprintf( painCave.errMsg,
286 "Attempt to get frc for atom %d before coords set.\n",
287 index );
288 painCave.isFatal = 1;
289 simError();
290 }
291 }
292
293 void Atom::addFrc( double theF[3] ){
294
295 if( hasCoords ){
296 frc[offsetX] += theF[0];
297 frc[offsetY] += theF[1];
298 frc[offsetZ] += theF[2];
299 }
300 else{
301
302 sprintf( painCave.errMsg,
303 "Attempt to add frc for atom %d before coords set.\n",
304 index );
305 painCave.isFatal = 1;
306 simError();
307 }
308 }
309
310
311 void GeneralAtom::zeroForces( void ){
312
313
314 if( hasCoords ){
315 frc[offsetX] = 0.0;
316 frc[offsetY] = 0.0;
317 frc[offsetZ] = 0.0;
318 }
319 else{
320
321 sprintf( painCave.errMsg,
322 "Attempt to zero frc for atom %d before coords set.\n",
323 index );
324 painCave.isFatal = 1;
325 simError();
326 }
327 }