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 1452 by tim, Mon Aug 23 15:11:36 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 >  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 34 | Line 33 | Atom::Atom(int theIndex) {
33    Azz = Axx+8;
34   }
35  
36 < void Atom::createArrays (int the_nElements) {
37 <  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 <  }
36 > void Atom::setIndex(int theIndex) {
37 >  index = theIndex;
38   }
39  
40 < void Atom::destroyArrays(void) {
78 <  delete[] pos;
79 <  delete[] vel;
80 <  delete[] frc;
81 <  delete[] trq;
82 <  delete[] Amat;
83 <  delete[] mu;
84 < }
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 >                     &quat);
53 >  }
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 <  Axx = index*9;
94 <  Axy = Axx+1;
95 <  Axz = Axx+2;
62 >  hasCoords = true;
63    
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;
64   }
65  
66 < 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;
66 > void Atom::getPos( double theP[3] ){
67    
68 <  for (i = 0; i < 3*nElements; i++) {
69 <    new_pos[i] = pos[i];
70 <    new_vel[i] = vel[i];
71 <    new_frc[i] = frc[i];
125 <    new_trq[i] = trq[i];
126 <    new_ul[i] = ul[i];
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 < 3*nAdded; i++) {
76 <    j = i + 3*nElements;
77 <    new_pos[j] = Apos[i];
78 <    new_vel[j] = Avel[i];
79 <    new_frc[j] = Afrc[i];
134 <    new_trq[j] = Atrq[i];
135 <    new_ul[j] = Aul[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 < 9*nElements; i++) {
139 <    new_Amat[i] = Amat[i];
140 <  }
83 > void Atom::setPos( double theP[3] ){
84  
85 <  for(i = 0; i < 9*nAdded; i++) {
86 <    j = i + 9*nElements;
87 <    new_Amat[j] = AAmat[i];
85 >  if( hasCoords ){
86 >    pos[offsetX] = theP[0];
87 >    pos[offsetY] = theP[1];
88 >    pos[offsetZ] = theP[2];
89    }
90 +  else{
91  
92 <  for (i = 0; i < nElements; i++) {
93 <    new_mu[i] = mu[i];
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 <  for(i = 0; i < nAdded; i++) {
101 <    j = i + nElements;
102 <    new_mu[j] = Amu[i];
100 > void Atom::getVel( double theV[3] ){
101 >  
102 >  if( hasCoords ){
103 >    theV[0] = vel[offsetX];
104 >    theV[1] = vel[offsetY];
105 >    theV[2] = vel[offsetZ];
106    }
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  
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;
116   }
117  
118 < void Atom::deleteAtom(int theIndex) {
119 <  deleteRange(theIndex, theIndex);
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 >  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 >  }
133   }
134  
135 < 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;
135 > void Atom::getFrc( double theF[3] ){
136    
137 <  for (i = 0; i < 3*startIndex; i++) {
138 <    new_pos[i] = pos[i];
139 <    new_vel[i] = vel[i];
140 <    new_frc[i] = frc[i];
195 <    new_trq[i] = trq[i];
196 <    new_ul[i] = ul[i];
137 >  if( hasCoords ){
138 >    theF[0] = frc[offsetX];
139 >    theF[1] = frc[offsetY];
140 >    theF[2] = frc[offsetZ];
141    }
142 <
143 <  for(i = 3*(stopIndex + 1); i < 3*nElements; i++) {
144 <    j = i - 3*startIndex + 1;
145 <    new_pos[j] = pos[i];
146 <    new_vel[j] = vel[i];
147 <    new_frc[j] = frc[i];
148 <    new_trq[j] = trq[i];
205 <    new_ul[j] = ul[i];
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 <  for (i = 0; i < 9*startIndex; i++) {
153 <    new_Amat[i] = Amat[i];
152 > void Atom::setFrc( double theF[3] ){
153 >  
154 >  if( hasCoords ){
155 >    frc[offsetX] = theF[0];
156 >    frc[offsetY] = theF[1];
157 >    frc[offsetZ] = theF[2];
158    }
159 <
160 <  for(i = 9*(stopIndex + 1); i < 9*nElements; i++) {
161 <    j = i - 9*startIndex + 1;
162 <    new_Amat[j] = Amat[i];
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 <  for (i = 0; i < startIndex; i++) {
170 <    new_mu[i] = mu[i];
169 > void Atom::addFrc( double theF[3] ){
170 >  
171 >  if( hasCoords ){
172 >    frc[offsetX] += theF[0];
173 >    frc[offsetY] += theF[1];
174 >    frc[offsetZ] += theF[2];
175    }
176 <
177 <  for(i = (stopIndex+1); i < nElements; i++) {
178 <    j = i - startIndex + 1;
179 <    new_mu[j] = mu[i];
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  
226  delete[] pos;
227  delete[] vel;
228  delete[] frc;
229  delete[] trq;
230  delete[] Amat;
231  delete[] mu;
186  
187 <  pos = new_pos;
188 <  vel = new_vel;
189 <  frc = new_frc;
190 <  trq = new_trq;
191 <  ul = new_ul;
192 <  Amat = new_Amat;
193 <  mu = new_mu;
194 <
195 <  nElements = nNew;
187 > void Atom::zeroForces( void ){
188 >  
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 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines