void BodyAttraction(std::vector<Body*> pBodies, float pSoftener) { for (unsigned int i = 0; i < pBodies.size(); i++) { for (unsigned int j = 0; j < pBodies.size(); j++) { CalculateForce(pBodies.at(i), pBodies.at(j), pSoftener); //for each body in pBodies: each other body in pBodies: Calculate attractive force exerted on the first body from the second one } } }
void AttractToCenter(std::vector<Body*> pBodies, float width, float height, float centerMass) { Body* Temp = CreateBody(width / 2, height / 2, centerMass); //Create a body at the center of the simulation for (unsigned int i = 0; i < pBodies.size(); i++) { CalculateForce(pBodies[i], Temp, Softener); } delete Temp; }
void GlobalMinimumSimulation(void) { int i,j,k,l; int success; REAL ran,GlobalMinimumEnergy,UInitial,UAfterMC; success=0; GlobalMinimumEnergy=EnergyOverlapCriteria; OpenOutputFile(); PrintPreSimulationStatus(); for(k=0;k<NumberOfCycles;k++) { do { CurrentSystem=0; for(i=0;i<NumberOfAdsorbateMolecules[0];i++) RemoveAdsorbateMolecule(); for(i=0;i<NumberOfCationMolecules[0];i++) RemoveCationMolecule(); for(j=0;j<NumberOfComponents;j++) { if(Components[j].CreateNumberOfMolecules[0]>0) { CurrentSystem=0; if(Components[j].ExtraFrameworkMolecule) MakeInitialCations(Components[j].CreateNumberOfMolecules[0],j); else MakeInitialAdsorbates(Components[j].CreateNumberOfMolecules[0],j); } } CalculateForce(); UInitial=UTotal[0]; for(l=0;l<NumberOfInitializationCycles;l++) { for(j=0;j<MAX2(MinimumInnerCycles,NumberOfAdsorbateMolecules[CurrentSystem]+NumberOfCationMolecules[CurrentSystem]);j++) { // choose component at random CurrentComponent=(int)(RandomNumber()*(REAL)NumberOfComponents); // choose the Monte Carlo move at random ran=RandomNumber(); if(Components[CurrentComponent].ExtraFrameworkMolecule) { if(ran<Components[CurrentComponent].ProbabilityTranslationMove) TranslationMoveCation(); if(ran<Components[CurrentComponent].ProbabilityRotationMove) RotationMoveCation(); else if(ran<Components[CurrentComponent].ProbabilityReinsertionMove) ReinsertionCationMove(); } else { if(ran<Components[CurrentComponent].ProbabilityTranslationMove) TranslationMoveAdsorbate(); if(ran<Components[CurrentComponent].ProbabilityRotationMove) RotationMoveAdsorbate(); else if(ran<Components[CurrentComponent].ProbabilityReinsertionMove) ReinsertionAdsorbateMove(); } } } CalculateForce(); UAfterMC=UTotal[0]; // do the minimization as //success=BakerMinimizationNoOutput(); if(success==0) fprintf(OutputFilePtr[0],"Minimization failed to convergence within %d steps\n",MaximumNumberOfMinimizationSteps); } while(success==0); // recompute energy CalculateForce(); CurrentSystem=0; fprintf(OutputFilePtr[0],"iteration: %d Energy before Monte-Carlo: %18.10f [K] Energy after Monte-Carlo: %18.10f [K]\n", k,UInitial*ENERGY_TO_KELVIN,UAfterMC*ENERGY_TO_KELVIN); fflush(OutputFilePtr[0]); if(UTotal[0]<GlobalMinimumEnergy) { fprintf(OutputFilePtr[0],"found lower new minimum, positions saved to restart-file\n"); GlobalMinimumEnergy=UTotal[0]; PrintRestartFile(); } fprintf(OutputFilePtr[0],"\t\tMinimization steps: %d Minimized energy: %18.10f [K] (%18.10f [kJ/mol]) Global minimum: %18.10f (%18.10f [kJ/mol])\n", success,UTotal[0]*ENERGY_TO_KELVIN,UTotal[0]*ENERGY_TO_KJ_PER_MOL,GlobalMinimumEnergy*ENERGY_TO_KELVIN,GlobalMinimumEnergy*ENERGY_TO_KJ_PER_MOL); fflush(OutputFilePtr[0]); } PrintPostSimulationStatus(); CloseOutputFile(); }