| 51 |
|
|
| 52 |
|
namespace OpenMD { |
| 53 |
|
|
| 54 |
< |
bool Morse::initialized_ = false; |
| 55 |
< |
bool Morse::shiftedPot_ = false; |
| 56 |
< |
bool Morse::shiftedFrc_ = false; |
| 57 |
< |
ForceField* Morse::forceField_ = NULL; |
| 58 |
< |
map<int, AtomType*> Morse::MorseMap; |
| 59 |
< |
map<pair<AtomType*, AtomType*>, MorseInteractionData> Morse::MixingMap; |
| 60 |
< |
map<string, MorseInteractionType> Morse::stringToEnumMap_; |
| 54 |
> |
Morse::Morse() : name_("Morse"), initialized_(false), forceField_(NULL), |
| 55 |
> |
shiftedPot_(false), shiftedFrc_(false) {} |
| 56 |
|
|
| 62 |
– |
Morse* Morse::_instance = NULL; |
| 63 |
– |
|
| 64 |
– |
Morse* Morse::Instance() { |
| 65 |
– |
if (!_instance) { |
| 66 |
– |
_instance = new Morse(); |
| 67 |
– |
} |
| 68 |
– |
return _instance; |
| 69 |
– |
} |
| 70 |
– |
|
| 57 |
|
void Morse::initialize() { |
| 58 |
|
|
| 59 |
|
stringToEnumMap_["shiftedMorse"] = shiftedMorse; |
| 126 |
|
RealType De, RealType Re, RealType beta, |
| 127 |
|
MorseInteractionType mit) { |
| 128 |
|
|
| 143 |
– |
AtomTypeProperties atp = atype1->getATP(); |
| 144 |
– |
MorseMap.insert( pair<int, AtomType*>(atp.ident, atype1) ); |
| 145 |
– |
|
| 146 |
– |
atp = atype2->getATP(); |
| 147 |
– |
MorseMap.insert( pair<int, AtomType*>(atp.ident, atype2) ); |
| 148 |
– |
|
| 129 |
|
MorseInteractionData mixer; |
| 130 |
|
mixer.De = De; |
| 131 |
|
mixer.Re = Re; |
| 142 |
|
} |
| 143 |
|
} |
| 144 |
|
|
| 145 |
< |
void Morse::calcForce(AtomType* at1, AtomType* at2, Vector3d d, |
| 166 |
< |
RealType r, RealType r2, RealType rcut, RealType sw, |
| 167 |
< |
RealType vdwMult, RealType &vpair, RealType &pot, |
| 168 |
< |
Vector3d &f1) { |
| 145 |
> |
void Morse::calcForce(InteractionData &idat) { |
| 146 |
|
|
| 147 |
|
if (!initialized_) initialize(); |
| 148 |
|
|
| 149 |
< |
RealType myPot = 0.0; |
| 150 |
< |
RealType myPotC = 0.0; |
| 151 |
< |
RealType myDeriv = 0.0; |
| 152 |
< |
RealType myDerivC = 0.0; |
| 153 |
< |
|
| 154 |
< |
pair<AtomType*, AtomType*> key = make_pair(at1, at2); |
| 155 |
< |
MorseInteractionData mixer = MixingMap[key]; |
| 156 |
< |
|
| 157 |
< |
RealType De = mixer.De; |
| 158 |
< |
RealType Re = mixer.Re; |
| 159 |
< |
RealType beta = mixer.beta; |
| 160 |
< |
MorseInteractionType interactionType = mixer.interactionType; |
| 161 |
< |
|
| 162 |
< |
// V(r) = D_e exp(-a(r-re)(exp(-a(r-re))-2) |
| 163 |
< |
|
| 164 |
< |
RealType expt = -beta*(r - Re); |
| 165 |
< |
RealType expfnc = exp(expt); |
| 166 |
< |
RealType expfnc2 = expfnc*expfnc; |
| 167 |
< |
|
| 168 |
< |
RealType exptC = 0.0; |
| 169 |
< |
RealType expfncC = 0.0; |
| 170 |
< |
RealType expfnc2C = 0.0; |
| 171 |
< |
|
| 172 |
< |
if (Morse::shiftedPot_ || Morse::shiftedFrc_) { |
| 173 |
< |
exptC = -beta*(rcut - Re); |
| 174 |
< |
expfncC = exp(exptC); |
| 175 |
< |
expfnc2C = expfncC*expfncC; |
| 176 |
< |
} |
| 177 |
< |
|
| 201 |
< |
|
| 202 |
< |
switch(interactionType) { |
| 203 |
< |
case shiftedMorse : { |
| 204 |
< |
|
| 205 |
< |
myPot = De * (expfnc2 - 2.0 * expfnc); |
| 206 |
< |
myDeriv = 2.0 * De * beta * (expfnc - expfnc2); |
| 207 |
< |
|
| 208 |
< |
if (Morse::shiftedPot_) { |
| 209 |
< |
myPotC = De * (expfnc2C - 2.0 * expfncC); |
| 210 |
< |
myDerivC = 0.0; |
| 211 |
< |
} else if (Morse::shiftedFrc_) { |
| 212 |
< |
myPotC = De * (expfnc2C - 2.0 * expfncC); |
| 213 |
< |
myDerivC = 2.0 * De * beta * (expfnc2C - expfnc2C); |
| 214 |
< |
myPotC += myDerivC * (r - rcut); |
| 215 |
< |
} else { |
| 216 |
< |
myPotC = 0.0; |
| 217 |
< |
myDerivC = 0.0; |
| 149 |
> |
map<pair<AtomType*, AtomType*>, MorseInteractionData>::iterator it; |
| 150 |
> |
it = MixingMap.find( idat.atypes ); |
| 151 |
> |
if (it != MixingMap.end()) { |
| 152 |
> |
MorseInteractionData mixer = (*it).second; |
| 153 |
> |
|
| 154 |
> |
RealType myPot = 0.0; |
| 155 |
> |
RealType myPotC = 0.0; |
| 156 |
> |
RealType myDeriv = 0.0; |
| 157 |
> |
RealType myDerivC = 0.0; |
| 158 |
> |
|
| 159 |
> |
RealType De = mixer.De; |
| 160 |
> |
RealType Re = mixer.Re; |
| 161 |
> |
RealType beta = mixer.beta; |
| 162 |
> |
MorseInteractionType interactionType = mixer.interactionType; |
| 163 |
> |
|
| 164 |
> |
// V(r) = D_e exp(-a(r-re)(exp(-a(r-re))-2) |
| 165 |
> |
|
| 166 |
> |
RealType expt = -beta*( *(idat.rij) - Re); |
| 167 |
> |
RealType expfnc = exp(expt); |
| 168 |
> |
RealType expfnc2 = expfnc*expfnc; |
| 169 |
> |
|
| 170 |
> |
RealType exptC = 0.0; |
| 171 |
> |
RealType expfncC = 0.0; |
| 172 |
> |
RealType expfnc2C = 0.0; |
| 173 |
> |
|
| 174 |
> |
if (Morse::shiftedPot_ || Morse::shiftedFrc_) { |
| 175 |
> |
exptC = -beta*( *(idat.rcut) - Re); |
| 176 |
> |
expfncC = exp(exptC); |
| 177 |
> |
expfnc2C = expfncC*expfncC; |
| 178 |
|
} |
| 179 |
< |
|
| 180 |
< |
break; |
| 181 |
< |
} |
| 182 |
< |
case repulsiveMorse : { |
| 183 |
< |
|
| 184 |
< |
myPot = De * expfnc2; |
| 185 |
< |
myDeriv = -2.0 * De * beta * expfnc2; |
| 186 |
< |
|
| 187 |
< |
if (Morse::shiftedPot_) { |
| 188 |
< |
myPotC = De * expfnc2C; |
| 189 |
< |
myDerivC = 0.0; |
| 190 |
< |
} else if (Morse::shiftedFrc_) { |
| 191 |
< |
myPotC = De * expfnc2C; |
| 192 |
< |
myDerivC = -2.0 * De * beta * expfnc2C; |
| 193 |
< |
myPotC += myDerivC * (r - rcut); |
| 194 |
< |
} else { |
| 195 |
< |
myPotC = 0.0; |
| 196 |
< |
myDerivC = 0.0; |
| 179 |
> |
|
| 180 |
> |
|
| 181 |
> |
switch(interactionType) { |
| 182 |
> |
case shiftedMorse : { |
| 183 |
> |
|
| 184 |
> |
myPot = De * (expfnc2 - 2.0 * expfnc); |
| 185 |
> |
myDeriv = 2.0 * De * beta * (expfnc - expfnc2); |
| 186 |
> |
|
| 187 |
> |
if (Morse::shiftedPot_) { |
| 188 |
> |
myPotC = De * (expfnc2C - 2.0 * expfncC); |
| 189 |
> |
myDerivC = 0.0; |
| 190 |
> |
} else if (Morse::shiftedFrc_) { |
| 191 |
> |
myPotC = De * (expfnc2C - 2.0 * expfncC); |
| 192 |
> |
myDerivC = 2.0 * De * beta * (expfnc2C - expfnc2C); |
| 193 |
> |
myPotC += myDerivC * ( *(idat.rij) - *(idat.rcut) ); |
| 194 |
> |
} else { |
| 195 |
> |
myPotC = 0.0; |
| 196 |
> |
myDerivC = 0.0; |
| 197 |
> |
} |
| 198 |
> |
|
| 199 |
> |
break; |
| 200 |
|
} |
| 201 |
< |
|
| 202 |
< |
break; |
| 201 |
> |
case repulsiveMorse : { |
| 202 |
> |
|
| 203 |
> |
myPot = De * expfnc2; |
| 204 |
> |
myDeriv = -2.0 * De * beta * expfnc2; |
| 205 |
> |
|
| 206 |
> |
if (Morse::shiftedPot_) { |
| 207 |
> |
myPotC = De * expfnc2C; |
| 208 |
> |
myDerivC = 0.0; |
| 209 |
> |
} else if (Morse::shiftedFrc_) { |
| 210 |
> |
myPotC = De * expfnc2C; |
| 211 |
> |
myDerivC = -2.0 * De * beta * expfnc2C; |
| 212 |
> |
myPotC += myDerivC * ( *(idat.rij) - *(idat.rcut)); |
| 213 |
> |
} else { |
| 214 |
> |
myPotC = 0.0; |
| 215 |
> |
myDerivC = 0.0; |
| 216 |
> |
} |
| 217 |
> |
|
| 218 |
> |
break; |
| 219 |
> |
} |
| 220 |
> |
} |
| 221 |
> |
|
| 222 |
> |
RealType pot_temp = *(idat.vdwMult) * (myPot - myPotC); |
| 223 |
> |
*(idat.vpair) += pot_temp; |
| 224 |
> |
|
| 225 |
> |
RealType dudr = *(idat.sw) * *(idat.vdwMult) * (myDeriv - myDerivC); |
| 226 |
> |
|
| 227 |
> |
idat.pot[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp; |
| 228 |
> |
*(idat.f1) = *(idat.d) * dudr / *(idat.rij); |
| 229 |
|
} |
| 241 |
– |
} |
| 242 |
– |
|
| 243 |
– |
RealType pot_temp = vdwMult * (myPot - myPotC); |
| 244 |
– |
vpair += pot_temp; |
| 245 |
– |
|
| 246 |
– |
RealType dudr = sw * vdwMult * (myDeriv - myDerivC); |
| 247 |
– |
|
| 248 |
– |
pot += sw * pot_temp; |
| 249 |
– |
f1 = d * dudr / r; |
| 250 |
– |
|
| 230 |
|
return; |
| 252 |
– |
|
| 253 |
– |
} |
| 254 |
– |
|
| 255 |
– |
void Morse::do_morse_pair(int *atid1, int *atid2, RealType *d, |
| 256 |
– |
RealType *rij, RealType *r2, RealType *rcut, |
| 257 |
– |
RealType *sw, RealType *vdwMult, |
| 258 |
– |
RealType *vpair, RealType *pot, RealType *f1) { |
| 259 |
– |
|
| 260 |
– |
if (!initialized_) initialize(); |
| 231 |
|
|
| 262 |
– |
AtomType* atype1 = MorseMap[*atid1]; |
| 263 |
– |
AtomType* atype2 = MorseMap[*atid2]; |
| 264 |
– |
|
| 265 |
– |
Vector3d disp(d[0], d[1], d[2]); |
| 266 |
– |
Vector3d frc(f1[0], f1[1], f1[2]); |
| 267 |
– |
|
| 268 |
– |
calcForce(atype1, atype2, disp, *rij, *r2, *rcut, *sw, *vdwMult, *vpair, |
| 269 |
– |
*pot, frc); |
| 270 |
– |
|
| 271 |
– |
f1[0] = frc.x(); |
| 272 |
– |
f1[1] = frc.y(); |
| 273 |
– |
f1[2] = frc.z(); |
| 274 |
– |
|
| 275 |
– |
return; |
| 232 |
|
} |
| 233 |
|
|
| 234 |
< |
void Morse::setMorseDefaultCutoff(RealType *thisRcut, int *sP, int *sF) { |
| 235 |
< |
shiftedPot_ = (bool)(*sP); |
| 236 |
< |
shiftedFrc_ = (bool)(*sF); |
| 237 |
< |
} |
| 238 |
< |
} |
| 234 |
> |
RealType Morse::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) { |
| 235 |
> |
if (!initialized_) initialize(); |
| 236 |
> |
map<pair<AtomType*, AtomType*>, MorseInteractionData>::iterator it; |
| 237 |
> |
it = MixingMap.find(atypes); |
| 238 |
> |
if (it == MixingMap.end()) |
| 239 |
> |
return 0.0; |
| 240 |
> |
else { |
| 241 |
> |
MorseInteractionData mixer = (*it).second; |
| 242 |
|
|
| 243 |
< |
extern "C" { |
| 244 |
< |
|
| 245 |
< |
#define fortranSetMorseCutoff FC_FUNC(setmorsedefaultcutoff, SETMORSEDEFAULTCUTOFF) |
| 246 |
< |
#define fortranDoMorsePair FC_FUNC(do_morse_pair, DO_MORSE_PAIR) |
| 247 |
< |
|
| 248 |
< |
void fortranSetMorseCutoff(RealType *rcut, int *shiftedPot, int *shiftedFrc) { |
| 249 |
< |
return OpenMD::Morse::Instance()->setMorseDefaultCutoff(rcut, shiftedPot, |
| 250 |
< |
shiftedFrc); |
| 243 |
> |
RealType Re = mixer.Re; |
| 244 |
> |
RealType beta = mixer.beta; |
| 245 |
> |
// This value of the r corresponds to an energy about 1.48% of |
| 246 |
> |
// the energy at the bottom of the Morse well. For comparison, the |
| 247 |
> |
// Lennard-Jones function is about 1.63% of it's minimum value at |
| 248 |
> |
// a distance of 2.5 sigma. |
| 249 |
> |
return (4.9 + beta * Re) / beta; |
| 250 |
> |
} |
| 251 |
|
} |
| 293 |
– |
void fortranDoMorsePair(int *atid1, int *atid2, RealType *d, RealType *rij, |
| 294 |
– |
RealType *r2, RealType *rcut, RealType *sw, |
| 295 |
– |
RealType *vdwMult, RealType* vpair, RealType* pot, |
| 296 |
– |
RealType *f1){ |
| 297 |
– |
|
| 298 |
– |
return OpenMD::Morse::Instance()->do_morse_pair(atid1, atid2, d, rij, r2, |
| 299 |
– |
rcut, sw, vdwMult, vpair, |
| 300 |
– |
pot, f1); |
| 301 |
– |
} |
| 252 |
|
} |
| 253 |
+ |
|