Changeset 4a7776a for src/atom.cpp


Ignore:
Timestamp:
Oct 12, 2009, 10:30:02 AM (16 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
5034e1
Parents:
ccd9f5
Message:

Complete refactoring of molecule_dynamics.cpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/atom.cpp

    rccd9f5 r4a7776a  
    77#include "atom.hpp"
    88#include "bond.hpp"
     9#include "config.hpp"
    910#include "element.hpp"
    1011#include "memoryallocator.hpp"
     
    265266};
    266267
     268/** Extends the trajectory STL vector to the new size.
     269 * Does nothing if \a MaxSteps is smaller than current size.
     270 * \param MaxSteps
     271 */
     272void atom::ResizeTrajectory(int MaxSteps)
     273{
     274  if (Trajectory.R.size() <= (unsigned int)(MaxSteps)) {
     275    //cout << "Increasing size for trajectory array of " << keyword << " to " << (MaxSteps+1) << "." << endl;
     276    Trajectory.R.resize(MaxSteps+1);
     277    Trajectory.U.resize(MaxSteps+1);
     278    Trajectory.F.resize(MaxSteps+1);
     279  }
     280};
     281
     282/** Copies a given trajectory step \a src onto another \a dest
     283 * \param dest index of destination step
     284 * \param src index of source step
     285 */
     286void atom::CopyStepOnStep(int dest, int src)
     287{
     288  if (dest == src)  // self assignment check
     289    return;
     290
     291  for (int n=NDIM;n--;) {
     292    Trajectory.R.at(dest).x[n] = Trajectory.R.at(src).x[n];
     293    Trajectory.U.at(dest).x[n] = Trajectory.U.at(src).x[n];
     294    Trajectory.F.at(dest).x[n] = Trajectory.F.at(src).x[n];
     295  }
     296};
     297
     298/** Performs a velocity verlet update of the trajectory.
     299 * Parameters are according to those in configuration class.
     300 * \param NextStep index of sequential step to set
     301 * \param *configuration pointer to configuration with parameters
     302 * \param *Force matrix with forces
     303 */
     304void atom::VelocityVerletUpdate(int NextStep, config *configuration, ForceMatrix *Force)
     305{
     306  //a = configuration.Deltat*0.5/walker->type->mass;        // (F+F_old)/2m = a and thus: v = (F+F_old)/2m * t = (F + F_old) * a
     307  for (int d=0; d<NDIM; d++) {
     308    Trajectory.F.at(NextStep).x[d] = -Force->Matrix[0][nr][d+5]*(configuration->GetIsAngstroem() ? AtomicLengthToAngstroem : 1.);
     309    Trajectory.R.at(NextStep).x[d] = Trajectory.R.at(NextStep-1).x[d];
     310    Trajectory.R.at(NextStep).x[d] += configuration->Deltat*(Trajectory.U.at(NextStep-1).x[d]);     // s(t) = s(0) + v * deltat + 1/2 a * deltat^2
     311    Trajectory.R.at(NextStep).x[d] += 0.5*configuration->Deltat*configuration->Deltat*(Trajectory.F.at(NextStep).x[d]/type->mass);     // F = m * a and s = 0.5 * F/m * t^2 = F * a * t
     312  }
     313  // Update U
     314  for (int d=0; d<NDIM; d++) {
     315    Trajectory.U.at(NextStep).x[d] = Trajectory.U.at(NextStep-1).x[d];
     316    Trajectory.U.at(NextStep).x[d] += configuration->Deltat * (Trajectory.F.at(NextStep).x[d]+Trajectory.F.at(NextStep-1).x[d]/type->mass); // v = F/m * t
     317  }
     318  // Update R (and F)
     319//      out << "Integrated position&velocity of step " << (NextStep) << ": (";
     320//      for (int d=0;d<NDIM;d++)
     321//        out << Trajectory.R.at(NextStep).x[d] << " ";          // next step
     322//      out << ")\t(";
     323//      for (int d=0;d<NDIM;d++)
     324//        cout << Trajectory.U.at(NextStep).x[d] << " ";          // next step
     325//      out << ")" << endl;
     326};
     327
     328/** Sums up mass and kinetics.
     329 * \param Step step to sum for
     330 * \param *TotalMass pointer to total mass sum
     331 * \param *TotalVelocity pointer to tota velocity sum
     332 */
     333void atom::SumUpKineticEnergy( int Step, double *TotalMass, Vector *TotalVelocity )
     334{
     335  *TotalMass += type->mass;  // sum up total mass
     336  for(int d=0;d<NDIM;d++) {
     337    TotalVelocity->x[d] += Trajectory.U.at(Step).x[d]*type->mass;
     338  }
     339};
     340
    267341/** Returns squared distance to a given vector.
    268342 * \param origin vector to calculate distance to
     
    312386    Force->Matrix[0][nr][5+i] += 2.*constant*sqrt(Trajectory.R.at(startstep).Distance(&Sprinter->Trajectory.R.at(endstep)));
    313387};
     388
     389/** Correct velocity against the summed \a CoGVelocity for \a step.
     390 * \param *ActualTemp sum up actual temperature meanwhile
     391 * \param Step MD step in atom::Tracjetory
     392 * \param *CoGVelocity remnant velocity (i.e. vector sum of all atom velocities)
     393 */
     394void atom::CorrectVelocity(double *ActualTemp, int Step, Vector *CoGVelocity)
     395{
     396  for(int d=0;d<NDIM;d++) {
     397    Trajectory.U.at(Step).x[d] -= CoGVelocity->x[d];
     398    *ActualTemp += 0.5 * type->mass * Trajectory.U.at(Step).x[d] * Trajectory.U.at(Step).x[d];
     399  }
     400};
     401
     402/** Scales velocity of atom according to Woodcock thermostat.
     403 * \param ScaleTempFactor factor to scale the velocities with (i.e. sqrt of energy scale factor)
     404 * \param Step MD step to scale
     405 * \param *ekin sum of kinetic energy
     406 */
     407void atom::Thermostat_Woodcock(double ScaleTempFactor, int Step, double *ekin)
     408{
     409  double *U = Trajectory.U.at(Step).x;
     410  if (FixedIon == 0) // even FixedIon moves, only not by other's forces
     411    for (int d=0; d<NDIM; d++) {
     412      U[d] *= ScaleTempFactor;
     413      *ekin += 0.5*type->mass * U[d]*U[d];
     414    }
     415};
     416
     417/** Scales velocity of atom according to Gaussian thermostat.
     418 * \param Step MD step to scale
     419 * \param *G
     420 * \param *E
     421 */
     422void atom::Thermostat_Gaussian_init(int Step, double *G, double *E)
     423{
     424  double *U = Trajectory.U.at(Step).x;
     425  double *F = Trajectory.F.at(Step).x;
     426  if (FixedIon == 0) // even FixedIon moves, only not by other's forces
     427    for (int d=0; d<NDIM; d++) {
     428      *G += U[d] * F[d];
     429      *E += U[d]*U[d]*type->mass;
     430    }
     431};
     432
     433/** Determines scale factors according to Gaussian thermostat.
     434 * \param Step MD step to scale
     435 * \param GE G over E ratio
     436 * \param *ekin sum of kinetic energy
     437 * \param *configuration configuration class with TempFrequency and TargetTemp
     438 */
     439void atom::Thermostat_Gaussian_least_constraint(int Step, double G_over_E, double *ekin, config *configuration)
     440{
     441  double *U = Trajectory.U.at(Step).x;
     442  if (FixedIon == 0) // even FixedIon moves, only not by other's forces
     443    for (int d=0; d<NDIM; d++) {
     444      U[d] += configuration->Deltat/type->mass * ( (G_over_E) * (U[d]*type->mass) );
     445      *ekin += type->mass * U[d]*U[d];
     446    }
     447};
     448
     449/** Scales velocity of atom according to Langevin thermostat.
     450 * \param Step MD step to scale
     451 * \param *r random number generator
     452 * \param *ekin sum of kinetic energy
     453 * \param *configuration configuration class with TempFrequency and TargetTemp
     454 */
     455void atom::Thermostat_Langevin(int Step, gsl_rng * r, double *ekin, config *configuration)
     456{
     457  double sigma  = sqrt(configuration->TargetTemp/type->mass); // sigma = (k_b T)/m (Hartree/atomicmass = atomiclength/atomictime)
     458  double *U = Trajectory.U.at(Step).x;
     459  if (FixedIon == 0) { // even FixedIon moves, only not by other's forces
     460    // throw a dice to determine whether it gets hit by a heat bath particle
     461    if (((((rand()/(double)RAND_MAX))*configuration->TempFrequency) < 1.)) {
     462      cout << Verbose(3) << "Particle " << *this << " was hit (sigma " << sigma << "): " << sqrt(U[0]*U[0]+U[1]*U[1]+U[2]*U[2]) << " -> ";
     463      // pick three random numbers from a Boltzmann distribution around the desired temperature T for each momenta axis
     464      for (int d=0; d<NDIM; d++) {
     465        U[d] = gsl_ran_gaussian (r, sigma);
     466      }
     467      cout << sqrt(U[0]*U[0]+U[1]*U[1]+U[2]*U[2]) << endl;
     468    }
     469    for (int d=0; d<NDIM; d++)
     470      *ekin += 0.5*type->mass * U[d]*U[d];
     471  }
     472};
     473
     474/** Scales velocity of atom according to Berendsen thermostat.
     475 * \param Step MD step to scale
     476 * \param ScaleTempFactor factor to scale energy (not velocity!) with
     477 * \param *ekin sum of kinetic energy
     478 * \param *configuration configuration class with TempFrequency and Deltat
     479 */
     480void atom::Thermostat_Berendsen(int Step, double ScaleTempFactor, double *ekin, config *configuration)
     481{
     482  double *U = Trajectory.U.at(Step).x;
     483  if (FixedIon == 0) { // even FixedIon moves, only not by other's forces
     484    for (int d=0; d<NDIM; d++) {
     485      U[d] *= sqrt(1+(configuration->Deltat/configuration->TempFrequency)*(ScaleTempFactor-1));
     486      *ekin += 0.5*type->mass * U[d]*U[d];
     487    }
     488  }
     489};
     490
     491/** Initializes current run of NoseHoover thermostat.
     492 * \param Step MD step to scale
     493 * \param *delta_alpha additional sum of kinetic energy on return
     494 */
     495void atom::Thermostat_NoseHoover_init(int Step, double *delta_alpha)
     496{
     497  double *U = Trajectory.U.at(Step).x;
     498  if (FixedIon == 0) { // even FixedIon moves, only not by other's forces
     499    for (int d=0; d<NDIM; d++) {
     500      *delta_alpha += U[d]*U[d]*type->mass;
     501    }
     502  }
     503};
     504
     505/** Initializes current run of NoseHoover thermostat.
     506 * \param Step MD step to scale
     507 * \param *ekin sum of kinetic energy
     508 * \param *configuration configuration class with TempFrequency and Deltat
     509 */
     510void atom::Thermostat_NoseHoover_scale(int Step, double *ekin, config *configuration)
     511{
     512  double *U = Trajectory.U.at(Step).x;
     513  if (FixedIon == 0) { // even FixedIon moves, only not by other's forces
     514    for (int d=0; d<NDIM; d++) {
     515        U[d] += configuration->Deltat/type->mass * (configuration->alpha * (U[d] * type->mass));
     516        *ekin += (0.5*type->mass) * U[d]*U[d];
     517      }
     518  }
     519};
Note: See TracChangeset for help on using the changeset viewer.