27#ifndef VLASIATOR_SPATIAL_CELL_CPU_HPP
28#define VLASIATOR_SPATIAL_CELL_CPU_HPP
39#include <unordered_map>
54 #ifndef DEBUG_SPATIAL_CELL
55 #define DEBUG_SPATIAL_CELL
88 float mlp_error = {std::numeric_limits<float>::max()};
103 for (uint
i=0;
i<2; ++
i) {
106 for (uint
i=0;
i<3; ++
i) {
109 for (uint
i=0;
i<6;
i++) {
128 for (uint
i=0;
i<2; ++
i) {
131 for (uint
i=0;
i<3; ++
i) {
136 for (uint
i=0;
i<6;
i++) {
155 for (uint
i=0;
i<2; ++
i) {
158 for (uint
i=0;
i<3; ++
i) {
163 for (uint
i=0;
i<6;
i++) {
174 vmesh->setNewSize(newSize);
175 vmesh->clearMap(newSize);
182 for (uint
i=0;
i<3; ++
i) {
193 toData[
i] = toData[
i] * factor;
208 if (toBlockLID ==
vmesh->invalidLocalID()) {
209 bool success =
vmesh->push_back(incBlockGID);
219 toData[
i] += fromData[
i] * factor;
290 const int& i_cell,
const int& j_cell,
const int& k_cell);
292 std::vector<vmesh::LocalID>& childrenLIDs,
323 bool doDeleteEmptyBlocks=
true);
325 template <
typename fileReal>
void add_velocity_blocks(
const uint popID,
const std::vector<vmesh::GlobalID>& blocks,fileReal* avgBuffer);
329 void clear(
const uint popID,
bool shrink=
false);
338 size_t size(
const uint popID)
const;
348 std::tuple<void*, int, MPI_Datatype>
get_mpi_datatype(
const CellID cellID,
const int sender_rank,
const int receiver_rank,
349 const bool receiving,
const int neighborhood);
361 std::array<Real, CellParams::N_SPATIAL_CELL_PARAMS>
parameters;
398 #ifdef DEBUG_SPATIAL_CELL
400 std::cerr <<
"ERROR, popID " << popID <<
" exceeds populations.size() " <<
populations.size() <<
" in ";
401 std::cerr << __FILE__ <<
":" << __LINE__ << std::endl;
408 #ifdef DEBUG_SPATIAL_CELL
409 if (blockLID >=
populations[popID].blockContainer->size()) {
410 std::cerr <<
"ERROR, block LID out of bounds, blockContainer->size() " <<
populations[popID].blockContainer->size() <<
" in ";
411 std::cerr << __FILE__ <<
":" << __LINE__ << std::endl;
419 return populations[popID].vmesh->findBlock(cellIndices);
424 return populations[popID].blockContainer->getData();
429 return populations[popID].blockContainer->getData();
437 return populations[popID].blockContainer->getData(blockLID);
445 return populations[popID].blockContainer->getData(blockLID);
450 return populations[popID].blockContainer->getParameters();
455 return populations[popID].blockContainer->getParameters();
460 return populations[popID].blockContainer->getParameters(blockLID);
465 return populations[popID].blockContainer->getParameters(blockLID);
532 populations[popID].vmesh->getBlockCoordinates(globalID,coords);
540 populations[popID].vmesh->getIndices(block,indices[0],indices[1],indices[2]);
548 return populations[popID].vmesh->getGlobalID(indices[0],indices[1],indices[2]);
552 return populations[popID].vmesh->getGlobalID(blockIndices[0],blockIndices[1],blockIndices[2]);
560 Real coords[3] = {vx,vy,vz};
561 return populations[popID].vmesh->getGlobalID(coords);
565 return populations[popID].vmesh->getGlobalID(coords);
570 return populations[popID].vmesh->getGlobalID(blockLID);
575 return populations[popID].vmesh->getLocalID(blockGID);
587 populations[popID].vmesh->getBlockCoordinates(block,coords);
596 populations[popID].vmesh->getBlockCoordinates(block,coords);
600 return coords[0]+
size[0];
608 populations[popID].vmesh->getBlockCoordinates(block,coords);
617 populations[popID].vmesh->getBlockCoordinates(block,coords);
621 return coords[1]+
size[1];
629 populations[popID].vmesh->getBlockCoordinates(block,coords);
638 populations[popID].vmesh->getBlockCoordinates(block,coords);
642 return coords[2]+
size[2];
738 uint64_t capacity = 0;
747 capacity +=
populations[p].vmesh->capacityInBytes();
748 capacity +=
populations[p].blockContainer->capacityInBytes();
788 const uint nBlocks = blocks.size();
793 populations[popID].blockContainer->setNewCapacity(nBlocks);
796 const uint8_t adds =
populations[popID].vmesh->push_back(blocks);
798 std::cerr <<
"Failed to add blocks" << std::endl;
806 #ifdef DEBUG_SPATIAL_CELL
808 std::cerr <<
"size mismatch in " << __FILE__ <<
' ' << __LINE__ << std::endl; exit(1);
813 for (
size_t b=0; b<nBlocks; ++b) {
821 Realf *cellBlockData =
populations[popID].blockContainer->getData(startLID);
822 for(uint64_t
i = 0;
i<
WID3 * nBlocks ;
i++){
823 cellBlockData[
i] = avgBuffer[
i];
848 if (lastLID == removedLID) {
854 populations[popID].vmesh->move(lastLID,removedLID);
855 populations[popID].blockContainer->move(lastLID,removedLID);
bool checkMesh(const uint popID)
vmesh::LocalID get_number_of_velocity_blocks(const uint popID) const
void debug_population_check(const uint popID) const
void fetch_data(const vmesh::GlobalID &blockGID, const vmesh::VelocityMesh *vmesh, const Realf *src, Realf *array)
void updateSparseMinValue(const uint popID)
uint64_t get_cell_memory_size()
void set_population(const Population &pop, cuint popID)
const Real * get_velocity_grid_cell_size(const uint popID)
Real get_velocity_block_vx_min(const uint popID, const vmesh::GlobalID block) const
Real * get_block_parameters(const uint popID)
vmesh::VelocityMesh * get_velocity_mesh(const size_t &popID)
void scale_population(creal factor, cuint popID)
vmesh::GlobalID get_velocity_block_global_id(const vmesh::LocalID &blockLID, const uint popID) const
vmesh::VelocityBlockContainer * get_velocity_blocks(const size_t &popID)
void merge_values(const uint popID)
size_t count(const vmesh::GlobalID &block, const uint popID) const
static vmesh::GlobalID invalid_global_id()
std::tuple< void *, int, MPI_Datatype > get_mpi_datatype(const CellID cellID, const int sender_rank, const int receiver_rank, const bool receiving, const int neighborhood)
size_t size(const uint popID) const
std::array< Realf *, MAX_NEIGHBORS_PER_DIM > neighbor_block_data
static void set_mpi_transfer_direction(const int dimension)
void increment_population(const Population &pop, creal factor, cuint popID)
void set_mpi_transfer_enabled(bool transferEnabled)
void set_max_r_dt(const uint popID, const Real &value)
void adjustSingleCellVelocityBlocks(const uint popID, bool doDeleteEmpty=false)
vmesh::GlobalID get_velocity_block_parent(const uint popID, const vmesh::GlobalID &blockGID)
vmesh::LocalID get_velocity_block_local_id(const vmesh::GlobalID &blockGID, const uint popID) const
static bool mpiTransferAtSysBoundaries
static bool setCommunicatedSpecies(const uint popID)
Real getVelocityBlockMinValue(const uint popID) const
Real get_velocity_block_vz_min(const uint popID, const vmesh::GlobalID block) const
Real get_velocity_block_vz_max(const uint popID, const vmesh::GlobalID block) const
void clear(const uint popID, bool shrink=false)
bool compute_block_has_content(const vmesh::GlobalID &block, const uint popID) const
static unsigned int invalid_block_index()
void prepare_to_receive_blocks(const uint popID)
Real get_velocity_block_vy_min(const uint popID, const vmesh::GlobalID block) const
uint64_t get_cell_memory_capacity()
std::vector< vmesh::GlobalID > * velocity_block_with_content_list
std::array< Real, vderivatives::N_V_DERIVATIVES > derivativesV
void add_values(const vmesh::GlobalID &targetGID, std::unordered_map< vmesh::GlobalID, Realf[(WID+2) *(WID+2) *(WID+2)]> &sourceData, const uint popID)
Real get_velocity_block_vy_max(const uint popID, const vmesh::GlobalID block) const
velocity_block_indices_t get_velocity_block_indices(const uint popID, const vmesh::GlobalID globalID)
void add_velocity_blocks(const uint popID, const std::vector< vmesh::GlobalID > &blocks, fileReal *avgBuffer)
std::vector< vmesh::GlobalID > * velocity_block_with_no_content_list
void remove_velocity_block(const vmesh::GlobalID &block, const uint popID)
std::array< Realf, WID3 > null_block_data
void get_velocity_block_size(const uint popID, const vmesh::GlobalID block, Real size[3])
void set_max_v_dt(const uint popID, const Real &value)
void setNewSizeClear(const uint popID, const vmesh::LocalID &newSize)
void fetch_acc_data(const vmesh::GlobalID &blockGID, const int &dim, vmesh::VelocityMesh *vmesh, const Realf *src, Realf *array, Real cellSizeFractions[2])
const Real & get_max_r_dt(const uint popID) const
vmesh::LocalID get_number_of_all_velocity_blocks() const
static void set_mpi_transfer_type(const uint64_t type, bool atSysBoundaries=false)
std::array< vmesh::LocalID, MAX_NEIGHBORS_PER_DIM > neighbor_number_of_blocks
std::vector< Population > & get_populations()
std::array< Real, bvolderivatives::N_BVOL_DERIVATIVES > derivativesBVOL
void adjust_velocity_blocks(const std::vector< SpatialCell * > &spatial_neighbors, const uint popID, bool doDeleteEmptyBlocks=true)
vmesh::GlobalID get_velocity_block_child(const uint popID, const vmesh::GlobalID &blockGID, const int &i_cell, const int &j_cell, const int &k_cell)
const vmesh::LocalID * get_velocity_grid_length(const uint popID)
Real * get_cell_parameters()
Realf * get_data(const uint popID)
const Real & get_max_v_dt(const uint popID) const
Population & get_population(const uint popID)
vmesh::GlobalID find_velocity_block(vmesh::GlobalID cellIndices[3], const uint popID)
vmesh::LocalID velocity_block_with_content_list_size
void get_velocity_block_coordinates(const uint popID, const vmesh::GlobalID &globalID, Real *coords)
Real get_velocity_block_vx_max(const uint popID, const vmesh::GlobalID block) const
void update_velocity_block_content_lists(const uint popID)
std::array< Real, CellParams::N_SPATIAL_CELL_PARAMS > parameters
const SpatialCell & operator=(const SpatialCell &other)
static uint64_t mpi_transfer_type
static uint64_t get_mpi_transfer_type(void)
int get_number_of_populations() const
void get_velocity_block_children_local_ids(const vmesh::GlobalID &blockGID, std::vector< vmesh::LocalID > &childrenLIDs, const uint popID)
std::vector< spatial_cell::Population > populations
vmesh::GlobalID get_velocity_block(const uint popID, vmesh::GlobalID blockIndices[3]) const
static vmesh::LocalID invalid_local_id()
std::map< int, std::set< int > > face_neighbor_ranks
bool add_velocity_block(const vmesh::GlobalID &block, const uint popID)
const Real * get_velocity_grid_block_size(const uint popID)
static vmesh::LocalID invalidBlockIndex()
static vmesh::LocalID invalidLocalID()
static vmesh::GlobalID invalidGlobalID()
dev_velocityBlockContainer[cellIdx] getData()[velocityIdx *WID3+k *WID2+j *WID+i]
@ N_VELOCITY_BLOCK_PARAMS
std::array< vmesh::LocalID, 3 > velocity_block_indices_t
std::array< unsigned int, 3 > velocity_cell_indices_t
Real velocityBlockMinValue
vmesh::VelocityBlockContainer * blockContainer
std::vector< char > compressed_state_buffer
void ResizeClear(const uint newSize)
const Population & operator=(const Population &other)
void Increment(const Population &other, creal factor)
vmesh::VelocityMesh * vmesh
Population(const Population &other)