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

Comparing:
branches/development/src/nonbonded/SC.cpp (file contents), Revision 1489 by gezelter, Tue Aug 10 18:34:59 2010 UTC vs.
branches/devel_omp/src/nonbonded/SC.cpp (file contents), Revision 1614 by mciznick, Tue Aug 23 20:55:51 2011 UTC

# Line 49 | Line 49 | namespace OpenMD {
49  
50   namespace OpenMD {
51  
52  bool SC::initialized_ = false;
53  RealType SC::scRcut_ = 0.0;
54  int SC::np_ = 3000;
55  ForceField* SC::forceField_ = NULL;
56  map<int, AtomType*> SC::SClist;
57  map<AtomType*, SCAtomData> SC::SCMap;
58  map<pair<AtomType*, AtomType*>, SCInteractionData> SC::MixingMap;
59  
60  SC* SC::_instance = NULL;
52  
53 <  SC* SC::Instance() {
54 <    if (!_instance) {
64 <      _instance = new SC();
65 <    }
66 <    return _instance;
67 <  }
53 >  SC::SC() : name_("SC"), initialized_(false), forceField_(NULL),
54 >             scRcut_(0.0), np_(3000) {}
55    
56    SCParam SC::getSCParam(AtomType* atomType) {
57      
# Line 315 | Line 302 | namespace OpenMD {
302      return;
303    }
304  
305 <  void SC::calcDensity(AtomType* at1, AtomType* at2, const RealType rij,
319 <                        RealType &rho_i_at_j, RealType &rho_j_at_i) {
305 >  void SC::calcDensity(InteractionData &idat) {
306      
307      if (!initialized_) initialize();
308      
309 <    SCInteractionData mixer = MixingMap[make_pair(at1, at2)];
309 >    SCInteractionData mixer = MixingMap[ idat.atypes ];
310  
311 <    rho_i_at_j = mixer.phi->getValueAt(rij);
326 <    rho_j_at_i = rho_i_at_j;
311 >    RealType rcij = mixer.rCut;
312  
313 +    if ( *(idat.rij)  < rcij) {
314 +      RealType rho = mixer.phi->getValueAt( *(idat.rij) );
315 +      *(idat.rho1) += rho;
316 +      *(idat.rho2) += rho;
317 +    }
318 +    
319      return;
320    }
321  
322 <  void SC::calcFunctional(AtomType* at1, RealType rho, RealType &frho,
332 <                          RealType &dfrhodrho) {
322 >  void SC::calcFunctional(SelfData &sdat) {
323  
324      if (!initialized_) initialize();
325  
326 <    SCAtomData data1 = SCMap[at1];
326 >    SCAtomData data1 = SCMap[sdat.atype];
327 >  
328 >    RealType u = - data1.c * data1.epsilon * sqrt( *(sdat.rho) );
329 >    *(sdat.frho) = u;
330 >    *(sdat.dfrhodrho) = 0.5 * *(sdat.frho) / *(sdat.rho);
331 >
332 >    (*(sdat.pot))[METALLIC_FAMILY] += u;
333 >    *(sdat.particlePot) += u;
334      
338    frho = - data1.c * data1.epsilon * sqrt(rho);
339    dfrhodrho = 0.5 * frho / rho;
340    
335      return;
336    }
337 +  
338 +  void SC::initForce() {
339 +        if (!initialized_) initialize();
340 +  }
341  
342 <
345 <  void SC::calcForce(AtomType* at1, AtomType* at2, Vector3d d,
346 <                     RealType rij, RealType r2, RealType sw,
347 <                     RealType &vpair, RealType &pot, Vector3d &f1,
348 <                     RealType rho_i, RealType rho_j,
349 <                     RealType dfrhodrho_i, RealType dfrhodrho_j,
350 <                     RealType &fshift_i, RealType &fshift_j) {
342 >  void SC::calcForce(InteractionData &idat) {
343      
344      if (!initialized_) initialize();
345      
346 <    SCAtomData data1 = SCMap[at1];
347 <    SCAtomData data2 = SCMap[at1];
346 >    SCAtomData data1 = SCMap[idat.atypes.first];
347 >    SCAtomData data2 = SCMap[idat.atypes.second];
348  
349 <    SCInteractionData mixer = MixingMap[make_pair(at1, at2)];
349 >    SCInteractionData mixer = MixingMap[idat.atypes];
350  
351      RealType rcij = mixer.rCut;
360    RealType vcij = mixer.vCut;
352  
353 <    pair<RealType, RealType> res;
354 <
355 <    res = mixer.phi->getValueAndDerivativeAt(rij);
356 <    RealType rhtmp = res.first;
357 <    RealType drhodr = res.second;
358 <
359 <    res = mixer.V->getValueAndDerivativeAt(rij);
360 <    RealType vptmp = res.first;
361 <    RealType dvpdr = res.second;
362 <
363 <    RealType pot_temp = vptmp - vcij;
364 <    vpair += pot_temp;
365 <
366 <    RealType dudr = drhodr * (dfrhodrho_i + dfrhodrho_j) + dvpdr;
367 <
368 <    f1 += d * dudr / rij;
353 >    if ( *(idat.rij)  < rcij) {
354 >      RealType vcij = mixer.vCut;
355 >      
356 >      pair<RealType, RealType> res;
357 >      
358 >      res = mixer.phi->getValueAndDerivativeAt( *(idat.rij) );
359 >      RealType rhtmp = res.first;
360 >      RealType drhodr = res.second;
361 >      
362 >      res = mixer.V->getValueAndDerivativeAt( *(idat.rij) );
363 >      RealType vptmp = res.first;
364 >      RealType dvpdr = res.second;
365 >      
366 >      RealType pot_temp = vptmp - vcij;
367 >      *(idat.vpair) += pot_temp;
368 >      
369 >      RealType dudr = drhodr * ( *(idat.dfrho1) + *(idat.dfrho2) ) + dvpdr;
370 >      
371 >      *(idat.f1) += *(idat.d) * dudr / *(idat.rij) ;
372          
373 <    // particle_pot is the difference between the full potential
374 <    // and the full potential without the presence of a particular
375 <    // particle (atom1).
376 <    //
377 <    // This reduces the density at other particle locations, so
378 <    // we need to recompute the density at atom2 assuming atom1
379 <    // didn't contribute.  This then requires recomputing the
380 <    // density functional for atom2 as well.
381 <    //
382 <    // Most of the particle_pot heavy lifting comes from the
383 <    // pair interaction, and will be handled by vpair.
390 <    
391 <    fshift_i = - data1.c * data1.epsilon * sqrt(rho_i - rhtmp);
392 <    fshift_j = - data2.c * data2.epsilon * sqrt(rho_j - rhtmp);
393 <    
394 <    pot += pot_temp;
373 >      // particlePot is the difference between the full potential and
374 >      // the full potential without the presence of a particular
375 >      // particle (atom1).
376 >      //
377 >      // This reduces the density at other particle locations, so we
378 >      // need to recompute the density at atom2 assuming atom1 didn't
379 >      // contribute.  This then requires recomputing the density
380 >      // functional for atom2 as well.
381 >          
382 >      *(idat.particlePot1) -= data2.c * data2.epsilon *
383 >        sqrt( *(idat.rho2) - rhtmp) + *(idat.frho2);
384  
385 +      *(idat.particlePot2) -= data1.c * data1.epsilon *
386 +        sqrt( *(idat.rho1) - rhtmp) + *(idat.frho1);
387 +      
388 +      (*(idat.pot))[METALLIC_FAMILY] += pot_temp;
389 +    }
390 +      
391      return;    
392    }
393  
394 +  RealType SC::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
395 +    if (!initialized_) initialize();  
396  
397 <  void SC::calc_sc_prepair_rho(int *atid1, int *atid2, RealType *rij,
398 <                               RealType* rho_i_at_j, RealType* rho_j_at_i){
399 <    
400 <    if (!initialized_) initialize();
401 <    
402 <    AtomType* atype1 = SClist[*atid1];
403 <    AtomType* atype2 = SClist[*atid2];
404 <    
408 <    calcDensity(atype1, atype2, *rij, *rho_i_at_j, *rho_j_at_i);
409 <    
410 <    return;    
397 >    map<pair<AtomType*, AtomType*>, SCInteractionData>::iterator it;
398 >    it = MixingMap.find(atypes);
399 >    if (it == MixingMap.end())
400 >      return 0.0;
401 >    else  {
402 >      SCInteractionData mixer = (*it).second;
403 >      return mixer.rCut;
404 >    }
405    }
412  
413  void SC::calc_sc_preforce_Frho(int *atid1, RealType *rho, RealType *frho,
414                                 RealType *dfrhodrho) {
415    
416    if (!initialized_) initialize();
417    
418    AtomType* atype1 = SClist[*atid1];  
419
420    calcFunctional(atype1, *rho, *frho, *dfrhodrho);
421    
422    return;    
423  }
424  
425  RealType SC::getSCcut(int *atid1) {
426
427    if (!initialized_) initialize();
428    
429    AtomType* atype1 = SClist[*atid1];  
430      
431    return 2.0 * getAlpha(atype1);
432  }
433
434  void SC::do_sc_pair(int *atid1, int *atid2, RealType *d, RealType *rij,
435                        RealType *r2, RealType *sw, RealType *vpair,
436                        RealType *pot, RealType *f1, RealType *rho1,
437                        RealType *rho2, RealType *dfrho1, RealType *dfrho2,
438                        RealType *fshift1, RealType *fshift2) {
439
440    if (!initialized_) initialize();
441    
442    AtomType* atype1 = SClist[*atid1];
443    AtomType* atype2 = SClist[*atid2];
444    
445    Vector3d disp(d[0], d[1], d[2]);
446    Vector3d frc(f1[0], f1[1], f1[2]);
447    
448    calcForce(atype1, atype2, disp, *rij, *r2, *sw, *vpair,  *pot, frc,
449              *rho1, *rho2, *dfrho1, *dfrho2, *fshift1, *fshift2);
450      
451    f1[0] = frc.x();
452    f1[1] = frc.y();
453    f1[2] = frc.z();
454
455    return;    
456  }
457  
458  void SC::setCutoffSC(RealType *thisRcut) {
459    scRcut_ = *thisRcut;
460  }
406   }
462
463 extern "C" {
464  
465 #define fortranCalcDensity FC_FUNC(calc_sc_prepair_rho, CALC_SC_PREPAIR_RHO)
466 #define fortranCalcFunctional FC_FUNC(calc_sc_preforce_frho, CALC_SC_PREFORCE_FRHO)
467 #define fortranCalcForce FC_FUNC(do_sc_pair, DO_SC_PAIR)
468 #define fortranSetCutoffSC FC_FUNC(setcutoffsc, SETCUTOFFSC)
469 #define fortranGetSCcut FC_FUNC(getsccut, GETSCCUT)
470  
471  
472  void fortranCalcDensity(int *atid1, int *atid2, RealType *rij,
473                          RealType *rho_i_at_j, RealType *rho_j_at_i) {
474    
475    return OpenMD::SC::Instance()->calc_sc_prepair_rho(atid1, atid2, rij,
476                                                       rho_i_at_j,  
477                                                       rho_j_at_i);
478  }
479  void fortranCalcFunctional(int *atid1, RealType *rho, RealType *frho,
480                             RealType *dfrhodrho) {  
481    
482    return OpenMD::SC::Instance()->calc_sc_preforce_Frho(atid1, rho, frho,
483                                                         dfrhodrho);
484    
485  }
486  void fortranSetCutoffSC(RealType *rcut) {
487    return OpenMD::SC::Instance()->setCutoffSC(rcut);
488  }
489  void fortranCalcForce(int *atid1, int *atid2, RealType *d, RealType *rij,
490                        RealType *r2, RealType *sw, RealType *vpair,
491                        RealType *pot, RealType *f1, RealType *rho1,
492                        RealType *rho2, RealType *dfrho1, RealType *dfrho2,
493                        RealType *fshift1, RealType *fshift2){
494    
495    return OpenMD::SC::Instance()->do_sc_pair(atid1, atid2, d, rij,
496                                              r2, sw, vpair,
497                                              pot, f1, rho1,
498                                              rho2, dfrho1, dfrho2,
499                                              fshift1,  fshift2);
500  }
501  RealType fortranGetSCcut(int* atid) {
502    return OpenMD::SC::Instance()->getSCcut(atid);
503  }
504  
505 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines