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.hpp
1
10#ifndef SIMULATION_HPP
11#define SIMULATION_HPP
12
13#include "Cell.hpp"
14
15#include <fstream>
16#include <vector>
17#include <SFML/Graphics.hpp>
18
26private:
27
28 int m_length_box; // Length of the box
29 int m_number_of_cases; // Number of cases in the box
30 int m_number_of_steps; // Number of steps in the simulation
31
32 float m_kT; // Temperature
33
34 std::vector<Cell*> m_cells_array;
35 std::vector<std::vector<int>> m_lattice; // Lattice of integer for cell id
36
37 std::vector<std::vector <float>> m_J; // J matrix
38 std::vector<float> m_lambda_surface; // Lambda surface vector for each cell type
39 std::vector<float> m_lambda_length; // Lambda length vector for each cell type
40 std::vector<float> m_lambda_chemotaxis; // Lambda chemotaxis vector for each cell type
41
42 std::vector<std::vector<double>> m_concentration_matrix; // Matrix for the concentration of every elements
43
44public:
45 // Constructor/Destructor
46 Simulation(int length_box, int number_of_steps, std::vector<std::vector <float>> J, std::vector<float> lambda_surface, std::vector<float> lambda_length,
47 std::vector<float> lambda_chemotaxis, float kT);
49
50 // Getters
51 int get_length_box();
55 std::vector<Cell*> get_cells_array();
56 std::vector<std::vector<int>> get_lattice();
57 std::vector<std::vector <float>> get_J();
58 std::vector<float> get_lambda_surface();
59
60 // Setters
61 void set_cells_array(std::vector<Cell*> cells_array);
62 void set_lattice(std::vector<std::vector<int>> lattice);
63
64 // Methods
65
66 // LATTICE MANIPULATION -----------------------------------------------------
67
68 // Initialize lattice
69 void initialize_lattice(bool is_periodic);
70 // Display lattice
71 void display_lattice();
72
73 // CELL MANIPULATION --------------------------------------------------------
74
75 // Create a cell
76 Cell* create_cell(int type, int target_surface, float target_length,sf::Color color);
77 // Add a cell to the lattice
78 void add_cell_to_lattice(Cell* c, int safe_distance);
79 // Remove a cell from the lattice
81 // Update the length of cells
82 void updateCellsLength();
83
84 // SAVING --------------------------------------------------------------------
85
86 // Create header of data file
87 void write_header(std::ofstream &file);
88 // Write tail of data file
89 void write_tail(std::ofstream &file, float total_time);
90 // Save the lattice
91 void save_lattice(std::ofstream &file, int step, float time);
92
93 // SIMULATION ----------------------------------------------------------------
94
95 float calculate_energy_of_two_sites(int x1, int y1, int x2, int y2);
96
97 float calculate_energy_of_site(int x, int y);
98
99 // Hamiltonian
100 float calculate_total_hamiltonian();
101
102 // Check if the connectivity is broken
103 bool is_connectivity_broken(int x_trial, int y_trial, int cell_id);
104
105 // Local hamiltonian, should be enough to calculate the change in energy
106 float calculate_local_hamiltonian(int x_trial, int y_trial, int cell_id_trial, int x, int y, int cell_id);
107
108 // Metropolis algorithm
109 void metropolis_algorithm(int x, int y, int x_trial, int y_trial, float delta_H);
110
111 // Monte Carlo step
112 std::vector<int> monte_carlo_step();
113
114 // Simulation step
115 void simulation_step();
116
117 // Running the simulation -----------------------------------------------------
118
119 // Run the simulation (no rendering)
120 void run_simulation();
121
122 // Run the simulation (no rendering) and save the data
123 void run_and_save_simulation(int nb_save, const char* filename);
124
125 // SMFL RENDERING ------------------------------------------------------------
126
127 void run_simulation_sfml(const char* filename);
128
129 void run_simulation_sfml_diff(const char* filename);
130
131 void updateCellShape(int x, int y, sf::RectangleShape& shape);
132};
133
134
135#endif // SIMULATION_HPP
This is the cell header file for the Cellular Potts Model simulation : cell class.
Definition Cell.hpp:15
This class represents the simulation of the Cellular Potts Model.
Definition Simulation.hpp:25
void remove_cell_from_lattice(Cell *c)
Remove a cell from the lattice.
Definition Simulation.cpp:302
void initialize_lattice(bool is_periodic)
Initialize the lattice.
Definition Simulation.cpp:201
std::vector< Cell * > get_cells_array()
Get the cells array This function returns the array of cells.
Definition Simulation.cpp:137
std::vector< int > monte_carlo_step()
Monte Carlo step of the simulation.
Definition Simulation.cpp:772
float calculate_energy_of_two_sites(int x1, int y1, int x2, int y2)
Calculate the energy of two sites.
Definition Simulation.cpp:491
Cell * create_cell(int type, int target_surface, float target_length, sf::Color color)
Create a cell.
Definition Simulation.cpp:256
void set_lattice(std::vector< std::vector< int > > lattice)
Set the lattice This function sets the lattice of the simulation.
Definition Simulation.cpp:187
void write_tail(std::ofstream &file, float total_time)
Write the tail of the data file to save the simulation.
Definition Simulation.cpp:418
std::vector< std::vector< int > > get_lattice()
Get the lattice This function returns the lattice of the simulation.
Definition Simulation.cpp:147
void updateCellShape(int x, int y, sf::RectangleShape &shape)
Update the shape of the cell.
Definition Simulation.cpp:1247
bool is_connectivity_broken(int x_trial, int y_trial, int cell_id)
Check if the connectivity is broken at a site.
Definition Simulation.cpp:629
void write_header(std::ofstream &file)
Write the header of the data file to save the simulation.
Definition Simulation.cpp:319
void run_simulation_sfml(const char *filename)
Run the simulation with SFML rendering.
Definition Simulation.cpp:1031
int get_number_of_steps()
Get the number of steps This function returns the number of steps of the simulation.
Definition Simulation.cpp:117
void save_lattice(std::ofstream &file, int step, float time)
Save the lattice to the data file.
Definition Simulation.cpp:445
~Simulation()
Destructor of the simulation.
Definition Simulation.cpp:81
float calculate_energy_of_site(int x, int y)
Calculate the energy of a site.
Definition Simulation.cpp:546
std::vector< float > get_lambda_surface()
Get the lambda surface vector This function returns the lambda surface vector of the simulation.
Definition Simulation.cpp:167
void run_simulation_sfml_diff(const char *filename)
Run the simulation with SFML rendering and diffusion.
Definition Simulation.cpp:1131
void run_simulation()
Run the simulation.
Definition Simulation.cpp:904
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.
Definition Simulation.cpp:670
void display_lattice()
Display the lattice.
Definition Simulation.cpp:227
std::vector< std::vector< float > > get_J()
Get the J matrix This function returns the J matrix of the simulation.
Definition Simulation.cpp:157
int get_length_box()
Get the length of the box This function returns the size of the lattice.
Definition Simulation.cpp:97
int get_number_of_cases()
Get the number of cases This function returns the number of cases in the lattice.
Definition Simulation.cpp:107
void set_cells_array(std::vector< Cell * > cells_array)
Set the cells array This function sets the cells array of the simulation.
Definition Simulation.cpp:177
int get_number_of_cells()
Get the number of cells This function returns the number of cells in the simulation.
Definition Simulation.cpp:127
void add_cell_to_lattice(Cell *c, int safe_distance)
Add a cell to the lattice.
Definition Simulation.cpp:277
void run_and_save_simulation(int nb_save, const char *filename)
Run the simulation and save the data.
Definition Simulation.cpp:934