Cellular Automata CHEM274B Group Project
Contributor(s): Chongye Feng, Emmanuel Cortes, Trevor Oldham
|
Class for create a galaxy cellular automata model. More...
#include <galaxydatatypes.h>
Public Member Functions | |
Galaxy () | |
Construct a new Galaxy object using the following default parameters: min_mass = 1; max_mass = 100; density = 0.3; boundary_radius = 3; axis1_dim = 1; axis2_dim = 6; axis3_dim = 6; boundary_radius = 1;. More... | |
Galaxy (double time_step, int min_mass, int max_mass, double density, int boundary_radius, int axis1_dim, int axis2_dim, int axis3_dim) | |
Create a Galaxy model instance using the provided values. More... | |
~Galaxy ()=default | |
Destroy the Galaxy object. More... | |
int | init_galaxy () |
Sets up the galaxy CA instance. More... | |
int | simulation (int steps) |
Runs the simulation for the specified amount of steps. More... | |
Static Public Member Functions | |
static void | galaxy_formation_rule (int *cell_index, const int index_size, GalaxyCell *neighborhood_cells, const int neighborhood_size, GalaxyCell &new_cell_state) |
Custom CA rule for simulating the motion of star systems. More... | |
static void | set_new_position (int *cell_index, GalaxyCell &new_cell_state, const std::vector< double > &displacement_vector) |
Set the new_cell_state's new position. More... | |
static bool | did_galaxies_collide (int *cell_index, const std::vector< int > &offset_index, GalaxyCell &new_cell_state) |
Determines if the new_cell_state collides with a cell at the current position: cell_index + offset_index. More... | |
static void | update_velocity_after_collision (GalaxyCell &new_cell, GalaxyCell collied_cell) |
compute the velocity after an inelastic collision https://www.plasmaphysics.org.uk/collision3d.htm More... | |
static GalaxyCell & | get_cell_state (int *cell_index, const std::vector< int > &offset_index) |
Get the cell state object at position cell_index + offset_index from the CellularAutomata instance. More... | |
static std::vector< int > | get_periodic_vector (int *cell_index, const std::vector< int > &offset_index) |
Get the periodic vector. More... | |
static int | round_int (double dbl) |
Rounds a double to an int. More... | |
static std::vector< double > | compute_gravitational_force (const GalaxyCell &cell_of_interest, const GalaxyCell &neighbor_cell, const std::vector< int > &neighbor_index) |
Computes the force between cell of interest and neighbor_index Note: cell of interest is at (0, 0, 0) More... | |
static std::vector< double > | compute_accel (const std::vector< double > &total_force, double mass) |
Computes the acceleration vector A = F/M. More... | |
static std::vector< double > | compute_velocity (const std::vector< double > &accel, const GalaxyCell &cell_of_interest, double time_step) |
Computes the velocity vector. More... | |
static std::vector< double > | compute_displacement (const std::vector< double > &velocity, const GalaxyCell &cell_of_interest, double time_step) |
Computes the displacement vector. More... | |
static double | compute_vector_norm (const std::vector< int > &vector) |
Computes the norm of a vector. More... | |
static std::vector< double > | compute_vector_difference (const std::vector< double > &vec1, const std::vector< double > &vec2) |
Computes the difference in vector for determining the direction and magnitude of the force vector. More... | |
Static Public Attributes | |
static double | time_step |
time_step for computing forces during each simulation step | |
static CellularAutomata< GalaxyCell > | CA |
the CA the simulation utilizes to model the formation of a galaxy | |
Class for create a galaxy cellular automata model.
Only one instance should be created since the CellularAutomata instance is static and will be shared among all instances. CellularAutomata accepts a free function and not a member function thus galaxy_formation_rule needs to be static. In order for galaxy_formation_rule to access the CellularAutomata and other class variable, they need to be static.
Galaxy::Galaxy | ( | ) |
Construct a new Galaxy object using the following default parameters:
min_mass = 1;
max_mass = 100;
density = 0.3;
boundary_radius = 3;
axis1_dim = 1;
axis2_dim = 6;
axis3_dim = 6;
boundary_radius = 1;.
Galaxy::Galaxy | ( | double | time_step, |
int | min_mass, | ||
int | max_mass, | ||
double | density, | ||
int | boundary_radius, | ||
int | axis1_dim, | ||
int | axis2_dim, | ||
int | axis3_dim | ||
) |
Create a Galaxy model instance using the provided values.
If given values are invalid then the default values are used.
time_step | simulation time step for computing forces and physical quantities |
min_mass | minimum cell mass |
max_mass | maximum cell mass |
density | density of occupied cell states |
boundary_radius | cutoff radius above which forces are not considered |
axis1_dim | cellular automata axis1 dimension |
axis2_dim | cellular automata axis2 dimension |
axis3_dim | cellular automata axis3 dimension |
|
default |
Destroy the Galaxy object.
|
static |
Computes the acceleration vector A = F/M.
total_force | Sum of all forces in component form |
mass | cell of interet's mass |
|
static |
Computes the displacement vector.
D = 1/2 * (velocity_i + velocity_f) * time_step
velocity | current step velocity |
cell_of_interest | contains initial velocity |
time_step | simulation time step |
|
static |
Computes the force between cell of interest and neighbor_index Note: cell of interest is at (0, 0, 0)
F = - m_1 * m_2 / | r_12 | * r_hat
r_hat = r_12 / | r_12 |
cell_of_interest | |
neighbor_cell | |
neighbor_index |
|
static |
Computes the difference in vector for determining the direction and magnitude of the force vector.
vec1 | Initial vector |
vec2 | Final vector |
|
static |
Computes the norm of a vector.
Used by compute_gravitational_force.
vector |
|
static |
Computes the velocity vector.
V = velocity_i + acceleration_i * time_step
accel | current step acceleration |
cell_of_interest | contains initial velocity |
time_step | simulation time step |
|
static |
Determines if the new_cell_state collides with a cell at the current position: cell_index + offset_index.
If there is a collision then we set the new_cell_state index to the current position. And also increases the cell state by one to represent the number of collision. The mass and velocity properties are also updated using the laws of physics. Else return false.
cell_index | new_cell_state position |
offset_index | keep track of path the cell takes |
new_cell_state | cell of interests |
|
static |
Custom CA rule for simulating the motion of star systems.
cell_index | new_cell_state position |
index_size | size of cell_index |
neighborhood_cells | array of neighboring cells for computing gravitational force |
neighborhood_size | size of neighborhood_cells array |
new_cell_state | reference to cell state that will be inserted into next state |
|
static |
Get the cell state object at position cell_index + offset_index from the CellularAutomata instance.
cell_index | current new_cell_state position |
offset_index | used to compute the neighboring cell position |
|
static |
Get the periodic vector.
cell_index | current new_cell_state position |
offset_index | used to compute the neighboring cell position |
int Galaxy::init_galaxy | ( | ) |
Sets up the galaxy CA instance.
This can be called multiple times if the user wants to restart the simulation using different parameters.
|
static |
Rounds a double to an int.
dbl |
|
static |
Set the new_cell_state's new position.
This function uses the Bresenham's line algorithm for computing the path from cell_index to cell_index + displacement_vector. This method accounts for the possibility that cells might collied.
Public domain algorithm and open source 3d implementation reference: https://antofthy.gitlab.io/info/graphics/bresenham.procs
cell_index | new_cell_state position |
new_cell_state | cell that contains mass and velocity |
displacement_vector | vector to the new desired position |
int Galaxy::simulation | ( | int | steps | ) |
Runs the simulation for the specified amount of steps.
steps |
|
static |
compute the velocity after an inelastic collision https://www.plasmaphysics.org.uk/collision3d.htm
new_cell | |
collied_cell |