ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/RepulsivePower.cpp
Revision: 1624
Committed: Tue Sep 13 14:12:54 2011 UTC (13 years, 7 months ago) by gezelter
File size: 7153 byte(s)
Log Message:
Adding RepulsivePower interaction to the development branch

File Contents

# Content
1 /*
2 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 *
4 * The University of Notre Dame grants you ("Licensee") a
5 * non-exclusive, royalty free, license to use, modify and
6 * redistribute this software in source and binary code form, provided
7 * that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
15 * distribution.
16 *
17 * This software is provided "AS IS," without a warranty of any
18 * kind. All express or implied conditions, representations and
19 * warranties, including any implied warranty of merchantability,
20 * fitness for a particular purpose or non-infringement, are hereby
21 * excluded. The University of Notre Dame and its licensors shall not
22 * be liable for any damages suffered by licensee as a result of
23 * using, modifying or distributing the software or its
24 * derivatives. In no event will the University of Notre Dame or its
25 * licensors be liable for any lost revenue, profit or data, or for
26 * direct, indirect, special, consequential, incidental or punitive
27 * damages, however caused and regardless of the theory of liability,
28 * arising out of the use of or inability to use software, even if the
29 * University of Notre Dame has been advised of the possibility of
30 * such damages.
31 *
32 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33 * research, please cite the appropriate papers when you publish your
34 * work. Good starting points are:
35 *
36 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).
39 * [4] Vardeman & Gezelter, in progress (2009).
40 */
41
42 #include <stdio.h>
43 #include <string.h>
44
45 #include <cmath>
46 #include "nonbonded/RepulsivePower.hpp"
47 #include "utils/simError.h"
48 #include "types/NonBondedInteractionType.hpp"
49
50 using namespace std;
51
52 namespace OpenMD {
53
54 RepulsivePower::RepulsivePower() : name_("RepulsivePower"),
55 initialized_(false), forceField_(NULL) {}
56
57 void RepulsivePower::initialize() {
58
59 ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes();
60 ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j;
61 NonBondedInteractionType* nbt;
62
63 for (nbt = nbiTypes->beginType(j); nbt != NULL;
64 nbt = nbiTypes->nextType(j)) {
65
66 if (nbt->isRepulsivePower()) {
67
68 pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
69
70 GenericData* data = nbt->getPropertyByName("RepulsivePower");
71 if (data == NULL) {
72 sprintf( painCave.errMsg, "RepulsivePower::initialize could not\n"
73 "\tfind RepulsivePower parameters for %s - %s interaction.\n",
74 atypes.first->getName().c_str(),
75 atypes.second->getName().c_str());
76 painCave.severity = OPENMD_ERROR;
77 painCave.isFatal = 1;
78 simError();
79 }
80
81 RepulsivePowerData* rpData = dynamic_cast<RepulsivePowerData*>(data);
82 if (rpData == NULL) {
83 sprintf( painCave.errMsg,
84 "RepulsivePower::initialize could not convert GenericData\n"
85 "\tto RepulsivePowerData for %s - %s interaction.\n",
86 atypes.first->getName().c_str(),
87 atypes.second->getName().c_str());
88 painCave.severity = OPENMD_ERROR;
89 painCave.isFatal = 1;
90 simError();
91 }
92
93 RepulsivePowerParam rpParam = rpData->getData();
94
95 RealType sigma = rpParam.sigma;
96 RealType epsilon = rpParam.epsilon;
97 int nRep = rpParam.nRep;
98
99 addExplicitInteraction(atypes.first, atypes.second,
100 sigma, epsilon, nRep);
101 }
102 }
103 initialized_ = true;
104 }
105
106 void RepulsivePower::addExplicitInteraction(AtomType* atype1,
107 AtomType* atype2,
108 RealType sigma,
109 RealType epsilon,
110 int nRep) {
111
112 RPInteractionData mixer;
113 mixer.sigma = sigma;
114 mixer.epsilon = epsilon;
115 mixer.sigmai = 1.0 / mixer.sigma;
116 mixer.nRep = nRep;
117
118 pair<AtomType*, AtomType*> key1, key2;
119 key1 = make_pair(atype1, atype2);
120 key2 = make_pair(atype2, atype1);
121
122 MixingMap[key1] = mixer;
123 if (key2 != key1) {
124 MixingMap[key2] = mixer;
125 }
126 }
127
128 void RepulsivePower::calcForce(InteractionData &idat) {
129
130 if (!initialized_) initialize();
131
132 map<pair<AtomType*, AtomType*>, RPInteractionData>::iterator it;
133 it = MixingMap.find( idat.atypes );
134
135 if (it != MixingMap.end()) {
136
137 RPInteractionData mixer = (*it).second;
138 RealType sigmai = mixer.sigmai;
139 RealType epsilon = mixer.epsilon;
140 int nRep = mixer.nRep;
141
142 RealType ros;
143 RealType rcos;
144 RealType myPot = 0.0;
145 RealType myPotC = 0.0;
146 RealType myDeriv = 0.0;
147 RealType myDerivC = 0.0;
148
149 ros = *(idat.rij) * sigmai;
150
151 getNRepulsionFunc(ros, nRep, myPot, myDeriv);
152
153 if (idat.shiftedPot) {
154 rcos = *(idat.rcut) * sigmai;
155 getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
156 myDerivC = 0.0;
157 } else if (idat.shiftedForce) {
158 rcos = *(idat.rcut) * sigmai;
159 getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
160 myPotC = myPotC + myDerivC * (*(idat.rij) - *(idat.rcut)) * sigmai;
161 } else {
162 myPotC = 0.0;
163 myDerivC = 0.0;
164 }
165
166 RealType pot_temp = *(idat.vdwMult) * epsilon * (myPot - myPotC);
167 *(idat.vpair) += pot_temp;
168
169 RealType dudr = *(idat.sw) * *(idat.vdwMult) * epsilon * (myDeriv -
170 myDerivC)*sigmai;
171
172 (*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp;
173 *(idat.f1) = *(idat.d) * dudr / *(idat.rij);
174 }
175 return;
176 }
177
178 void RepulsivePower::getNRepulsionFunc(RealType r, int n, RealType &pot, RealType &deriv) {
179
180 RealType ri = 1.0 / r;
181 RealType rin = pow(ri, n);
182 RealType rin1 = rin * ri;
183
184 pot = rin;
185 deriv = -n * rin1;
186
187 return;
188 }
189
190
191 RealType RepulsivePower::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
192 if (!initialized_) initialize();
193 map<pair<AtomType*, AtomType*>, RPInteractionData>::iterator it;
194 it = MixingMap.find(atypes);
195 if (it == MixingMap.end())
196 return 0.0;
197 else {
198 RPInteractionData mixer = (*it).second;
199 return 2.5 * mixer.sigma;
200 }
201 }
202
203 }
204

Properties

Name Value
svn:eol-style native