![]() |
PixCells
This project is a Cellular Potts Model (CPM) simulator. It was developped during a Master's degree in Physics as a master project.
|
This class represents the simulation of the Cellular Potts Model. More...
#include <Simulation.hpp>
Public Member Functions | |
Simulation (int length_box, int number_of_steps, std::vector< std::vector< float > > J, std::vector< float > lambda_surface, std::vector< float > lambda_length, std::vector< float > lambda_chemotaxis, float kT) | |
Construct a new Simulation:: Simulation object. | |
~Simulation () | |
Destructor of the simulation. | |
int | get_length_box () |
Get the length of the box This function returns the size of the lattice. | |
int | get_number_of_cases () |
Get the number of cases This function returns the number of cases in the lattice. | |
int | get_number_of_steps () |
Get the number of steps This function returns the number of steps of the simulation. | |
int | get_number_of_cells () |
Get the number of cells This function returns the number of cells in the simulation. | |
std::vector< Cell * > | get_cells_array () |
Get the cells array This function returns the array of cells. | |
std::vector< std::vector< int > > | get_lattice () |
Get the lattice This function returns the lattice of the simulation. | |
std::vector< std::vector< float > > | get_J () |
Get the J matrix This function returns the J matrix of the simulation. | |
std::vector< float > | get_lambda_surface () |
Get the lambda surface vector This function returns the lambda surface vector of the simulation. | |
void | set_cells_array (std::vector< Cell * > cells_array) |
Set the cells array This function sets the cells array of the simulation. | |
void | set_lattice (std::vector< std::vector< int > > lattice) |
Set the lattice This function sets the lattice of the simulation. | |
void | initialize_lattice (bool is_periodic) |
Initialize the lattice. | |
void | display_lattice () |
Display the lattice. | |
Cell * | create_cell (int type, int target_surface, float target_length, sf::Color color) |
Create a cell. | |
void | add_cell_to_lattice (Cell *c, int safe_distance) |
Add a cell to the lattice. | |
void | remove_cell_from_lattice (Cell *c) |
Remove a cell from the lattice. | |
void | updateCellsLength () |
void | write_header (std::ofstream &file) |
Write the header of the data file to save the simulation. | |
void | write_tail (std::ofstream &file, float total_time) |
Write the tail of the data file to save the simulation. | |
void | save_lattice (std::ofstream &file, int step, float time) |
Save the lattice to the data file. | |
float | calculate_energy_of_two_sites (int x1, int y1, int x2, int y2) |
Calculate the energy of two sites. | |
float | calculate_energy_of_site (int x, int y) |
Calculate the energy of a site. | |
float | calculate_total_hamiltonian () |
bool | is_connectivity_broken (int x_trial, int y_trial, int cell_id) |
Check if the connectivity is broken at a site. | |
float | calculate_local_hamiltonian (int x_trial, int y_trial, int cell_id_trial, int x, int y, int cell_id) |
Calculate the local Hamiltonian of the simulation. | |
void | metropolis_algorithm (int x, int y, int x_trial, int y_trial, float delta_H) |
std::vector< int > | monte_carlo_step () |
Monte Carlo step of the simulation. | |
void | simulation_step () |
void | run_simulation () |
Run the simulation. | |
void | run_and_save_simulation (int nb_save, const char *filename) |
Run the simulation and save the data. | |
void | run_simulation_sfml (const char *filename) |
Run the simulation with SFML rendering. | |
void | run_simulation_sfml_diff (const char *filename) |
Run the simulation with SFML rendering and diffusion. | |
void | updateCellShape (int x, int y, sf::RectangleShape &shape) |
Update the shape of the cell. | |
This class represents the simulation of the Cellular Potts Model.
This class contains all the methods and attributes to run a simulation of the Cellular Potts Model.
Simulation::Simulation | ( | int | length_box, |
int | number_of_steps, | ||
std::vector< std::vector< float > > | J, | ||
std::vector< float > | lambda_surface, | ||
std::vector< float > | lambda_length, | ||
std::vector< float > | lambda_chemotaxis, | ||
float | kT | ||
) |
Construct a new Simulation:: Simulation object.
This constructor initializes the simulation with the parameters given.
length_box | the size of the lattice |
number_of_steps | the number of steps of the simulation |
J | the J matrix |
lambda_surface | the lambda surface vector |
lambda_length | the lambda length vector |
lambda_chemotaxis | the lambda chemotaxis vector |
kT | the temperature |
Simulation::~Simulation | ( | ) |
Destructor of the simulation.
This destructor cleans up the dynamically allocated cells. Not that much to do here as almost everything is in an array.
void Simulation::add_cell_to_lattice | ( | Cell * | c, |
int | safe_distance | ||
) |
Add a cell to the lattice.
c | the cell to add |
safe_distance | the safe distance : distance from the end of the lattice where the cell can be added. |
This function adds a cell to the lattice at a random position. The cell is added to the lattice and its position is updated. Only one case is added, and then the cell will add the other cases in the lattice with the surface energy.
float Simulation::calculate_energy_of_site | ( | int | x, |
int | y | ||
) |
Calculate the energy of a site.
x | x coordinate of the site |
y | y coordinate of the site |
This function calculates the energy of a site with its neighbors. The energy is calculated with the J matrix.
float Simulation::calculate_energy_of_two_sites | ( | int | x1, |
int | y1, | ||
int | x2, | ||
int | y2 | ||
) |
Calculate the energy of two sites.
x1 | x coordinate of the first site |
y1 | y coordinate of the first site |
x2 | x coordinate of the second site |
y2 | y coordinate of the second site |
This function calculates the energy of two sites with the J matrix. The energy is calculated with the kronecker delta.
float Simulation::calculate_local_hamiltonian | ( | int | x_trial, |
int | y_trial, | ||
int | cell_id_trial, | ||
int | x, | ||
int | y, | ||
int | cell_id | ||
) |
Calculate the local Hamiltonian of the simulation.
x_trial | the x coordinate of the trial site |
y_trial | the y coordinate of the trial site |
cell_id_trial | the id of the cell in the trial site |
x | the x coordinate of the site |
y | the y coordinate of the site |
cell_id | the id of the cell in the site |
This function calculates the local Hamiltonian of the simulation. The local Hamiltonian is the energy of the site and the energy of the site of its neighbors. This is not the total hamiltonian and is a simplification to calculate the change in energy.
Cell * Simulation::create_cell | ( | int | type, |
int | target_surface, | ||
float | target_length, | ||
sf::Color | color | ||
) |
Create a cell.
type | the type of the cell |
surface | the surface of the cell |
target_surface | the target surface of the cell |
target_length | the target length of the cell |
color | the color of the cell |
This function creates a cell with the given parameters and adds it to the cells array.
void Simulation::display_lattice | ( | ) |
Display the lattice.
This function displays the lattice in the console.
std::vector< Cell * > Simulation::get_cells_array | ( | ) |
Get the cells array This function returns the array of cells.
std::vector< std::vector< float > > Simulation::get_J | ( | ) |
Get the J matrix This function returns the J matrix of the simulation.
std::vector< float > Simulation::get_lambda_surface | ( | ) |
Get the lambda surface vector This function returns the lambda surface vector of the simulation.
std::vector< std::vector< int > > Simulation::get_lattice | ( | ) |
Get the lattice This function returns the lattice of the simulation.
int Simulation::get_length_box | ( | ) |
Get the length of the box This function returns the size of the lattice.
int Simulation::get_number_of_cases | ( | ) |
Get the number of cases This function returns the number of cases in the lattice.
int Simulation::get_number_of_cells | ( | ) |
Get the number of cells This function returns the number of cells in the simulation.
int Simulation::get_number_of_steps | ( | ) |
Get the number of steps This function returns the number of steps of the simulation.
void Simulation::initialize_lattice | ( | bool | is_periodic = true | ) |
Initialize the lattice.
is_periodic | if the lattice is periodic |
This function initializes the lattice with zeros. If the lattice is not periodic, it adds walls to the lattice (represented by cells with id -1).
bool Simulation::is_connectivity_broken | ( | int | x_trial, |
int | y_trial, | ||
int | cell_id | ||
) |
Check if the connectivity is broken at a site.
x_trial | x coordinate of the site |
y_trial | y coordinate of the site |
cell_id | the id of the cell to check the connectivity |
This function checks if the connectivity is broken at a site. The site is locally disconnected if the connectivity loss exceeds 2. The connectivity loss is calculated with the kronecker delta.
std::vector< int > Simulation::monte_carlo_step | ( | ) |
Monte Carlo step of the simulation.
This function performs a Monte Carlo step of the simulation. It takes a random site and a random move. It calculates the energy difference of the move and decides if the move is accepted with the Metropolis algorithm.
void Simulation::remove_cell_from_lattice | ( | Cell * | c | ) |
Remove a cell from the lattice.
c | the cell to remove |
This function removes a cell from the lattice. The cell is removed from the lattice and its position is cleared.
void Simulation::run_and_save_simulation | ( | int | nb_save, |
const char * | filename | ||
) |
Run the simulation and save the data.
nb_save | the number of saves |
filename | the name of the file to save the data |
This function runs the simulation and saves the data. It performs a Monte Carlo step for each step of the simulation and saves the data every nb_save steps.
void Simulation::run_simulation | ( | ) |
Run the simulation.
This function runs the simulation. It performs a Monte Carlo step for each step of the simulation.
void Simulation::run_simulation_sfml | ( | const char * | filename | ) |
Run the simulation with SFML rendering.
filename | the name of the file to save the data |
This function runs the simulation with SFML rendering. It performs a Monte Carlo step for each step of the simulation and renders the lattice with SFML.
void Simulation::run_simulation_sfml_diff | ( | const char * | filename | ) |
Run the simulation with SFML rendering and diffusion.
filename | the name of the file to save the data |
This function runs the simulation with SFML rendering and diffusion. It performs a Monte Carlo step for each step of the simulation and renders the lattice with SFML. It also updates the concentration matrix with the diffusion equation.
void Simulation::save_lattice | ( | std::ofstream & | file, |
int | step, | ||
float | time | ||
) |
Save the lattice to the data file.
file | the file to save the simulation |
step | the step of the simulation |
time | the time of the simulation |
This function saves the lattice to the data file. It writes the step, the time, the lattice, and the concentration matrix.
void Simulation::set_cells_array | ( | std::vector< Cell * > | cells_array | ) |
Set the cells array This function sets the cells array of the simulation.
cells_array | the cells array |
void Simulation::set_lattice | ( | std::vector< std::vector< int > > | lattice | ) |
Set the lattice This function sets the lattice of the simulation.
lattice | the lattice |
void Simulation::updateCellShape | ( | int | x, |
int | y, | ||
sf::RectangleShape & | shape | ||
) |
Update the shape of the cell.
x | x coordinate of the cell |
y | y coordinate of the cell |
shape | the shape of the cell |
This function updates the shape of the cell. It sets the color of the cell according to the cell type.
void Simulation::write_header | ( | std::ofstream & | file | ) |
Write the header of the data file to save the simulation.
file | the file to save the simulation |
This function writes the header of the data file to save the simulation. It writes the date and time, the simulation parameters, the J matrix, the lambda vectors, the Hamiltonian terms,
void Simulation::write_tail | ( | std::ofstream & | file, |
float | total_time | ||
) |
Write the tail of the data file to save the simulation.
file | the file to save the simulation |
total_time | the total time of the simulation |
This function writes the tail of the data file to save the simulation. It writes the date and time, the total time of the simulation.