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 561 by mmeineke, Fri Jun 20 20:29:36 2003 UTC vs.
Revision 1126 by tim, Tue Apr 20 05:39:38 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 >  }
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 <  Axx = index*9;
98 <  Axy = Axx+1;
99 <  Axz = Axx+2;
61 >  hasCoords = true;
62    
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;
63   }
64  
65 < 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;
65 > void Atom::getPos( double theP[3] ){
66    
67 <  for (i = 0; i < 3*nElements; i++) {
68 <    new_pos[i] = pos[i];
69 <    new_vel[i] = vel[i];
70 <    new_frc[i] = frc[i];
129 <    new_trq[i] = trq[i];
130 <    new_ul[i] = ul[i];
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 < 3*nAdded; i++) {
75 <    j = i + 3*nElements;
76 <    new_pos[j] = Apos[i];
77 <    new_vel[j] = Avel[i];
78 <    new_frc[j] = Afrc[i];
138 <    new_trq[j] = Atrq[i];
139 <    new_ul[j] = Aul[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 < 9*nElements; i++) {
143 <    new_Amat[i] = Amat[i];
144 <  }
82 > void Atom::setPos( double theP[3] ){
83  
84 <  for(i = 0; i < 9*nAdded; i++) {
85 <    j = i + 9*nElements;
86 <    new_Amat[j] = AAmat[i];
84 >  if( hasCoords ){
85 >    pos[offsetX] = theP[0];
86 >    pos[offsetY] = theP[1];
87 >    pos[offsetZ] = theP[2];
88    }
89 +  else{
90  
91 <  for (i = 0; i < nElements; i++) {
92 <    new_mu[i] = mu[i];
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 <  for(i = 0; i < nAdded; i++) {
100 <    j = i + nElements;
101 <    new_mu[j] = Amu[i];
99 > void Atom::getVel( double theV[3] ){
100 >  
101 >  if( hasCoords ){
102 >    theV[0] = vel[offsetX];
103 >    theV[1] = vel[offsetY];
104 >    theV[2] = vel[offsetZ];
105    }
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  
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;
115   }
116  
117 < 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;
117 > void Atom::setVel( double theV[3] ){
118    
119 <  for (i = 0; i < 3*startIndex; i++) {
120 <    new_pos[i] = pos[i];
121 <    new_vel[i] = vel[i];
122 <    new_frc[i] = frc[i];
199 <    new_trq[i] = trq[i];
200 <    new_ul[i] = ul[i];
119 >  if( hasCoords ){
120 >    vel[offsetX] = theV[0];
121 >    vel[offsetY] = theV[1];
122 >    vel[offsetZ] = theV[2];
123    }
124 <
125 <  for(i = 3*(stopIndex + 1); i < 3*nElements; i++) {
126 <    j = i - 3*startIndex + 1;
127 <    new_pos[j] = pos[i];
128 <    new_vel[j] = vel[i];
129 <    new_frc[j] = frc[i];
130 <    new_trq[j] = trq[i];
209 <    new_ul[j] = ul[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    }
132 + }
133  
134 <  for (i = 0; i < 9*startIndex; i++) {
135 <    new_Amat[i] = Amat[i];
134 > void Atom::getFrc( double theF[3] ){
135 >  
136 >  if( hasCoords ){
137 >    theF[0] = frc[offsetX];
138 >    theF[1] = frc[offsetY];
139 >    theF[2] = frc[offsetZ];
140    }
141 <
142 <  for(i = 9*(stopIndex + 1); i < 9*nElements; i++) {
143 <    j = i - 9*startIndex + 1;
144 <    new_Amat[j] = Amat[i];
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 <  for (i = 0; i < startIndex; i++) {
152 <    new_mu[i] = mu[i];
151 > void Atom::addFrc( double theF[3] ){
152 >  
153 >  if( hasCoords ){
154 >    frc[offsetX] += theF[0];
155 >    frc[offsetY] += theF[1];
156 >    frc[offsetZ] += theF[2];
157    }
158 <
159 <  for(i = (stopIndex+1); i < nElements; i++) {
160 <    j = i - startIndex + 1;
161 <    new_mu[j] = mu[i];
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  
230  delete[] pos;
231  delete[] vel;
232  delete[] frc;
233  delete[] trq;
234  delete[] Amat;
235  delete[] mu;
168  
169 <  pos = new_pos;
170 <  vel = new_vel;
171 <  frc = new_frc;
172 <  trq = new_trq;
173 <  ul = new_ul;
174 <  Amat = new_Amat;
175 <  mu = new_mu;
176 <
177 <  nElements = nNew;
169 > void Atom::zeroForces( void ){
170 >  
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 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines