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

Comparing branches/development/src/nonbonded/EAM.cpp (file contents):
Revision 1575 by gezelter, Fri Jun 3 21:39:49 2011 UTC vs.
Revision 1586 by gezelter, Tue Jun 21 06:34:35 2011 UTC

# Line 51 | Line 51 | namespace OpenMD {
51   namespace OpenMD {
52  
53    EAM::EAM() : name_("EAM"), initialized_(false), forceField_(NULL),
54 <               mixMeth_(eamJohnson), eamRcut_(0.0) {}
54 >               mixMeth_(eamJohnson), eamRcut_(0.0), haveCutoffRadius_(false) {}
55    
56    EAMParam EAM::getEAMParam(AtomType* atomType) {
57      
# Line 193 | Line 193 | namespace OpenMD {
193      CubicSpline* cs = new CubicSpline();
194      cs->addPoints(rvals, phivals);
195      return cs;
196 +  }
197 +
198 +  void EAM::setCutoffRadius( RealType rCut ) {
199 +    eamRcut_ = rCut;
200 +    haveCutoffRadius_ = true;
201    }
202  
203    void EAM::initialize() {
# Line 353 | Line 358 | namespace OpenMD {
358      
359      EAMAtomData data1 = EAMMap[idat.atypes.first];
360      EAMAtomData data2 = EAMMap[idat.atypes.second];
361 <
362 <    if ( *(idat.rij) < data1.rcut)
361 >    
362 >    if (haveCutoffRadius_)
363 >      if ( *(idat.rij) > eamRcut_) return;
364 >    
365 >    if ( *(idat.rij) < data1.rcut) {
366        *(idat.rho1) += data1.rho->getValueAt( *(idat.rij));
367 <
368 <
369 <    if ( *(idat.rij) < data2.rcut)
370 <      *(idat.rho2) += data2.rho->getValueAt( *(idat.rij));
371 <
372 <    return;
367 >      
368 >      
369 >      if ( *(idat.rij) < data2.rcut)
370 >        *(idat.rho2) += data2.rho->getValueAt( *(idat.rij));
371 >      
372 >      return;
373 >    }
374    }
375 <
375 >  
376    void EAM::calcFunctional(SelfData &sdat) {
377 <
377 >    
378      if (!initialized_) initialize();
379  
380      EAMAtomData data1 = EAMMap[ sdat.atype ];
# Line 375 | Line 384 | namespace OpenMD {
384      *(sdat.frho) = result.first;
385      *(sdat.dfrhodrho) = result.second;
386  
387 <    sdat.pot[METALLIC_FAMILY] += result.first;
387 >    (*(sdat.pot))[METALLIC_FAMILY] += result.first;
388      *(sdat.particlePot) += result.first;
389  
390      return;
# Line 386 | Line 395 | namespace OpenMD {
395  
396      if (!initialized_) initialize();
397  
389    pair<RealType, RealType> res;
390    
391    if ( *(idat.rij) < eamRcut_) {
398  
393      EAMAtomData data1 = EAMMap[idat.atypes.first];
394      EAMAtomData data2 = EAMMap[idat.atypes.second];
399  
400 <      // get type-specific cutoff radii
401 <
402 <      RealType rci = data1.rcut;
403 <      RealType rcj = data2.rcut;
400 >    if (haveCutoffRadius_)
401 >      if ( *(idat.rij) > eamRcut_) return;
402 >  
403 >    pair<RealType, RealType> res;
404 >    
405 >    
406 >    EAMAtomData data1 = EAMMap[idat.atypes.first];
407 >    EAMAtomData data2 = EAMMap[idat.atypes.second];
408 >    
409 >    // get type-specific cutoff radii
410 >    
411 >    RealType rci = data1.rcut;
412 >    RealType rcj = data2.rcut;
413 >    
414 >    RealType rha(0.0), drha(0.0), rhb(0.0), drhb(0.0);
415 >    RealType pha(0.0), dpha(0.0), phb(0.0), dphb(0.0);
416 >    RealType phab(0.0), dvpdr(0.0);
417 >    RealType drhoidr, drhojdr, dudr;
418 >    
419 >    if ( *(idat.rij) < rci) {
420 >      res = data1.rho->getValueAndDerivativeAt( *(idat.rij));
421 >      rha = res.first;
422 >      drha = res.second;
423        
424 <      RealType rha(0.0), drha(0.0), rhb(0.0), drhb(0.0);
425 <      RealType pha(0.0), dpha(0.0), phb(0.0), dphb(0.0);
426 <      RealType phab(0.0), dvpdr(0.0);
427 <      RealType drhoidr, drhojdr, dudr;
424 >      res = MixingMap[make_pair(idat.atypes.first, idat.atypes.first)].phi->getValueAndDerivativeAt( *(idat.rij) );
425 >      pha = res.first;
426 >      dpha = res.second;
427 >    }
428 >    
429 >    if ( *(idat.rij) < rcj) {
430 >      res = data2.rho->getValueAndDerivativeAt( *(idat.rij) );
431 >      rhb = res.first;
432 >      drhb = res.second;
433        
434 <      if ( *(idat.rij) < rci) {
435 <        res = data1.rho->getValueAndDerivativeAt( *(idat.rij));
436 <        rha = res.first;
437 <        drha = res.second;
434 >      res = MixingMap[make_pair(idat.atypes.second, idat.atypes.second)].phi->getValueAndDerivativeAt( *(idat.rij) );
435 >      phb = res.first;
436 >      dphb = res.second;
437 >    }
438  
439 <        res = MixingMap[make_pair(idat.atypes.first, idat.atypes.first)].phi->getValueAndDerivativeAt( *(idat.rij) );
440 <        pha = res.first;
441 <        dpha = res.second;
439 >    switch(mixMeth_) {
440 >    case eamJohnson:
441 >      
442 >      if ( *(idat.rij) < rci) {
443 >        phab = phab + 0.5 * (rhb / rha) * pha;
444 >        dvpdr = dvpdr + 0.5*((rhb/rha)*dpha +
445 >                             pha*((drhb/rha) - (rhb*drha/rha/rha)));
446        }
447 <
447 >      
448 >      
449 >      
450        if ( *(idat.rij) < rcj) {
451 <        res = data2.rho->getValueAndDerivativeAt( *(idat.rij) );
452 <        rhb = res.first;
453 <        drhb = res.second;
420 <
421 <        res = MixingMap[make_pair(idat.atypes.second, idat.atypes.second)].phi->getValueAndDerivativeAt( *(idat.rij) );
422 <        phb = res.first;
423 <        dphb = res.second;
424 <      }
425 <
426 <      switch(mixMeth_) {
427 <      case eamJohnson:
428 <      
429 <        if ( *(idat.rij) < rci) {
430 <          phab = phab + 0.5 * (rhb / rha) * pha;
431 <          dvpdr = dvpdr + 0.5*((rhb/rha)*dpha +
432 <                               pha*((drhb/rha) - (rhb*drha/rha/rha)));
433 <        }
434 <          
435 <          
436 <
437 <        if ( *(idat.rij) < rcj) {
438 <          phab = phab + 0.5 * (rha / rhb) * phb;
439 <          dvpdr = dvpdr + 0.5 * ((rha/rhb)*dphb +
440 <                                 phb*((drha/rhb) - (rha*drhb/rhb/rhb)));
441 <        }
442 <
443 <        break;
444 <
445 <      case eamDaw:
446 <        res = MixingMap[idat.atypes].phi->getValueAndDerivativeAt( *(idat.rij));
447 <        phab = res.first;
448 <        dvpdr = res.second;
449 <
450 <        break;
451 <      case eamUnknown:
452 <      default:
453 <
454 <        sprintf(painCave.errMsg,
455 <                "EAM::calcForce hit a mixing method it doesn't know about!\n"
456 <                );
457 <        painCave.severity = OPENMD_ERROR;
458 <        painCave.isFatal = 1;
459 <        simError();        
460 <          
451 >        phab = phab + 0.5 * (rha / rhb) * phb;
452 >        dvpdr = dvpdr + 0.5 * ((rha/rhb)*dphb +
453 >                               phb*((drha/rhb) - (rha*drhb/rhb/rhb)));
454        }
455        
456 <      drhoidr = drha;
457 <      drhojdr = drhb;
458 <
459 <      dudr = drhojdr* *(idat.dfrho1) + drhoidr* *(idat.dfrho2) + dvpdr;
460 <
461 <      *(idat.f1) = *(idat.d) * dudr / *(idat.rij);
462 <        
463 <      // particlePot is the difference between the full potential and
464 <      // the full potential without the presence of a particular
465 <      // particle (atom1).
466 <      //
467 <      // This reduces the density at other particle locations, so we
468 <      // need to recompute the density at atom2 assuming atom1 didn't
469 <      // contribute.  This then requires recomputing the density
470 <      // functional for atom2 as well.
471 <
472 <      *(idat.particlePot1) += data2.F->getValueAt( *(idat.rho2) - rha )
473 <        - *(idat.frho2);
481 <
482 <      *(idat.particlePot2) += data1.F->getValueAt( *(idat.rho1) - rhb)
483 <        - *(idat.frho1);
484 <
485 <      idat.pot[METALLIC_FAMILY] += phab;
486 <
487 <      *(idat.vpair) += phab;
456 >      break;
457 >      
458 >    case eamDaw:
459 >      res = MixingMap[idat.atypes].phi->getValueAndDerivativeAt( *(idat.rij));
460 >      phab = res.first;
461 >      dvpdr = res.second;
462 >      
463 >      break;
464 >    case eamUnknown:
465 >    default:
466 >      
467 >      sprintf(painCave.errMsg,
468 >              "EAM::calcForce hit a mixing method it doesn't know about!\n"
469 >              );
470 >      painCave.severity = OPENMD_ERROR;
471 >      painCave.isFatal = 1;
472 >      simError();        
473 >      
474      }
475 <
475 >    
476 >    drhoidr = drha;
477 >    drhojdr = drhb;
478 >    
479 >    dudr = drhojdr* *(idat.dfrho1) + drhoidr* *(idat.dfrho2) + dvpdr;
480 >    
481 >    *(idat.f1) += *(idat.d) * dudr / *(idat.rij);
482 >        
483 >    // particlePot is the difference between the full potential and
484 >    // the full potential without the presence of a particular
485 >    // particle (atom1).
486 >    //
487 >    // This reduces the density at other particle locations, so we
488 >    // need to recompute the density at atom2 assuming atom1 didn't
489 >    // contribute.  This then requires recomputing the density
490 >    // functional for atom2 as well.
491 >    
492 >    *(idat.particlePot1) += data2.F->getValueAt( *(idat.rho2) - rha )
493 >      - *(idat.frho2);
494 >    
495 >    *(idat.particlePot2) += data1.F->getValueAt( *(idat.rho1) - rhb)
496 >      - *(idat.frho1);
497 >    
498 >    (*(idat.pot))[METALLIC_FAMILY] += phab;
499 >    
500 >    *(idat.vpair) += phab;
501 >  
502      return;
503      
504    }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines