GCMC Simulation
A C++ and Python-based Monte Carlo simulation framework for interacting particles.
Loading...
Searching...
No Matches
Simulation Class Reference

Manages the entire simulation process, including initialization, running the simulation, and logging results. More...

#include <simulation.h>

Public Member Functions

 Simulation (const SimulationBox &box, PotentialType potentialType, SimulationType simtype, double temperature, int numParticles, double maxDisplacement, double r2cut, float f_prime, double mu, unsigned int seed, bool useCellList, int cellListUpdateFrequency)
 Constructs a Simulation object with the specified parameters.
 
void initializeParticles (bool randomPlacement)
 Initializes particles in the simulation box.
 
void setParticlePosition (size_t index, double x, double y)
 Sets the position of a specific particle.
 
double computeEnergy ()
 Calculates and updates the total energy of the system.
 
void removeParticleFromCellList (int particleIndex, int cellIndex)
 remove a particle from cell list.
 
double getEnergy () const
 Gets the current energy of the system.
 
int getNumParticles () const
 Gets the number of particles in the simulation.
 
double getTemperature () const
 Gets the temperature in the simulation.
 
bool monteCarloMove ()
 Perform a single Monte Carlo move.
 
bool monteCarloAddRemove ()
 Attempt to exchange a particle with a resorvoir.
 
void run (int numSteps, int equilibrationTime, int outputFrequency, Logging &logger)
 Run the simulation.
 
void buildCellList ()
 
void clearCellList ()
 Clears the current cell list.
 
double computeLocalEnergy (int particleIndex) const
 Computes the interaction energy of a particle with particles in its cell and neighboring cells.
 
double computeTotalForce () const
 Computes the interaction forces of all particles.
 
double calculatePressure () const
 Calculates the pressure of the system using the virial theorem.
 
double getPressure () const
 Gets the pressure in the simulation.
 
double tail_correction_energy_2d () const
 Calculate tail correction for internal energy in 2D.
 
double tail_correction_pressure_2d () const
 Calculate tail correction for pressure in 2D.
 

Public Attributes

double energy
 

Detailed Description

Manages the entire simulation process, including initialization, running the simulation, and logging results.

Constructor & Destructor Documentation

◆ Simulation()

Simulation::Simulation ( const SimulationBox & box,
PotentialType potentialType,
SimulationType simtype,
double temperature,
int numParticles,
double maxDisplacement,
double r2cut,
float f_prime,
double mu,
unsigned int seed,
bool useCellList,
int cellListUpdateFrequency )

Constructs a Simulation object with the specified parameters.

Initializes a Simulation object with the given parameters.

This constructor initializes the simulation environment, setting up the simulation box, interaction potential, temperature, particle count, and other key parameters. It also handles the seeding of the random number generator and prepares the system for simulation.

Parameters
boxThe simulation box that defines the boundaries of the system.
potentialTypeThe type of interaction potential used for particle interactions.
simtypeThe type of simulation being performed (e.g., Monte Carlo, GCMC).
temperatureThe temperature of the system, affecting the acceptance of moves.
numParticlesThe initial number of particles in the simulation.
maxDisplacementThe maximum displacement allowed for particles in Monte Carlo steps.
r2cutThe square of the cutoff distance beyond which interactions are neglected.
f_primeA parameter specific to certain potential types, such as the athermal star potential.
muThe chemical potential, relevant for grand canonical simulations.
seedThe seed for the random number generator. A value of zero will result in seeding with the current time.
useCellListBoolean indicating whether to use a cell list for efficient neighbor searching.
cellListUpdateFrequencyThe frequency (in simulation steps) at which the cell list should be updated.

This constructor sets up the simulation environment, including the simulation box, interaction potential, temperature, and other relevant parameters. It also seeds the random number generator and computes the initial energy of the system.

Parameters
boxThe simulation box that defines the boundaries of the system.
simtypeThe type of simulation being performed (e.g., Monte Carlo, GCMC).
potentialTypeThe type of interaction potential used for particle interactions.
temperatureThe temperature of the system, which influences the acceptance of moves.
numParticlesThe initial number of particles in the simulation.
maxDisplacementThe maximum displacement allowed for particle moves in Monte Carlo steps.
r2cutThe square of the cutoff distance beyond which interactions are ignored.
f_primeAn additional parameter related to the specific potential type (e.g., athermal star potential).
muThe chemical potential, relevant for grand canonical simulations.
seedThe seed for the random number generator. If zero, the current time is used as the seed.
useCellListA boolean flag indicating whether to use a cell list for efficient neighbor searching.
cellListUpdateFrequencyThe frequency (in simulation steps) at which the cell list is updated.

Member Function Documentation

◆ buildCellList()

void Simulation::buildCellList ( )

◆ calculatePressure()

double Simulation::calculatePressure ( ) const

Calculates the pressure of the system using the virial theorem.

The pressure is computed based on the kinetic energy and the virial of the system.

Returns
The calculated pressure.

The pressure is calculated as P = (N * k_B * T + virial) / V, where N is the number of particles, k_B is the Boltzmann constant, T is the temperature, the virial is the sum of r_ij * f_ij over all pairs, and V is the volume of the simulation box.

Returns
The calculated pressure.

◆ clearCellList()

void Simulation::clearCellList ( )

Clears the current cell list.

◆ computeEnergy()

double Simulation::computeEnergy ( )

Calculates and updates the total energy of the system.

Calculates the total energy of the system.

Returns
The total energy of the system.

◆ computeLocalEnergy()

double Simulation::computeLocalEnergy ( int particleIndex) const

Computes the interaction energy of a particle with particles in its cell and neighboring cells.

Parameters
particleIndexThe index of the particle.
Returns
The computed interaction energy.

◆ computeTotalForce()

double Simulation::computeTotalForce ( ) const

Computes the interaction forces of all particles.

Returns
The computed interaction froces.

◆ getEnergy()

double Simulation::getEnergy ( ) const

Gets the current energy of the system.

Returns
The total energy of the system.

◆ getNumParticles()

int Simulation::getNumParticles ( ) const

Gets the number of particles in the simulation.

Returns
The number of particles.

◆ getPressure()

double Simulation::getPressure ( ) const

Gets the pressure in the simulation.

Returns
Pressure.

◆ getTemperature()

double Simulation::getTemperature ( ) const

Gets the temperature in the simulation.

Returns
Temperature.

◆ initializeParticles()

void Simulation::initializeParticles ( bool randomPlacement)

Initializes particles in the simulation box.

Parameters
randomPlacementIf true, particles are placed randomly; otherwise, in a grid.

◆ monteCarloAddRemove()

bool Simulation::monteCarloAddRemove ( )

Attempt to exchange a particle with a resorvoir.

Returns
True if the move is accepted, false otherwise.

◆ monteCarloMove()

bool Simulation::monteCarloMove ( )

Perform a single Monte Carlo move.

Returns
True if the move is accepted, false otherwise.

◆ removeParticleFromCellList()

void Simulation::removeParticleFromCellList ( int particleIndex,
int cellIndex )

remove a particle from cell list.

Parameters
particleIndexThe index of the particle to be removed
cellIndexThe index of particle to be removed.

◆ run()

void Simulation::run ( int numSteps,
int equilibrationTime,
int outputFrequency,
Logging & logger )

Run the simulation.

Runs the simulation for a specified number of steps.

Parameters
numStepsThe number of steps to run the simulation.
equilibrationTimeThe number of steps for equilibration before logging.
outputFrequencyHow often to log the results.
loggerThe logging object for output.
simTypeThe type of simulation to run (e.g., Monte Carlo NVT).
numStepsThe number of steps to run the simulation.
equilibrationTimeThe number of steps for equilibration before logging.
outputFrequencyHow often to log the results.
loggerThe logging object for output.

◆ setParticlePosition()

void Simulation::setParticlePosition ( size_t index,
double x,
double y )

Sets the position of a specific particle.

Parameters
indexThe index of the particle to modify.
xThe new x-coordinate of the particle.
yThe new y-coordinate of the particle.

◆ tail_correction_energy_2d()

double Simulation::tail_correction_energy_2d ( ) const

Calculate tail correction for internal energy in 2D.

Returns
Energy Correction.

in two dimension considering we have same densities, we are going to have,
the enrgy correction as follows: u_{tail} = \frac{1}{2} 2 \pi int_{r_c}^{\inf} dr r \rho u(r) = \pi * rho * int_{r_c}^{inf} dr r u(r)

Returns
Energy Correction.

◆ tail_correction_pressure_2d()

double Simulation::tail_correction_pressure_2d ( ) const

Calculate tail correction for pressure in 2D.

Returns
Pressure Correction.

g(r) = 1 -> P_cut = \frac{\rho^2 pi}{2} \int_{r_{cut}}^{\inf} f(r) r^2 dr

Returns
Pressure Correction.

Member Data Documentation

◆ energy

double Simulation::energy

The documentation for this class was generated from the following files: