| 1 | gezelter | 409 | #include "Atom.hpp" | 
| 2 |  |  |  | 
| 3 | mmeineke | 413 | 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; | 
| 11 |  |  |  | 
| 12 | gezelter | 409 | Atom::Atom(int theIndex) { | 
| 13 |  |  | c_n_hyd = 0; | 
| 14 |  |  | has_dipole = 0; | 
| 15 |  |  | is_VDW = 0; | 
| 16 |  |  | is_LJ = 0; | 
| 17 |  |  |  | 
| 18 |  |  | index = theIndex; | 
| 19 |  |  | offset = 3 * index; | 
| 20 |  |  | offsetX = offset; | 
| 21 |  |  | offsetY = offset+1; | 
| 22 |  |  | offsetZ = offset+2; | 
| 23 |  |  |  | 
| 24 |  |  | Axx = index*9; | 
| 25 |  |  | Axy = Axx+1; | 
| 26 |  |  | Axz = Axx+2; | 
| 27 |  |  |  | 
| 28 |  |  | Ayx = Axx+3; | 
| 29 |  |  | Ayy = Axx+4; | 
| 30 |  |  | Ayz = Axx+5; | 
| 31 |  |  |  | 
| 32 |  |  | Azx = Axx+6; | 
| 33 |  |  | Azy = Axx+7; | 
| 34 |  |  | Azz = Axx+8; | 
| 35 |  |  | } | 
| 36 |  |  |  | 
| 37 | mmeineke | 413 | void Atom::createArrays (int the_nElements) { | 
| 38 | gezelter | 409 | int i; | 
| 39 |  |  |  | 
| 40 | mmeineke | 413 | nElements = the_nElements; | 
| 41 |  |  |  | 
| 42 | gezelter | 409 | 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 |  |  | } | 
| 75 |  |  | } | 
| 76 |  |  |  | 
| 77 |  |  | void Atom::destroyArrays(void) { | 
| 78 |  |  | delete[] pos; | 
| 79 |  |  | delete[] vel; | 
| 80 |  |  | delete[] frc; | 
| 81 |  |  | delete[] trq; | 
| 82 |  |  | delete[] Amat; | 
| 83 |  |  | delete[] mu; | 
| 84 |  |  | } | 
| 85 |  |  |  | 
| 86 |  |  | void Atom::setIndex(int theIndex) { | 
| 87 |  |  | index = theIndex; | 
| 88 |  |  | offset = index*3; | 
| 89 |  |  | offsetX = offset; | 
| 90 |  |  | offsetY = offset+1; | 
| 91 |  |  | offsetZ = offset+2; | 
| 92 |  |  |  | 
| 93 |  |  | Axx = index*9; | 
| 94 |  |  | Axy = Axx+1; | 
| 95 |  |  | Axz = Axx+2; | 
| 96 |  |  |  | 
| 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; | 
| 104 |  |  | } | 
| 105 |  |  |  | 
| 106 |  |  | 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; | 
| 120 |  |  |  | 
| 121 |  |  | for (i = 0; i < 3*nElements; i++) { | 
| 122 |  |  | new_pos[i] = pos[i]; | 
| 123 |  |  | new_vel[i] = vel[i]; | 
| 124 |  |  | new_frc[i] = frc[i]; | 
| 125 |  |  | new_trq[i] = trq[i]; | 
| 126 |  |  | new_ul[i] = ul[i]; | 
| 127 |  |  | } | 
| 128 |  |  |  | 
| 129 |  |  | for(i = 0; i < 3*nAdded; i++) { | 
| 130 |  |  | j = i + 3*nElements; | 
| 131 | gezelter | 410 | new_pos[j] = Apos[i]; | 
| 132 |  |  | new_vel[j] = Avel[i]; | 
| 133 |  |  | new_frc[j] = Afrc[i]; | 
| 134 |  |  | new_trq[j] = Atrq[i]; | 
| 135 |  |  | new_ul[j] = Aul[i]; | 
| 136 | gezelter | 409 | } | 
| 137 |  |  |  | 
| 138 |  |  | for (i = 0; i < 9*nElements; i++) { | 
| 139 |  |  | new_Amat[i] = Amat[i]; | 
| 140 |  |  | } | 
| 141 |  |  |  | 
| 142 |  |  | for(i = 0; i < 9*nAdded; i++) { | 
| 143 |  |  | j = i + 9*nElements; | 
| 144 | gezelter | 410 | new_Amat[j] = AAmat[i]; | 
| 145 | gezelter | 409 | } | 
| 146 |  |  |  | 
| 147 |  |  | for (i = 0; i < nElements; i++) { | 
| 148 |  |  | new_mu[i] = mu[i]; | 
| 149 |  |  | } | 
| 150 |  |  |  | 
| 151 |  |  | for(i = 0; i < nAdded; i++) { | 
| 152 |  |  | j = i + nElements; | 
| 153 | gezelter | 410 | new_mu[j] = Amu[i]; | 
| 154 | gezelter | 409 | } | 
| 155 |  |  |  | 
| 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; | 
| 172 |  |  | } | 
| 173 |  |  |  | 
| 174 |  |  | void Atom::deleteAtom(int theIndex) { | 
| 175 |  |  | deleteRange(theIndex, theIndex); | 
| 176 |  |  | } | 
| 177 |  |  |  | 
| 178 |  |  | 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; | 
| 190 |  |  |  | 
| 191 |  |  | for (i = 0; i < 3*startIndex; i++) { | 
| 192 |  |  | new_pos[i] = pos[i]; | 
| 193 |  |  | new_vel[i] = vel[i]; | 
| 194 |  |  | new_frc[i] = frc[i]; | 
| 195 |  |  | new_trq[i] = trq[i]; | 
| 196 |  |  | new_ul[i] = ul[i]; | 
| 197 |  |  | } | 
| 198 |  |  |  | 
| 199 |  |  | for(i = 3*(stopIndex + 1); i < 3*nElements; i++) { | 
| 200 |  |  | j = i - 3*startIndex + 1; | 
| 201 |  |  | new_pos[j] = pos[i]; | 
| 202 |  |  | new_vel[j] = vel[i]; | 
| 203 |  |  | new_frc[j] = frc[i]; | 
| 204 |  |  | new_trq[j] = trq[i]; | 
| 205 |  |  | new_ul[j] = ul[i]; | 
| 206 |  |  | } | 
| 207 |  |  |  | 
| 208 |  |  | for (i = 0; i < 9*startIndex; i++) { | 
| 209 |  |  | new_Amat[i] = Amat[i]; | 
| 210 |  |  | } | 
| 211 |  |  |  | 
| 212 |  |  | for(i = 9*(stopIndex + 1); i < 9*nElements; i++) { | 
| 213 |  |  | j = i - 9*startIndex + 1; | 
| 214 |  |  | new_Amat[j] = Amat[i]; | 
| 215 |  |  | } | 
| 216 |  |  |  | 
| 217 |  |  | for (i = 0; i < startIndex; i++) { | 
| 218 |  |  | new_mu[i] = mu[i]; | 
| 219 |  |  | } | 
| 220 |  |  |  | 
| 221 |  |  | for(i = (stopIndex+1); i < nElements; i++) { | 
| 222 |  |  | j = i - startIndex + 1; | 
| 223 |  |  | new_mu[j] = mu[i]; | 
| 224 |  |  | } | 
| 225 |  |  |  | 
| 226 |  |  | delete[] pos; | 
| 227 |  |  | 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; | 
| 242 |  |  | } |