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

Comparing trunk/src/integrators/VelocityVerletIntegrator.cpp (file contents):
Revision 276 by tim, Wed Jan 26 15:26:47 2005 UTC vs.
Revision 1360 by cli2, Mon Sep 7 16:31:51 2009 UTC

# Line 1 | Line 1
1 < /*
1 > /*
2   * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3   *
4   * The University of Notre Dame grants you ("Licensee") a
# Line 52 | Line 52 | namespace oopse {
52   #include "utils/StringUtils.hpp"
53  
54   namespace oopse {
55 < VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info), rotAlgo(NULL) {
55 >  VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info), rotAlgo(NULL) {
56      dt2 = 0.5 * dt;
57      rotAlgo = new DLM();
58      rattle = new Rattle(info);
59 < }
60 <
61 < VelocityVerletIntegrator::~VelocityVerletIntegrator() {
59 >  }
60 >  
61 >  VelocityVerletIntegrator::~VelocityVerletIntegrator() {
62      delete rotAlgo;
63      delete rattle;
64 < }
65 <
66 < void VelocityVerletIntegrator::initialize(){
67 <
64 >  }
65 >  
66 >  void VelocityVerletIntegrator::initialize(){
67 >    
68      forceMan_->init();
69 <
70 <    // remove center of mass drift velocity (in case we passed in a configuration
71 <    // that was drifting
69 >    
70 >    // remove center of mass drift velocity (in case we passed in a
71 >    // configuration that was drifting)
72      velocitizer_->removeComDrift();
73 <
73 >    
74      // initialize the forces before the first step
75      calcForce(true, true);
76 <
77 <    //execute constraint algorithm to make sure at the very beginning the system is constrained  
76 >    
77 >    // execute the constraint algorithm to make sure that the system is
78 >    // constrained at the very beginning  
79      if (info_->getNGlobalConstraints() > 0) {
80 <        rattle->constraintA();
81 <        calcForce(true, true);
82 <        rattle->constraintB();        
83 <        info_->getSnapshotManager()->advance();//copy the current snapshot to previous snapshot
80 >      rattle->constraintA();
81 >      calcForce(true, true);
82 >      rattle->constraintB();      
83 >      //copy the current snapshot to previous snapshot
84 >      info_->getSnapshotManager()->advance();
85      }
86 <
86 >    
87      if (needVelocityScaling) {
88 <        velocitizer_->velocitize(targetScalingTemp);
88 >      velocitizer_->velocitize(targetScalingTemp);
89      }
90      
91      dumpWriter = createDumpWriter();
92 <    eorWriter = createEorWriter();
92 >    
93      statWriter = createStatWriter();
94 +
95 +    dumpWriter->writeDumpAndEor();
96  
93    dumpWriter->writeDump();
94    eorWriter->writeDump();
95    
97      //save statistics, before writeStat,  we must save statistics
98      thermo.saveStat();
99      saveConservedQuantity();
100 <    statWriter->writeStat(currentSnapshot_->statData);
100 >    if (simParams->getUseRNEMD())
101 >      rnemd_->getStatus();
102  
103 +    statWriter->writeStat(currentSnapshot_->statData);
104 +    
105      currSample = sampleTime + currentSnapshot_->getTime();
106 <    currStatus =  statusTime + currentSnapshot_->getTime();;
107 <    currThermal = thermalTime +  + currentSnapshot_->getTime();
106 >    currStatus =  statusTime + currentSnapshot_->getTime();
107 >    currThermal = thermalTime + currentSnapshot_->getTime();
108 >    if (needReset) {
109 >      currReset = resetTime + currentSnapshot_->getTime();
110 >    }
111 >    if (simParams->getUseRNEMD()){
112 >      currRNEMD = RNEMD_swapTime + currentSnapshot_->getTime();
113 >    }
114      needPotential = false;
115      needStress = false;      
116 <  
117 < }
108 <        
109 < void VelocityVerletIntegrator::doIntegrate() {
116 >    
117 >  }
118  
119 <
119 >  void VelocityVerletIntegrator::doIntegrate() {
120 >  
121 >  
122      initialize();
123 <
123 >  
124      while (currentSnapshot_->getTime() < runTime) {
125 <        
126 <        preStep();
127 <
128 <        integrateStep();
129 <        
130 <        postStep();
131 <
125 >    
126 >      preStep();
127 >    
128 >      integrateStep();
129 >    
130 >      postStep();
131 >    
132      }
133 <
133 >  
134      finalize();
135 <    
136 < }
135 >  
136 >  }
137  
138  
139 < void VelocityVerletIntegrator::preStep() {
140 <        double difference = currentSnapshot_->getTime() + dt - currStatus;
139 >  void VelocityVerletIntegrator::preStep() {
140 >    RealType difference = currentSnapshot_->getTime() + dt - currStatus;
141 >  
142 >    if (difference > 0 || fabs(difference) < oopse::epsilon) {
143 >      needPotential = true;
144 >      needStress = true;  
145 >    }
146 >  }
147  
148 <        if (difference > 0 || fabs(difference) < oopse::epsilon) {
133 <            needPotential = true;
134 <            needStress = true;  
135 <        }
148 >  void VelocityVerletIntegrator::postStep() {
149  
150 < }
150 >    //save snapshot
151 >    info_->getSnapshotManager()->advance();
152 >  
153 >    //increase time
154 >    currentSnapshot_->increaseTime(dt);        
155 >  
156 >    if (needVelocityScaling) {
157 >      if (currentSnapshot_->getTime() >= currThermal) {
158 >        velocitizer_->velocitize(targetScalingTemp);
159 >        currThermal += thermalTime;
160 >      }
161 >    }
162 >    if (useRNEMD) {
163 >      if (currentSnapshot_->getTime() >= currRNEMD) {
164 >        rnemd_->doSwap();
165 >        currRNEMD += RNEMD_swapTime;
166 >      }
167 >    }
168 >    
169 >    if (currentSnapshot_->getTime() >= currSample) {
170 >      dumpWriter->writeDumpAndEor();
171 >      
172 >      currSample += sampleTime;
173 >    }
174 >    
175 >    if (currentSnapshot_->getTime() >= currStatus) {
176 >      //save statistics, before writeStat,  we must save statistics
177 >      thermo.saveStat();
178 >      saveConservedQuantity();
179  
180 < void VelocityVerletIntegrator::postStep() {
180 >      if (simParams->getUseRNEMD())
181 >        rnemd_->getStatus();
182  
183 <        //save snapshot
184 <        info_->getSnapshotManager()->advance();
183 >      statWriter->writeStat(currentSnapshot_->statData);
184 >      
185 >      needPotential = false;
186 >      needStress = false;
187 >      currStatus += statusTime;
188 >    }
189 >    
190 >    if (needReset && currentSnapshot_->getTime() >= currReset) {    
191 >      resetIntegrator();
192 >      currReset += resetTime;
193 >    }        
194 >  }
195  
144        //increase time
145        currentSnapshot_->increaseTime(dt);        
146        
147        if (needVelocityScaling) {
148            if (currentSnapshot_->getTime() >= currThermal) {
149                velocitizer_->velocitize(targetScalingTemp);
150                currThermal += thermalTime;
151            }
152        }
196  
197 <        if (currentSnapshot_->getTime() >= currSample) {
198 <            dumpWriter->writeDump();
199 <            eorWriter->writeDump();
157 <            currSample += sampleTime;
158 <        }
159 <
160 <        if (currentSnapshot_->getTime() >= currStatus) {
161 <            //save statistics, before writeStat,  we must save statistics
162 <            thermo.saveStat();
163 <            saveConservedQuantity();
164 <            statWriter->writeStat(currentSnapshot_->statData);
165 <
166 <            needPotential = false;
167 <            needStress = false;
168 <            currStatus += statusTime;
169 <        }
170 <
171 <        
172 < }
173 <
174 <
175 < void VelocityVerletIntegrator::finalize() {
176 <
177 <    dumpWriter->writeDump();
178 <    eorWriter->writeDump();
179 <
197 >  void VelocityVerletIntegrator::finalize() {
198 >    dumpWriter->writeEor();
199 >  
200      delete dumpWriter;
181    delete eorWriter;
201      delete statWriter;
202 <
202 >  
203      dumpWriter = NULL;
185    eorWriter = NULL;
204      statWriter = NULL;
205 <    
206 < }
205 >  
206 >  }
207  
208 < void VelocityVerletIntegrator::integrateStep() {
209 <
208 >  void VelocityVerletIntegrator::integrateStep() {
209 >  
210      moveA();
211      calcForce(needPotential, needStress);
212      moveB();
213 < }
213 >  }
214  
215  
216 < void VelocityVerletIntegrator::calcForce(bool needPotential,
217 <                                         bool needStress) {
216 >  void VelocityVerletIntegrator::calcForce(bool needPotential,
217 >                                           bool needStress) {
218      forceMan_->calcForces(needPotential, needStress);
219 < }
219 >  }
220  
221 < DumpWriter* VelocityVerletIntegrator::createDumpWriter() {
222 <    return new DumpWriter(info_, info_->getDumpFileName());
223 < }
221 >  DumpWriter* VelocityVerletIntegrator::createDumpWriter() {
222 >    return new DumpWriter(info_);
223 >  }
224  
225 < DumpWriter* VelocityVerletIntegrator::createEorWriter() {
208 <    return new DumpWriter(info_, getPrefix(info_->getDumpFileName()) + ".eor");
209 < }
225 >  StatWriter* VelocityVerletIntegrator::createStatWriter() {
226  
227 < StatWriter* VelocityVerletIntegrator::createStatWriter() {
228 <    return new StatWriter(info_->getStatFileName());
229 < }
227 >    std::string statFileFormatString = simParams->getStatFileFormat();
228 >    StatsBitSet mask = parseStatFileFormat(statFileFormatString);
229 >  
230 >    // if we're doing a thermodynamic integration, we'll want the raw
231 >    // potential as well as the full potential:
232  
233 +
234 +    if (simParams->getUseThermodynamicIntegration())
235 +      mask.set(Stats::VRAW);
236  
237 +    // if we've got restraints turned on, we'll also want a report of the
238 +    // total harmonic restraints
239 +    if (simParams->getUseRestraints()){
240 +      mask.set(Stats::VHARM);
241 +    }
242 +
243 +    if (simParams->havePrintPressureTensor() &&
244 +        simParams->getPrintPressureTensor()){
245 +      mask.set(Stats::PRESSURE_TENSOR_XX);
246 +      mask.set(Stats::PRESSURE_TENSOR_XY);
247 +      mask.set(Stats::PRESSURE_TENSOR_XZ);
248 +      mask.set(Stats::PRESSURE_TENSOR_YX);
249 +      mask.set(Stats::PRESSURE_TENSOR_YY);
250 +      mask.set(Stats::PRESSURE_TENSOR_YZ);
251 +      mask.set(Stats::PRESSURE_TENSOR_ZX);
252 +      mask.set(Stats::PRESSURE_TENSOR_ZY);
253 +      mask.set(Stats::PRESSURE_TENSOR_ZZ);
254 +    }
255 +    
256 +    if (simParams->getAccumulateBoxDipole()) {
257 +      mask.set(Stats::BOX_DIPOLE_X);
258 +      mask.set(Stats::BOX_DIPOLE_Y);
259 +      mask.set(Stats::BOX_DIPOLE_Z);
260 +    }
261 +  
262 +    if (simParams->haveTaggedAtomPair() && simParams->havePrintTaggedPairDistance()) {
263 +      if (simParams->getPrintTaggedPairDistance()) {
264 +        mask.set(Stats::TAGGED_PAIR_DISTANCE);
265 +      }
266 +    }
267 +
268 +    if (simParams->getUseRNEMD()) {
269 +      mask.set(Stats::RNEMD_SWAP_TOTAL);
270 +    }
271 +      
272 +
273 +     return new StatWriter(info_->getStatFileName(), mask);
274 +  }
275 +
276 +
277   } //end namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines