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 1125 by gezelter, Mon Apr 19 22:13:01 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  
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;
124 <  
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    }
53 <
54 <  for(i = 0; i < 3*nAdded; i++) {
55 <    j = i + 3*nElements;
56 <    new_pos[j] = Apos[i];
57 <    new_vel[j] = Avel[i];
58 <    new_frc[j] = Afrc[i];
138 <    new_trq[j] = Atrq[i];
139 <    new_ul[j] = Aul[i];
53 >  else{
54 >    sprintf( painCave.errMsg,
55 >             "Attempted to set Atom %d  coordinates with an unallocated "
56 >             "SimState object.\n", index );
57 >    painCave.isFatal = 1;
58 >    simError();
59    }
60 +  
61 +  hasCoords = true;
62 +  
63 + }
64  
65 <  for (i = 0; i < 9*nElements; i++) {
66 <    new_Amat[i] = Amat[i];
65 > void Atom::getPos( double theP[3] ){
66 >  
67 >  if( hasCoords ){
68 >    theP[0] = pos[offsetX];
69 >    theP[1] = pos[offsetY];
70 >    theP[2] = pos[offsetZ];
71    }
72 +  else{
73  
74 <  for(i = 0; i < 9*nAdded; i++) {
75 <    j = i + 9*nElements;
76 <    new_Amat[j] = AAmat[i];
74 >    sprintf( painCave.errMsg,
75 >             "Attempt to get Pos for atom %d before coords set.\n",
76 >             index );
77 >    painCave.isFatal = 1;
78 >    simError();
79    }
80 + }
81  
82 <  for (i = 0; i < nElements; i++) {
152 <    new_mu[i] = mu[i];
153 <  }
82 > void Atom::setPos( double theP[3] ){
83  
84 <  for(i = 0; i < nAdded; i++) {
85 <    j = i + nElements;
86 <    new_mu[j] = Amu[i];
84 >  if( hasCoords ){
85 >    pos[offsetX] = theP[0];
86 >    pos[offsetY] = theP[1];
87 >    pos[offsetZ] = theP[2];
88    }
89 +  else{
90  
91 <  delete[] pos;
92 <  delete[] vel;
93 <  delete[] frc;
94 <  delete[] trq;
95 <  delete[] Amat;
96 <  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;
91 >    sprintf( painCave.errMsg,
92 >             "Attempt to set Pos for atom %d before coords set.\n",
93 >             index );
94 >    painCave.isFatal = 1;
95 >    simError();
96 >  }
97   }
98  
99 < 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;
99 > void Atom::getVel( double theV[3] ){
100    
101 <  for (i = 0; i < 3*startIndex; i++) {
102 <    new_pos[i] = pos[i];
103 <    new_vel[i] = vel[i];
104 <    new_frc[i] = frc[i];
199 <    new_trq[i] = trq[i];
200 <    new_ul[i] = ul[i];
101 >  if( hasCoords ){
102 >    theV[0] = vel[offsetX];
103 >    theV[1] = vel[offsetY];
104 >    theV[2] = vel[offsetZ];
105    }
106 <
107 <  for(i = 3*(stopIndex + 1); i < 3*nElements; i++) {
108 <    j = i - 3*startIndex + 1;
109 <    new_pos[j] = pos[i];
110 <    new_vel[j] = vel[i];
111 <    new_frc[j] = frc[i];
112 <    new_trq[j] = trq[i];
209 <    new_ul[j] = ul[i];
106 >  else{
107 >    
108 >    sprintf( painCave.errMsg,
109 >             "Attempt to get vel for atom %d before coords set.\n",
110 >             index );
111 >    painCave.isFatal = 1;
112 >    simError();
113    }
114  
115 <  for (i = 0; i < 9*startIndex; i++) {
213 <    new_Amat[i] = Amat[i];
214 <  }
115 > }
116  
117 <  for(i = 9*(stopIndex + 1); i < 9*nElements; i++) {
118 <    j = i - 9*startIndex + 1;
119 <    new_Amat[j] = Amat[i];
117 > void Atom::setVel( double theV[3] ){
118 >  
119 >  if( hasCoords ){
120 >    vel[offsetX] = theV[0];
121 >    vel[offsetY] = theV[1];
122 >    vel[offsetZ] = theV[2];
123    }
124 <
125 <  for (i = 0; i < startIndex; i++) {
126 <    new_mu[i] = mu[i];
124 >  else{
125 >    
126 >    sprintf( painCave.errMsg,
127 >             "Attempt to set vel for atom %d before coords set.\n",
128 >             index );
129 >    painCave.isFatal = 1;
130 >    simError();
131    }
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;
132   }
133  
134 <
249 < void Atom::getPos( double theP[3] ){
134 > void Atom::getFrc( double theF[3] ){
135    
136 <  theP[0] = pos[offsetX];
137 <  theP[1] = pos[offsetY];
138 <  theP[2] = pos[offsetZ];
136 >  if( hasCoords ){
137 >    theF[0] = frc[offsetX];
138 >    theF[1] = frc[offsetY];
139 >    theF[2] = frc[offsetZ];
140 >  }
141 >  else{
142 >    
143 >    sprintf( painCave.errMsg,
144 >             "Attempt to get frc for atom %d before coords set.\n",
145 >             index );
146 >    painCave.isFatal = 1;
147 >    simError();
148 >  }
149   }
150  
151 < void Atom::setPos( double theP[3] ){
151 > void Atom::addFrc( double theF[3] ){
152    
153 <  pos[offsetX] = theP[0];
154 <  pos[offsetY] = theP[1];
155 <  pos[offsetZ] = theP[2];
153 >  if( hasCoords ){
154 >    frc[offsetX] += theF[0];
155 >    frc[offsetY] += theF[1];
156 >    frc[offsetZ] += theF[2];
157 >  }
158 >  else{
159 >    
160 >    sprintf( painCave.errMsg,
161 >             "Attempt to add frc for atom %d before coords set.\n",
162 >             index );
163 >    painCave.isFatal = 1;
164 >    simError();
165 >  }
166   }
167  
263 void Atom::getVel( double theV[3] ){
264  
265  theV[0] = vel[offsetX];
266  theV[1] = vel[offsetY];
267  theV[2] = vel[offsetZ];
268 }
168  
169 < void Atom::setVel( double theV[3] ){
169 > void Atom::zeroForces( void ){
170    
171 <  vel[offsetX] = theV[0];
172 <  vel[offsetY] = theV[1];
173 <  vel[offsetZ] = theV[2];
171 >  if( hasCoords ){
172 >    frc[offsetX] = 0.0;
173 >    frc[offsetY] = 0.0;
174 >    frc[offsetZ] = 0.0;
175 >  }
176 >  else{
177 >    
178 >    sprintf( painCave.errMsg,
179 >             "Attempt to zero frc for atom %d before coords set.\n",
180 >             index );
181 >    painCave.isFatal = 1;
182 >    simError();
183 >  }
184   }
185  
186 < void Atom::getFrc( double theF[3] ){
187 <  
279 <  theF[0] = frc[offsetX];
280 <  theF[1] = frc[offsetY];
281 <  theF[2] = frc[offsetZ];
186 > void Atom::accept(BaseVisitor* v){
187 >  v->visit(this);
188   }
189  
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