Cellular Automata CHEM274B Group Project
Contributor(s): Chongye Feng, Emmanuel Cortes, Trevor Oldham
Loading...
Searching...
No Matches
Functions
CA_utils.cpp File Reference

Implementation file for the utility functions utilized by CellularAutomata class defined in CAutils.h. More...

#include "CAdatatypes.h"
#include <utility>
#include <cmath>
#include <string>
#include <map>
#include <sstream>
#include <fstream>

Functions

bool is_diagonal_neighboring_cell_2d (int i, int j)
 determines if a cell is diagonal to the central cell
diagram of slice: 1 = diagonal cell
1 0 1
0 0 0
1 0 1
More...
 
bool is_diagonal_neighboring_cell_3d (int i, int j, int k)
 determines if a cell is diagonal to the central cell
if k == 0 then both i and j have be non-zero
diagram of slice: 1 = diagonal cell
1 0 1
0 0 0
1 0 1
More...
 
bool less_than_votes (const std::pair< int, int > &a, const std::pair< int, int > &b)
 Determines if a has less votes than b. More...
 
int get_periodic_index (int i, int di, int axis_dim)
 get the periodic index used for finding periodic boundary neighbors More...
 
void get_periodic_moore_neighbor_index (int rank, int radius, int neighborhood_array_index, int *neighbor_index)
 Get the periodic Moore neighbor index [x, y, z] from a flattened neighborhood array index. More...
 
void get_periodic_von_neumann_neighbor_index (int rank, int radius, int neighborhood_array_index, int *neighbor_index)
 Get the periodic Von Neumann neighbor index [x, y, z] from a flattened neighborhood array index. More...
 
void get_density (std::ifstream &data, std::ofstream &result)
 Get the density result output to the result file. More...
 

Detailed Description

Implementation file for the utility functions utilized by CellularAutomata class defined in CAutils.h.

Author
Emmanuel Cortes (ecort.nosp@m.es@b.nosp@m.erkel.nosp@m.ey.e.nosp@m.du)

Contributor(s)
   Chongye Feng

Date
2022-12-06

Function Documentation

◆ get_density()

void get_density ( std::ifstream &  data,
std::ofstream &  result 
)

Get the density result output to the result file.

Parameters
data
resultLine1 n_states; Line2 dims; Line3 counts of states of each step.

◆ get_periodic_index()

int get_periodic_index ( int  i,
int  di,
int  axis_dim 
)

get the periodic index used for finding periodic boundary neighbors

Parameters
icell's i-th index
dineighbor's cell i-th offset
axis_dimdimension of i-th axis
Returns
int

◆ get_periodic_moore_neighbor_index()

void get_periodic_moore_neighbor_index ( int  rank,
int  radius,
int  neighborhood_array_index,
int *  neighbor_index 
)

Get the periodic Moore neighbor index [x, y, z] from a flattened neighborhood array index.

Parameters
rankcell data rank
radiusneighborhood radius
neighborhood_array_indexflat array index to be converted to [x, y, z]
neighbor_indexint array containing x, y and z coordinates

◆ get_periodic_von_neumann_neighbor_index()

void get_periodic_von_neumann_neighbor_index ( int  rank,
int  radius,
int  neighborhood_array_index,
int *  neighbor_index 
)

Get the periodic Von Neumann neighbor index [x, y, z] from a flattened neighborhood array index.

Parameters
rankcell data rank
radiusneighborhood radius
neighborhood_array_indexflat array index to be converted to [x, y, z]
neighbor_indexint array containing x, y and z coordinates

◆ is_diagonal_neighboring_cell_2d()

bool is_diagonal_neighboring_cell_2d ( int  i,
int  j 
)

determines if a cell is diagonal to the central cell
diagram of slice: 1 = diagonal cell
1 0 1
0 0 0
1 0 1

Parameters
icell's i-th index
jcell's j-th index
Returns
true: cell is diagonal
false: cell is not diagonal

◆ is_diagonal_neighboring_cell_3d()

bool is_diagonal_neighboring_cell_3d ( int  i,
int  j,
int  k 
)

determines if a cell is diagonal to the central cell
if k == 0 then both i and j have be non-zero
diagram of slice: 1 = diagonal cell
1 0 1
0 0 0
1 0 1

if k != 0 then either i or j can be non-zero
diagram of slice: 1 = diagonal cell
1 1 1
1 0 1
1 1 1

Parameters
icell's i-th index
jcell's j-th index
kcell's k-th index
Returns
true: cell is diagonal
false: cell is not diagonal

◆ less_than_votes()

bool less_than_votes ( const std::pair< int, int > &  a,
const std::pair< int, int > &  b 
)

Determines if a has less votes than b.

Used to determine max element in a MajorityCounter instance.

Parameters
apair instance with the votes stored in the second property
bother pair with the votes stored in the second property