26 Array <dVec,1> &initialPos) :
27 externalPtr(_externalPtr),
28 interactionPtr(_interactionPtr),
34 numParticles = config.extent(firstDim);
40 energy = getTotalEnergy();
54 aveNumParticles = 0.0;
69 double ClassicalMonteCarlo::getTotalEnergy()
71 double locEnergy = 0.0;
73 for (
int part1 = 0; part1 < numParticles; part1++) {
74 locEnergy += externalPtr->
V(config(part1));
76 for (
int part2 = part1+1; part2 < numParticles; part2++) {
77 sep = config(part1)-config(part2);
79 locEnergy += interactionPtr->
V(sep);
92 for(
uint32 n = 1; n < numMCSteps; n++) {
103 else if (x < 2.0/3.0)
110 aveNumParticles += numParticles;
111 aveEoN += energy/(1.0*numParticles);
115 }
while (m < numParticles);
122 config.resizeAndPreserve(numParticles);
129 void ClassicalMonteCarlo::moveParticle() {
137 int p = random.randInt(numParticles-1);
140 oldV = externalPtr->
V(config(p));
141 for (
int p2 = 0; p2 < numParticles; p2++) {
143 sep = config(p)-config(p2);
145 oldV += interactionPtr->
V(sep);
152 config(p) = boxPtr->
randUpdate(random,oldPos);
155 newV = externalPtr->
V(config(p));
156 for (
int p2 = 0; p2 < numParticles; p2++) {
158 sep = config(p)-config(p2);
160 newV += interactionPtr->
V(sep);
164 deltaV = newV - oldV;
167 if (random.rand() < exp(-deltaV/
constants()->T())) {
180 void ClassicalMonteCarlo::insertParticle() {
190 deltaV = externalPtr->
V(newPos);
191 for (
int p2 = 0; p2 < numParticles; p2++) {
192 sep = newPos-config(p2);
194 deltaV += interactionPtr->
V(sep);
197 double factor = z*boxPtr->
volume/(numParticles+1);
200 if (random.rand() < factor*exp(-deltaV/
constants()->T())) {
202 if (config.extent(firstDim) < (numParticles+1))
203 config.resizeAndPreserve(numParticles+1);
204 config(numParticles) = newPos;
214 void ClassicalMonteCarlo::deleteParticle() {
218 int p = random.randInt(numParticles-1);
221 deltaV = -externalPtr->
V(config(p));
222 for (
int p2 = 0; p2 < numParticles; p2++) {
224 sep = config(p)-config(p2);
226 deltaV -= interactionPtr->
V(sep);
230 double factor = numParticles/(z*boxPtr->
volume);
233 if (random.rand() < factor*exp(-deltaV/
constants()->T())) {
235 config(p) = config(numParticles-1);
245 void ClassicalMonteCarlo::measure(
int &numMeasure) {
246 cout << aveEnergy/(numMeasure) <<
"\t" << aveNumParticles/(numMeasure)
247 <<
"\t" << (3.0/2.0)*
constants()->
T() + aveEoN/(numMeasure)
248 <<
"\t" << aveNumParticles/(numMeasure*boxPtr->
volume)
249 <<
"\t" << 1.0*numMoveAccept/(1.0*numMoveTotal)
250 <<
"\t" << 1.0*numInsertAccept/(1.0*numInsertTotal)
251 <<
"\t" << 1.0*numDeleteAccept/(1.0*numDeleteTotal) << endl;
254 aveNumParticles = 0.0;
~ClassicalMonteCarlo()
Destructor.
ClassicalMonteCarlo(PotentialBase *, PotentialBase *, MTRand &, const Container *, Array< dVec, 1 > &)
Constructor.
void run(uint32, bool)
Perform the Monte Carlo equilibration.
double T() const
Get temperature.
The base class which holds details on the generalized box that our system will be simulated inside of...
virtual dVec randPosition(MTRand &) const =0
Random position inside a box.
double volume
The volume of the container in A^3.
virtual dVec randUpdate(MTRand &, const dVec &) const =0
Random updated position inside a box.
virtual void putInside(dVec &) const =0
Place a vector inside the simulation cell.
The base class from which all specific potentials are derived from.
virtual double V(const dVec &)
The potential.
ClassicalMonteCarlo class definition.
Global common header with shared dependencies and methods.
#define NDIM
Number of spatial dimnsions.
unsigned long uint32
Unsigned integer type, at least 32 bits.
TinyVector< double, NDIM > dVec
A NDIM-vector of type double.
Class definitions for all file input/output.
ConstantParameters class definition.
ConstantParameters * constants()
Global public access to the constants.
All possible potential classes.