ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/InteractionManager.cpp
Revision: 1874
Committed: Wed May 15 15:09:35 2013 UTC (11 years, 11 months ago) by gezelter
File size: 15332 byte(s)
Log Message:
Fixed a bunch of cppcheck warnings.

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 "nonbonded/InteractionManager.hpp"
44
45 namespace OpenMD {
46
47 InteractionManager::InteractionManager() {
48
49 initialized_ = false;
50
51 lj_ = new LJ();
52 gb_ = new GB();
53 sticky_ = new Sticky();
54 morse_ = new Morse();
55 repulsivePower_ = new RepulsivePower();
56 eam_ = new EAM();
57 sc_ = new SC();
58 electrostatic_ = new Electrostatic();
59 maw_ = new MAW();
60 }
61
62 InteractionManager::~InteractionManager() {
63 delete lj_;
64 delete gb_;
65 delete sticky_;
66 delete morse_;
67 delete repulsivePower_;
68 delete eam_;
69 delete sc_;
70 delete electrostatic_;
71 delete maw_;
72 }
73
74 void InteractionManager::initialize() {
75
76 if (initialized_) return;
77
78 ForceField* forceField_ = info_->getForceField();
79
80 lj_->setForceField(forceField_);
81 gb_->setForceField(forceField_);
82 sticky_->setForceField(forceField_);
83 eam_->setForceField(forceField_);
84 sc_->setForceField(forceField_);
85 morse_->setForceField(forceField_);
86 electrostatic_->setSimInfo(info_);
87 electrostatic_->setForceField(forceField_);
88 maw_->setForceField(forceField_);
89 repulsivePower_->setForceField(forceField_);
90
91 ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
92 ForceField::AtomTypeContainer::MapTypeIterator i1, i2;
93 AtomType* atype1;
94 AtomType* atype2;
95 pair<AtomType*, AtomType*> key;
96
97 for (atype1 = atomTypes->beginType(i1); atype1 != NULL;
98 atype1 = atomTypes->nextType(i1)) {
99
100 // add it to the map:
101
102 pair<map<int,AtomType*>::iterator,bool> ret;
103 ret = typeMap_.insert( pair<int, AtomType*>(atype1->getIdent(), atype1) );
104 if (ret.second == false) {
105 sprintf( painCave.errMsg,
106 "InteractionManager already had a previous entry with ident %d\n",
107 atype1->getIdent());
108 painCave.severity = OPENMD_INFO;
109 painCave.isFatal = 0;
110 simError();
111 }
112 }
113
114 // Now, iterate over all known types and add to the interaction map:
115
116 map<int, AtomType*>::iterator it1, it2;
117 for (it1 = typeMap_.begin(); it1 != typeMap_.end(); ++it1) {
118 atype1 = (*it1).second;
119
120 for( it2 = typeMap_.begin(); it2 != typeMap_.end(); ++it2) {
121 atype2 = (*it2).second;
122
123 key = make_pair(atype1, atype2);
124
125 if (atype1->isLennardJones() && atype2->isLennardJones()) {
126 interactions_[key].insert(lj_);
127 }
128 if (atype1->isElectrostatic() && atype2->isElectrostatic() ) {
129 interactions_[key].insert(electrostatic_);
130 }
131 if (atype1->isSticky() && atype2->isSticky() ) {
132 interactions_[key].insert(sticky_);
133 }
134 if (atype1->isStickyPower() && atype2->isStickyPower() ) {
135 interactions_[key].insert(sticky_);
136 }
137 if (atype1->isEAM() && atype2->isEAM() ) {
138 interactions_[key].insert(eam_);
139 }
140 if (atype1->isSC() && atype2->isSC() ) {
141 interactions_[key].insert(sc_);
142 }
143 if (atype1->isGayBerne() && atype2->isGayBerne() ) {
144 interactions_[key].insert(gb_);
145 }
146 if ((atype1->isGayBerne() && atype2->isLennardJones())
147 || (atype1->isLennardJones() && atype2->isGayBerne())) {
148 interactions_[key].insert(gb_);
149 }
150
151 // look for an explicitly-set non-bonded interaction type using the
152 // two atom types.
153 NonBondedInteractionType* nbiType = forceField_->getNonBondedInteractionType(atype1->getName(), atype2->getName());
154
155 if (nbiType != NULL) {
156
157 bool vdwExplicit = false;
158 bool metExplicit = false;
159 // bool hbExplicit = false;
160
161 if (nbiType->isLennardJones()) {
162 // We found an explicit Lennard-Jones interaction.
163 // override all other vdw entries for this pair of atom types:
164 set<NonBondedInteraction*>::iterator it;
165 for (it = interactions_[key].begin();
166 it != interactions_[key].end(); ++it) {
167 InteractionFamily ifam = (*it)->getFamily();
168 if (ifam == VANDERWAALS_FAMILY) interactions_[key].erase(*it);
169 }
170 interactions_[key].insert(lj_);
171 vdwExplicit = true;
172 }
173
174 if (nbiType->isMorse()) {
175 if (vdwExplicit) {
176 sprintf( painCave.errMsg,
177 "InteractionManager::initialize found more than one "
178 "explicit \n"
179 "\tvan der Waals interaction for atom types %s - %s\n",
180 atype1->getName().c_str(), atype2->getName().c_str());
181 painCave.severity = OPENMD_ERROR;
182 painCave.isFatal = 1;
183 simError();
184 }
185 // We found an explicit Morse interaction.
186 // override all other vdw entries for this pair of atom types:
187 set<NonBondedInteraction*>::iterator it;
188 for (it = interactions_[key].begin();
189 it != interactions_[key].end(); ++it) {
190 InteractionFamily ifam = (*it)->getFamily();
191 if (ifam == VANDERWAALS_FAMILY) interactions_[key].erase(*it);
192 }
193 interactions_[key].insert(morse_);
194 vdwExplicit = true;
195 }
196
197 if (nbiType->isRepulsivePower()) {
198 if (vdwExplicit) {
199 sprintf( painCave.errMsg,
200 "InteractionManager::initialize found more than one "
201 "explicit \n"
202 "\tvan der Waals interaction for atom types %s - %s\n",
203 atype1->getName().c_str(), atype2->getName().c_str());
204 painCave.severity = OPENMD_ERROR;
205 painCave.isFatal = 1;
206 simError();
207 }
208 // We found an explicit RepulsivePower interaction.
209 // override all other vdw entries for this pair of atom types:
210 set<NonBondedInteraction*>::iterator it;
211 for (it = interactions_[key].begin();
212 it != interactions_[key].end(); ++it) {
213 InteractionFamily ifam = (*it)->getFamily();
214 if (ifam == VANDERWAALS_FAMILY) interactions_[key].erase(*it);
215 }
216 interactions_[key].insert(repulsivePower_);
217 vdwExplicit = true;
218 }
219
220
221 if (nbiType->isEAM()) {
222 // We found an explicit EAM interaction.
223 // override all other metallic entries for this pair of atom types:
224 set<NonBondedInteraction*>::iterator it;
225 for (it = interactions_[key].begin();
226 it != interactions_[key].end(); ++it) {
227 InteractionFamily ifam = (*it)->getFamily();
228 if (ifam == METALLIC_FAMILY) interactions_[key].erase(*it);
229 }
230 interactions_[key].insert(eam_);
231 metExplicit = true;
232 }
233
234 if (nbiType->isSC()) {
235 if (metExplicit) {
236 sprintf( painCave.errMsg,
237 "InteractionManager::initialize found more than one "
238 "explicit\n"
239 "\tmetallic interaction for atom types %s - %s\n",
240 atype1->getName().c_str(), atype2->getName().c_str());
241 painCave.severity = OPENMD_ERROR;
242 painCave.isFatal = 1;
243 simError();
244 }
245 // We found an explicit Sutton-Chen interaction.
246 // override all other metallic entries for this pair of atom types:
247 set<NonBondedInteraction*>::iterator it;
248 for (it = interactions_[key].begin();
249 it != interactions_[key].end(); ++it) {
250 InteractionFamily ifam = (*it)->getFamily();
251 if (ifam == METALLIC_FAMILY) interactions_[key].erase(*it);
252 }
253 interactions_[key].insert(sc_);
254 metExplicit = true;
255 }
256
257 if (nbiType->isMAW()) {
258 if (vdwExplicit) {
259 sprintf( painCave.errMsg,
260 "InteractionManager::initialize found more than one "
261 "explicit\n"
262 "\tvan der Waals interaction for atom types %s - %s\n",
263 atype1->getName().c_str(), atype2->getName().c_str());
264 painCave.severity = OPENMD_ERROR;
265 painCave.isFatal = 1;
266 simError();
267 }
268 // We found an explicit MAW interaction.
269 // override all other vdw entries for this pair of atom types:
270 set<NonBondedInteraction*>::iterator it;
271 for (it = interactions_[key].begin();
272 it != interactions_[key].end(); ++it) {
273 InteractionFamily ifam = (*it)->getFamily();
274 if (ifam == VANDERWAALS_FAMILY) interactions_[key].erase(*it);
275 }
276 interactions_[key].insert(maw_);
277 vdwExplicit = true;
278 }
279 }
280 }
281 }
282
283
284 // Make sure every pair of atom types in this simulation has a
285 // non-bonded interaction. If not, just inform the user.
286
287 set<AtomType*> simTypes = info_->getSimulatedAtomTypes();
288 set<AtomType*>::iterator it, jt;
289
290 for (it = simTypes.begin(); it != simTypes.end(); ++it) {
291 atype1 = (*it);
292 for (jt = it; jt != simTypes.end(); ++jt) {
293 atype2 = (*jt);
294 key = make_pair(atype1, atype2);
295
296 if (interactions_[key].size() == 0) {
297 sprintf( painCave.errMsg,
298 "InteractionManager could not find a matching non-bonded\n"
299 "\tinteraction for atom types %s - %s\n"
300 "\tProceeding without this interaction.\n",
301 atype1->getName().c_str(), atype2->getName().c_str());
302 painCave.severity = OPENMD_INFO;
303 painCave.isFatal = 0;
304 simError();
305 }
306 }
307 }
308
309 initialized_ = true;
310 }
311
312 void InteractionManager::setCutoffRadius(RealType rcut) {
313
314 electrostatic_->setCutoffRadius(rcut);
315 eam_->setCutoffRadius(rcut);
316 }
317
318 void InteractionManager::doPrePair(InteractionData idat){
319
320 if (!initialized_) initialize();
321
322 // excluded interaction, so just return
323 if (idat.excluded) return;
324
325 set<NonBondedInteraction*>::iterator it;
326
327 for (it = interactions_[ idat.atypes ].begin();
328 it != interactions_[ idat.atypes ].end(); ++it){
329 if ((*it)->getFamily() == METALLIC_FAMILY) {
330 dynamic_cast<MetallicInteraction*>(*it)->calcDensity(idat);
331 }
332 }
333
334 return;
335 }
336
337 void InteractionManager::doPreForce(SelfData sdat){
338
339 if (!initialized_) initialize();
340
341 pair<AtomType*, AtomType*> key = make_pair(sdat.atype, sdat.atype);
342 set<NonBondedInteraction*>::iterator it;
343
344 for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
345 if ((*it)->getFamily() == METALLIC_FAMILY) {
346 dynamic_cast<MetallicInteraction*>(*it)->calcFunctional(sdat);
347 }
348 }
349
350 return;
351 }
352
353 void InteractionManager::doPair(InteractionData idat){
354
355 if (!initialized_) initialize();
356
357 set<NonBondedInteraction*>::iterator it;
358
359 for (it = interactions_[ idat.atypes ].begin();
360 it != interactions_[ idat.atypes ].end(); ++it) {
361
362 // electrostatics still has to worry about indirect
363 // contributions from excluded pairs of atoms:
364
365 if (!idat.excluded || (*it)->getFamily() == ELECTROSTATIC_FAMILY) {
366 (*it)->calcForce(idat);
367 }
368 }
369
370 return;
371 }
372
373 void InteractionManager::doSelfCorrection(SelfData sdat){
374
375 if (!initialized_) initialize();
376
377 pair<AtomType*, AtomType*> key = make_pair(sdat.atype, sdat.atype);
378 set<NonBondedInteraction*>::iterator it;
379
380 for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
381 if ((*it)->getFamily() == ELECTROSTATIC_FAMILY) {
382 dynamic_cast<ElectrostaticInteraction*>(*it)->calcSelfCorrection(sdat);
383 }
384 }
385
386 return;
387 }
388
389 RealType InteractionManager::getSuggestedCutoffRadius(int *atid) {
390 if (!initialized_) initialize();
391
392 AtomType* atype = typeMap_[*atid];
393
394 pair<AtomType*, AtomType*> key = make_pair(atype, atype);
395 set<NonBondedInteraction*>::iterator it;
396 RealType cutoff = 0.0;
397
398 for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it)
399 cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(key));
400 return cutoff;
401 }
402
403 RealType InteractionManager::getSuggestedCutoffRadius(AtomType* atype) {
404 if (!initialized_) initialize();
405
406 pair<AtomType*, AtomType*> key = make_pair(atype, atype);
407 set<NonBondedInteraction*>::iterator it;
408 RealType cutoff = 0.0;
409
410 for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it)
411 cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(key));
412 return cutoff;
413 }
414 } //end namespace OpenMD

Properties

Name Value
svn:eol-style native
svn:executable *