ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/nonbonded/RepulsivePower.cpp
Revision: 2033
Committed: Sat Nov 1 14:12:16 2014 UTC (10 years, 6 months ago) by gezelter
File size: 7418 byte(s)
Log Message:
Fixed a selection issue in ParticleTimeCorrFunc, other whitespace stuff

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, 234107 (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 RPtypes.clear();
61 RPtids.clear();
62 MixingMap.clear();
63 RPtids.resize( forceField_->getNAtomType(), -1);
64
65 ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes();
66 ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j;
67 ForceField::NonBondedInteractionTypeContainer::KeyType keys;
68 NonBondedInteractionType* nbt;
69 int rptid1, rptid2;
70
71 for (nbt = nbiTypes->beginType(j); nbt != NULL;
72 nbt = nbiTypes->nextType(j)) {
73
74 if (nbt->isRepulsivePower()) {
75 keys = nbiTypes->getKeys(j);
76 AtomType* at1 = forceField_->getAtomType(keys[0]);
77 AtomType* at2 = forceField_->getAtomType(keys[1]);
78
79 int atid1 = at1->getIdent();
80 if (RPtids[atid1] == -1) {
81 rptid1 = RPtypes.size();
82 RPtypes.insert(atid1);
83 RPtids[atid1] = rptid1;
84 }
85 int atid2 = at2->getIdent();
86 if (RPtids[atid2] == -1) {
87 rptid2 = RPtypes.size();
88 RPtypes.insert(atid2);
89 RPtids[atid2] = rptid2;
90 }
91
92 RepulsivePowerInteractionType* rpit = dynamic_cast<RepulsivePowerInteractionType*>(nbt);
93 if (rpit == NULL) {
94 sprintf( painCave.errMsg,
95 "RepulsivePower::initialize could not convert NonBondedInteractionType\n"
96 "\tto RepulsivePowerInteractionType for %s - %s interaction.\n",
97 at1->getName().c_str(),
98 at2->getName().c_str());
99 painCave.severity = OPENMD_ERROR;
100 painCave.isFatal = 1;
101 simError();
102 }
103
104 RealType sigma = rpit->getSigma();
105 RealType epsilon = rpit->getEpsilon();
106 int nRep = rpit->getNrep();
107
108 addExplicitInteraction(at1, at2, sigma, epsilon, nRep);
109 }
110 }
111 initialized_ = true;
112 }
113
114 void RepulsivePower::addExplicitInteraction(AtomType* atype1,
115 AtomType* atype2,
116 RealType sigma,
117 RealType epsilon,
118 int nRep) {
119
120 RPInteractionData mixer;
121 mixer.sigma = sigma;
122 mixer.epsilon = epsilon;
123 mixer.sigmai = 1.0 / mixer.sigma;
124 mixer.nRep = nRep;
125
126 int rptid1 = RPtids[atype1->getIdent()];
127 int rptid2 = RPtids[atype2->getIdent()];
128 int nRP = RPtypes.size();
129
130 MixingMap.resize(nRP);
131 MixingMap[rptid1].resize(nRP);
132
133 MixingMap[rptid1][rptid2] = mixer;
134 if (rptid2 != rptid1) {
135 MixingMap[rptid2].resize(nRP);
136 MixingMap[rptid2][rptid1] = mixer;
137 }
138 }
139
140 void RepulsivePower::calcForce(InteractionData &idat) {
141
142 if (!initialized_) initialize();
143
144 RPInteractionData &mixer = MixingMap[RPtids[idat.atid1]][RPtids[idat.atid2]];
145 RealType sigmai = mixer.sigmai;
146 RealType epsilon = mixer.epsilon;
147 int nRep = mixer.nRep;
148
149 RealType ros;
150 RealType rcos;
151 RealType myPot = 0.0;
152 RealType myPotC = 0.0;
153 RealType myDeriv = 0.0;
154 RealType myDerivC = 0.0;
155
156 ros = *(idat.rij) * sigmai;
157
158 getNRepulsionFunc(ros, nRep, myPot, myDeriv);
159
160 if (idat.shiftedPot) {
161 rcos = *(idat.rcut) * sigmai;
162 getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
163 myDerivC = 0.0;
164 } else if (idat.shiftedForce) {
165 rcos = *(idat.rcut) * sigmai;
166 getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
167 myPotC = myPotC + myDerivC * (*(idat.rij) - *(idat.rcut)) * sigmai;
168 } else {
169 myPotC = 0.0;
170 myDerivC = 0.0;
171 }
172
173 RealType pot_temp = *(idat.vdwMult) * epsilon * (myPot - myPotC);
174 *(idat.vpair) += pot_temp;
175
176 RealType dudr = *(idat.sw) * *(idat.vdwMult) * epsilon * (myDeriv -
177 myDerivC)*sigmai;
178
179 (*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp;
180 *(idat.f1) = *(idat.d) * dudr / *(idat.rij);
181
182 return;
183 }
184
185 void RepulsivePower::getNRepulsionFunc(const RealType &r, int &n,
186 RealType &pot, RealType &deriv) {
187
188 RealType ri = 1.0 / r;
189 RealType rin = pow(ri, n);
190 RealType rin1 = rin * ri;
191
192 pot = rin;
193 deriv = -n * rin1;
194
195 return;
196 }
197
198
199 RealType RepulsivePower::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
200 if (!initialized_) initialize();
201
202 int atid1 = atypes.first->getIdent();
203 int atid2 = atypes.second->getIdent();
204 int rptid1 = RPtids[atid1];
205 int rptid2 = RPtids[atid2];
206
207 if (rptid1 == -1 || rptid2 == -1) return 0.0;
208 else {
209 RPInteractionData mixer = MixingMap[rptid1][rptid2];
210 return 2.5 * mixer.sigma;
211 }
212 }
213 }
214

Properties

Name Value
svn:eol-style native