void NormalModeLangLf::run(int numTimesteps) { //Real h = getTimestep() * Constant::INV_TIMEFACTOR; Real actTime; if( numTimesteps < 1 ) return; //check valid eigenvectors if(*Q == NULL) report << error << "No Eigenvectors for NormalMode integrator."<<endr; // //time calculated in forces! so fix here actTime = app->topology->time + numTimesteps * getTimestep(); // //main loop for( int i = 0; i < numTimesteps; i++ ) { //****main loop************************************* preStepModify(); genProjGauss(&gaussRandCoord1, app->topology); doHalfKick(); // //nmlDrift(&app->positions, &app->velocities, h, app->topology); doDrift(); //constraints? app->energies.clear(); //run minimizer if any remaining modes if(testRemainingModes()) myNextIntegrator->run(myCycleLength); //cyclelength if(app->eigenInfo.reDiagonalize){ //rediagonalize? app->topology->time = actTime + (i - numTimesteps) * getTimestep(); if(myPreviousIntegrator == NULL) report << error << "[NormalModeLangLf::Run] Re-diagonalization forced with NormalModeLangLf as outermost Integrator. Aborting."<<endr; return; } //calculate sub space forces app->energies.clear(); calculateForces(); // genProjGauss(&gaussRandCoord1, app->topology); doHalfKick(); // postStepModify(); } //fix time app->topology->time = actTime; // }
void NormalModeMinimizer::run(int numTimesteps) { if( numTimesteps < 1 ) return; //check valid eigenvectors if(*Q == NULL) report << error << "No Eigenvectors for NormalMode integrator."<<endr; // preStepModify(); //remove last random pertubation if(randforce) app->positions.intoSubtract(gaussRandCoord1); //(*myPositions).intoWeightedAdd(-randStp,gaussRandCoord1); //do minimization with local forces, max loop rediagOnMaxMinSteps, set subSpace minimization true itrs = minimizer(minLim, rediagOnMaxMinSteps>0 ? rediagOnMaxMinSteps : 100 , simpleMin, reDiag, true, &forceCalc, &lastLambda, &app->energies, &app->positions, app->topology); //flag excessive minimizations if(itrs > 10) report << debug(1) << "[NormalModeMinimizer::run] iterations = " << itrs << "." << endr; else report << debug(3) << "[NormalModeMinimizer::run] iterations = " << itrs << "." << endr; avItrs += itrs; //rediagonalize if minimization steps exceeds 'rediagOnMaxMinSteps' if(reDiag && rediagOnMaxMinSteps > 0 && itrs >= rediagOnMaxMinSteps){ report << debug(1) << "[NormalModeMinimizer::run] Minimization steps (" << itrs << ") exceeded maximum (" << rediagOnMaxMinSteps << "), forcing re-diagonalize." << endr; itrs = -1; //force re-diag } numSteps++; avMinForceCalc += forceCalc; report <<debug(5)<<"[NormalModeMinimizer::run] iterations = "<<itrs<<" average = "<< (float)avItrs/(float)numSteps<<" force calcs = "<<forceCalc<<" average = "<<(float)avMinForceCalc/(float)numSteps<<endl; if(randforce && itrs != -1 && lastLambda > 0){ //add random force, but not if rediagonalizing //add random force if(myPreviousNormalMode->genCompNoise) gaussRandCoord1 = myPreviousNormalMode->tempV3DBlk; else genProjGauss(&gaussRandCoord1, app->topology); //lambda = eUFactor / *eigValP; //user factor randStp = sqrt(2 * Constant::BOLTZMANN * myTemp * lastLambda); //step length //(*myPositions).intoWeightedAdd(randStp,gaussRandCoord1); gaussRandCoord1.intoWeighted(randStp,gaussRandCoord1); app->positions.intoAdd(gaussRandCoord1); //additional random steps? if(randforce > 1){ eUFactor = 0.5; Real lambda; for(int i=1;i<randforce;i++){ utilityCalculateForces(); nonSubspaceForce(myForces, myForces); for(int j=0;j<_N;j++) (*myForces)[j] /= app->topology->atoms[j].scaledMass; lambda = eUFactor / *eigValP; //user factor //update positions app->positions.intoWeightedAdd(lambda,*myForces); gaussRandCoord1.intoWeightedAdd(lambda,*myForces); //add to grc1 so can be removed at the next step //random force genProjGauss(&gaussRandCoord2, app->topology); randStp = sqrt(2 * Constant::BOLTZMANN * myTemp * lambda); app->positions.intoWeightedAdd(randStp,gaussRandCoord2); //add to grc1 so can be removed at the next step gaussRandCoord1.intoWeightedAdd(randStp,gaussRandCoord2); } } }else{ gaussRandCoord1.zero(-1); //flag re-diagonalize if detected if(itrs == -1) app->eigenInfo.reDiagonalize = true; } // postStepModify(); }
long NormalModeMori::run(const long numTimesteps) { Real h = getTimestep() * Constant::INV_TIMEFACTOR; Real actTime; if( numTimesteps < 1 ) return 0; //check valid eigenvectors if(*Q == NULL) report << error << "No Eigenvectors for NormalMode integrator."<<endr; // //time calculated in forces! so fix here actTime = app->topology->time + numTimesteps * getTimestep(); // //main loop for( int i = 0; i < numTimesteps; i++ ) { //****main loop************************************* preStepModify(); doHalfKick(); // nmlDrift(&app->positions, &app->velocities, h, app->topology); //constraints? app->energies.clear(); //run minimizer if any remaining modes if(testRemainingModes()) myNextIntegrator->run(myCycleLength); //cyclelength if(*Q == NULL){ //rediagonalize? app->topology->time = actTime - (i - numTimesteps) * getTimestep(); if(myPreviousIntegrator == NULL) report << error << "[NormalModeMori::Run] Re-diagonalization forced with NormalModeMori as outermost Integrator. Aborting."<<endr; return i; } //#################Put averaged force code here############################## //calculate sub space forces, just do this for the energy Real minPotEnergy = (app->energies)[ScalarStructure::OTHER]; //save minimum potential energy app->energies.clear(); calculateForces(); //transfer the real average force, Note: force fields must be identical if(!instForce){ for( unsigned int i=0;i < app->positions.size(); i++) (*myForces)[i] = myBottomNormalMode->tempV3DBlk[i]; } (app->energies)[ScalarStructure::OTHER] = minPotEnergy; //restore minimum potential energy //########################################################################### // doHalfKick(); // postStepModify(); } //####diagnostics //output modes? if(modeOutput != ""){ //get modes modeSpaceProj(tmpC, &app->positions, ex0); //Output modes for analysis ofstream myFile; myFile.open(modeOutput.c_str(),ofstream::app); myFile.precision(10); for(int ii=0;ii<_rfM-1;ii++) myFile << tmpC[ii] << ", "; myFile << tmpC[_rfM-1] << endl; //last //close file myFile.close(); } //#### //fix time app->topology->time = actTime; return numTimesteps; }
void NormalModeQuadratic::run( int numTimesteps ) { //check valid eigenvectors if ( *Q == NULL ){ report << error << "No Eigenvectors for NormalMode integrator." << endr; } if ( app->eigenInfo.myEigenvalues.size() < (unsigned)firstMode + numMode - 1 ){ report << error << "Insufficient Eigenvalues for Quadratic integrator (" << app->eigenInfo.myEigenvalues.size() << "." << endr; } if ( numTimesteps < 1 ){ return; } //timestep Real h = getTimestep() * Constant::INV_TIMEFACTOR; //time calculated in forces! so fix here Real actTime = app->topology->time + numTimesteps * getTimestep(); Real tempFrq; Real tempKt = sqrt( 2.0 * myTemp * Constant::BOLTZMANN ); //find ex0 if re-diag present if ( myPreviousNormalMode && myPreviousNormalMode->newDiag ) { //reset ex0 and restart time for \omega t if new diagonalization *ex0 = myPreviousNormalMode->diagAt; total_time = 0; } //main loop for ( int i = 0; i < numTimesteps; i++ ) { preStepModify(); numSteps++; if ( stepModes ) { //set mode if ( !( numSteps % cycleSteps ) ) { cPos[currMode++] = 0.0; app->positions = *ex0; if ( currMode >= firstMode + numMode - 1 ) { currMode = firstMode - 1; } } app->eigenInfo.currentMode = currMode + 1; //****Analytical mode integrator loop***** tempFrq = sqrt( fabs( app->eigenInfo.myEigenvalues[currMode] ) ); cPos[currMode] = tempKt * sin( ( double )( numSteps % cycleSteps ) / ( double )cycleSteps * 2.0 * M_PI ); cPos[currMode] /= fScale ? tempFrq : sqrt( tempFrq ); subspaceProj( cPos, &app->positions ); } else { //full dynamics here int startm = firstMode - 1; if ( startm < 7 ) { startm = 7; } for ( int i = startm; i < firstMode + numMode - 1;i++ ) { //****Analytical mode integrator loop***** tempFrq = sqrt( fabs( app->eigenInfo.myEigenvalues[i] ) ); cPos[i] = tempKt * sin( total_time * tempFrq ); cPos[i] /= fScale ? tempFrq : sqrt( tempFrq ); } subspaceProj( cPos, &app->positions ); } postStepModify(); total_time += h; } //fix time app->topology->time = actTime; }