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

This header files contains utility functions used by CellularAutomata class. More...

#include <utility>
#include <fstream>

Go to the source code of this file.

Functions

template<typename T >
void swap_states (T *vector, T *next_vector, int axis1_dim)
 swaps the computed next_vector to the current vector More...
 
template<typename T >
void swap_states (T **matrix, T **next_matrix, int axis1_dim, int axis2_dim)
 swaps the computed next_matrix to the current matrix More...
 
template<typename T >
void swap_states (T ***tensor, T ***next_tensor, int axis1_dim, int axis2_dim, int axis3_dim)
 swaps the computed next_tensor to the current tensor More...
 
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

This header files contains utility functions used by CellularAutomata class.

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

◆ swap_states() [1/3]

template<typename T >
void swap_states ( T ***  tensor,
T ***  next_tensor,
int  axis1_dim,
int  axis2_dim,
int  axis3_dim 
)

swaps the computed next_tensor to the current tensor

Parameters
tensorcellular automata current tensor state
next_tensorcellular automata next tensor state
axis1_dimfirst tensor dimension
axis2_dimsecond tensor dimension
axis3_dimthird tensor dimension

◆ swap_states() [2/3]

template<typename T >
void swap_states ( T **  matrix,
T **  next_matrix,
int  axis1_dim,
int  axis2_dim 
)

swaps the computed next_matrix to the current matrix

Parameters
matrixcellular automata current matrix state
next_matrixcellular automata next matrix state
axis1_dimfirst matrix dimension
axis2_dimsecond matrix dimension

◆ swap_states() [3/3]

template<typename T >
void swap_states ( T *  vector,
T *  next_vector,
int  axis1_dim 
)

swaps the computed next_vector to the current vector

Parameters
vectorcellular automata current vector state
next_vectorcellular automata next vector state
axis1_dimvector dimension