GCMC Simulation
A C++ and Python-based Monte Carlo simulation framework for interacting particles.
Loading...
Searching...
No Matches
simulation.h
Go to the documentation of this file.
1#ifndef SIMULATION_H
2#define SIMULATION_H
3
4#include <vector>
5#include "initial.h"
6#include "potential.h"
7#include "logging.h"
11
12 CellListNode(int idx) : particleIndex(idx), next(nullptr) {}
13};
14
15
16
17enum class SimulationType {
19 GCMC,
20 // Other simulation types can be added here
21 };
22
29SimulationType selectSimulationType(const std::string &simulationName);
30
36private:
37 SimulationBox box;
38 std::vector<Particle> particles;
39 SimulationType simtype;
40 PotentialType potentialType;
41 double temperature;
42 int numParticles;
43 double maxDisplacement;
44 double r2cut;
45 double rcut;
46 unsigned int seed;
47 bool useCellList;
48 int cellListUpdateFrequency;
49 std::vector<CellListNode*> cellList;
50 float f_prime;
51 double mu;
52 int numCellsX;
53 int numCellsY;
54 int maxNumParticle;
55
56public:
57 double energy;
58
59
60
79Simulation(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);
80
86 void initializeParticles(bool randomPlacement);
87
94 void setParticlePosition(size_t index, double x, double y);
95
99 double computeEnergy();
100
106 void removeParticleFromCellList(int particleIndex, int cellIndex);
107
112 double getEnergy() const;
113
118 int getNumParticles() const;
119
124 double getTemperature() const;
125
130 bool monteCarloMove();
131
136 bool monteCarloAddRemove();
137
146 void run(int numSteps, int equilibrationTime, int outputFrequency, Logging &logger);
147
148 void buildCellList();
149
153 void clearCellList();
154
160 double computeLocalEnergy(int particleIndex) const;
161
166 double computeTotalForce() const;
167
175 double calculatePressure() const;
176
181 double getPressure() const;
186 double tail_correction_energy_2d() const;
191 double tail_correction_pressure_2d() const;
192};
193
194#endif // SIMULATION_H
Manages logging of simulation data to files.
Definition logging.h:13
Manages the 2D simulation box, including periodic boundary conditions.
Definition initial.h:31
Manages the entire simulation process, including initialization, running the simulation,...
Definition simulation.h:35
int getNumParticles() const
Gets the number of particles in the simulation.
Definition simulation.cpp:309
void run(int numSteps, int equilibrationTime, int outputFrequency, Logging &logger)
Run the simulation.
Definition simulation.cpp:271
double calculatePressure() const
Calculates the pressure of the system using the virial theorem.
Definition simulation.cpp:411
double computeEnergy()
Calculates and updates the total energy of the system.
Definition simulation.cpp:243
double getPressure() const
Gets the pressure in the simulation.
Definition simulation.cpp:425
void clearCellList()
Clears the current cell list.
Definition simulation.cpp:319
double getEnergy() const
Gets the current energy of the system.
Definition simulation.cpp:305
void initializeParticles(bool randomPlacement)
Initializes particles in the simulation box.
Definition simulation.cpp:46
bool monteCarloMove()
Perform a single Monte Carlo move.
Definition simulation.cpp:77
double getTemperature() const
Gets the temperature in the simulation.
Definition simulation.cpp:314
bool monteCarloAddRemove()
Attempt to exchange a particle with a resorvoir.
Definition simulation.cpp:134
double tail_correction_energy_2d() const
Calculate tail correction for internal energy in 2D.
Definition simulation.cpp:439
double computeTotalForce() const
Computes the interaction forces of all particles.
Definition simulation.cpp:388
double energy
Definition simulation.h:57
void setParticlePosition(size_t index, double x, double y)
Sets the position of a specific particle.
Definition simulation.cpp:60
void buildCellList()
Definition simulation.cpp:333
void removeParticleFromCellList(int particleIndex, int cellIndex)
remove a particle from cell list.
Definition simulation.cpp:499
double tail_correction_pressure_2d() const
Calculate tail correction for pressure in 2D.
Definition simulation.cpp:473
double computeLocalEnergy(int particleIndex) const
Computes the interaction energy of a particle with particles in its cell and neighboring cells.
Definition simulation.cpp:350
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.
Definition simulation.cpp:23
PotentialType
Enumeration of available potential types.
Definition potential.h:11
SimulationType selectSimulationType(const std::string &simulationName)
Selects the simulation type based on a string input.
Definition simulation.cpp:381
SimulationType
Definition simulation.h:17
Definition simulation.h:8
CellListNode * next
Pointer to the next node in the linked list.
Definition simulation.h:10
int particleIndex
Index of the particle in the particles vector.
Definition simulation.h:9
CellListNode(int idx)
Definition simulation.h:12