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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines