ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Atom.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/Atom.cpp (file contents):
Revision 599 by mmeineke, Mon Jul 14 21:48:43 2003 UTC vs.
Revision 1136 by tim, Tue Apr 27 16:26:44 2004 UTC

# Line 2 | Line 2 | using namespace std;
2  
3   using namespace std;
4  
5 + #include "simError.h"
6   #include "Atom.hpp"
7  
8 < double* Atom::pos; // the position array
8 < double* Atom::vel; // the velocity array
9 < double* Atom::frc; // the forc array
10 < double* Atom::trq; // the torque vector  ( space fixed )
11 < double* Atom::Amat; // the rotation matrix
12 < double* Atom::mu;   // the array of dipole moments
13 < double* Atom::ul;   // the lab frame unit directional vector
14 < int Atom::nElements;
8 > Atom::Atom(int theIndex, SimState* theConfig) {
9  
10 < Atom::Atom(int theIndex) {
11 <  c_n_hyd = 0;
10 >  objType = OT_ATOM;
11 >  myConfig = theConfig;
12 >  hasCoords = false;
13 >
14    has_dipole = 0;
15 <  is_VDW = 0;
20 <  is_LJ = 0;
15 >  has_charge = 0;
16    
17    index = theIndex;
18 <  offset = 3 * index;
18 >  offset = 0;
19    offsetX = offset;
20    offsetY = offset+1;
21    offsetZ = offset+2;
22    
23 <  Axx = index*9;
23 >  Axx = 0;
24    Axy = Axx+1;
25    Axz = Axx+2;
26    
# Line 38 | Line 33 | void Atom::createArrays (int the_nElements) {
33    Azz = Axx+8;
34   }
35  
36 < void Atom::createArrays (int the_nElements) {
37 <  int i;
43 <  
44 <  nElements = the_nElements;
45 <
46 <  pos = new double[nElements*3];
47 <  vel = new double[nElements*3];
48 <  frc = new double[nElements*3];
49 <  trq = new double[nElements*3];
50 <  Amat = new double[nElements*9];
51 <  mu = new double[nElements];
52 <  ul = new double[nElements*3];
53 <  
54 <  // init directional values to zero
55 <  
56 <  for( i=0; i<nElements; i++){
57 <    trq[i] = 0.0;
58 <    trq[i+1] = 0.0;
59 <    trq[i+2] = 0.0;
60 <    
61 <    Amat[i] = 1.0;
62 <    Amat[i+1] = 0.0;
63 <    Amat[i+2] = 0.0;
64 <    
65 <    Amat[i+3] = 0.0;
66 <    Amat[i+4] = 1.0;
67 <    Amat[i+5] = 0.0;
68 <    
69 <    Amat[i+6] = 0.0;
70 <    Amat[i+7] = 0.0;
71 <    Amat[i+8] = 1.0;
72 <    
73 <    mu[i] = 0.0;    
74 <    
75 <    ul[i] = 1.0;
76 <    ul[i+1] = 0.0;
77 <    ul[i+2] = 0.0;
78 <  }
36 > void Atom::setIndex(int theIndex) {
37 >  index = theIndex;
38   }
39  
40 < void Atom::destroyArrays(void) {
82 <  delete[] pos;
83 <  delete[] vel;
84 <  delete[] frc;
85 <  delete[] trq;
86 <  delete[] Amat;
87 <  delete[] mu;
88 < }
40 > void Atom::setCoords(void){
41  
42 < void Atom::setIndex(int theIndex) {
43 <  index = theIndex;
44 <  offset = index*3;
45 <  offsetX = offset;
46 <  offsetY = offset+1;
47 <  offsetZ = offset+2;
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 <  Axx = index*9;
98 <  Axy = Axx+1;
99 <  Axz = Axx+2;
63 >  hasCoords = true;
64    
101  Ayx = Axx+3;
102  Ayy = Axx+4;
103  Ayz = Axx+5;
104  
105  Azx = Axx+6;
106  Azy = Axx+7;
107  Azz = Axx+8;
65   }
66  
67 < void Atom::addAtoms(int nAdded, double* Apos, double* Avel, double* Afrc,
111 <                   double* Atrq, double* AAmat, double* Amu,
112 <                   double* Aul) {
113 <
114 <  int nNew = nElements+nAdded;
115 <
116 <  double* new_pos = new double[nNew*3];
117 <  double* new_vel = new double[nNew*3];
118 <  double* new_frc = new double[nNew*3];
119 <  double* new_trq = new double[nNew*3];
120 <  double* new_Amat = new double[nNew*9];
121 <  double* new_mu = new double[nNew];
122 <  double* new_ul = new double[nNew*3];
123 <  int i, j;
67 > void Atom::getPos( double theP[3] ){
68    
69 <  for (i = 0; i < 3*nElements; i++) {
70 <    new_pos[i] = pos[i];
71 <    new_vel[i] = vel[i];
72 <    new_frc[i] = frc[i];
129 <    new_trq[i] = trq[i];
130 <    new_ul[i] = ul[i];
69 >  if( hasCoords ){
70 >    theP[0] = pos[offsetX];
71 >    theP[1] = pos[offsetY];
72 >    theP[2] = pos[offsetZ];
73    }
74 +  else{
75  
76 <  for(i = 0; i < 3*nAdded; i++) {
77 <    j = i + 3*nElements;
78 <    new_pos[j] = Apos[i];
79 <    new_vel[j] = Avel[i];
80 <    new_frc[j] = Afrc[i];
138 <    new_trq[j] = Atrq[i];
139 <    new_ul[j] = Aul[i];
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 <  for (i = 0; i < 9*nElements; i++) {
143 <    new_Amat[i] = Amat[i];
144 <  }
84 > void Atom::setPos( double theP[3] ){
85  
86 <  for(i = 0; i < 9*nAdded; i++) {
87 <    j = i + 9*nElements;
88 <    new_Amat[j] = AAmat[i];
86 >  if( hasCoords ){
87 >    pos[offsetX] = theP[0];
88 >    pos[offsetY] = theP[1];
89 >    pos[offsetZ] = theP[2];
90    }
91 +  else{
92  
93 <  for (i = 0; i < nElements; i++) {
94 <    new_mu[i] = mu[i];
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 <  for(i = 0; i < nAdded; i++) {
102 <    j = i + nElements;
103 <    new_mu[j] = Amu[i];
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  
160  delete[] pos;
161  delete[] vel;
162  delete[] frc;
163  delete[] trq;
164  delete[] Amat;
165  delete[] mu;
166
167  pos = new_pos;
168  vel = new_vel;
169  frc = new_frc;
170  trq = new_trq;
171  ul = new_ul;
172  Amat = new_Amat;
173  mu = new_mu;
174
175  nElements = nNew;
117   }
118  
119 < void Atom::deleteAtom(int theIndex) {
179 <  deleteRange(theIndex, theIndex);
180 < }
181 <
182 < void Atom::deleteRange(int startIndex, int stopIndex) {
183 <
184 <  int nNew = nElements-(stopIndex-startIndex+1);
185 <
186 <  double* new_pos = new double[nNew*3];
187 <  double* new_vel = new double[nNew*3];
188 <  double* new_frc = new double[nNew*3];
189 <  double* new_trq = new double[nNew*3];
190 <  double* new_Amat = new double[nNew*9];
191 <  double* new_mu = new double[nNew];
192 <  double* new_ul = new double[nNew*3];
193 <  int i, j;
119 > void Atom::setVel( double theV[3] ){
120    
121 <  for (i = 0; i < 3*startIndex; i++) {
122 <    new_pos[i] = pos[i];
123 <    new_vel[i] = vel[i];
124 <    new_frc[i] = frc[i];
199 <    new_trq[i] = trq[i];
200 <    new_ul[i] = ul[i];
121 >  if( hasCoords ){
122 >    vel[offsetX] = theV[0];
123 >    vel[offsetY] = theV[1];
124 >    vel[offsetZ] = theV[2];
125    }
126 <
127 <  for(i = 3*(stopIndex + 1); i < 3*nElements; i++) {
128 <    j = i - 3*startIndex + 1;
129 <    new_pos[j] = pos[i];
130 <    new_vel[j] = vel[i];
131 <    new_frc[j] = frc[i];
132 <    new_trq[j] = trq[i];
209 <    new_ul[j] = ul[i];
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 <  for (i = 0; i < 9*startIndex; i++) {
137 <    new_Amat[i] = Amat[i];
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 <
144 <  for(i = 9*(stopIndex + 1); i < 9*nElements; i++) {
145 <    j = i - 9*startIndex + 1;
146 <    new_Amat[j] = Amat[i];
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 <  for (i = 0; i < startIndex; i++) {
154 <    new_mu[i] = mu[i];
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 <
161 <  for(i = (stopIndex+1); i < nElements; i++) {
162 <    j = i - startIndex + 1;
163 <    new_mu[j] = mu[i];
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    }
229
230  delete[] pos;
231  delete[] vel;
232  delete[] frc;
233  delete[] trq;
234  delete[] Amat;
235  delete[] mu;
236
237  pos = new_pos;
238  vel = new_vel;
239  frc = new_frc;
240  trq = new_trq;
241  ul = new_ul;
242  Amat = new_Amat;
243  mu = new_mu;
244
245  nElements = nNew;
168   }
169  
170  
171 < void Atom::getPos( double theP[3] ){
171 > void Atom::zeroForces( void ){
172    
173 <  theP[0] = pos[offsetX];
174 <  theP[1] = pos[offsetY];
175 <  theP[2] = pos[offsetZ];
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::setPos( double theP[3] ){
257 <  
258 <  pos[offsetX] = theP[0];
259 <  pos[offsetY] = theP[1];
260 <  pos[offsetZ] = theP[2];
261 < }
188 > void Atom::getRc(double theRc[3]){
189  
190 < void Atom::getVel( double theV[3] ){
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    
265  theV[0] = vel[offsetX];
266  theV[1] = vel[offsetY];
267  theV[2] = vel[offsetZ];
204   }
205  
206 < void Atom::setVel( double theV[3] ){
207 <  
208 <  vel[offsetX] = theV[0];
209 <  vel[offsetY] = theV[1];
210 <  vel[offsetZ] = theV[2];
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   }
276
277 void Atom::getFrc( double theF[3] ){
278  
279  theF[0] = frc[offsetX];
280  theF[1] = frc[offsetY];
281  theF[2] = frc[offsetZ];
282 }
283
284 void Atom::addFrc( double theF[3] ){
285  
286  frc[offsetX] += theF[0];
287  frc[offsetY] += theF[1];
288  frc[offsetZ] += theF[2];
289 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines