ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Atom.cpp
Revision: 787
Committed: Thu Sep 25 19:27:15 2003 UTC (20 years, 9 months ago) by mmeineke
File size: 6351 byte(s)
Log Message:
cleaned things with gcc -Wall and g++ -Wall

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