Cellular Automata CHEM274B Group Project
Contributor(s): Chongye Feng, Emmanuel Cortes, Trevor Oldham
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Galaxy Class Reference

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

Public Attributes

int min_mass
 minimum cell mass (int required for rand)
 
int max_mass
 maximum cell mass (int required for rand)
 
double density
 density of galaxy
 
int boundary_radius
 cutoff radius above which forces are not considered
 
int axis1_dim
 cellular automata axis1 dimension
 
int axis2_dim
 cellular automata axis2 dimension
 
int axis3_dim
 cellular automata axis3 dimension
 

Static Public Attributes

static double time_step
 time_step for computing forces during each simulation step
 
static CellularAutomata< GalaxyCellCA
 the CA the simulation utilizes to model the formation of a galaxy
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Galaxy() [1/2]

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() [2/2]

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.

Parameters
time_stepsimulation time step for computing forces and physical quantities
min_massminimum cell mass
max_massmaximum cell mass
densitydensity of occupied cell states
boundary_radiuscutoff radius above which forces are not considered
axis1_dimcellular automata axis1 dimension
axis2_dimcellular automata axis2 dimension
axis3_dimcellular automata axis3 dimension

◆ ~Galaxy()

Galaxy::~Galaxy ( )
default

Destroy the Galaxy object.

Member Function Documentation

◆ compute_accel()

static std::vector< double > Galaxy::compute_accel ( const std::vector< double > &  total_force,
double  mass 
)
static

Computes the acceleration vector A = F/M.

Parameters
total_forceSum of all forces in component form
masscell of interet's mass
Returns
std::vector<double>

◆ compute_displacement()

static std::vector< double > Galaxy::compute_displacement ( const std::vector< double > &  velocity,
const GalaxyCell cell_of_interest,
double  time_step 
)
static

Computes the displacement vector.

D = 1/2 * (velocity_i + velocity_f) * time_step

Parameters
velocitycurrent step velocity
cell_of_interestcontains initial velocity
time_stepsimulation time step
Returns
std::vector<double>

◆ compute_gravitational_force()

static std::vector< double > Galaxy::compute_gravitational_force ( const GalaxyCell cell_of_interest,
const GalaxyCell neighbor_cell,
const std::vector< int > &  neighbor_index 
)
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 |

Parameters
cell_of_interest
neighbor_cell
neighbor_index
Returns
std::vector<double>

◆ compute_vector_difference()

static std::vector< double > Galaxy::compute_vector_difference ( const std::vector< double > &  vec1,
const std::vector< double > &  vec2 
)
static

Computes the difference in vector for determining the direction and magnitude of the force vector.

Parameters
vec1Initial vector
vec2Final vector
Returns
std::vector<double>

◆ compute_vector_norm()

static double Galaxy::compute_vector_norm ( const std::vector< int > &  vector)
static

Computes the norm of a vector.

Used by compute_gravitational_force.

Parameters
vector
Returns
double

◆ compute_velocity()

static std::vector< double > Galaxy::compute_velocity ( const std::vector< double > &  accel,
const GalaxyCell cell_of_interest,
double  time_step 
)
static

Computes the velocity vector.

V = velocity_i + acceleration_i * time_step

Parameters
accelcurrent step acceleration
cell_of_interestcontains initial velocity
time_stepsimulation time step
Returns
std::vector<double>

◆ did_galaxies_collide()

static bool Galaxy::did_galaxies_collide ( int *  cell_index,
const std::vector< int > &  offset_index,
GalaxyCell new_cell_state 
)
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.

Parameters
cell_indexnew_cell_state position
offset_indexkeep track of path the cell takes
new_cell_statecell of interests
Returns
true : collision occurred
false : collision didn't occur

◆ galaxy_formation_rule()

static void Galaxy::galaxy_formation_rule ( int *  cell_index,
const int  index_size,
GalaxyCell neighborhood_cells,
const int  neighborhood_size,
GalaxyCell new_cell_state 
)
static

Custom CA rule for simulating the motion of star systems.

Parameters
cell_indexnew_cell_state position
index_sizesize of cell_index
neighborhood_cellsarray of neighboring cells for computing gravitational force
neighborhood_sizesize of neighborhood_cells array
new_cell_statereference to cell state that will be inserted into next state

◆ get_cell_state()

static GalaxyCell & Galaxy::get_cell_state ( int *  cell_index,
const std::vector< int > &  offset_index 
)
static

Get the cell state object at position cell_index + offset_index from the CellularAutomata instance.

Parameters
cell_indexcurrent new_cell_state position
offset_indexused to compute the neighboring cell position
Returns
const GalaxyCell&

◆ get_periodic_vector()

static std::vector< int > Galaxy::get_periodic_vector ( int *  cell_index,
const std::vector< int > &  offset_index 
)
static

Get the periodic vector.

Parameters
cell_indexcurrent new_cell_state position
offset_indexused to compute the neighboring cell position
Returns
std::vector<int>

◆ init_galaxy()

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.

Returns
int - error code
Error codes returned by CellularAutomata instance
0: no error

◆ round_int()

static int Galaxy::round_int ( double  dbl)
static

Rounds a double to an int.

Parameters
dbl
Returns
int

◆ set_new_position()

static void Galaxy::set_new_position ( int *  cell_index,
GalaxyCell new_cell_state,
const std::vector< double > &  displacement_vector 
)
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

Parameters
cell_indexnew_cell_state position
new_cell_statecell that contains mass and velocity
displacement_vectorvector to the new desired position

◆ simulation()

int Galaxy::simulation ( int  steps)

Runs the simulation for the specified amount of steps.

Parameters
steps
Returns
int - error code
Error codes returned by CellularAutomata instance
0: no error

◆ update_velocity_after_collision()

static void Galaxy::update_velocity_after_collision ( GalaxyCell new_cell,
GalaxyCell  collied_cell 
)
static

compute the velocity after an inelastic collision https://www.plasmaphysics.org.uk/collision3d.htm

Parameters
new_cell
collied_cell

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