Changeset 4a7776a
- Timestamp:
- Oct 12, 2009, 10:30:02 AM (15 years ago)
- 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
- Location:
- src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/atom.cpp
rccd9f5 r4a7776a 7 7 #include "atom.hpp" 8 8 #include "bond.hpp" 9 #include "config.hpp" 9 10 #include "element.hpp" 10 11 #include "memoryallocator.hpp" … … 265 266 }; 266 267 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 */ 272 void 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 */ 286 void 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 */ 304 void 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 */ 333 void 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 267 341 /** Returns squared distance to a given vector. 268 342 * \param origin vector to calculate distance to … … 312 386 Force->Matrix[0][nr][5+i] += 2.*constant*sqrt(Trajectory.R.at(startstep).Distance(&Sprinter->Trajectory.R.at(endstep))); 313 387 }; 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 */ 394 void 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 */ 407 void 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 */ 422 void 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 */ 439 void 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 */ 455 void 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 */ 480 void 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 */ 495 void 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 */ 510 void 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 }; -
src/atom.hpp
rccd9f5 r4a7776a 21 21 #include <vector> 22 22 23 #include <gsl/gsl_randist.h> 24 23 25 #include "tesselation.hpp" 24 26 … … 26 28 27 29 class bond; 30 class config; 28 31 class element; 29 32 class ForceMatrix; … … 80 83 bool Compare(const atom &ptr); 81 84 85 // trajectory stuff 86 void ResizeTrajectory(int MaxSteps); 87 void CopyStepOnStep(int dest, int src); 88 void VelocityVerletUpdate(int MDSteps, config *configuration, ForceMatrix *Force); 89 void SumUpKineticEnergy( int Step, double *TotalMass, Vector *TotalVelocity ); 90 82 91 double DistanceToVector(Vector &origin); 83 92 double DistanceSquaredToVector(Vector &origin); 84 93 94 bool IsInParallelepiped(Vector offset, double *parallelepiped); 95 96 // constraint potential and dynamics stuff 85 97 void AddKineticToTemperature(double *temperature, int step) const; 86 98 void EvaluateConstrainedForce(int startstep, int endstep, atom **PermutationMap, ForceMatrix *Force); 99 void CorrectVelocity(double *ActualTemp, int Step, Vector *CoGVelocity); 87 100 88 bool IsInParallelepiped(Vector offset, double *parallelepiped); 101 // thermostats 102 void Thermostat_Woodcock(double ScaleTempFactor, int Step, double *ekin); 103 void Thermostat_Gaussian_init(int Step, double *G, double *E); 104 void Thermostat_Gaussian_least_constraint(int Step, double G_over_E, double *ekin, config *configuration); 105 void Thermostat_Langevin(int Step, gsl_rng * r, double *ekin, config *configuration); 106 void Thermostat_Berendsen(int Step, double ScaleTempFactor, double *ekin, config *configuration); 107 void Thermostat_NoseHoover_init(int Step, double *delta_alpha); 108 void Thermostat_NoseHoover_scale(int Step, double *ekin, config *configuration); 109 89 110 90 111 ostream & operator << (ostream &ost); -
src/molecule.cpp
rccd9f5 r4a7776a 1140 1140 return true; 1141 1141 }; 1142 1143 void molecule::SetIndexedArrayForEachAtomTo ( atom **array, int TesselPoint::*index) 1144 { 1145 atom *Walker = start; 1146 while (Walker->next != end) { 1147 Walker = Walker->next; 1148 array[(Walker->*index)] = Walker; 1149 } 1150 }; -
src/molecule.hpp
rccd9f5 r4a7776a 176 176 177 177 // templates for allowing global manipulation of an array with one entry per atom 178 void SetIndexedArrayForEachAtomTo ( atom **array, int TesselPoint::* index); 178 179 template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::* index, void (*Setor)(T *, T)); 179 180 template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::* index, void (*Setor)(T *, T), T t); -
src/molecule_dynamics.cpp
rccd9f5 r4a7776a 497 497 else { 498 498 PermutationMap = Malloc<atom *>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap"); 499 Walker = start; 500 while (Walker->next != end) { 501 Walker = Walker->next; 502 PermutationMap[Walker->nr] = Walker; // always pick target with the smallest distance 503 } 499 SetIndexedArrayForEachAtomTo( PermutationMap, &atom::nr ); 504 500 } 505 501 506 502 // check whether we have sufficient space in Trajectories for each atom 507 Walker = start; 508 while (Walker->next != end) { 509 Walker = Walker->next; 510 if (Walker->Trajectory.R.size() <= (unsigned int)(MaxSteps)) { 511 //cout << "Increasing size for trajectory array of " << keyword << " to " << (MaxSteps+1) << "." << endl; 512 Walker->Trajectory.R.resize(MaxSteps+1); 513 Walker->Trajectory.U.resize(MaxSteps+1); 514 Walker->Trajectory.F.resize(MaxSteps+1); 515 } 516 } 503 ActOnAllAtoms( &atom::ResizeTrajectory, MaxSteps ); 517 504 // push endstep to last one 518 Walker = start; 519 while (Walker->next != end) { // remove the endstep (is now the very last one) 520 Walker = Walker->next; 521 for (int n=NDIM;n--;) { 522 Walker->Trajectory.R.at(MaxSteps).x[n] = Walker->Trajectory.R.at(endstep).x[n]; 523 Walker->Trajectory.U.at(MaxSteps).x[n] = Walker->Trajectory.U.at(endstep).x[n]; 524 Walker->Trajectory.F.at(MaxSteps).x[n] = Walker->Trajectory.F.at(endstep).x[n]; 525 } 526 } 505 ActOnAllAtoms( &atom::CopyStepOnStep, MaxSteps, endstep ); 527 506 endstep = MaxSteps; 528 507 … … 578 557 bool molecule::VerletForceIntegration(ofstream *out, char *file, config &configuration) 579 558 { 580 atom *walker = NULL;581 559 ifstream input(file); 582 560 string token; 583 561 stringstream item; 584 double IonMass, Vector[NDIM], ConstrainedPotentialEnergy, ActualTemp; 562 double IonMass, ConstrainedPotentialEnergy, ActualTemp; 563 Vector Velocity; 585 564 ForceMatrix Force; 586 565 … … 601 580 } 602 581 // correct Forces 603 for(int d=0;d<NDIM;d++) 604 Vector[d] = 0.; 582 Velocity.Zero(); 605 583 for(int i=0;i<AtomCount;i++) 606 584 for(int d=0;d<NDIM;d++) { 607 Ve ctor[d] += Force.Matrix[0][i][d+5];585 Velocity.x[d] += Force.Matrix[0][i][d+5]; 608 586 } 609 587 for(int i=0;i<AtomCount;i++) 610 588 for(int d=0;d<NDIM;d++) { 611 Force.Matrix[0][i][d+5] -= Ve ctor[d]/(double)AtomCount;589 Force.Matrix[0][i][d+5] -= Velocity.x[d]/(double)AtomCount; 612 590 } 613 591 // solve a constrained potential if we are meant to … … 621 599 622 600 // and perform Verlet integration for each atom with position, velocity and force vector 623 walker = start; 624 while (walker->next != end) { // go through every atom of this element 625 walker = walker->next; 626 //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 627 // check size of vectors 628 if (walker->Trajectory.R.size() <= (unsigned int)(MDSteps)) { 629 //out << "Increasing size for trajectory array of " << *walker << " to " << (size+10) << "." << endl; 630 walker->Trajectory.R.resize(MDSteps+10); 631 walker->Trajectory.U.resize(MDSteps+10); 632 walker->Trajectory.F.resize(MDSteps+10); 633 } 634 635 // Update R (and F) 636 for (int d=0; d<NDIM; d++) { 637 walker->Trajectory.F.at(MDSteps).x[d] = -Force.Matrix[0][walker->nr][d+5]*(configuration.GetIsAngstroem() ? AtomicLengthToAngstroem : 1.); 638 walker->Trajectory.R.at(MDSteps).x[d] = walker->Trajectory.R.at(MDSteps-1).x[d]; 639 walker->Trajectory.R.at(MDSteps).x[d] += configuration.Deltat*(walker->Trajectory.U.at(MDSteps-1).x[d]); // s(t) = s(0) + v * deltat + 1/2 a * deltat^2 640 walker->Trajectory.R.at(MDSteps).x[d] += 0.5*configuration.Deltat*configuration.Deltat*(walker->Trajectory.F.at(MDSteps).x[d]/walker->type->mass); // F = m * a and s = 0.5 * F/m * t^2 = F * a * t 641 } 642 // Update U 643 for (int d=0; d<NDIM; d++) { 644 walker->Trajectory.U.at(MDSteps).x[d] = walker->Trajectory.U.at(MDSteps-1).x[d]; 645 walker->Trajectory.U.at(MDSteps).x[d] += configuration.Deltat * (walker->Trajectory.F.at(MDSteps).x[d]+walker->Trajectory.F.at(MDSteps-1).x[d]/walker->type->mass); // v = F/m * t 646 } 647 // out << "Integrated position&velocity of step " << (MDSteps) << ": ("; 648 // for (int d=0;d<NDIM;d++) 649 // out << walker->Trajectory.R.at(MDSteps).x[d] << " "; // next step 650 // out << ")\t("; 651 // for (int d=0;d<NDIM;d++) 652 // cout << walker->Trajectory.U.at(MDSteps).x[d] << " "; // next step 653 // out << ")" << endl; 654 // next atom 655 } 601 // check size of vectors 602 ActOnAllAtoms( &atom::ResizeTrajectory, MDSteps+10 ); 603 604 ActOnAllAtoms( &atom::VelocityVerletUpdate, MDSteps, &configuration, &Force); 656 605 } 657 606 // correct velocities (rather momenta) so that center of mass remains motionless 658 for(int d=0;d<NDIM;d++) 659 Vector[d] = 0.; 607 Velocity.Zero(); 660 608 IonMass = 0.; 661 walker = start; 662 while (walker->next != end) { // go through every atom 663 walker = walker->next; 664 IonMass += walker->type->mass; // sum up total mass 665 for(int d=0;d<NDIM;d++) { 666 Vector[d] += walker->Trajectory.U.at(MDSteps).x[d]*walker->type->mass; 667 } 668 } 609 ActOnAllAtoms ( &atom::SumUpKineticEnergy, MDSteps, &IonMass, &Velocity ); 610 669 611 // correct velocities (rather momenta) so that center of mass remains motionless 670 for(int d=0;d<NDIM;d++) 671 Vector[d] /= IonMass; 612 Velocity.Scale(1./IonMass); 672 613 ActualTemp = 0.; 673 walker = start; 674 while (walker->next != end) { // go through every atom of this element 675 walker = walker->next; 676 for(int d=0;d<NDIM;d++) { 677 walker->Trajectory.U.at(MDSteps).x[d] -= Vector[d]; 678 ActualTemp += 0.5 * walker->type->mass * walker->Trajectory.U.at(MDSteps).x[d] * walker->Trajectory.U.at(MDSteps).x[d]; 679 } 680 } 614 ActOnAllAtoms ( &atom::CorrectVelocity, &ActualTemp, MDSteps, &Velocity ); 681 615 Thermostats(configuration, ActualTemp, Berendsen); 682 616 MDSteps++; 683 684 617 685 618 // exit … … 712 645 double delta_alpha = 0.; 713 646 double ScaleTempFactor; 714 double sigma;715 double IonMass;716 int d;717 647 gsl_rng * r; 718 648 const gsl_rng_type * T; 719 double *U = NULL, *F = NULL, FConstraint[NDIM];720 atom *walker = NULL;721 649 722 650 // calculate scale configuration … … 731 659 if ((configuration.ScaleTempStep > 0) && ((MDSteps-1) % configuration.ScaleTempStep == 0)) { 732 660 cout << Verbose(2) << "Applying Woodcock thermostat..." << endl; 733 walker = start; 734 while (walker->next != end) { // go through every atom of this element 735 walker = walker->next; 736 IonMass = walker->type->mass; 737 U = walker->Trajectory.U.at(MDSteps).x; 738 if (walker->FixedIon == 0) // even FixedIon moves, only not by other's forces 739 for (d=0; d<NDIM; d++) { 740 U[d] *= sqrt(ScaleTempFactor); 741 ekin += 0.5*IonMass * U[d]*U[d]; 742 } 743 } 661 ActOnAllAtoms( &atom::Thermostat_Woodcock, sqrt(ScaleTempFactor), MDSteps, &ekin ); 744 662 } 745 663 break; 746 664 case Gaussian: 747 665 cout << Verbose(2) << "Applying Gaussian thermostat..." << endl; 748 walker = start; 749 while (walker->next != end) { // go through every atom of this element 750 walker = walker->next; 751 IonMass = walker->type->mass; 752 U = walker->Trajectory.U.at(MDSteps).x; 753 F = walker->Trajectory.F.at(MDSteps).x; 754 if (walker->FixedIon == 0) // even FixedIon moves, only not by other's forces 755 for (d=0; d<NDIM; d++) { 756 G += U[d] * F[d]; 757 E += U[d]*U[d]*IonMass; 758 } 759 } 666 ActOnAllAtoms( &atom::Thermostat_Gaussian_init, MDSteps, &G, &E ); 667 760 668 cout << Verbose(1) << "Gaussian Least Constraint constant is " << G/E << "." << endl; 761 walker = start; 762 while (walker->next != end) { // go through every atom of this element 763 walker = walker->next; 764 IonMass = walker->type->mass; 765 U = walker->Trajectory.U.at(MDSteps).x; 766 F = walker->Trajectory.F.at(MDSteps).x; 767 if (walker->FixedIon == 0) // even FixedIon moves, only not by other's forces 768 for (d=0; d<NDIM; d++) { 769 FConstraint[d] = (G/E) * (U[d]*IonMass); 770 U[d] += configuration.Deltat/IonMass * (FConstraint[d]); 771 ekin += IonMass * U[d]*U[d]; 772 } 773 } 669 ActOnAllAtoms( &atom::Thermostat_Gaussian_least_constraint, MDSteps, G/E, &ekin, &configuration); 670 774 671 break; 775 672 case Langevin: … … 780 677 r = gsl_rng_alloc (T); 781 678 // Go through each ion 782 walker = start; 783 while (walker->next != end) { // go through every atom of this element 784 walker = walker->next; 785 IonMass = walker->type->mass; 786 sigma = sqrt(configuration.TargetTemp/IonMass); // sigma = (k_b T)/m (Hartree/atomicmass = atomiclength/atomictime) 787 U = walker->Trajectory.U.at(MDSteps).x; 788 F = walker->Trajectory.F.at(MDSteps).x; 789 if (walker->FixedIon == 0) { // even FixedIon moves, only not by other's forces 790 // throw a dice to determine whether it gets hit by a heat bath particle 791 if (((((rand()/(double)RAND_MAX))*configuration.TempFrequency) < 1.)) { 792 cout << Verbose(3) << "Particle " << *walker << " was hit (sigma " << sigma << "): " << sqrt(U[0]*U[0]+U[1]*U[1]+U[2]*U[2]) << " -> "; 793 // pick three random numbers from a Boltzmann distribution around the desired temperature T for each momenta axis 794 for (d=0; d<NDIM; d++) { 795 U[d] = gsl_ran_gaussian (r, sigma); 796 } 797 cout << sqrt(U[0]*U[0]+U[1]*U[1]+U[2]*U[2]) << endl; 798 } 799 for (d=0; d<NDIM; d++) 800 ekin += 0.5*IonMass * U[d]*U[d]; 801 } 802 } 679 ActOnAllAtoms( &atom::Thermostat_Langevin, MDSteps, r, &ekin, &configuration ); 803 680 break; 681 804 682 case Berendsen: 805 683 cout << Verbose(2) << "Applying Berendsen-VanGunsteren thermostat..." << endl; 806 walker = start; 807 while (walker->next != end) { // go through every atom of this element 808 walker = walker->next; 809 IonMass = walker->type->mass; 810 U = walker->Trajectory.U.at(MDSteps).x; 811 F = walker->Trajectory.F.at(MDSteps).x; 812 if (walker->FixedIon == 0) { // even FixedIon moves, only not by other's forces 813 for (d=0; d<NDIM; d++) { 814 U[d] *= sqrt(1+(configuration.Deltat/configuration.TempFrequency)*(ScaleTempFactor-1)); 815 ekin += 0.5*IonMass * U[d]*U[d]; 816 } 817 } 818 } 684 ActOnAllAtoms( &atom::Thermostat_Berendsen, MDSteps, ScaleTempFactor, &ekin, &configuration ); 819 685 break; 686 820 687 case NoseHoover: 821 688 cout << Verbose(2) << "Applying Nose-Hoover thermostat..." << endl; 822 689 // dynamically evolve alpha (the additional degree of freedom) 823 690 delta_alpha = 0.; 824 walker = start; 825 while (walker->next != end) { // go through every atom of this element 826 walker = walker->next; 827 IonMass = walker->type->mass; 828 U = walker->Trajectory.U.at(MDSteps).x; 829 if (walker->FixedIon == 0) { // even FixedIon moves, only not by other's forces 830 for (d=0; d<NDIM; d++) { 831 delta_alpha += U[d]*U[d]*IonMass; 832 } 833 } 834 } 691 ActOnAllAtoms( &atom::Thermostat_NoseHoover_init, MDSteps, &delta_alpha ); 835 692 delta_alpha = (delta_alpha - (3.*AtomCount+1.) * configuration.TargetTemp)/(configuration.HooverMass*Units2Electronmass); 836 693 configuration.alpha += delta_alpha*configuration.Deltat; 837 694 cout << Verbose(3) << "alpha = " << delta_alpha << " * " << configuration.Deltat << " = " << configuration.alpha << "." << endl; 838 695 // apply updated alpha as additional force 839 walker = start; 840 while (walker->next != end) { // go through every atom of this element 841 walker = walker->next; 842 IonMass = walker->type->mass; 843 U = walker->Trajectory.U.at(MDSteps).x; 844 if (walker->FixedIon == 0) { // even FixedIon moves, only not by other's forces 845 for (d=0; d<NDIM; d++) { 846 FConstraint[d] = - configuration.alpha * (U[d] * IonMass); 847 U[d] += configuration.Deltat/IonMass * (FConstraint[d]); 848 ekin += (0.5*IonMass) * U[d]*U[d]; 849 } 850 } 851 } 696 ActOnAllAtoms( &atom::Thermostat_NoseHoover_scale, MDSteps, &ekin, &configuration ); 852 697 break; 853 698 } -
src/molecule_template.hpp
rccd9f5 r4a7776a 436 436 }; 437 437 438 // ===================== Access sing arrays indexed by some integer for each atom ======================438 // ===================== Accessing arrays indexed by some integer for each atom ====================== 439 439 440 440 // for atom ints
Note:
See TracChangeset
for help on using the changeset viewer.