| 1 | #include <iostream> | 
| 2 |  | 
| 3 | using namespace std; | 
| 4 |  | 
| 5 | #include "simError.h" | 
| 6 | #include "Atom.hpp" | 
| 7 |  | 
| 8 | Atom::Atom(int theIndex, SimState* theConfig) { | 
| 9 |  | 
| 10 | objType = OT_ATOM; | 
| 11 | myConfig = theConfig; | 
| 12 | hasCoords = false; | 
| 13 |  | 
| 14 | has_dipole = 0; | 
| 15 |  | 
| 16 | index = theIndex; | 
| 17 | offset = 0; | 
| 18 | offsetX = offset; | 
| 19 | offsetY = offset+1; | 
| 20 | offsetZ = offset+2; | 
| 21 |  | 
| 22 | Axx = 0; | 
| 23 | Axy = Axx+1; | 
| 24 | Axz = Axx+2; | 
| 25 |  | 
| 26 | Ayx = Axx+3; | 
| 27 | Ayy = Axx+4; | 
| 28 | Ayz = Axx+5; | 
| 29 |  | 
| 30 | Azx = Axx+6; | 
| 31 | Azy = Axx+7; | 
| 32 | Azz = Axx+8; | 
| 33 | } | 
| 34 |  | 
| 35 | void Atom::setIndex(int theIndex) { | 
| 36 | index = theIndex; | 
| 37 | } | 
| 38 |  | 
| 39 | void Atom::setCoords(void){ | 
| 40 |  | 
| 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 | hasCoords = true; | 
| 61 |  | 
| 62 | } | 
| 63 |  | 
| 64 | void Atom::getPos( double theP[3] ){ | 
| 65 |  | 
| 66 | if( hasCoords ){ | 
| 67 | theP[0] = pos[offsetX]; | 
| 68 | theP[1] = pos[offsetY]; | 
| 69 | theP[2] = pos[offsetZ]; | 
| 70 | } | 
| 71 | else{ | 
| 72 |  | 
| 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 | void Atom::setPos( double theP[3] ){ | 
| 82 |  | 
| 83 | if( hasCoords ){ | 
| 84 | pos[offsetX] = theP[0]; | 
| 85 | pos[offsetY] = theP[1]; | 
| 86 | pos[offsetZ] = theP[2]; | 
| 87 | } | 
| 88 | else{ | 
| 89 |  | 
| 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 | 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 |  | 
| 114 | } | 
| 115 |  | 
| 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::getFrc( double theF[3] ){ | 
| 134 |  | 
| 135 | if( hasCoords ){ | 
| 136 | theF[0] = frc[offsetX]; | 
| 137 | theF[1] = frc[offsetY]; | 
| 138 | theF[2] = frc[offsetZ]; | 
| 139 | } | 
| 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 | 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 | 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 |  | 
| 167 |  | 
| 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 | } |