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 1126 by gezelter, Fri Apr 6 21:53:43 2007 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  
97 <    dumpWriter->writeDump();
98 <    eorWriter->writeDump();
97 >    if (simParams->getUseSolidThermInt()) {
98 >      restWriter = createRestWriter();
99 >      restWriter->writeZAngFile();
100 >    }
101      
102      //save statistics, before writeStat,  we must save statistics
103      thermo.saveStat();
104      saveConservedQuantity();
105      statWriter->writeStat(currentSnapshot_->statData);
106 <
106 >    
107      currSample = sampleTime + currentSnapshot_->getTime();
108      currStatus =  statusTime + currentSnapshot_->getTime();;
109 <    currThermal = thermalTime +  + currentSnapshot_->getTime();
109 >    currThermal = thermalTime + currentSnapshot_->getTime();
110 >    if (needReset) {
111 >      currReset = resetTime + currentSnapshot_->getTime();
112 >    }
113      needPotential = false;
114      needStress = false;      
115 <  
116 < }
108 <        
109 < void VelocityVerletIntegrator::doIntegrate() {
115 >    
116 >  }
117  
118 <
118 >  void VelocityVerletIntegrator::doIntegrate() {
119 >  
120 >  
121      initialize();
122 <
122 >  
123      while (currentSnapshot_->getTime() < runTime) {
124 <        
125 <        preStep();
126 <
127 <        integrateStep();
128 <        
129 <        postStep();
130 <
124 >    
125 >      preStep();
126 >    
127 >      integrateStep();
128 >    
129 >      postStep();
130 >    
131      }
132 <
132 >  
133      finalize();
134 <    
135 < }
134 >  
135 >  }
136  
137  
138 < void VelocityVerletIntegrator::preStep() {
139 <        double difference = currentSnapshot_->getTime() + dt - currStatus;
138 >  void VelocityVerletIntegrator::preStep() {
139 >    RealType difference = currentSnapshot_->getTime() + dt - currStatus;
140 >  
141 >    if (difference > 0 || fabs(difference) < oopse::epsilon) {
142 >      needPotential = true;
143 >      needStress = true;  
144 >    }
145 >  }
146  
147 <        if (difference > 0 || fabs(difference) < oopse::epsilon) {
133 <            needPotential = true;
134 <            needStress = true;  
135 <        }
147 >  void VelocityVerletIntegrator::postStep() {
148  
149 < }
149 >    //save snapshot
150 >    info_->getSnapshotManager()->advance();
151 >  
152 >    //increase time
153 >    currentSnapshot_->increaseTime(dt);        
154 >  
155 >    if (needVelocityScaling) {
156 >      if (currentSnapshot_->getTime() >= currThermal) {
157 >        velocitizer_->velocitize(targetScalingTemp);
158 >        currThermal += thermalTime;
159 >      }
160 >    }
161  
162 < void VelocityVerletIntegrator::postStep() {
162 >    if (currentSnapshot_->getTime() >= currSample) {
163 >      dumpWriter->writeDumpAndEor();
164  
165 <        //save snapshot
166 <        info_->getSnapshotManager()->advance();
165 >      if (simParams->getUseSolidThermInt())
166 >        restWriter->writeZAngFile();
167 >    
168 >      currSample += sampleTime;
169 >    }
170  
171 <        //increase time
172 <        currentSnapshot_->increaseTime(dt);        
173 <        
174 <        if (needVelocityScaling) {
175 <            if (currentSnapshot_->getTime() >= currThermal) {
176 <                velocitizer_->velocitize(targetScalingTemp);
177 <                currThermal += thermalTime;
178 <            }
179 <        }
171 >    if (currentSnapshot_->getTime() >= currStatus) {
172 >      //save statistics, before writeStat,  we must save statistics
173 >      thermo.saveStat();
174 >      saveConservedQuantity();
175 >      statWriter->writeStat(currentSnapshot_->statData);
176 >    
177 >      needPotential = false;
178 >      needStress = false;
179 >      currStatus += statusTime;
180 >    }
181  
182 <        if (currentSnapshot_->getTime() >= currSample) {
183 <            dumpWriter->writeDump();
184 <            eorWriter->writeDump();
185 <            currSample += sampleTime;
186 <        }
182 >      if (needReset && currentSnapshot_->getTime() >= currReset) {    
183 >        resetIntegrator();
184 >        currReset += resetTime;
185 >      }
186 >  
187 >  }
188  
160        if (currentSnapshot_->getTime() >= currStatus) {
161            //save statistics, before writeStat,  we must save statistics
162            thermo.saveStat();
163            saveConservedQuantity();
164            statWriter->writeStat(currentSnapshot_->statData);
189  
190 <            needPotential = false;
191 <            needStress = false;
192 <            currStatus += statusTime;
193 <        }
194 <
195 <        
196 < }
197 <
198 <
175 < void VelocityVerletIntegrator::finalize() {
176 <
177 <    dumpWriter->writeDump();
178 <    eorWriter->writeDump();
179 <
190 >  void VelocityVerletIntegrator::finalize() {
191 >    dumpWriter->writeEor();
192 >  
193 >    if (simParams->getUseSolidThermInt()) {
194 >      restWriter->writeZAngFile();
195 >      delete restWriter;
196 >      restWriter = NULL;
197 >    }
198 >  
199      delete dumpWriter;
181    delete eorWriter;
200      delete statWriter;
201 <
201 >  
202      dumpWriter = NULL;
185    eorWriter = NULL;
203      statWriter = NULL;
204 <    
205 < }
204 >  
205 >  }
206  
207 < void VelocityVerletIntegrator::integrateStep() {
208 <
207 >  void VelocityVerletIntegrator::integrateStep() {
208 >  
209      moveA();
210      calcForce(needPotential, needStress);
211      moveB();
212 < }
212 >  }
213  
214  
215 < void VelocityVerletIntegrator::calcForce(bool needPotential,
216 <                                         bool needStress) {
215 >  void VelocityVerletIntegrator::calcForce(bool needPotential,
216 >                                           bool needStress) {
217      forceMan_->calcForces(needPotential, needStress);
218 < }
218 >  }
219  
220 < DumpWriter* VelocityVerletIntegrator::createDumpWriter() {
221 <    return new DumpWriter(info_, info_->getDumpFileName());
222 < }
220 >  DumpWriter* VelocityVerletIntegrator::createDumpWriter() {
221 >    return new DumpWriter(info_);
222 >  }
223  
224 < DumpWriter* VelocityVerletIntegrator::createEorWriter() {
208 <    return new DumpWriter(info_, getPrefix(info_->getDumpFileName()) + ".eor");
209 < }
224 >  StatWriter* VelocityVerletIntegrator::createStatWriter() {
225  
226 < StatWriter* VelocityVerletIntegrator::createStatWriter() {
227 <    return new StatWriter(info_->getStatFileName());
228 < }
226 >    std::string statFileFormatString = simParams->getStatFileFormat();
227 >    StatsBitSet mask = parseStatFileFormat(statFileFormatString);
228 >    
229 >    // if solidThermInt is true, add extra information to the statfile
230 >    if (simParams->getUseSolidThermInt()){
231 >      mask.set(Stats::VRAW);
232 >      mask.set(Stats::VHARM);
233 >    }
234  
235 +    if (simParams->havePrintPressureTensor() &&
236 +        simParams->getPrintPressureTensor()){
237 +        mask.set(Stats::PRESSURE_TENSOR_XX);
238 +        mask.set(Stats::PRESSURE_TENSOR_XY);
239 +        mask.set(Stats::PRESSURE_TENSOR_XZ);
240 +        mask.set(Stats::PRESSURE_TENSOR_YX);
241 +        mask.set(Stats::PRESSURE_TENSOR_YY);
242 +        mask.set(Stats::PRESSURE_TENSOR_YZ);
243 +        mask.set(Stats::PRESSURE_TENSOR_ZX);
244 +        mask.set(Stats::PRESSURE_TENSOR_ZY);
245 +        mask.set(Stats::PRESSURE_TENSOR_ZZ);
246 +    }
247 +    
248 +    if (simParams->getAccumulateBoxDipole()) {
249 +      mask.set(Stats::BOX_DIPOLE_X);
250 +      mask.set(Stats::BOX_DIPOLE_Y);
251 +      mask.set(Stats::BOX_DIPOLE_Z);
252 +    }
253  
254 +     return new StatWriter(info_->getStatFileName(), mask);
255 +  }
256 +
257 +  RestWriter* VelocityVerletIntegrator::createRestWriter(){
258 +    return new RestWriter(info_);
259 +  }
260 +
261 +
262   } //end namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines