ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/InteractionManager.cpp
(Generate patch)

Comparing branches/development/src/nonbonded/InteractionManager.cpp (file contents):
Revision 1502 by gezelter, Sat Oct 2 19:53:32 2010 UTC vs.
Revision 1554 by gezelter, Sat Apr 30 02:54:02 2011 UTC

# Line 42 | Line 42 | namespace OpenMD {
42   #include "nonbonded/InteractionManager.hpp"
43  
44   namespace OpenMD {
45 <
45 >
46 >  InteractionManager* InteractionManager::_instance = NULL;
47 >  SimInfo* InteractionManager::info_ = NULL;
48    bool InteractionManager::initialized_ = false;
49 <  ForceField* InteractionManager::forceField_ = NULL;  
50 <  InteractionManager* InteractionManager::_instance = NULL;
49 >
50 >  RealType InteractionManager::rCut_ = 0.0;
51 >  RealType InteractionManager::rSwitch_ = 0.0;
52 >  RealType InteractionManager::skinThickness_ = 0.0;
53 >  RealType InteractionManager::listRadius_ = 0.0;
54 >  CutoffMethod InteractionManager::cutoffMethod_ = SHIFTED_FORCE;
55 >  SwitchingFunctionType InteractionManager::sft_ = cubic;
56 >  RealType InteractionManager::vdwScale_[4] = {1.0, 0.0, 0.0, 0.0};
57 >  RealType InteractionManager::electrostaticScale_[4] = {1.0, 0.0, 0.0, 0.0};
58 >
59    map<int, AtomType*> InteractionManager::typeMap_;
60    map<pair<AtomType*, AtomType*>, set<NonBondedInteraction*> > InteractionManager::interactions_;
61 +
62 +  LJ* InteractionManager::lj_ = new LJ();
63 +  GB* InteractionManager::gb_ = new GB();
64 +  Sticky* InteractionManager::sticky_ = new Sticky();
65 +  Morse* InteractionManager::morse_ = new Morse();
66 +  EAM* InteractionManager::eam_ = new EAM();
67 +  SC* InteractionManager::sc_ = new SC();
68 +  Electrostatic* InteractionManager::electrostatic_ = new Electrostatic();
69 +  MAW* InteractionManager::maw_ = new MAW();
70 +  SwitchingFunction* InteractionManager::switcher_ = new SwitchingFunction();
71  
72    InteractionManager* InteractionManager::Instance() {
73      if (!_instance) {
# Line 58 | Line 78 | namespace OpenMD {
78  
79    void InteractionManager::initialize() {
80      
81 <    lj_ = new LJ();
82 <    gb_ = new GB();
63 <    sticky_ = new Sticky();
64 <    eam_ = new EAM();
65 <    sc_ = new SC();
66 <    morse_ = new Morse();
67 <    electrostatic_ = new Electrostatic();
68 <
81 >    ForceField* forceField_ = info_->getForceField();
82 >    
83      lj_->setForceField(forceField_);
84      gb_->setForceField(forceField_);
85      sticky_->setForceField(forceField_);
# Line 73 | Line 87 | namespace OpenMD {
87      sc_->setForceField(forceField_);
88      morse_->setForceField(forceField_);
89      electrostatic_->setForceField(forceField_);
90 +    maw_->setForceField(forceField_);
91  
92 +    ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
93 +
94 +    // Force fields can set options on how to scale van der Waals and electrostatic
95 +    // interactions for atoms connected via bonds, bends and torsions
96 +    // in this case the topological distance between atoms is:
97 +    // 0 = topologically unconnected
98 +    // 1 = bonded together
99 +    // 2 = connected via a bend
100 +    // 3 = connected via a torsion
101 +
102 +    vdwScale_[0] = 1.0;
103 +    vdwScale_[1] = fopts.getvdw12scale();
104 +    vdwScale_[2] = fopts.getvdw13scale();
105 +    vdwScale_[3] = fopts.getvdw14scale();
106 +
107 +    electrostaticScale_[0] = 1.0;
108 +    electrostaticScale_[1] = fopts.getelectrostatic12scale();
109 +    electrostaticScale_[2] = fopts.getelectrostatic13scale();
110 +    electrostaticScale_[3] = fopts.getelectrostatic14scale();    
111 +
112      ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
113      ForceField::AtomTypeContainer::MapTypeIterator i1, i2;
114      AtomType* atype1;
# Line 143 | Line 178 | namespace OpenMD {
178          // look for an explicitly-set non-bonded interaction type using the
179          // two atom types.
180          NonBondedInteractionType* nbiType = forceField_->getNonBondedInteractionType(atype1->getName(), atype2->getName());
181 +        
182 +        if (nbiType != NULL) {
183  
184 <        if (nbiType->isLennardJones()) {
185 <          // We found an explicit Lennard-Jones interaction.  
186 <          // override all other vdw entries for this pair of atom types:
187 <          set<NonBondedInteraction*>::iterator it;
188 <          for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it) {
189 <            InteractionFamily ifam = (*it)->getFamily();
190 <            if (ifam == VANDERWAALS_FAMILY) interactions_[key].erase(*it);
184 >          if (nbiType->isLennardJones()) {
185 >            // We found an explicit Lennard-Jones 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(lj_);
194 >            vdwExplicit = true;
195            }
196 <          interactions_[key].insert(lj_);
197 <          vdwExplicit = true;
198 <        }
199 <
200 <        if (nbiType->isMorse()) {
201 <          if (vdwExplicit) {
202 <            sprintf( painCave.errMsg,
203 <                     "InteractionManager::initialize found more than one explicit\n"
204 <                     "\tvan der Waals interaction for atom types %s - %s\n",
205 <                     atype1->getName().c_str(), atype2->getName().c_str());
206 <            painCave.severity = OPENMD_ERROR;
207 <            painCave.isFatal = 1;
208 <            simError();
196 >          
197 >          if (nbiType->isMorse()) {
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 Morse 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(morse_);
217 >            vdwExplicit = true;
218            }
219 <          // We found an explicit Morse interaction.  
220 <          // override all other vdw entries for this pair of atom types:
221 <          set<NonBondedInteraction*>::iterator it;
222 <          for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it) {
223 <            InteractionFamily ifam = (*it)->getFamily();
224 <            if (ifam == VANDERWAALS_FAMILY) interactions_[key].erase(*it);
219 >          
220 >          if (nbiType->isEAM()) {
221 >            // We found an explicit EAM interaction.  
222 >            // override all other metallic entries for this pair of atom types:
223 >            set<NonBondedInteraction*>::iterator it;
224 >            for (it = interactions_[key].begin();
225 >                 it != interactions_[key].end(); ++it) {
226 >              InteractionFamily ifam = (*it)->getFamily();
227 >              if (ifam == METALLIC_FAMILY) interactions_[key].erase(*it);
228 >            }
229 >            interactions_[key].insert(eam_);
230 >            metExplicit = true;
231            }
232 <          interactions_[key].insert(morse_);
233 <          vdwExplicit = true;
234 <        }
235 <
236 <        if (nbiType->isEAM()) {
237 <          // We found an explicit EAM interaction.  
238 <          // override all other metallic entries for this pair of atom types:
239 <          set<NonBondedInteraction*>::iterator it;
240 <          for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it) {
241 <            InteractionFamily ifam = (*it)->getFamily();
242 <            if (ifam == METALLIC_FAMILY) interactions_[key].erase(*it);
243 <          }
244 <          interactions_[key].insert(eam_);
245 <          metExplicit = true;
246 <        }
247 <
248 <        if (nbiType->isSC()) {
249 <          if (metExplicit) {
250 <            sprintf( painCave.errMsg,
251 <                     "InteractionManager::initialize found more than one explicit\n"
252 <                     "\tmetallic interaction for atom types %s - %s\n",
253 <                     atype1->getName().c_str(), atype2->getName().c_str());
198 <            painCave.severity = OPENMD_ERROR;
199 <            painCave.isFatal = 1;
200 <            simError();
201 <          }
202 <          // We found an explicit Sutton-Chen interaction.  
203 <          // override all other metallic entries for this pair of atom types:
204 <          set<NonBondedInteraction*>::iterator it;
205 <          for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it) {
206 <            InteractionFamily ifam = (*it)->getFamily();
207 <            if (ifam == METALLIC_FAMILY) interactions_[key].erase(*it);
232 >          
233 >          if (nbiType->isSC()) {
234 >            if (metExplicit) {
235 >              sprintf( painCave.errMsg,
236 >                       "InteractionManager::initialize found more than one "
237 >                       "explicit\n"
238 >                       "\tmetallic interaction for atom types %s - %s\n",
239 >                       atype1->getName().c_str(), atype2->getName().c_str());
240 >              painCave.severity = OPENMD_ERROR;
241 >              painCave.isFatal = 1;
242 >              simError();
243 >            }
244 >            // We found an explicit Sutton-Chen interaction.  
245 >            // override all other metallic entries for this pair of atom types:
246 >            set<NonBondedInteraction*>::iterator it;
247 >            for (it = interactions_[key].begin();
248 >                 it != interactions_[key].end(); ++it) {
249 >              InteractionFamily ifam = (*it)->getFamily();
250 >              if (ifam == METALLIC_FAMILY) interactions_[key].erase(*it);
251 >            }
252 >            interactions_[key].insert(sc_);
253 >            metExplicit = true;
254            }
255 <          interactions_[key].insert(sc_);
256 <          metExplicit = true;
255 >          
256 >          if (nbiType->isMAW()) {
257 >            if (vdwExplicit) {
258 >              sprintf( painCave.errMsg,
259 >                       "InteractionManager::initialize found more than one "
260 >                       "explicit\n"
261 >                       "\tvan der Waals interaction for atom types %s - %s\n",
262 >                       atype1->getName().c_str(), atype2->getName().c_str());
263 >              painCave.severity = OPENMD_ERROR;
264 >              painCave.isFatal = 1;
265 >              simError();
266 >            }
267 >            // We found an explicit MAW interaction.  
268 >            // override all other vdw entries for this pair of atom types:
269 >            set<NonBondedInteraction*>::iterator it;
270 >            for (it = interactions_[key].begin();
271 >                 it != interactions_[key].end(); ++it) {
272 >              InteractionFamily ifam = (*it)->getFamily();
273 >              if (ifam == VANDERWAALS_FAMILY) interactions_[key].erase(*it);
274 >            }
275 >            interactions_[key].insert(maw_);
276 >            vdwExplicit = true;
277 >          }        
278          }
279        }
280      }
281      
282 <    // make sure every pair of atom types has a non-bonded interaction:
283 <    for (atype1 = atomTypes->beginType(i1); atype1 != NULL;
284 <         atype1 = atomTypes->nextType(i1)) {
285 <      for (atype2 = atomTypes->beginType(i2); atype2 != NULL;
286 <           atype2 = atomTypes->nextType(i2)) {
282 >    
283 >    // make sure every pair of atom types in this simulation has a
284 >    // non-bonded interaction:
285 >
286 >    set<AtomType*> simTypes = info_->getSimulatedAtomTypes();
287 >    set<AtomType*>::iterator it, jt;
288 >    for (it = simTypes.begin(); it != simTypes.end(); ++it) {
289 >      atype1 = (*it);
290 >      for (jt = simTypes.begin(); jt != simTypes.end(); ++jt) {
291 >        atype2 = (*jt);
292          key = make_pair(atype1, atype2);
293          
294          if (interactions_[key].size() == 0) {
# Line 230 | Line 302 | namespace OpenMD {
302          }
303        }
304      }
233  }
305  
306 +    setupCutoffs();
307 +    setupSwitching();
308 +    setupNeighborlists();
309  
310 <  void InteractionManager::doPrePair(AtomType* atype1,
311 <                                     AtomType* atype2,
312 <                                     RealType rij,
313 <                                     RealType &rho_i_at_j,
314 <                                     RealType &rho_j_at_i) {
310 >    //int ljsp = cutoffMethod_ == SHIFTED_POTENTIAL ? 1 : 0;
311 >    //int ljsf = cutoffMethod_ == SHIFTED_FORCE ? 1 : 0;
312 >    //notifyFortranCutoffs(&rCut_, &rSwitch_, &ljsp, &ljsf);
313 >    //notifyFortranSkinThickness(&skinThickness_);
314 >
315 >    initialized_ = true;
316 >  }
317 >  
318 >  /**
319 >   * setupCutoffs
320 >   *
321 >   * Sets the values of cutoffRadius and cutoffMethod
322 >   *
323 >   * cutoffRadius : realType
324 >   *  If the cutoffRadius was explicitly set, use that value.
325 >   *  If the cutoffRadius was not explicitly set:
326 >   *      Are there electrostatic atoms?  Use 12.0 Angstroms.
327 >   *      No electrostatic atoms?  Poll the atom types present in the
328 >   *      simulation for suggested cutoff values (e.g. 2.5 * sigma).
329 >   *      Use the maximum suggested value that was found.
330 >   *
331 >   * cutoffMethod : (one of HARD, SWITCHED, SHIFTED_FORCE, SHIFTED_POTENTIAL)
332 >   *      If cutoffMethod was explicitly set, use that choice.
333 >   *      If cutoffMethod was not explicitly set, use SHIFTED_FORCE
334 >   */
335 >  void InteractionManager::setupCutoffs() {
336 >    
337 >    Globals* simParams_ = info_->getSimParams();
338 >    
339 >    if (simParams_->haveCutoffRadius()) {
340 >      rCut_ = simParams_->getCutoffRadius();
341 >    } else {      
342 >      if (info_->usesElectrostaticAtoms()) {
343 >        sprintf(painCave.errMsg,
344 >                "InteractionManager::setupCutoffs: No value was set for the cutoffRadius.\n"
345 >                "\tOpenMD will use a default value of 12.0 angstroms"
346 >                "\tfor the cutoffRadius.\n");
347 >        painCave.isFatal = 0;
348 >        painCave.severity = OPENMD_INFO;
349 >        simError();
350 >        rCut_ = 12.0;
351 >      } else {
352 >        RealType thisCut;
353 >        set<AtomType*>::iterator i;
354 >        set<AtomType*> atomTypes;
355 >        atomTypes = info_->getSimulatedAtomTypes();        
356 >        for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
357 >          thisCut = getSuggestedCutoffRadius((*i));
358 >          rCut_ = max(thisCut, rCut_);
359 >        }
360 >        sprintf(painCave.errMsg,
361 >                "InteractionManager::setupCutoffs: No value was set for the cutoffRadius.\n"
362 >                "\tOpenMD will use %lf angstroms.\n",
363 >                rCut_);
364 >        painCave.isFatal = 0;
365 >        painCave.severity = OPENMD_INFO;
366 >        simError();
367 >      }            
368 >    }
369 >
370 >    map<string, CutoffMethod> stringToCutoffMethod;
371 >    stringToCutoffMethod["HARD"] = HARD;
372 >    stringToCutoffMethod["SWITCHED"] = SWITCHED;
373 >    stringToCutoffMethod["SHIFTED_POTENTIAL"] = SHIFTED_POTENTIAL;    
374 >    stringToCutoffMethod["SHIFTED_FORCE"] = SHIFTED_FORCE;
375 >  
376 >    if (simParams_->haveCutoffMethod()) {
377 >      string cutMeth = toUpperCopy(simParams_->getCutoffMethod());
378 >      map<string, CutoffMethod>::iterator i;
379 >      i = stringToCutoffMethod.find(cutMeth);
380 >      if (i == stringToCutoffMethod.end()) {
381 >        sprintf(painCave.errMsg,
382 >                "InteractionManager::setupCutoffs: Could not find chosen cutoffMethod %s\n"
383 >                "\tShould be one of: "
384 >                "HARD, SWITCHED, SHIFTED_POTENTIAL, or SHIFTED_FORCE\n",
385 >                cutMeth.c_str());
386 >        painCave.isFatal = 1;
387 >        painCave.severity = OPENMD_ERROR;
388 >        simError();
389 >      } else {
390 >        cutoffMethod_ = i->second;
391 >      }
392 >    } else {
393 >      sprintf(painCave.errMsg,
394 >              "InteractionManager::setupCutoffs: No value was set for the cutoffMethod.\n"
395 >              "\tOpenMD will use SHIFTED_FORCE.\n");
396 >        painCave.isFatal = 0;
397 >        painCave.severity = OPENMD_INFO;
398 >        simError();
399 >        cutoffMethod_ = SHIFTED_FORCE;        
400 >    }
401 >  }
402 >
403 >
404 >  /**
405 >   * setupSwitching
406 >   *
407 >   * Sets the values of switchingRadius and
408 >   *  If the switchingRadius was explicitly set, use that value (but check it)
409 >   *  If the switchingRadius was not explicitly set: use 0.85 * cutoffRadius_
410 >   */
411 >  void InteractionManager::setupSwitching() {
412 >    Globals* simParams_ = info_->getSimParams();
413 >
414 >    if (simParams_->haveSwitchingRadius()) {
415 >      rSwitch_ = simParams_->getSwitchingRadius();
416 >      if (rSwitch_ > rCut_) {        
417 >        sprintf(painCave.errMsg,
418 >                "InteractionManager::setupSwitching: switchingRadius (%f) is larger than cutoffRadius(%f)\n",
419 >                rSwitch_, rCut_);
420 >        painCave.isFatal = 1;
421 >        painCave.severity = OPENMD_ERROR;
422 >        simError();
423 >      }
424 >    } else {      
425 >      rSwitch_ = 0.85 * rCut_;
426 >      sprintf(painCave.errMsg,
427 >              "InteractionManager::setupSwitching: No value was set for the switchingRadius.\n"
428 >              "\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n"
429 >              "\tswitchingRadius = %f. for this simulation\n", rSwitch_);
430 >      painCave.isFatal = 0;
431 >      painCave.severity = OPENMD_WARNING;
432 >      simError();
433 >    }          
434      
435 +    if (simParams_->haveSwitchingFunctionType()) {
436 +      string funcType = simParams_->getSwitchingFunctionType();
437 +      toUpper(funcType);
438 +      if (funcType == "CUBIC") {
439 +        sft_ = cubic;
440 +      } else {
441 +        if (funcType == "FIFTH_ORDER_POLYNOMIAL") {
442 +          sft_ = fifth_order_poly;
443 +        } else {
444 +          // throw error        
445 +          sprintf( painCave.errMsg,
446 +                   "InteractionManager::setupSwitching : Unknown switchingFunctionType. (Input file specified %s .)\n"
447 +                   "\tswitchingFunctionType must be one of: "
448 +                   "\"cubic\" or \"fifth_order_polynomial\".",
449 +                   funcType.c_str() );
450 +          painCave.isFatal = 1;
451 +          painCave.severity = OPENMD_ERROR;
452 +          simError();
453 +        }          
454 +      }
455 +    }
456 +
457 +    switcher_->setSwitchType(sft_);
458 +    switcher_->setSwitch(rSwitch_, rCut_);
459    }
460 +
461 +  /**
462 +   * setupNeighborlists
463 +   *
464 +   *  If the skinThickness was explicitly set, use that value (but check it)
465 +   *  If the skinThickness was not explicitly set: use 1.0 angstroms
466 +   */
467 +  void InteractionManager::setupNeighborlists() {  
468 +
469 +    Globals* simParams_ = info_->getSimParams();    
470    
471 <  void InteractionManager::doPreForce(AtomType* atype,
472 <                                      RealType rho,      
473 <                                      RealType &frho,
474 <                                      RealType &dfrhodrho) {
475 <  }
471 >    if (simParams_->haveSkinThickness()) {
472 >      skinThickness_ = simParams_->getSkinThickness();
473 >    } else {      
474 >      skinThickness_ = 1.0;
475 >      sprintf(painCave.errMsg,
476 >              "InteractionManager::setupNeighborlists: No value was set for the skinThickness.\n"
477 >              "\tOpenMD will use a default value of %f Angstroms\n"
478 >              "\tfor this simulation\n", skinThickness_);
479 >      painCave.severity = OPENMD_INFO;
480 >      painCave.isFatal = 0;
481 >      simError();
482 >    }            
483  
484 <  void InteractionManager::doSkipCorrection(AtomType* atype1,      
251 <                                            AtomType* atype2,
252 <                                            Vector3d d,
253 <                                            RealType rij,
254 <                                            RealType &skippedCharge1,
255 <                                            RealType &skippedCharge2,
256 <                                            RealType sw,
257 <                                            RealType electroMult,
258 <                                            RealType &pot,
259 <                                            RealType &vpair,
260 <                                            Vector3d &f1,
261 <                                            Mat3x3d eFrame1,
262 <                                            Mat3x3d eFrame2,
263 <                                            Vector3d &t1,
264 <                                            Vector3d &t2) {
484 >    listRadius_ = rCut_ + skinThickness_;
485    }
266  
267  void InteractionManager::doSelfCorrection(AtomType* atype,
268                                            Mat3x3d eFrame,
269                                            RealType skippedCharge,
270                                            RealType &pot,
271                                            Vector3d &t) {
272  }
486  
487 <  void InteractionManager::do_prepair(int *atid1, int *atid2, RealType *rij, RealType *rho_i_at_j, RealType *rho_j_at_i){
487 >
488 >  void InteractionManager::doPrePair(InteractionData idat){
489      
490      if (!initialized_) initialize();
491 <    AtomType* atype1 = typeMap_[*atid1];
492 <    AtomType* atype2 = typeMap_[*atid2];
491 >        
492 >    set<NonBondedInteraction*>::iterator it;
493 >
494 >    for (it = interactions_[ *(idat.atypes) ].begin();
495 >         it != interactions_[ *(idat.atypes) ].end(); ++it){
496 >      if ((*it)->getFamily() == METALLIC_FAMILY) {
497 >        dynamic_cast<MetallicInteraction*>(*it)->calcDensity(idat);
498 >      }
499 >    }
500      
280    doPrePair(atype1, atype2, *rij, *rho_i_at_j, *rho_j_at_i);
281    
501      return;    
502    }
503 +  
504 +  void InteractionManager::doPreForce(SelfData sdat){
505  
506 <  void InteractionManager::do_preforce(int *atid, RealType *rho, RealType *frho, RealType *dfrhodrho){
286 <
287 <    if (!initialized_) initialize();    
288 <    AtomType* atype = typeMap_[*atid];
289 <
290 <    doPreForce(atype, *rho, *frho, *dfrhodrho);
506 >    if (!initialized_) initialize();
507      
508 +    pair<AtomType*, AtomType*> key = make_pair(sdat.atype, sdat.atype);
509 +    set<NonBondedInteraction*>::iterator it;
510 +    
511 +    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
512 +      if ((*it)->getFamily() == METALLIC_FAMILY) {
513 +        dynamic_cast<MetallicInteraction*>(*it)->calcFunctional(sdat);
514 +      }
515 +    }
516 +    
517      return;    
518    }
519  
520 <  void InteractionManager::do_pair(int *atid1, int *atid2, RealType *d, RealType *r, RealType *r2, RealType *rcut, RealType *sw, RealType *vdwMult,RealType *electroMult, RealType *pot, RealType *vpair, RealType *f1, RealType *eFrame1, RealType *eFrame2, RealType *A1, RealType *A2, RealType *t1, RealType *t2, RealType *rho1, RealType *rho2, RealType *dfrho1, RealType *dfrho2, RealType *fshift1, RealType *fshift2){
521 <
520 >  void InteractionManager::doPair(InteractionData idat){
521 >    
522      if (!initialized_) initialize();
523 <          
299 <    InteractionData idat;
300 <
301 <    idat.atype1 = typeMap_[*atid1];
302 <    idat.atype2 = typeMap_[*atid2];
303 <    idat.d = Vector3d(d);
304 <    idat.rij = *r;
305 <    idat.r2 = *r2;
306 <    idat.rcut = *rcut;
307 <    idat.sw = *sw;
308 <    idat.vdwMult = *vdwMult;
309 <    idat.electroMult = *electroMult;
310 <    idat.pot = *pot;
311 <    idat.vpair = *vpair;
312 <    idat.f1 = Vector3d(f1);
313 <    idat.eFrame1 = Mat3x3d(eFrame1);
314 <    idat.eFrame2 = Mat3x3d(eFrame2);
315 <    idat.A1 = RotMat3x3d(A1);
316 <    idat.A2 = RotMat3x3d(A2);
317 <    idat.t1 = Vector3d(t1);
318 <    idat.t2 = Vector3d(t2);
319 <    idat.rho1 = *rho1;
320 <    idat.rho2 = *rho2;
321 <    idat.dfrho1 = *dfrho1;
322 <    idat.dfrho2 = *dfrho2;
323 <    idat.fshift1 = *fshift1;
324 <    idat.fshift2 = *fshift2;
325 <
326 <    pair<AtomType*, AtomType*> key = make_pair(idat.atype1, idat.atype2);
523 >  
524      set<NonBondedInteraction*>::iterator it;
525  
526 <    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it)
526 >    for (it = interactions_[ *(idat.atypes) ].begin();
527 >         it != interactions_[ *(idat.atypes) ].end(); ++it)
528        (*it)->calcForce(idat);
529      
332    f1[0] = idat.f1.x();
333    f1[1] = idat.f1.y();
334    f1[2] = idat.f1.z();
335    
336    t1[0] = idat.t1.x();
337    t1[1] = idat.t1.y();
338    t1[2] = idat.t1.z();
339    
340    t2[0] = idat.t2.x();
341    t2[1] = idat.t2.y();
342    t2[2] = idat.t2.z();
343
530      return;    
531    }
532  
533 <  void InteractionManager::do_skip_correction(int *atid1, int *atid2, RealType *d, RealType *r, RealType *skippedCharge1, RealType *skippedCharge2, RealType *sw, RealType *electroMult, RealType *pot, RealType *vpair, RealType *f1, RealType *eFrame1, RealType *eFrame2, RealType *t1, RealType *t2){
533 >  void InteractionManager::doSkipCorrection(InteractionData idat){
534  
535 <    if (!initialized_) initialize();
350 <          
351 <    AtomType* atype1 = typeMap_[*atid1];
352 <    AtomType* atype2 = typeMap_[*atid2];
353 <    Vector3d disp(d);
354 <    Vector3d frc(f1);
355 <    Vector3d trq1(t1);
356 <    Vector3d trq2(t2);
357 <    Mat3x3d eFi(eFrame1);
358 <    Mat3x3d eFj(eFrame2);
359 <      
360 <    doSkipCorrection(atype1, atype2, disp, *r, *skippedCharge1, *skippedCharge2, *sw,
361 <                     *electroMult, *pot,  *vpair, frc, eFi, eFj, trq1, trq2);
362 <
363 <    f1[0] = frc.x();
364 <    f1[1] = frc.y();
365 <    f1[2] = frc.z();
535 >    if (!initialized_) initialize();  
536      
537 <    t1[0] = trq1.x();
368 <    t1[1] = trq1.y();
369 <    t1[2] = trq1.z();
370 <    
371 <    t2[0] = trq2.x();
372 <    t2[1] = trq2.y();
373 <    t2[2] = trq2.z();
537 >    set<NonBondedInteraction*>::iterator it;
538  
539 <    return;
539 >    for (it = interactions_[ *(idat.atypes) ].begin();
540 >         it != interactions_[ *(idat.atypes) ].end(); ++it){
541 >      if ((*it)->getFamily() == ELECTROSTATIC_FAMILY) {
542 >        dynamic_cast<ElectrostaticInteraction*>(*it)->calcSkipCorrection(idat);
543 >      }
544 >    }
545 >    
546 >    return;    
547    }
548  
549 <  void InteractionManager::do_self_correction(int *atid, RealType *eFrame, RealType *skippedCharge, RealType *pot, RealType *t){
549 >  void InteractionManager::doSelfCorrection(SelfData sdat){
550  
551      if (!initialized_) initialize();
552 <          
553 <    AtomType* atype = typeMap_[*atid];
554 <    Mat3x3d eFi(eFrame);
384 <    Vector3d trq1(t);
385 <      
386 <    doSelfCorrection(atype, eFi, *skippedCharge, *pot, trq1);
552 >    
553 >    pair<AtomType*, AtomType*> key = make_pair(sdat.atype, sdat.atype);
554 >    set<NonBondedInteraction*>::iterator it;
555  
556 <    t[0] = trq1.x();
557 <    t[1] = trq1.y();
558 <    t[2] = trq1.z();
559 <
560 <    return;
556 >    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
557 >      if ((*it)->getFamily() == ELECTROSTATIC_FAMILY) {
558 >        dynamic_cast<ElectrostaticInteraction*>(*it)->calcSelfCorrection(sdat);
559 >      }
560 >    }
561 >      
562 >    return;    
563    }
564  
565 < } //end namespace OpenMD
566 <
397 < extern "C" {
398 <  
399 < #define fortranDoPrePair FC_FUNC(do_prepair, DO_PREPAIR)
400 < #define fortranDoPreForce FC_FUNC(do_preforce, DO_PREFORCE)
401 < #define fortranDoPair FC_FUNC(do_pair, DO_PAIR)
402 < #define fortranDoSkipCorrection FC_FUNC(do_skip_correction, DO_SKIP_CORRECTION)
403 < #define fortranDoSelfCorrection FC_FUNC(do_self_correction, DO_SELF_CORRECTION)
404 < #define fortranGetCutoff FC_FUNC(get_cutoff, GET_CUTOFF)
405 <
406 <  void fortranDoPrePair(int *atid1, int *atid2, RealType *rij,
407 <                        RealType *rho_i_at_j, RealType *rho_j_at_i) {
408 <            
409 <    return OpenMD::InteractionManager::Instance()->do_prepair(atid1, atid2, rij,
410 <                                                              rho_i_at_j,  
411 <                                                              rho_j_at_i);
412 <  }
413 <  void fortranDoPreforce(int *atid, RealType *rho, RealType *frho,
414 <                         RealType *dfrhodrho) {  
565 >  RealType InteractionManager::getSuggestedCutoffRadius(int *atid) {
566 >    if (!initialized_) initialize();
567      
568 <    return OpenMD::InteractionManager::Instance()->do_preforce(atid, rho, frho,
417 <                                                               dfrhodrho);    
418 <  }
419 <  
420 <  void fortranDoPair(int *atid1, int *atid2, RealType *d, RealType *r,
421 <                     RealType *r2, RealType *rcut, RealType *sw, RealType *vdwMult,
422 <                     RealType *electroMult, RealType *pot, RealType *vpair, RealType *f1,
423 <                     RealType *eFrame1, RealType *eFrame2, RealType *A1, RealType *A2,
424 <                     RealType *t1, RealType *t2,
425 <                     RealType *rho1, RealType *rho2, RealType *dfrho1, RealType *dfrho2,
426 <                     RealType *fshift1, RealType *fshift2){
427 <    
428 <    return OpenMD::InteractionManager::Instance()->do_pair(atid1, atid2, d, r, r2, rcut,
429 <                                                           sw, vdwMult, electroMult, pot,
430 <                                                           vpair, f1, eFrame1, eFrame2,
431 <                                                           A1, A2, t1, t2, rho1, rho2,
432 <                                                           dfrho1, dfrho2, fshift1, fshift2);
433 <  }
568 >    AtomType* atype = typeMap_[*atid];
569  
570 <  void fortranDoSkipCorrection(int *atid1, int *atid2, RealType *d, RealType *r,
571 <                               RealType *skippedCharge1, RealType *skippedCharge2,
572 <                               RealType *sw, RealType *electroMult, RealType *pot,
438 <                               RealType *vpair, RealType *f1,
439 <                               RealType *eFrame1, RealType *eFrame2,
440 <                               RealType *t1, RealType *t2){
570 >    pair<AtomType*, AtomType*> key = make_pair(atype, atype);
571 >    set<NonBondedInteraction*>::iterator it;
572 >    RealType cutoff = 0.0;
573      
574 <    return OpenMD::InteractionManager::Instance()->do_skip_correction(atid1, atid2, d, r,
575 <                                                                      skippedCharge1,
576 <                                                                      skippedCharge2,
445 <                                                                      sw, electroMult, pot,
446 <                                                                      vpair, f1, eFrame1,
447 <                                                                      eFrame2, t1, t2);
574 >    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it)
575 >      cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(key));  
576 >    return cutoff;    
577    }
578  
579 <  void fortranDoSelfCorrection(int *atid, RealType *eFrame, RealType *skippedCharge,
580 <                               RealType *pot, RealType *t) {
579 >  RealType InteractionManager::getSuggestedCutoffRadius(AtomType* atype) {
580 >    if (!initialized_) initialize();
581      
582 <    return OpenMD::InteractionManager::Instance()->do_self_correction(atid, eFrame,
583 <                                                                      skippedCharge,
584 <                                                                      pot, t);
582 >    pair<AtomType*, AtomType*> key = make_pair(atype, atype);
583 >    set<NonBondedInteraction*>::iterator it;
584 >    RealType cutoff = 0.0;
585 >    
586 >    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it)
587 >      cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(key));  
588 >    return cutoff;    
589    }
590 <  RealType fortranGetCutoff() {
458 <    return OpenMD::InteractionManager::Instance()->getCutoff();
459 <  }
460 < }
590 > } //end namespace OpenMD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines