ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/RepulsivePower.cpp
Revision: 1656
Committed: Tue Oct 11 19:46:51 2011 UTC (13 years, 6 months ago) by jmichalk
File size: 6739 byte(s)
Log Message:
First few fixes for explicit interactions.

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

Properties

Name Value
svn:eol-style native