23#include <unordered_set>
29#ifndef DEBUG_SPATIAL_CELL
30 #define DEBUG_SPATIAL_CELL
44 for (
unsigned int i=0;
i<
WID3; ++
i) {
70 for (uint popID=0; popID<
populations.size(); ++popID) {
108 for (
unsigned int i=0;
i<
WID3; ++
i) {
145 for (
unsigned int i=0;
i<
WID3; ++
i) {
180 const uint popID,
bool doDeleteEmptyBlocks) {
188 std::unordered_set<vmesh::GlobalID> neighbors_have_content;
194 for (
vmesh::LocalID block_index=0; block_index<local_content_list_size; ++block_index) {
198 neighbors_have_content.insert(block);
201 for (
int offset_vx=-addWidthV;offset_vx<=addWidthV;offset_vx++) {
202 for (
int offset_vy=-addWidthV;offset_vy<=addWidthV;offset_vy++) {
203 for (
int offset_vz=-addWidthV;offset_vz<=addWidthV;offset_vz++) {
205 =
get_velocity_block(popID,{{indices[0]+offset_vx,indices[1]+offset_vy,indices[2]+offset_vz}});
206 neighbors_have_content.insert(neighbor_block);
215 for (std::vector<SpatialCell*>::const_iterator neighbor = spatial_neighbors.begin();
216 neighbor != spatial_neighbors.end(); ++neighbor) {
217 size_t n_neigh_blocks = (*neighbor)->velocity_block_with_content_list->size();
218 for (
vmesh::LocalID block_index=0; block_index < n_neigh_blocks; ++block_index) {
219 vmesh::GlobalID block = (*neighbor)->velocity_block_with_content_list->at(block_index);
220 neighbors_have_content.insert(block);
227 if (doDeleteEmptyBlocks) {
230 #ifdef DEBUG_SPATIAL_CELL
232 cerr <<
"Got invalid block at " << __FILE__ <<
' ' << __LINE__ << endl;
237 #ifdef DEBUG_SPATIAL_CELL
239 cerr <<
"Could not find block in " << __FILE__ <<
' ' << __LINE__ << endl;
244 bool removeBlock =
false;
245 std::unordered_set<vmesh::GlobalID>::iterator it = neighbors_have_content.find(blockGID);
246 if (it == neighbors_have_content.end()) {
250 if (removeBlock ==
true) {
258 for (
unsigned int i=0;
i<
WID3; ++
i) {
270 for (std::unordered_set<vmesh::GlobalID>::iterator it=neighbors_have_content.begin(); it != neighbors_have_content.end(); ++it) {
279 std::vector<SpatialCell*> neighbor_ptrs;
292 #ifdef DEBUG_SPATIAL_CELL
295 std::cerr <<
"ERROR, popID " << popID <<
" found invalid GID " << blockGID <<
" for LID "<< blockLID;
296 std::cerr << __FILE__ <<
":" << __LINE__ << std::endl;
305 bool has_content =
false;
307 const Realf* block_data =
populations[popID].blockContainer->getData(blockLID);
308 for (
unsigned int i=0;
i<
WID3; ++
i) {
309 if (block_data[
i] >= velocity_block_min_value) {
343 const int sender_rank,
344 const int receiver_rank,
345 const bool receiving,
346 const int neighborhood
349 std::vector<MPI_Aint> displacements;
350 std::vector<int> block_lengths;
382 displacements.push_back(0);
383 block_lengths.push_back(0);
405 displacements.push_back(0);
406 block_lengths.push_back(0);
436 displacements.push_back((uint8_t*) &(this->
parameters[0]) - (uint8_t*)
this);
443 block_lengths.push_back(
sizeof(
Real) * 6);
449 block_lengths.push_back(
sizeof(
Real) * 6);
455 block_lengths.push_back(
sizeof(
Real) * 4);
461 block_lengths.push_back(
sizeof(
Real) * 4);
467 block_lengths.push_back(
sizeof(
Real));
473 block_lengths.push_back(
sizeof(
Real));
478 displacements.push_back((uint8_t*) &(this->
derivativesBVOL[0]) - (uint8_t*)
this);
483 displacements.push_back((uint8_t*) &(this->
ioLocalCellId) - (uint8_t*)
this);
484 block_lengths.push_back(
sizeof(uint64_t));
490 block_lengths.push_back(
sizeof(
Real) * 3);
497 block_lengths.push_back(
sizeof(
Real) * 3);
502 block_lengths.push_back(
sizeof(
Real) * 3);
507 displacements.push_back((uint8_t*) &(this->
sysBoundaryFlag) - (uint8_t*)
this);
508 block_lengths.push_back(
sizeof(uint));
509 displacements.push_back((uint8_t*) &(this->
sysBoundaryLayer) - (uint8_t*)
this);
510 block_lengths.push_back(
sizeof(uint));
519 for (uint popID=0; popID<
populations.size(); ++popID) {
520 displacements.push_back((uint8_t*) &(
populations[popID].RHO) - (uint8_t*)
this);
533 void* address =
this;
535 MPI_Datatype datatype;
537 if (displacements.size() > 0) {
539 MPI_Type_create_hindexed(
540 displacements.size(),
551 const bool printMpiDatatype =
false;
552 if (printMpiDatatype) {
555 MPI_Type_size(datatype,&mpiSize);
556 MPI_Comm_rank(MPI_COMM_WORLD,&
myRank);
557 cout <<
myRank <<
" get_mpi_datatype: " << cellID <<
" " << sender_rank <<
" " << receiver_rank <<
" " << mpiSize <<
", Nblocks = " <<
populations[
activePopID].N_blocks <<
", nbr Nblocks =";
560 if ( receiving || ranks.find(receiver_rank) != ranks.end()) {
566 cout <<
" face_neighbor_ranks =";
573 return std::make_tuple(address,
count,datatype);
620 #ifdef DEBUG_SPATIAL_CELL
623 std::cerr << __FILE__ <<
":" << __LINE__ << std::endl;
660 *
populations[p].blockContainer->getBlockAllocationFactor();
663 if (
populations[p].blockContainer->capacity() > amount ) {
664 if (
populations[p].blockContainer->setNewCapacityShrink(amount) ==
false) {
691 cerr <<
"SC::printMeshSizes:" << endl;
693 cerr <<
"\t pop " << p <<
" " <<
populations[p].vmesh->size() <<
' ' <<
populations[p].blockContainer->size() << endl;
713 const Real newMinValue =
k*x+b;
719 populations[popID].velocityBlockMinValue = newMinValue;
set(gca, 'YDir', 'normal')
vmesh::LocalID get_number_of_velocity_blocks(const uint popID) const
void debug_population_check(const uint popID) const
void updateSparseMinValue(const uint popID)
Real * get_block_parameters(const uint popID)
vmesh::GlobalID get_velocity_block_global_id(const vmesh::LocalID &blockLID, const uint popID) const
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
void set_max_r_dt(const uint popID, const Real &value)
void adjustSingleCellVelocityBlocks(const uint popID, bool doDeleteEmpty=false)
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
bool compute_block_has_content(const vmesh::GlobalID &block, const uint popID) const
void prepare_to_receive_blocks(const uint popID)
std::vector< vmesh::GlobalID > * velocity_block_with_content_list
velocity_block_indices_t get_velocity_block_indices(const uint popID, const vmesh::GlobalID globalID)
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 set_max_v_dt(const uint popID, const Real &value)
const Real & get_max_r_dt(const uint popID) const
std::array< vmesh::LocalID, MAX_NEIGHBORS_PER_DIM > neighbor_number_of_blocks
std::array< Real, bvolderivatives::N_BVOL_DERIVATIVES > derivativesBVOL
void adjust_velocity_blocks(const std::vector< SpatialCell * > &spatial_neighbors, const uint popID, bool doDeleteEmptyBlocks=true)
Realf * get_data(const uint popID)
const Real & get_max_v_dt(const uint popID) const
vmesh::LocalID velocity_block_with_content_list_size
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
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)
#define MAX_NEIGHBORS_PER_DIM
ObjectWrapper & getObjectWrapper()
@ N_VELOCITY_BLOCK_PARAMS
static const uint64_t CELL_GRADPE_TERM
static const uint64_t VEL_BLOCK_PARAMETERS
static const uint64_t CELL_P
static const uint64_t REFINEMENT_PARAMETERS
static const uint64_t CELL_SYSBOUNDARYFLAG
static const uint64_t CELL_BVOL
static const uint64_t CELL_RHOM_V
static const uint64_t CELL_RHOMDT2_VDT2
static const uint64_t POP_METADATA
static const uint64_t VEL_BLOCK_LIST_STAGE2
static const uint64_t CELL_BVOL_DERIVATIVES
static const uint64_t VEL_BLOCK_LIST_STAGE1
static const uint64_t CELL_PDT2
static const uint64_t CELL_IOLOCALCELLID
static const uint64_t VEL_BLOCK_WITH_CONTENT_STAGE1
static const uint64_t VEL_BLOCK_DATA
static const uint64_t CELL_RHOQ
static const uint64_t NEIGHBOR_VEL_BLOCK_DATA
static const uint64_t VEL_BLOCK_WITH_CONTENT_STAGE2
static const uint64_t CELL_PARAMETERS
static const uint64_t CELL_RHOQDT2
static const uint64_t CELL_DIMENSIONS
std::array< vmesh::LocalID, 3 > velocity_block_indices_t
std::vector< species::Species > particleSpecies
static int amrMaxSpatialRefLevel
Real sparseDynamicMinValue2
Real sparseDynamicMinValue1
Real sparseDynamicBulkValue2
Real sparseDynamicBulkValue1
int sparseDynamicAlgorithm