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 413 by mmeineke, Wed Mar 26 21:54:49 2003 UTC vs.
Revision 1118 by tim, Mon Apr 19 03:52:27 2004 UTC

# Line 1 | Line 1
1 + #include <iostream>
2 +
3 + using namespace std;
4 +
5 + #include "simError.h"
6   #include "Atom.hpp"
7  
8 < double* Atom::pos; // the position array
4 < double* Atom::vel; // the velocity array
5 < double* Atom::frc; // the forc array
6 < double* Atom::trq; // the torque vector  ( space fixed )
7 < double* Atom::Amat; // the rotation matrix
8 < double* Atom::mu;   // the array of dipole moments
9 < double* Atom::ul;   // the lab frame unit directional vector
10 < 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;
16  is_LJ = 0;
15    
16    index = theIndex;
17 <  offset = 3 * index;
17 >  offset = 0;
18    offsetX = offset;
19    offsetY = offset+1;
20    offsetZ = offset+2;
21    
22 <  Axx = index*9;
22 >  Axx = 0;
23    Axy = Axx+1;
24    Axz = Axx+2;
25    
# Line 34 | Line 32 | void Atom::createArrays (int the_nElements) {
32    Azz = Axx+8;
33   }
34  
35 < void Atom::createArrays (int the_nElements) {
36 <  int i;
39 <  
40 <  nElements = the_nElements;
41 <
42 <  pos = new double[nElements*3];
43 <  vel = new double[nElements*3];
44 <  frc = new double[nElements*3];
45 <  trq = new double[nElements*3];
46 <  Amat = new double[nElements*9];
47 <  mu = new double[nElements];
48 <  ul = new double[nElements*3];
49 <  
50 <  // init directional values to zero
51 <  
52 <  for( i=0; i<nElements; i++){
53 <    trq[i] = 0.0;
54 <    trq[i+1] = 0.0;
55 <    trq[i+2] = 0.0;
56 <    
57 <    Amat[i] = 1.0;
58 <    Amat[i+1] = 0.0;
59 <    Amat[i+2] = 0.0;
60 <    
61 <    Amat[i+3] = 0.0;
62 <    Amat[i+4] = 1.0;
63 <    Amat[i+5] = 0.0;
64 <    
65 <    Amat[i+6] = 0.0;
66 <    Amat[i+7] = 0.0;
67 <    Amat[i+8] = 1.0;
68 <    
69 <    mu[i] = 0.0;    
70 <    
71 <    ul[i] = 1.0;
72 <    ul[i+1] = 0.0;
73 <    ul[i+2] = 0.0;
74 <  }
35 > void Atom::setIndex(int theIndex) {
36 >  index = theIndex;
37   }
38  
39 < void Atom::destroyArrays(void) {
78 <  delete[] pos;
79 <  delete[] vel;
80 <  delete[] frc;
81 <  delete[] trq;
82 <  delete[] Amat;
83 <  delete[] mu;
84 < }
39 > void Atom::setCoords(void){
40  
41 < void Atom::setIndex(int theIndex) {
42 <  index = theIndex;
43 <  offset = index*3;
44 <  offsetX = offset;
45 <  offsetY = offset+1;
46 <  offsetZ = offset+2;
41 >  if( myConfig->isAllocated() ){
42 >
43 >    myConfig->getAtomPointers( index,
44 >                     &pos,
45 >                     &vel,
46 >                     &frc,
47 >                     &trq,
48 >                     &Amat,
49 >                     &mu,  
50 >                     &ul );
51 >  }
52 >  else{
53 >    sprintf( painCave.errMsg,
54 >             "Attempted to set Atom %d  coordinates with an unallocated "
55 >             "SimState object.\n", index );
56 >    painCave.isFatal = 1;
57 >    simError();
58 >  }
59    
60 <  Axx = index*9;
94 <  Axy = Axx+1;
95 <  Axz = Axx+2;
60 >  hasCoords = true;
61    
97  Ayx = Axx+3;
98  Ayy = Axx+4;
99  Ayz = Axx+5;
100  
101  Azx = Axx+6;
102  Azy = Axx+7;
103  Azz = Axx+8;
62   }
63  
64 < void Atom::addAtoms(int nAdded, double* Apos, double* Avel, double* Afrc,
107 <                   double* Atrq, double* AAmat, double* Amu,
108 <                   double* Aul) {
109 <
110 <  int nNew = nElements+nAdded;
111 <
112 <  double* new_pos = new double[nNew*3];
113 <  double* new_vel = new double[nNew*3];
114 <  double* new_frc = new double[nNew*3];
115 <  double* new_trq = new double[nNew*3];
116 <  double* new_Amat = new double[nNew*9];
117 <  double* new_mu = new double[nNew];
118 <  double* new_ul = new double[nNew*3];
119 <  int i, j;
64 > void Atom::getPos( double theP[3] ){
65    
66 <  for (i = 0; i < 3*nElements; i++) {
67 <    new_pos[i] = pos[i];
68 <    new_vel[i] = vel[i];
69 <    new_frc[i] = frc[i];
125 <    new_trq[i] = trq[i];
126 <    new_ul[i] = ul[i];
66 >  if( hasCoords ){
67 >    theP[0] = pos[offsetX];
68 >    theP[1] = pos[offsetY];
69 >    theP[2] = pos[offsetZ];
70    }
71 +  else{
72  
73 <  for(i = 0; i < 3*nAdded; i++) {
74 <    j = i + 3*nElements;
75 <    new_pos[j] = Apos[i];
76 <    new_vel[j] = Avel[i];
77 <    new_frc[j] = Afrc[i];
134 <    new_trq[j] = Atrq[i];
135 <    new_ul[j] = Aul[i];
73 >    sprintf( painCave.errMsg,
74 >             "Attempt to get Pos for atom %d before coords set.\n",
75 >             index );
76 >    painCave.isFatal = 1;
77 >    simError();
78    }
79 + }
80  
81 <  for (i = 0; i < 9*nElements; i++) {
139 <    new_Amat[i] = Amat[i];
140 <  }
81 > void Atom::setPos( double theP[3] ){
82  
83 <  for(i = 0; i < 9*nAdded; i++) {
84 <    j = i + 9*nElements;
85 <    new_Amat[j] = AAmat[i];
83 >  if( hasCoords ){
84 >    pos[offsetX] = theP[0];
85 >    pos[offsetY] = theP[1];
86 >    pos[offsetZ] = theP[2];
87    }
88 +  else{
89  
90 <  for (i = 0; i < nElements; i++) {
91 <    new_mu[i] = mu[i];
90 >    sprintf( painCave.errMsg,
91 >             "Attempt to set Pos for atom %d before coords set.\n",
92 >             index );
93 >    painCave.isFatal = 1;
94 >    simError();
95    }
96 + }
97  
98 <  for(i = 0; i < nAdded; i++) {
99 <    j = i + nElements;
100 <    new_mu[j] = Amu[i];
98 > void Atom::getVel( double theV[3] ){
99 >  
100 >  if( hasCoords ){
101 >    theV[0] = vel[offsetX];
102 >    theV[1] = vel[offsetY];
103 >    theV[2] = vel[offsetZ];
104    }
105 +  else{
106 +    
107 +    sprintf( painCave.errMsg,
108 +             "Attempt to get vel for atom %d before coords set.\n",
109 +             index );
110 +    painCave.isFatal = 1;
111 +    simError();
112 +  }
113  
156  delete[] pos;
157  delete[] vel;
158  delete[] frc;
159  delete[] trq;
160  delete[] Amat;
161  delete[] mu;
162
163  pos = new_pos;
164  vel = new_vel;
165  frc = new_frc;
166  trq = new_trq;
167  ul = new_ul;
168  Amat = new_Amat;
169  mu = new_mu;
170
171  nElements = nNew;
114   }
115  
116 < void Atom::deleteAtom(int theIndex) {
117 <  deleteRange(theIndex, theIndex);
116 > void Atom::setVel( double theV[3] ){
117 >  
118 >  if( hasCoords ){
119 >    vel[offsetX] = theV[0];
120 >    vel[offsetY] = theV[1];
121 >    vel[offsetZ] = theV[2];
122 >  }
123 >  else{
124 >    
125 >    sprintf( painCave.errMsg,
126 >             "Attempt to set vel for atom %d before coords set.\n",
127 >             index );
128 >    painCave.isFatal = 1;
129 >    simError();
130 >  }
131   }
132  
133 < void Atom::deleteRange(int startIndex, int stopIndex) {
179 <
180 <  int nNew = nElements-(stopIndex-startIndex+1);
181 <
182 <  double* new_pos = new double[nNew*3];
183 <  double* new_vel = new double[nNew*3];
184 <  double* new_frc = new double[nNew*3];
185 <  double* new_trq = new double[nNew*3];
186 <  double* new_Amat = new double[nNew*9];
187 <  double* new_mu = new double[nNew];
188 <  double* new_ul = new double[nNew*3];
189 <  int i, j;
133 > void Atom::getFrc( double theF[3] ){
134    
135 <  for (i = 0; i < 3*startIndex; i++) {
136 <    new_pos[i] = pos[i];
137 <    new_vel[i] = vel[i];
138 <    new_frc[i] = frc[i];
195 <    new_trq[i] = trq[i];
196 <    new_ul[i] = ul[i];
135 >  if( hasCoords ){
136 >    theF[0] = frc[offsetX];
137 >    theF[1] = frc[offsetY];
138 >    theF[2] = frc[offsetZ];
139    }
140 <
141 <  for(i = 3*(stopIndex + 1); i < 3*nElements; i++) {
142 <    j = i - 3*startIndex + 1;
143 <    new_pos[j] = pos[i];
144 <    new_vel[j] = vel[i];
145 <    new_frc[j] = frc[i];
146 <    new_trq[j] = trq[i];
205 <    new_ul[j] = ul[i];
140 >  else{
141 >    
142 >    sprintf( painCave.errMsg,
143 >             "Attempt to get frc for atom %d before coords set.\n",
144 >             index );
145 >    painCave.isFatal = 1;
146 >    simError();
147    }
148 + }
149  
150 <  for (i = 0; i < 9*startIndex; i++) {
151 <    new_Amat[i] = Amat[i];
150 > void Atom::addFrc( double theF[3] ){
151 >  
152 >  if( hasCoords ){
153 >    frc[offsetX] += theF[0];
154 >    frc[offsetY] += theF[1];
155 >    frc[offsetZ] += theF[2];
156    }
157 <
158 <  for(i = 9*(stopIndex + 1); i < 9*nElements; i++) {
159 <    j = i - 9*startIndex + 1;
160 <    new_Amat[j] = Amat[i];
157 >  else{
158 >    
159 >    sprintf( painCave.errMsg,
160 >             "Attempt to add frc for atom %d before coords set.\n",
161 >             index );
162 >    painCave.isFatal = 1;
163 >    simError();
164    }
165 + }
166  
217  for (i = 0; i < startIndex; i++) {
218    new_mu[i] = mu[i];
219  }
167  
168 <  for(i = (stopIndex+1); i < nElements; i++) {
169 <    j = i - startIndex + 1;
170 <    new_mu[j] = mu[i];
168 > void Atom::zeroForces( void ){
169 >  
170 >  if( hasCoords ){
171 >    frc[offsetX] = 0.0;
172 >    frc[offsetY] = 0.0;
173 >    frc[offsetZ] = 0.0;
174    }
175 +  else{
176 +    
177 +    sprintf( painCave.errMsg,
178 +             "Attempt to zero frc for atom %d before coords set.\n",
179 +             index );
180 +    painCave.isFatal = 1;
181 +    simError();
182 +  }
183 + }
184  
185 <  delete[] pos;
186 <  delete[] vel;
228 <  delete[] frc;
229 <  delete[] trq;
230 <  delete[] Amat;
231 <  delete[] mu;
232 <
233 <  pos = new_pos;
234 <  vel = new_vel;
235 <  frc = new_frc;
236 <  trq = new_trq;
237 <  ul = new_ul;
238 <  Amat = new_Amat;
239 <  mu = new_mu;
240 <
241 <  nElements = nNew;
185 > void Atom::accept(BaseVisitor* v){
186 >  v->visit(this);
187   }
188 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines