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 1452 by tim, Mon Aug 23 15:11:36 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 | Atom::Atom(int theIndex) {
33    Azz = Axx+8;
34   }
35  
41 void Atom::createArrays (int the_nElements) {
42  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  }
79 }
80
81 void Atom::destroyArrays(void) {
82  delete[] pos;
83  delete[] vel;
84  delete[] frc;
85  delete[] trq;
86  delete[] Amat;
87  delete[] mu;
88 }
89
36   void Atom::setIndex(int theIndex) {
37    index = theIndex;
92  offset = index*3;
93  offsetX = offset;
94  offsetY = offset+1;
95  offsetZ = offset+2;
96  
97  Axx = index*9;
98  Axy = Axx+1;
99  Axz = Axx+2;
100  
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;
38   }
39  
40 < void Atom::addAtoms(int nAdded, double* Apos, double* Avel, double* Afrc,
111 <                   double* Atrq, double* AAmat, double* Amu,
112 <                   double* Aul) {
40 > void Atom::setCoords(void){
41  
42 <  int nNew = nElements+nAdded;
42 >  if( myConfig->isAllocated() ){
43  
44 <  double* new_pos = new double[nNew*3];
45 <  double* new_vel = new double[nNew*3];
46 <  double* new_frc = new double[nNew*3];
47 <  double* new_trq = new double[nNew*3];
48 <  double* new_Amat = new double[nNew*9];
49 <  double* new_mu = new double[nNew];
50 <  double* new_ul = new double[nNew*3];
51 <  int i, j;
52 <  
125 <  for (i = 0; i < 3*nElements; i++) {
126 <    new_pos[i] = pos[i];
127 <    new_vel[i] = vel[i];
128 <    new_frc[i] = frc[i];
129 <    new_trq[i] = trq[i];
130 <    new_ul[i] = ul[i];
44 >    myConfig->getAtomPointers( index,
45 >                     &pos,
46 >                     &vel,
47 >                     &frc,
48 >                     &trq,
49 >                     &Amat,
50 >                     &mu,  
51 >                     &ul,
52 >                     &quat);
53    }
54 <
55 <  for(i = 0; i < 3*nAdded; i++) {
56 <    j = i + 3*nElements;
57 <    new_pos[j] = Apos[i];
58 <    new_vel[j] = Avel[i];
59 <    new_frc[j] = Afrc[i];
138 <    new_trq[j] = Atrq[i];
139 <    new_ul[j] = Aul[i];
54 >  else{
55 >    sprintf( painCave.errMsg,
56 >             "Attempted to set Atom %d  coordinates with an unallocated "
57 >             "SimState object.\n", index );
58 >    painCave.isFatal = 1;
59 >    simError();
60    }
61 +  
62 +  hasCoords = true;
63 +  
64 + }
65  
66 <  for (i = 0; i < 9*nElements; i++) {
67 <    new_Amat[i] = Amat[i];
66 > void Atom::getPos( double theP[3] ){
67 >  
68 >  if( hasCoords ){
69 >    theP[0] = pos[offsetX];
70 >    theP[1] = pos[offsetY];
71 >    theP[2] = pos[offsetZ];
72    }
73 +  else{
74  
75 <  for(i = 0; i < 9*nAdded; i++) {
76 <    j = i + 9*nElements;
77 <    new_Amat[j] = AAmat[i];
75 >    sprintf( painCave.errMsg,
76 >             "Attempt to get Pos for atom %d before coords set.\n",
77 >             index );
78 >    painCave.isFatal = 1;
79 >    simError();
80    }
81 + }
82  
83 <  for (i = 0; i < nElements; i++) {
152 <    new_mu[i] = mu[i];
153 <  }
83 > void Atom::setPos( double theP[3] ){
84  
85 <  for(i = 0; i < nAdded; i++) {
86 <    j = i + nElements;
87 <    new_mu[j] = Amu[i];
85 >  if( hasCoords ){
86 >    pos[offsetX] = theP[0];
87 >    pos[offsetY] = theP[1];
88 >    pos[offsetZ] = theP[2];
89    }
90 +  else{
91  
92 <  delete[] pos;
93 <  delete[] vel;
94 <  delete[] frc;
95 <  delete[] trq;
96 <  delete[] Amat;
97 <  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;
92 >    sprintf( painCave.errMsg,
93 >             "Attempt to set Pos for atom %d before coords set.\n",
94 >             index );
95 >    painCave.isFatal = 1;
96 >    simError();
97 >  }
98   }
99  
100 < 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;
100 > void Atom::getVel( double theV[3] ){
101    
102 <  for (i = 0; i < 3*startIndex; i++) {
103 <    new_pos[i] = pos[i];
104 <    new_vel[i] = vel[i];
105 <    new_frc[i] = frc[i];
199 <    new_trq[i] = trq[i];
200 <    new_ul[i] = ul[i];
102 >  if( hasCoords ){
103 >    theV[0] = vel[offsetX];
104 >    theV[1] = vel[offsetY];
105 >    theV[2] = vel[offsetZ];
106    }
107 <
108 <  for(i = 3*(stopIndex + 1); i < 3*nElements; i++) {
109 <    j = i - 3*startIndex + 1;
110 <    new_pos[j] = pos[i];
111 <    new_vel[j] = vel[i];
112 <    new_frc[j] = frc[i];
113 <    new_trq[j] = trq[i];
209 <    new_ul[j] = ul[i];
107 >  else{
108 >    
109 >    sprintf( painCave.errMsg,
110 >             "Attempt to get vel for atom %d before coords set.\n",
111 >             index );
112 >    painCave.isFatal = 1;
113 >    simError();
114    }
115  
116 <  for (i = 0; i < 9*startIndex; i++) {
213 <    new_Amat[i] = Amat[i];
214 <  }
116 > }
117  
118 <  for(i = 9*(stopIndex + 1); i < 9*nElements; i++) {
119 <    j = i - 9*startIndex + 1;
120 <    new_Amat[j] = Amat[i];
118 > void Atom::setVel( double theV[3] ){
119 >  
120 >  if( hasCoords ){
121 >    vel[offsetX] = theV[0];
122 >    vel[offsetY] = theV[1];
123 >    vel[offsetZ] = theV[2];
124    }
125 <
126 <  for (i = 0; i < startIndex; i++) {
127 <    new_mu[i] = mu[i];
125 >  else{
126 >    
127 >    sprintf( painCave.errMsg,
128 >             "Attempt to set vel for atom %d before coords set.\n",
129 >             index );
130 >    painCave.isFatal = 1;
131 >    simError();
132    }
224
225  for(i = (stopIndex+1); i < nElements; i++) {
226    j = i - startIndex + 1;
227    new_mu[j] = mu[i];
228  }
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;
133   }
134  
135 <
249 < void Atom::getPos( double theP[3] ){
135 > void Atom::getFrc( double theF[3] ){
136    
137 <  theP[0] = pos[offsetX];
138 <  theP[1] = pos[offsetY];
139 <  theP[2] = pos[offsetZ];
137 >  if( hasCoords ){
138 >    theF[0] = frc[offsetX];
139 >    theF[1] = frc[offsetY];
140 >    theF[2] = frc[offsetZ];
141 >  }
142 >  else{
143 >    
144 >    sprintf( painCave.errMsg,
145 >             "Attempt to get frc for atom %d before coords set.\n",
146 >             index );
147 >    painCave.isFatal = 1;
148 >    simError();
149 >  }
150   }
151  
152 < void Atom::setPos( double theP[3] ){
152 > void Atom::setFrc( double theF[3] ){
153    
154 <  pos[offsetX] = theP[0];
155 <  pos[offsetY] = theP[1];
156 <  pos[offsetZ] = theP[2];
154 >  if( hasCoords ){
155 >    frc[offsetX] = theF[0];
156 >    frc[offsetY] = theF[1];
157 >    frc[offsetZ] = theF[2];
158 >  }
159 >  else{
160 >    
161 >    sprintf( painCave.errMsg,
162 >             "Attempt to set frc for atom %d before coords set.\n",
163 >             index );
164 >    painCave.isFatal = 1;
165 >    simError();
166 >  }
167   }
168  
169 < void Atom::getVel( double theV[3] ){
169 > void Atom::addFrc( double theF[3] ){
170    
171 <  theV[0] = vel[offsetX];
172 <  theV[1] = vel[offsetY];
173 <  theV[2] = vel[offsetZ];
171 >  if( hasCoords ){
172 >    frc[offsetX] += theF[0];
173 >    frc[offsetY] += theF[1];
174 >    frc[offsetZ] += theF[2];
175 >  }
176 >  else{
177 >    
178 >    sprintf( painCave.errMsg,
179 >             "Attempt to add frc for atom %d before coords set.\n",
180 >             index );
181 >    painCave.isFatal = 1;
182 >    simError();
183 >  }
184   }
185  
270 void Atom::setVel( double theV[3] ){
271  
272  vel[offsetX] = theV[0];
273  vel[offsetY] = theV[1];
274  vel[offsetZ] = theV[2];
275 }
186  
187 < void Atom::getFrc( double theF[3] ){
187 > void Atom::zeroForces( void ){
188    
189 <  theF[0] = frc[offsetX];
190 <  theF[1] = frc[offsetY];
191 <  theF[2] = frc[offsetZ];
189 >  if( hasCoords ){
190 >    frc[offsetX] = 0.0;
191 >    frc[offsetY] = 0.0;
192 >    frc[offsetZ] = 0.0;
193 >  }
194 >  else{
195 >    
196 >    sprintf( painCave.errMsg,
197 >             "Attempt to zero frc for atom %d before coords set.\n",
198 >             index );
199 >    painCave.isFatal = 1;
200 >    simError();
201 >  }
202   }
203  
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