ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/flucq/FluctuatingChargeNVT.cpp
(Generate patch)

Comparing:
branches/development/src/integrators/FluctuatingChargeNVT.cpp (file contents), Revision 1716 by gezelter, Wed May 23 01:26:15 2012 UTC vs.
trunk/src/flucq/FluctuatingChargeNVT.cpp (file contents), Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

# Line 35 | Line 35
35   *                                                                      
36   * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37   * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 < * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
38 > * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).          
39   * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40   * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
# Line 45 | Line 45
45   #include "utils/simError.h"
46   #include "utils/PhysicalConstants.hpp"
47  
48 +
49   namespace OpenMD {
50  
51    FluctuatingChargeNVT::FluctuatingChargeNVT(SimInfo* info) :
52 <    FluctuatingChargePropagator(info), chiTolerance_ (1e-6), maxIterNum_(4),
53 <    thermo(info),
53 <    currentSnapshot_(info->getSnapshotManager()->getCurrentSnapshot()) {
54 <
55 <    if (info_->usesFluctuatingCharges()) {
56 <      if (info_->getNFluctuatingCharges() > 0) {
57 <
58 <        hasFlucQ_ = true;
59 <        Globals* simParams = info_->getSimParams();
60 <
61 <        if (simParams->haveDt()) {
62 <          dt_ = simParams->getDt();
63 <          dt2_ = dt_ * 0.5;
64 <        } else {
65 <          sprintf(painCave.errMsg,
66 <                  "FluctuatingChargeNVT Error: dt is not set\n");
67 <          painCave.isFatal = 1;
68 <          simError();
69 <        }
70 <        
71 <        if (!simParams->getUseIntialExtendedSystemState()) {
72 <          currentSnapshot_->setChiElectronic(0.0);
73 <          currentSnapshot_->setIntegralOfChiElectronicDt(0.0);
74 <        }
75 <        
76 <        if (!simParams->haveFlucQTargetTemp()) {
77 <          sprintf(painCave.errMsg, "You can't use the FluctuatingChargeNVT "
78 <                  "propagator without a flucQ.targetTemp!\n");
79 <          painCave.isFatal = 1;
80 <          painCave.severity = OPENMD_ERROR;
81 <          simError();
82 <        } else {
83 <          targetTemp_ = simParams->getFlucQTargetTemp();
84 <        }
85 <        
86 <        // We must set tauThermostat.
87 <        
88 <        if (!simParams->haveFlucQtauThermostat()) {
89 <          sprintf(painCave.errMsg, "If you use the FluctuatingChargeNVT\n"
90 <                  "\tpropagator, you must set flucQ.tauThermostat .\n");
91 <          
92 <          painCave.severity = OPENMD_ERROR;
93 <          painCave.isFatal = 1;
94 <          simError();
95 <        } else {
96 <          tauThermostat_ = simParams->getFlucQtauThermostat();
97 <        }
98 <        updateSizes();
99 <      }
100 <    }      
52 >    FluctuatingChargePropagator(info), maxIterNum_(4), chiTolerance_ (1e-6),
53 >    snap(info->getSnapshotManager()->getCurrentSnapshot()), thermo(info) {  
54    }
55  
56    void FluctuatingChargeNVT::initialize() {
57 <
58 <    if (!hasFlucQ_) return;
59 <
60 <    SimInfo::MoleculeIterator i;
61 <    Molecule::FluctuatingChargeIterator  j;
62 <    Molecule* mol;
63 <    Atom* atom;
64 <    
65 <    for (mol = info_->beginMolecule(i); mol != NULL;
66 <         mol = info_->nextMolecule(i)) {
114 <      for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
115 <           atom = mol->nextFluctuatingCharge(j)) {
116 <        atom->setFlucQPos(0.0);
117 <        atom->setFlucQVel(0.0);
57 >    FluctuatingChargePropagator::initialize();  
58 >    if (hasFlucQ_) {
59 >      if (info_->getSimParams()->haveDt()) {
60 >        dt_ = info_->getSimParams()->getDt();
61 >        dt2_ = dt_ * 0.5;
62 >      } else {
63 >        sprintf(painCave.errMsg,
64 >                "FluctuatingChargeNVT Error: dt is not set\n");
65 >        painCave.isFatal = 1;
66 >        simError();
67        }
68 +      
69 +      if (!info_->getSimParams()->getUseIntialExtendedSystemState()) {
70 +        snap->setElectronicThermostat(make_pair(0.0, 0.0));
71 +      }
72 +      
73 +      if (!fqParams_->haveTargetTemp()) {
74 +        sprintf(painCave.errMsg, "You can't use the FluctuatingChargeNVT "
75 +                "propagator without a flucQ.targetTemp!\n");
76 +        painCave.isFatal = 1;
77 +        painCave.severity = OPENMD_ERROR;
78 +        simError();
79 +      } else {
80 +        targetTemp_ = fqParams_->getTargetTemp();
81 +      }
82 +      
83 +      // We must set tauThermostat.
84 +      
85 +      if (!fqParams_->haveTauThermostat()) {
86 +        sprintf(painCave.errMsg, "If you use the FluctuatingChargeNVT\n"
87 +                "\tpropagator, you must set flucQ.tauThermostat .\n");
88 +        
89 +        painCave.severity = OPENMD_ERROR;
90 +        painCave.isFatal = 1;
91 +        simError();
92 +      } else {
93 +        tauThermostat_ = fqParams_->getTauThermostat();
94 +      }
95 +      updateSizes();
96      }
120    
121    cerr << "Yeah, you should probably implement this\n";
97    }
98  
99 +
100    void FluctuatingChargeNVT::moveA() {
101  
102      if (!hasFlucQ_) return;
# Line 131 | Line 107 | namespace OpenMD {
107      Atom* atom;
108      RealType cvel, cpos, cfrc, cmass;
109  
110 <    RealType chi = currentSnapshot_->getChiElectronic();
111 <    RealType integralOfChidt = currentSnapshot_->getIntegralOfChiElectronicDt();
110 >    pair<RealType, RealType> thermostat = snap->getElectronicThermostat();
111 >    RealType chi = thermostat.first;
112 >    RealType integralOfChidt = thermostat.second;
113      RealType instTemp = thermo.getElectronicTemperature();
114  
138    cerr << "why are we here?\n";
139
115      for (mol = info_->beginMolecule(i); mol != NULL;
116           mol = info_->nextMolecule(i)) {
117        for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
# Line 145 | Line 120 | namespace OpenMD {
120          cvel = atom->getFlucQVel();
121          cpos = atom->getFlucQPos();
122          cfrc = atom->getFlucQFrc();
123 <        cmass = atom->getChargeMass();
124 <        
125 <        // velocity half step
126 <        cvel += dt2_ *PhysicalConstants::energyConvert/cmass*cfrc - dt2_*chi*cvel;                    
123 >        cmass = atom->getChargeMass();      
124 >
125 >        // velocity half step
126 >        cvel += dt2_ * cfrc / cmass - dt2_*chi*cvel;                    
127          // position whole step
128          cpos += dt_ * cvel;
129 <        
129 >        
130          atom->setFlucQVel(cvel);
131          atom->setFlucQPos(cpos);
132        }
# Line 161 | Line 136 | namespace OpenMD {
136        (tauThermostat_ * tauThermostat_);
137  
138      integralOfChidt += chi * dt2_;
139 <    currentSnapshot_->setChiElectronic(chi);
165 <    currentSnapshot_->setIntegralOfChiElectronicDt(integralOfChidt);
166 <      
139 >    snap->setElectronicThermostat(make_pair(chi, integralOfChidt));
140    }
141  
142    void FluctuatingChargeNVT::updateSizes() {
170    if (!hasFlucQ_) return;
143      oldVel_.resize(info_->getNFluctuatingCharges());
144    }
145  
# Line 178 | Line 150 | namespace OpenMD {
150      Molecule* mol;
151      Atom* atom;
152      RealType instTemp;
153 <    RealType chi = currentSnapshot_->getChiElectronic();
153 >    pair<RealType, RealType> thermostat = snap->getElectronicThermostat();
154 >    RealType chi = thermostat.first;
155      RealType oldChi = chi;
156      RealType prevChi;
157 <    RealType integralOfChidt = currentSnapshot_->getIntegralOfChiElectronicDt();
157 >    RealType integralOfChidt = thermostat.second;
158      int index;
159      RealType cfrc, cvel, cmass;
160  
# Line 201 | Line 174 | namespace OpenMD {
174      for(int k = 0; k < maxIterNum_; k++) {
175        index = 0;
176        instTemp = thermo.getElectronicTemperature();
204
177        // evolve chi another half step using the temperature at t + dt/2
178        prevChi = chi;
179        chi = oldChi + dt2_ * (instTemp / targetTemp_ - 1.0) /
# Line 213 | Line 185 | namespace OpenMD {
185               atom = mol->nextFluctuatingCharge(j)) {
186  
187            cfrc = atom->getFlucQFrc();
216          cvel =atom->getFlucQVel();
188            cmass = atom->getChargeMass();
189            
190            // velocity half step
191 <          cvel = oldVel_[index] + dt2_/cmass*PhysicalConstants::energyConvert * cfrc - dt2_*chi*oldVel_[index];
221 <          
191 >          cvel = oldVel_[index] + dt2_ * cfrc / cmass - dt2_*chi*oldVel_[index];
192            atom->setFlucQVel(cvel);      
193            ++index;          
194          }
# Line 227 | Line 197 | namespace OpenMD {
197          break;
198      }
199      integralOfChidt += dt2_ * chi;
200 <    currentSnapshot_->setChiElectronic(chi);
231 <    currentSnapshot_->setIntegralOfChiElectronicDt(integralOfChidt);
200 >    snap->setElectronicThermostat(make_pair(chi, integralOfChidt));
201    }
202    
203    void FluctuatingChargeNVT::resetPropagator() {
204      if (!hasFlucQ_) return;
205 <    currentSnapshot_->setChiElectronic(0.0);
237 <    currentSnapshot_->setIntegralOfChiElectronicDt(0.0);
205 >    snap->setElectronicThermostat(make_pair(0.0, 0.0));
206    }
207    
208    RealType FluctuatingChargeNVT::calcConservedQuantity() {
209      if (!hasFlucQ_) return 0.0;
210 <    RealType chi = currentSnapshot_->getChiElectronic();
211 <    RealType integralOfChidt = currentSnapshot_->getIntegralOfChiElectronicDt();
210 >    pair<RealType, RealType> thermostat = snap->getElectronicThermostat();
211 >    RealType chi = thermostat.first;
212 >    RealType integralOfChidt = thermostat.second;
213      RealType fkBT = info_->getNFluctuatingCharges() *
214        PhysicalConstants::kB *targetTemp_;
215  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines