ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Atom.cpp
Revision: 670
Committed: Thu Aug 7 21:47:18 2003 UTC (20 years, 11 months ago) by mmeineke
File size: 6345 byte(s)
Log Message:
switched SimInfo to use a system configuration from SimState rather than arrays from Atom

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