ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/RepulsivePower.cpp
Revision: 1665
Committed: Tue Nov 22 20:38:56 2011 UTC (13 years, 5 months ago) by gezelter
File size: 6805 byte(s)
Log Message:
updated copyright notices

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] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 */
42
43 #include <stdio.h>
44 #include <string.h>
45
46 #include <cmath>
47 #include "nonbonded/RepulsivePower.hpp"
48 #include "utils/simError.h"
49 #include "types/RepulsivePowerInteractionType.hpp"
50
51 using namespace std;
52
53 namespace OpenMD {
54
55 RepulsivePower::RepulsivePower() : name_("RepulsivePower"),
56 initialized_(false), forceField_(NULL) {}
57
58 void RepulsivePower::initialize() {
59
60 ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes();
61 ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j;
62 ForceField::NonBondedInteractionTypeContainer::KeyType keys;
63 NonBondedInteractionType* nbt;
64
65 for (nbt = nbiTypes->beginType(j); nbt != NULL;
66 nbt = nbiTypes->nextType(j)) {
67
68 if (nbt->isRepulsivePower()) {
69 keys = nbiTypes->getKeys(j);
70 AtomType* at1 = forceField_->getAtomType(keys[0]);
71 AtomType* at2 = forceField_->getAtomType(keys[1]);
72
73
74 RepulsivePowerInteractionType* rpit = dynamic_cast<RepulsivePowerInteractionType*>(nbt);
75
76 if (rpit == NULL) {
77 sprintf( painCave.errMsg,
78 "RepulsivePower::initialize could not convert NonBondedInteractionType\n"
79 "\tto RepulsivePowerInteractionType for %s - %s interaction.\n",
80 at1->getName().c_str(),
81 at2->getName().c_str());
82 painCave.severity = OPENMD_ERROR;
83 painCave.isFatal = 1;
84 simError();
85 }
86
87
88 RealType sigma = rpit->getSigma();
89 RealType epsilon = rpit->getEpsilon();
90 int nRep = rpit->getNrep();
91
92 addExplicitInteraction(at1, at2, sigma, epsilon, nRep);
93 }
94 }
95 initialized_ = true;
96 }
97
98 void RepulsivePower::addExplicitInteraction(AtomType* atype1,
99 AtomType* atype2,
100 RealType sigma,
101 RealType epsilon,
102 int nRep) {
103
104 RPInteractionData mixer;
105 mixer.sigma = sigma;
106 mixer.epsilon = epsilon;
107 mixer.sigmai = 1.0 / mixer.sigma;
108 mixer.nRep = nRep;
109
110 pair<AtomType*, AtomType*> key1, key2;
111 key1 = make_pair(atype1, atype2);
112 key2 = make_pair(atype2, atype1);
113
114 MixingMap[key1] = mixer;
115 if (key2 != key1) {
116 MixingMap[key2] = mixer;
117 }
118 }
119
120 void RepulsivePower::calcForce(InteractionData &idat) {
121
122 if (!initialized_) initialize();
123
124 map<pair<AtomType*, AtomType*>, RPInteractionData>::iterator it;
125 it = MixingMap.find( idat.atypes );
126
127 if (it != MixingMap.end()) {
128
129 RPInteractionData mixer = (*it).second;
130 RealType sigmai = mixer.sigmai;
131 RealType epsilon = mixer.epsilon;
132 int nRep = mixer.nRep;
133
134 RealType ros;
135 RealType rcos;
136 RealType myPot = 0.0;
137 RealType myPotC = 0.0;
138 RealType myDeriv = 0.0;
139 RealType myDerivC = 0.0;
140
141 ros = *(idat.rij) * sigmai;
142
143 getNRepulsionFunc(ros, nRep, myPot, myDeriv);
144
145 if (idat.shiftedPot) {
146 rcos = *(idat.rcut) * sigmai;
147 getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
148 myDerivC = 0.0;
149 } else if (idat.shiftedForce) {
150 rcos = *(idat.rcut) * sigmai;
151 getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
152 myPotC = myPotC + myDerivC * (*(idat.rij) - *(idat.rcut)) * sigmai;
153 } else {
154 myPotC = 0.0;
155 myDerivC = 0.0;
156 }
157
158 RealType pot_temp = *(idat.vdwMult) * epsilon * (myPot - myPotC);
159 *(idat.vpair) += pot_temp;
160
161 RealType dudr = *(idat.sw) * *(idat.vdwMult) * epsilon * (myDeriv -
162 myDerivC)*sigmai;
163
164 (*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp;
165 *(idat.f1) = *(idat.d) * dudr / *(idat.rij);
166 }
167 return;
168 }
169
170 void RepulsivePower::getNRepulsionFunc(RealType r, int n, RealType &pot, RealType &deriv) {
171
172 RealType ri = 1.0 / r;
173 RealType rin = pow(ri, n);
174 RealType rin1 = rin * ri;
175
176 pot = rin;
177 deriv = -n * rin1;
178
179 return;
180 }
181
182
183 RealType RepulsivePower::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
184 if (!initialized_) initialize();
185 map<pair<AtomType*, AtomType*>, RPInteractionData>::iterator it;
186 it = MixingMap.find(atypes);
187 if (it == MixingMap.end())
188 return 0.0;
189 else {
190 RPInteractionData mixer = (*it).second;
191 return 2.5 * mixer.sigma;
192 }
193 }
194
195 }
196

Properties

Name Value
svn:eol-style native