--- branches/new_design/OOPSE-3.0/src/integrators/VelocityVerletIntegrator.cpp 2004/11/18 23:26:27 1756 +++ branches/new_design/OOPSE-3.0/src/integrators/VelocityVerletIntegrator.cpp 2004/12/02 00:09:35 1820 @@ -32,136 +32,148 @@ */ #include "integrators/VelocityVerletIntegrator.hpp" +#include "integrators/DLM.hpp" namespace oopse { -VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info) { } +VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info), rotAlgo(NULL) { + rotAlgo = new DLM(); + dt2 = 0.5 * dt; +} -VelocityVerletIntegrator::~VelocityVerletIntegrator() { } +VelocityVerletIntegrator::~VelocityVerletIntegrator() { + delete rotAlgo; +} -void VelocityVerletIntegrator::integrate() { - double runTime = info_->run_time; +void VelocityVerletIntegrator::initialize(){ - int calcPot; - int calcStress; + currSample = 0.0; + currStatus = 0.0; + currThermal = 0.0; + needPotential = false; + needStress = false; - - fullStep_ = info_->dt; - halfStep_ = 0.5 * fullStep_; - - readyCheck(); - // remove center of mass drift velocity (in case we passed in a configuration // that was drifting - tStats->removeCOMdrift(); + velocitizer_->removeComDrift(); // initialize the forces before the first step + calcForce(true, true); - calcForce(1, 1); - //execute constraint algorithm to make sure at the very beginning the system is constrained - if (nConstrained) { - constrainA(); - calcForce(1, 1); - constrainB(); - } + //if (nConstrained) { + // constrainA(); + // calcForce(true, true); + // constrainB(); + //} - if (info_->setTemp) { - thermalize(); + if (needVelocityScaling) { + velocitizer_->velocitize(targetScalingTemp); } + + dumpWriter = createDumpWriter(); + statWriter = createStatWriter(); - calcPot = 0; - calcStress = 0; + dumpWriter->writeDump(); + statWriter->writeStat(currentSnapshot_->statData); + +} + +void VelocityVerletIntegrator::doIntegrate() { - tStats = new Thermo(info_); - statOut = new StatWriter(info_); - dumpOut = new DumpWriter(info_); - - dumpOut->writeDump(info_->getTime()); - statOut->writeStat(info_->getTime()); -#ifdef IS_MPI + initialize(); - strcpy(checkPointMsg, "The integrator is ready to go."); - MPIcheckPoint(); + while (currentSnapshot_->getTime() < runTime) { + + preStep(); -#endif // is_mpi + integrateStep(); + + postStep(); - while (info_->getTime() < runTime) { - difference = info_->getTime() + fullStep_ - currStatus; + } - if (difference > 0 || fabs(difference) < 1e - 4) { - calcPot = 1; - calcStress = 1; + finalize(); + +} + + +void VelocityVerletIntegrator::preStep() { + double difference = currentSnapshot_->getTime() + dt - currStatus; + + if (difference > 0 || fabs(difference) < oopse::epsilon) { + needPotential = true; + needStress = true; } - //notify before integrateStep - notify() - integrateStep(calcPot, calcStress); +} + +void VelocityVerletIntegrator::postStep() { + + //save snapshot + info_->getSnapshotManager()->advance(); + + //increase time + currentSnapshot_->increaseTime(dt); + + //save statistics + thermo.saveStat(); - info_->incrTime(fullStep_); - - //notify after integratreStep - notify(); - - if (info_->setTemp) { - if (info_->getTime() >= currThermal) { - thermalize(); + if (needVelocityScaling) { + if (currentSnapshot_->getTime() >= currThermal) { + velocitizer_->velocitize(targetScalingTemp); currThermal += thermalTime; } } - if (info_->getTime() >= currSample) { - dumpOut->writeDump(info_->getTime()); + if (currentSnapshot_->getTime() >= currSample) { + dumpWriter->writeDump(); currSample += sampleTime; } - if (info_->getTime() >= currStatus) { - statOut->writeStat(info_->getTime()); - calcPot = 0; - calcStress = 0; + if (currentSnapshot_->getTime() >= currStatus) { + statWriter->writeStat(currentSnapshot_->statData); + needPotential = false; + needStress = false; currStatus += statusTime; } - if (info_->resetIntegrator) { - if (info_->getTime() >= currReset) { - this->resetIntegrator(); - currReset += resetTime; - } - } + +} -#ifdef IS_MPI - strcpy(checkPointMsg, "successfully took a time step."); - MPIcheckPoint(); +void VelocityVerletIntegrator::finalize() { -#endif // is_mpi + dumpWriter->writeDump(); - } + delete dumpWriter; + delete statWriter; - dumpOut->writeFinal(info_->getTime()); - - delete dumpOut; - delete statOut; + dumpWriter = NULL; + statWriter = NULL; + } -void VelocityVerletIntegrator::integrateStep() { } +void VelocityVerletIntegrator::integrateStep() { + moveA(); + calcForce(needPotential, needStress); + moveB(); +} -void VelocityVerletIntegrator::thermalize() { - if (!info__->have_target_temp) { - sprintf(painCave.errMsg, - "You can't resample the velocities without a targetTemp!\n"); - painCave.isFatal = 1; - painCave.severity = OOPSE_ERROR; - simError(); - return; - } +void VelocityVerletIntegrator::calcForce(bool needPotential, + bool needStress) { + forceMan_->calcForces(needPotential, needStress); +} +DumpWriter* VelocityVerletIntegrator::createDumpWriter() { + return new DumpWriter(info_, info_->getDumpFileName()); } -void VelocityVerletIntegrator::calcForce(bool needPotential, - bool needStress) { } +StatWriter* VelocityVerletIntegrator::createStatWriter() { + return new StatWriter(info_->getStatFileName()); +} } //end namespace oopse