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 1505 by gezelter, Sun Oct 3 22:18:59 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      }
305 <  }
305 >
306 >    setupCutoffs();
307 >    setupSwitching();
308 >    setupNeighborlists();
309 >
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 <  void InteractionManager::doPrePair(int *atid1, int *atid2, RealType *rij, RealType *rho_i_at_j, RealType *rho_j_at_i){
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 <    if (!initialized_) initialize();
338 <          
339 <    DensityData ddat;
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 <    ddat.atype1 = typeMap_[*atid1];
371 <    ddat.atype2 = typeMap_[*atid2];
372 <    ddat.rij = *rij;
373 <    ddat.rho_i_at_j = *rho_i_at_j;
374 <    ddat.rho_j_at_i = *rho_j_at_i;
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 <    pair<AtomType*, AtomType*> key = make_pair(ddat.atype1, ddat.atype2);
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 >    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 >    listRadius_ = rCut_ + skinThickness_;
485 >  }
486 >
487 >
488 >  void InteractionManager::doPrePair(InteractionData idat){
489 >    
490 >    if (!initialized_) initialize();
491 >        
492      set<NonBondedInteraction*>::iterator it;
493  
494 <    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
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(ddat);
497 >        dynamic_cast<MetallicInteraction*>(*it)->calcDensity(idat);
498        }
499      }
500      
501      return;    
502    }
503    
504 <  void InteractionManager::doPreForce(int *atid, RealType *rho, RealType *frho, RealType *dfrhodrho){
504 >  void InteractionManager::doPreForce(SelfData sdat){
505  
506      if (!initialized_) initialize();
507 <          
508 <    FunctionalData fdat;
264 <
265 <    fdat.atype = typeMap_[*atid];
266 <    fdat.rho = *rho;
267 <    fdat.frho = *frho;
268 <    fdat.dfrhodrho = *dfrhodrho;
269 <
270 <    pair<AtomType*, AtomType*> key = make_pair(fdat.atype, fdat.atype);
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(fdat);
513 >        dynamic_cast<MetallicInteraction*>(*it)->calcFunctional(sdat);
514        }
515      }
516      
517      return;    
518    }
519  
520 <  void InteractionManager::doPair(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){
520 >  void InteractionManager::doPair(InteractionData idat){
521      
522      if (!initialized_) initialize();
523 <    
286 <    InteractionData idat;
287 <    
288 <    idat.atype1 = typeMap_[*atid1];
289 <    idat.atype2 = typeMap_[*atid2];
290 <    idat.d = Vector3d(d);
291 <    idat.rij = *r;
292 <    idat.r2 = *r2;
293 <    idat.rcut = *rcut;
294 <    idat.sw = *sw;
295 <    idat.vdwMult = *vdwMult;
296 <    idat.electroMult = *electroMult;
297 <    idat.pot = *pot;
298 <    idat.vpair = *vpair;
299 <    idat.f1 = Vector3d(f1);
300 <    idat.eFrame1 = Mat3x3d(eFrame1);
301 <    idat.eFrame2 = Mat3x3d(eFrame2);
302 <    idat.A1 = RotMat3x3d(A1);
303 <    idat.A2 = RotMat3x3d(A2);
304 <    idat.t1 = Vector3d(t1);
305 <    idat.t2 = Vector3d(t2);
306 <    idat.rho1 = *rho1;
307 <    idat.rho2 = *rho2;
308 <    idat.dfrho1 = *dfrho1;
309 <    idat.dfrho2 = *dfrho2;
310 <    idat.fshift1 = *fshift1;
311 <    idat.fshift2 = *fshift2;
312 <
313 <    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      
319    f1[0] = idat.f1.x();
320    f1[1] = idat.f1.y();
321    f1[2] = idat.f1.z();
322    
323    t1[0] = idat.t1.x();
324    t1[1] = idat.t1.y();
325    t1[2] = idat.t1.z();
326    
327    t2[0] = idat.t2.x();
328    t2[1] = idat.t2.y();
329    t2[2] = idat.t2.z();
330
530      return;    
531    }
532  
533 <  void InteractionManager::doSkipCorrection(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();
535 >    if (!initialized_) initialize();  
536      
338    SkipCorrectionData skdat;
339    
340    skdat.atype1 = typeMap_[*atid1];
341    skdat.atype2 = typeMap_[*atid2];
342    skdat.d = Vector3d(d);
343    skdat.rij = *r;
344    skdat.skippedCharge1 = *skippedCharge1;
345    skdat.skippedCharge2 = *skippedCharge2;
346    skdat.sw = *sw;
347    skdat.electroMult = *electroMult;
348    skdat.pot = *pot;
349    skdat.vpair = *vpair;
350    skdat.f1 = Vector3d(f1);
351    skdat.eFrame1 = Mat3x3d(eFrame1);
352    skdat.eFrame2 = Mat3x3d(eFrame2);
353    skdat.t1 = Vector3d(t1);
354    skdat.t2 = Vector3d(t2);
355
356    pair<AtomType*, AtomType*> key = make_pair(skdat.atype1, skdat.atype2);
537      set<NonBondedInteraction*>::iterator it;
538  
539 <    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
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(skdat);
542 >        dynamic_cast<ElectrostaticInteraction*>(*it)->calcSkipCorrection(idat);
543        }
544      }
545      
365    f1[0] = skdat.f1.x();
366    f1[1] = skdat.f1.y();
367    f1[2] = skdat.f1.z();
368    
369    t1[0] = skdat.t1.x();
370    t1[1] = skdat.t1.y();
371    t1[2] = skdat.t1.z();
372    
373    t2[0] = skdat.t2.x();
374    t2[1] = skdat.t2.y();
375    t2[2] = skdat.t2.z();
376
546      return;    
547    }
548  
549 <  void InteractionManager::doSelfCorrection(int *atid, RealType *eFrame, RealType *skippedCharge, RealType *pot, RealType *t){
549 >  void InteractionManager::doSelfCorrection(SelfData sdat){
550  
551      if (!initialized_) initialize();
552      
553 <    SelfCorrectionData scdat;
385 <    
386 <    scdat.atype = typeMap_[*atid];
387 <    scdat.eFrame = Mat3x3d(eFrame);
388 <    scdat.skippedCharge = *skippedCharge;
389 <    scdat.pot = *pot;
390 <    scdat.t = Vector3d(t);
391 <
392 <    pair<AtomType*, AtomType*> key = make_pair(scdat.atype, scdat.atype);
553 >    pair<AtomType*, AtomType*> key = make_pair(sdat.atype, sdat.atype);
554      set<NonBondedInteraction*>::iterator it;
555  
556      for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it){
557        if ((*it)->getFamily() == ELECTROSTATIC_FAMILY) {
558 <        dynamic_cast<ElectrostaticInteraction*>(*it)->calcSelfCorrection(scdat);
558 >        dynamic_cast<ElectrostaticInteraction*>(*it)->calcSelfCorrection(sdat);
559        }
560      }
561 <        
401 <    t[0] = scdat.t.x();
402 <    t[1] = scdat.t.y();
403 <    t[2] = scdat.t.z();
404 <
561 >      
562      return;    
563    }
564  
408
565    RealType InteractionManager::getSuggestedCutoffRadius(int *atid) {
566      if (!initialized_) initialize();
567      
# Line 416 | Line 572 | namespace OpenMD {
572      RealType cutoff = 0.0;
573      
574      for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it)
575 <      cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(atype, atype));  
575 >      cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(key));  
576      return cutoff;    
577    }
578  
579 < } //end namespace OpenMD
580 <
425 < extern "C" {
426 <  
427 < #define fortranDoPrePair FC_FUNC(do_prepair, DO_PREPAIR)
428 < #define fortranDoPreForce FC_FUNC(do_preforce, DO_PREFORCE)
429 < #define fortranDoPair FC_FUNC(do_pair, DO_PAIR)
430 < #define fortranDoSkipCorrection FC_FUNC(do_skip_correction, DO_SKIP_CORRECTION)
431 < #define fortranDoSelfCorrection FC_FUNC(do_self_correction, DO_SELF_CORRECTION)
432 < #define fortranGetCutoff FC_FUNC(get_cutoff, GET_CUTOFF)
433 <
434 <  void fortranDoPrePair(int *atid1, int *atid2, RealType *rij,
435 <                        RealType *rho_i_at_j, RealType *rho_j_at_i) {
436 <            
437 <    return OpenMD::InteractionManager::Instance()->doPrePair(atid1, atid2, rij,
438 <                                                             rho_i_at_j,  
439 <                                                             rho_j_at_i);
440 <  }
441 <  void fortranDoPreforce(int *atid, RealType *rho, RealType *frho,
442 <                         RealType *dfrhodrho) {  
579 >  RealType InteractionManager::getSuggestedCutoffRadius(AtomType* atype) {
580 >    if (!initialized_) initialize();
581      
582 <    return OpenMD::InteractionManager::Instance()->doPreForce(atid, rho, frho,
583 <                                                              dfrhodrho);    
584 <  }
447 <  
448 <  void fortranDoPair(int *atid1, int *atid2, RealType *d, RealType *r,
449 <                     RealType *r2, RealType *rcut, RealType *sw,
450 <                     RealType *vdwMult, RealType *electroMult, RealType *pot,
451 <                     RealType *vpair, RealType *f1, RealType *eFrame1,
452 <                     RealType *eFrame2, RealType *A1, RealType *A2,
453 <                     RealType *t1, RealType *t2, RealType *rho1, RealType *rho2,
454 <                     RealType *dfrho1, RealType *dfrho2, RealType *fshift1,
455 <                     RealType *fshift2){
582 >    pair<AtomType*, AtomType*> key = make_pair(atype, atype);
583 >    set<NonBondedInteraction*>::iterator it;
584 >    RealType cutoff = 0.0;
585      
586 <    return OpenMD::InteractionManager::Instance()->doPair(atid1, atid2, d, r,
587 <                                                          r2, rcut, sw,
588 <                                                          vdwMult, electroMult,
460 <                                                          pot, vpair, f1,
461 <                                                          eFrame1, eFrame2,
462 <                                                          A1, A2, t1, t2, rho1,
463 <                                                          rho2, dfrho1, dfrho2,
464 <                                                          fshift1, fshift2);
586 >    for (it = interactions_[key].begin(); it != interactions_[key].end(); ++it)
587 >      cutoff = max(cutoff, (*it)->getSuggestedCutoffRadius(key));  
588 >    return cutoff;    
589    }
590 <  
467 <  void fortranDoSkipCorrection(int *atid1, int *atid2, RealType *d,
468 <                               RealType *r, RealType *skippedCharge1,
469 <                               RealType *skippedCharge2, RealType *sw,
470 <                               RealType *electroMult, RealType *pot,
471 <                               RealType *vpair, RealType *f1,
472 <                               RealType *eFrame1, RealType *eFrame2,
473 <                               RealType *t1, RealType *t2){
474 <    
475 <    return OpenMD::InteractionManager::Instance()->doSkipCorrection(atid1,
476 <                                                                    atid2, d,
477 <                                                                    r,
478 <                                                                    skippedCharge1,
479 <                                                                    skippedCharge2,
480 <                                                                    sw, electroMult, pot,
481 <                                                                    vpair, f1, eFrame1,
482 <                                                                    eFrame2, t1, t2);
483 <  }
484 <  
485 <  void fortranDoSelfCorrection(int *atid, RealType *eFrame, RealType *skippedCharge,
486 <                               RealType *pot, RealType *t) {
487 <    
488 <    return OpenMD::InteractionManager::Instance()->doSelfCorrection(atid,
489 <                                                                    eFrame,
490 <                                                                    skippedCharge,
491 <                                                                    pot, t);
492 <  }
493 <  RealType fortranGetCutoff(int *atid) {    
494 <    return OpenMD::InteractionManager::Instance()->getSuggestedCutoffRadius(atid);
495 <  }
496 < }
590 > } //end namespace OpenMD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines