GCMC Simulation
A C++ and Python-based Monte Carlo simulation framework for interacting particles.
|
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 |
Manages the entire simulation process, including initialization, running the simulation, and logging results.
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.
box | The simulation box that defines the boundaries of the system. |
potentialType | The type of interaction potential used for particle interactions. |
simtype | The type of simulation being performed (e.g., Monte Carlo, GCMC). |
temperature | The temperature of the system, affecting the acceptance of moves. |
numParticles | The initial number of particles in the simulation. |
maxDisplacement | The maximum displacement allowed for particles in Monte Carlo steps. |
r2cut | The square of the cutoff distance beyond which interactions are neglected. |
f_prime | A parameter specific to certain potential types, such as the athermal star potential. |
mu | The chemical potential, relevant for grand canonical simulations. |
seed | The seed for the random number generator. A value of zero will result in seeding with the current time. |
useCellList | Boolean indicating whether to use a cell list for efficient neighbor searching. |
cellListUpdateFrequency | The 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.
box | The simulation box that defines the boundaries of the system. |
simtype | The type of simulation being performed (e.g., Monte Carlo, GCMC). |
potentialType | The type of interaction potential used for particle interactions. |
temperature | The temperature of the system, which influences the acceptance of moves. |
numParticles | The initial number of particles in the simulation. |
maxDisplacement | The maximum displacement allowed for particle moves in Monte Carlo steps. |
r2cut | The square of the cutoff distance beyond which interactions are ignored. |
f_prime | An additional parameter related to the specific potential type (e.g., athermal star potential). |
mu | The chemical potential, relevant for grand canonical simulations. |
seed | The seed for the random number generator. If zero, the current time is used as the seed. |
useCellList | A boolean flag indicating whether to use a cell list for efficient neighbor searching. |
cellListUpdateFrequency | The frequency (in simulation steps) at which the cell list is updated. |
void Simulation::buildCellList | ( | ) |
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.
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.
void Simulation::clearCellList | ( | ) |
Clears the current cell list.
double Simulation::computeEnergy | ( | ) |
Calculates and updates the total energy of the system.
Calculates the total energy of the system.
double Simulation::computeLocalEnergy | ( | int | particleIndex | ) | const |
Computes the interaction energy of a particle with particles in its cell and neighboring cells.
particleIndex | The index of the particle. |
double Simulation::computeTotalForce | ( | ) | const |
Computes the interaction forces of all particles.
double Simulation::getEnergy | ( | ) | const |
Gets the current energy of the system.
int Simulation::getNumParticles | ( | ) | const |
Gets the number of particles in the simulation.
double Simulation::getPressure | ( | ) | const |
Gets the pressure in the simulation.
double Simulation::getTemperature | ( | ) | const |
Gets the temperature in the simulation.
void Simulation::initializeParticles | ( | bool | randomPlacement | ) |
Initializes particles in the simulation box.
randomPlacement | If true, particles are placed randomly; otherwise, in a grid. |
bool Simulation::monteCarloAddRemove | ( | ) |
Attempt to exchange a particle with a resorvoir.
bool Simulation::monteCarloMove | ( | ) |
Perform a single Monte Carlo move.
void Simulation::removeParticleFromCellList | ( | int | particleIndex, |
int | cellIndex ) |
remove a particle from cell list.
particleIndex | The index of the particle to be removed |
cellIndex | The index of particle to be removed. |
void Simulation::run | ( | int | numSteps, |
int | equilibrationTime, | ||
int | outputFrequency, | ||
Logging & | logger ) |
Run the simulation.
Runs the simulation for a specified number of steps.
numSteps | The number of steps to run the simulation. |
equilibrationTime | The number of steps for equilibration before logging. |
outputFrequency | How often to log the results. |
logger | The logging object for output. |
simType | The type of simulation to run (e.g., Monte Carlo NVT). |
numSteps | The number of steps to run the simulation. |
equilibrationTime | The number of steps for equilibration before logging. |
outputFrequency | How often to log the results. |
logger | The logging object for output. |
void Simulation::setParticlePosition | ( | size_t | index, |
double | x, | ||
double | y ) |
Sets the position of a specific particle.
index | The index of the particle to modify. |
x | The new x-coordinate of the particle. |
y | The new y-coordinate of the particle. |
double Simulation::tail_correction_energy_2d | ( | ) | const |
Calculate tail correction for internal energy in 2D.
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)
double Simulation::tail_correction_pressure_2d | ( | ) | const |
Calculate tail correction for pressure in 2D.
g(r) = 1 -> P_cut = \frac{\rho^2 pi}{2} \int_{r_{cut}}^{\inf} f(r) r^2 dr
double Simulation::energy |