PixCells
This project is a Cellular Potts Model (CPM) simulator. It was developped during a Master's degree in Physics as a master project.
Loading...
Searching...
No Matches
Simulation Class Reference

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.
 
Cellcreate_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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Simulation()

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.

Parameters
length_boxthe size of the lattice
number_of_stepsthe number of steps of the simulation
Jthe J matrix
lambda_surfacethe lambda surface vector
lambda_lengththe lambda length vector
lambda_chemotaxisthe lambda chemotaxis vector
kTthe temperature

◆ ~Simulation()

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.

Returns
void

Member Function Documentation

◆ add_cell_to_lattice()

void Simulation::add_cell_to_lattice ( Cell c,
int  safe_distance 
)

Add a cell to the lattice.

Parameters
cthe cell to add
safe_distancethe safe distance : distance from the end of the lattice where the cell can be added.
Returns
void
Note
Here this only works if the cell has a surface energy. If not, only one case is added, and the cell might be deleted with monte carlo steps.

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.

◆ calculate_energy_of_site()

float Simulation::calculate_energy_of_site ( int  x,
int  y 
)

Calculate the energy of a site.

Parameters
xx coordinate of the site
yy coordinate of the site
Returns
the energy of the site

This function calculates the energy of a site with its neighbors. The energy is calculated with the J matrix.

◆ calculate_energy_of_two_sites()

float Simulation::calculate_energy_of_two_sites ( int  x1,
int  y1,
int  x2,
int  y2 
)

Calculate the energy of two sites.

Parameters
x1x coordinate of the first site
y1y coordinate of the first site
x2x coordinate of the second site
y2y coordinate of the second site
Returns
the energy of the two sites
Note
The energy is calculated with the J matrix

This function calculates the energy of two sites with the J matrix. The energy is calculated with the kronecker delta.

◆ calculate_local_hamiltonian()

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.

Parameters
x_trialthe x coordinate of the trial site
y_trialthe y coordinate of the trial site
cell_id_trialthe id of the cell in the trial site
xthe x coordinate of the site
ythe y coordinate of the site
cell_idthe id of the cell in the site
Returns
float the local Hamiltonian of the simulation

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.

◆ create_cell()

Cell * Simulation::create_cell ( int  type,
int  target_surface,
float  target_length,
sf::Color  color 
)

Create a cell.

Parameters
typethe type of the cell
surfacethe surface of the cell
target_surfacethe target surface of the cell
target_lengththe target length of the cell
colorthe color of the cell
Returns
the created cell
Note
The cell is added to the cells array m_cells_array

This function creates a cell with the given parameters and adds it to the cells array.

◆ display_lattice()

void Simulation::display_lattice ( )

Display the lattice.

Returns
void
Note
This function is used for debug

This function displays the lattice in the console.

◆ get_cells_array()

std::vector< Cell * > Simulation::get_cells_array ( )

Get the cells array This function returns the array of cells.

Returns
std::vector<Cell*> the cells array

◆ get_J()

std::vector< std::vector< float > > Simulation::get_J ( )

Get the J matrix This function returns the J matrix of the simulation.

Returns
std::vector<std::vector <float>> the J matrix

◆ get_lambda_surface()

std::vector< float > Simulation::get_lambda_surface ( )

Get the lambda surface vector This function returns the lambda surface vector of the simulation.

Returns
std::vector<float> the lambda surface vector

◆ get_lattice()

std::vector< std::vector< int > > Simulation::get_lattice ( )

Get the lattice This function returns the lattice of the simulation.

Returns
std::vector<std::vector<int>> the lattice

◆ get_length_box()

int Simulation::get_length_box ( )

Get the length of the box This function returns the size of the lattice.

Returns
int the length of the box

◆ get_number_of_cases()

int Simulation::get_number_of_cases ( )

Get the number of cases This function returns the number of cases in the lattice.

Returns
int the number of cases

◆ get_number_of_cells()

int Simulation::get_number_of_cells ( )

Get the number of cells This function returns the number of cells in the simulation.

Returns
int the number of cells

◆ get_number_of_steps()

int Simulation::get_number_of_steps ( )

Get the number of steps This function returns the number of steps of the simulation.

Returns
int the number of steps

◆ initialize_lattice()

void Simulation::initialize_lattice ( bool  is_periodic = true)

Initialize the lattice.

Parameters
is_periodicif the lattice is periodic
Returns
void

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).

◆ is_connectivity_broken()

bool Simulation::is_connectivity_broken ( int  x_trial,
int  y_trial,
int  cell_id 
)

Check if the connectivity is broken at a site.

Parameters
x_trialx coordinate of the site
y_trialy coordinate of the site
cell_idthe 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.

◆ monte_carlo_step()

std::vector< int > Simulation::monte_carlo_step ( )

Monte Carlo step of the simulation.

Returns
the coordinate and id of the changed cell
Note
The Monte Carlo step is a Metropolis algorithm

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.

◆ remove_cell_from_lattice()

void Simulation::remove_cell_from_lattice ( Cell c)

Remove a cell from the lattice.

Parameters
cthe cell to remove
Returns
void

This function removes a cell from the lattice. The cell is removed from the lattice and its position is cleared.

◆ run_and_save_simulation()

void Simulation::run_and_save_simulation ( int  nb_save,
const char *  filename 
)

Run the simulation and save the data.

Parameters
nb_savethe number of saves
filenamethe name of the file to save the data
Returns
void

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.

◆ run_simulation()

void Simulation::run_simulation ( )

Run the simulation.

Returns
void

This function runs the simulation. It performs a Monte Carlo step for each step of the simulation.

◆ run_simulation_sfml()

void Simulation::run_simulation_sfml ( const char *  filename)

Run the simulation with SFML rendering.

Parameters
filenamethe name of the file to save the data
Returns
void

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.

◆ run_simulation_sfml_diff()

void Simulation::run_simulation_sfml_diff ( const char *  filename)

Run the simulation with SFML rendering and diffusion.

Parameters
filenamethe 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.

◆ save_lattice()

void Simulation::save_lattice ( std::ofstream &  file,
int  step,
float  time 
)

Save the lattice to the data file.

Parameters
filethe file to save the simulation
stepthe step of the simulation
timethe time of the simulation
Returns
void

This function saves the lattice to the data file. It writes the step, the time, the lattice, and the concentration matrix.

◆ set_cells_array()

void Simulation::set_cells_array ( std::vector< Cell * >  cells_array)

Set the cells array This function sets the cells array of the simulation.

Parameters
cells_arraythe cells array

◆ set_lattice()

void Simulation::set_lattice ( std::vector< std::vector< int > >  lattice)

Set the lattice This function sets the lattice of the simulation.

Parameters
latticethe lattice

◆ updateCellShape()

void Simulation::updateCellShape ( int  x,
int  y,
sf::RectangleShape &  shape 
)

Update the shape of the cell.

Parameters
xx coordinate of the cell
yy coordinate of the cell
shapethe shape of the cell
Returns
void

This function updates the shape of the cell. It sets the color of the cell according to the cell type.

◆ write_header()

void Simulation::write_header ( std::ofstream &  file)

Write the header of the data file to save the simulation.

Parameters
filethe file to save the simulation
Returns
void

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,

◆ write_tail()

void Simulation::write_tail ( std::ofstream &  file,
float  total_time 
)

Write the tail of the data file to save the simulation.

Parameters
filethe file to save the simulation
total_timethe total time of the simulation
Returns
void

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.


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