7#include <unordered_map>
9#include "eigen_matrix_defs.h"
10#include "compact_data_representations.h"
15#include <condition_variable>
23 typedef uint64_t bit64;
24 typedef uint32_t bit32;
25 typedef uint16_t bit16;
28 typedef int64_t int64;
29 typedef int32_t int32;
30 typedef int16_t int16;
33 typedef std::mt19937 rng_type;
44 static const int max_num_neigbours = 5;
47 void Init(
int num_individuals);
52 int SelectedNeigbours(
int my_index,
int neigbour_indices[max_num_neigbours], Fish::vec3& density_gradient);
57 void AsyncUpdate(std::vector<Fish::IndividualFish>& individuals,
const double*
const X);
62 bool AsyncUpdateIsComplete();
69 std::vector<int>& SortedZcurveOrdering();
75 std::vector<int> m_sorted_Z_curve_ordering;
76 std::vector<int> m_inverse_sorted_Z_curve_ordering;
81 Particle(
const Fish::vec3& p,
const Fish::vec3& v,
int n);
83 static bit32 expand(bit32 a);
84 static bit32 make_Z_index(bit8 X, bit8 Y, bit8 Z);
85 static bit32 make_Z_index(
const Eigen::Vector3d & P);
87 Z_index = make_Z_index(P);
90 Eigen::Matrix<bit8, 3, 1> decompress_Z_index();
102 std::vector<Particle> m_particle_temp_buffer;
103 std::vector<Particle> m_particle;
105 std::vector<bit32> m_Z_map;
106 std::vector<bit32> m_Cell;
107 std::vector<int> m_neighbour_fast_map;
109 struct neighbour_set {
110 neighbour_set() {
for(
int i = 0; i < max_num_neigbours; ++i){ix[i]=-1;}num = 0;density_gradient_unit.setZero();}
111 int ix[max_num_neigbours];
113 Eigen::Vector3d density_gradient_unit;
116 std::vector<neighbour_set> m_neighbours_buffer1;
117 std::vector<neighbour_set> m_neighbours_buffer2;
119 neighbour_set* read_buffer;
120 neighbour_set* write_buffer;
122 void UpdateWorkingLoop();
123 enum async_state {IDLE, WORKING, TERMINATING};
124 async_state m_async_state;
126 std::mutex m_async_mutex;
127 std::thread m_async_thread;
128 std::condition_variable m_async_condition_variable;