Cellular Automata CHEM274B Group Project
Contributor(s): Chongye Feng, Emmanuel Cortes, Trevor Oldham
Loading...
Searching...
No Matches
CAutils.h
Go to the documentation of this file.
1
9#pragma once
10#include <utility> // pair
11#include <fstream>
12
20template <typename T>
21void swap_states(T *vector, T *next_vector, int axis1_dim)
22{
23 for (int i = 0; i < axis1_dim; i++)
24 {
25 std::swap(vector[i], next_vector[i]);
26 next_vector[i] = T();
27 }
28}
29
38template <typename T>
39void swap_states(T **matrix, T **next_matrix, int axis1_dim, int axis2_dim)
40{
41 for (int i = 0; i < axis1_dim; i++)
42 {
43 for (int j = 0; j < axis2_dim; j++)
44 {
45 std::swap(matrix[i][j], next_matrix[i][j]);
46 next_matrix[i][j] = T();
47 }
48 }
49}
50
60template <typename T>
61void swap_states(T ***tensor, T ***next_tensor, int axis1_dim, int axis2_dim, int axis3_dim)
62{
63 for (int i = 0; i < axis1_dim; i++)
64 {
65 for (int j = 0; j < axis2_dim; j++)
66 {
67 for (int k = 0; k < axis3_dim; k++)
68 {
69 std::swap(tensor[i][j][k], next_tensor[i][j][k]);
70 next_tensor[i][j][k] = T();
71 }
72 }
73 }
74}
75
88bool is_diagonal_neighboring_cell_2d(int i, int j);
89
110bool is_diagonal_neighboring_cell_3d(int i, int j, int k);
111
119bool less_than_votes(const std::pair<int, int> &a, const std::pair<int, int> &b);
120
129int get_periodic_index(int i, int di, int axis_dim);
130
139void get_periodic_moore_neighbor_index(int rank, int radius, int neighborhood_array_index, int *neighbor_index);
140
149void get_periodic_von_neumann_neighbor_index(int rank, int radius, int neighborhood_array_index, int *neighbor_index);
150
157void get_density(std::ifstream& data, std::ofstream& result);
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 dia...
Definition: CA_utils.cpp:28
bool less_than_votes(const std::pair< int, int > &a, const std::pair< int, int > &b)
Determines if a has less votes than b.
Definition: CA_utils.cpp:49
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 ...
Definition: CA_utils.cpp:19
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.
Definition: CA_utils.cpp:114
void swap_states(T *vector, T *next_vector, int axis1_dim)
swaps the computed next_vector to the current vector
Definition: CAutils.h:21
int get_periodic_index(int i, int di, int axis_dim)
get the periodic index used for finding periodic boundary neighbors
Definition: CA_utils.cpp:54
void get_density(std::ifstream &data, std::ofstream &result)
Get the density result output to the result file.
Definition: CA_utils.cpp:217
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.
Definition: CA_utils.cpp:59