99 RP::add(
"Project_common.seed",
"Seed for the RNG", 42);
105 RP::get(
"Project_common.seed", this->
seed);
131 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
133 cerr <<
"(Project.cpp) WARNING: Base class 'setCellBackgroundField' in " << __FILE__ <<
":" << __LINE__ <<
" called." << endl;
138 void Project::hook(
cuint& stage,
const dccrg::Dccrg<spatial_cell::SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
156 #ifdef DEBUG_VLASIATOR
159 if (vmeshSize != vbcSize) {
160 printf(
"ERROR: population vmesh %ul and blockcontainer %ul sizes do not match!\n",vmeshSize,vbcSize);
179 const uint blocksCount = vblocks_ini[0]*vblocks_ini[1]*vblocks_ini[2];
187 vmesh->setNewSize(blocksCount);
192 for (uint kv=0; kv<vblocks_ini[2]; ++kv) {
193 for (uint jv=0; jv<vblocks_ini[1]; ++jv) {
194 for (uint iv=0; iv<vblocks_ini[0]; ++iv) {
196 blockIndices[0] = iv;
197 blockIndices[1] = jv;
198 blockIndices[2] = kv;
200 GIDbuffer[LID] = GID;
220 logFile <<
"(PROJECT): Loaded particle populations are:" << endl;
224 logFile <<
"Population #" << popID << endl;
225 logFile <<
"\t name : '" << spec.
name <<
"'" << endl;
227 logFile <<
"\t mass : '" << spec.
mass <<
"'" << endl;
279 for (
unsigned int i=0;
i<
WID3; ++
i) {
280 tmp += data[blockLID*
WID3+
i];
288 const Real ratio = correctSum / sum;
298 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
300 cerr <<
"(Project.cpp) WARNING: Base class 'calcCellParameters' in " << __FILE__ <<
":" << __LINE__ <<
" called." << endl;
309 cerr <<
"ERROR: Project::getCorrectNumberDensity called instead of derived class function!" << endl;
318 return std::uniform_real_distribution<>(0,1)(randGen);
327 randGen.seed(this->
seed+seedModifier);
355 phiprof::Timer refineSCTimer {
"Project: refine spatial cells"};
357 MPI_Comm_rank(MPI_COMM_WORLD,&
myRank);
360 std::cout <<
"Maximum refinement level is " << mpiGrid.mapping.get_maximum_refinement_level() << std::endl;
363 std::vector<bool> refineSuccess;
365 for (
int level = 0; level < mpiGrid.mapping.get_maximum_refinement_level(); level++) {
369 const int maxloop = pow(2, level+1);
370 #pragma omp parallel for schedule(guided) collapse(3)
375 std::array<double,3> xyz;
382 if (mpiGrid.refine_completely_at(xyz)) {
385 CellID myCell = mpiGrid.get_existing_cell(xyz);
386 std::cout <<
"Rank " <<
myRank <<
" is refining cell " << myCell << std::endl;
395 int totalRefineCount;
396 MPI_Allreduce(&refineCount, &totalRefineCount, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
397 if(totalRefineCount > 0) {
398 std::vector<CellID> refinedCells = mpiGrid.stop_refining();
400 if(refinedCells.size() > 0) {
401 std::cerr <<
"Refined cells produced by rank " <<
myRank <<
" for level " << level <<
" are: ";
402 for (
auto cellid : refinedCells) {
403 std::cout << cellid <<
" ";
413 std::cout <<
"Finished level of refinement " << level+1 << endl;
431 std::array<double,3> xyz {mpiGrid.get_center(
id)};
433 int refLevel {mpiGrid.get_refinement_level(
id)};
434 Real r2 {pow(xyz[0], 2) + pow(xyz[1], 2) + pow(xyz[2], 2)};
443 alpha1ShouldRefine ||
444 alpha2ShouldRefine ||
445 vorticityShouldRefine ||
446 anisotropyShouldRefine
451 bool outsideAllRefineBoxes =
true;
459 outsideAllRefineBoxes =
false;
464 shouldRefine = shouldRefine && !outsideAllRefineBoxes;
476 std::array<double,3> xyz {mpiGrid.get_center(
id)};
478 int refLevel {mpiGrid.get_refinement_level(
id)};
479 Real r2 {pow(xyz[0], 2) + pow(xyz[1], 2) + pow(xyz[2], 2)};
486 bool shouldUnrefine {
488 alpha1ShouldUnrefine &&
489 alpha2ShouldUnrefine &&
490 vorticityShouldUnrefine &&
491 anisotropyShouldUnrefine
496 bool outsideAllRefineBoxes =
true;
505 outsideAllRefineBoxes =
false;
510 shouldUnrefine = shouldUnrefine || outsideAllRefineBoxes;
513 return shouldUnrefine;
517 phiprof::Timer refinesTimer {
"Set refines"};
519 MPI_Comm_rank(MPI_COMM_WORLD,&
myRank);
521 uint64_t refines {0};
524 std::cout <<
"WARNING All refinement indices disabled" << std::endl;
532 #pragma omp parallel for
533 for (uint cid = 0; cid < cells.size(); ++cid) {
535 int refLevel {mpiGrid.get_refinement_level(
id)};
541 mpiGrid.dont_refine(
id);
542 mpiGrid.dont_unrefine(
id);
550 int refined_neighbors {0};
551 int coarser_neighbors {0};
552 for (
const auto& [neighbor, dir] : mpiGrid.get_face_neighbors_of(
id)) {
556 int neighborRef {mpiGrid.get_refinement_level(neighbor)};
558 if (neighborRef > refLevel && !shouldUnrefineNeighbor) {
560 }
else if (neighborRef < refLevel && !shouldRefineNeighbor) {
562 }
else if (shouldRefineNeighbor) {
564 refined_neighbors += 4;
565 }
else if (shouldUnrefineNeighbor) {
576 }
else if (refLevel > 0 && shouldUnrefine && coarser_neighbors > 0) {
579 mpiGrid.unrefine_completely(
id);
582 mpiGrid.dont_unrefine(
id);
593 MPI_Comm_rank(MPI_COMM_WORLD,&
myRank);
595 cerr <<
"(Project.cpp) Base class 'forceRefinement' in " << __FILE__ <<
":" << __LINE__ <<
" called. Function is not implemented for project." << endl;
603 MPI_Comm_rank(MPI_COMM_WORLD,&
myRank);
606 std::map<CellID, SpatialCell> cellsMap;
609 cellsMap.insert({id, *mpiGrid[id]});
613 for (
auto cellPair : cellsMap) {
614 CellID id = cellPair.first;
616 int refLevel = mpiGrid.get_refinement_level(
id);
617 std::vector<CellID> refinedNeighbors;
620 refinedNeighbors.push_back(neighbor.first);
624 if (refinedNeighbors.size() == 7) {
629 Real fluffiness = (
Real) refinedNeighbors.size() / 27.0;
637 for (
auto cellPair : cellsMap) {
638 *mpiGrid[cellPair.first] = cellPair.second;
643 std::cout <<
"Filtered refined cells!" << std::endl;
652 cerr <<
"No project specified! Please set 'project' parameter!" << endl;
720 if (rvalue == NULL) {
721 cerr <<
"Unknown project name!" << endl;
#define gpuStreamSynchronize
#define gpuMemcpyHostToDevice
void calculateCellMoments(spatial_cell::SpatialCell *cell, const bool &computeSecond, const bool &computePopulationMomentsOnly, const bool &doNotSkip)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
virtual void setupBeforeSetCell(const std::vector< CellID > &cells)
virtual bool forceRefinement(dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, int n) const
Refine/unrefine spatial cells one level to the static criteria in the config.
virtual Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const =0
virtual uint64_t adaptRefinement(dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid) const
Adapts refinement by one level according to the project. Returns true if any cells were refined,...
virtual bool canRefine(spatial_cell::SpatialCell *cell) const
Real getRandomNumber(std::default_random_engine &randGen) const
virtual Real getCorrectNumberDensity(spatial_cell::SpatialCell *cell, const uint popID) const
virtual bool initialize()
virtual void getParameters()
virtual uint findBlocksToInitialize(spatial_cell::SpatialCell *cell, const uint popID) const
Prepares a list of blocks to loop through when initialising.
virtual bool shouldRefineCell(dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, CellID id, Real r_max2) const
static char rngStateBuffer[256]
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid)
virtual bool refineSpatialCells(dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid) const
static void addParameters()
virtual bool rescalesDensity(const uint popID) const
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t)
void rescaleDensity(spatial_cell::SpatialCell *cell, const uint popID) const
virtual bool shouldUnrefineCell(dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, CellID id, Real r_max2) const
void setRandomSeed(uint64_t seedModifier, std::default_random_engine &randGen) const
virtual void hook(cuint &stage, const dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, fsgrids::perbspan perb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) const
void setRandomCellSeed(spatial_cell::SpatialCell *cell, std::default_random_engine &randGen) const
void setVelocitySpace(const uint popID, spatial_cell::SpatialCell *cell) const
Sets the distribution function in a cell.
bool baseClassInitialized
virtual bool filterRefined(dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid) const
Boxcar filters spatial cells that were recently refined.
void setCell(spatial_cell::SpatialCell *cell)
Set the perturbed fields and distribution of a cell according to the default simulation settings....
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
vmesh::LocalID get_number_of_velocity_blocks(const uint popID) const
Real * get_block_parameters(const uint popID)
vmesh::VelocityMesh * get_velocity_mesh(const size_t &popID)
vmesh::VelocityBlockContainer * get_velocity_blocks(const size_t &popID)
void prepare_to_receive_blocks(const uint popID)
void dev_resize_vmesh(const uint popID, const uint nBlocks)
void applyReservation(const uint popID)
const vmesh::LocalID * get_velocity_grid_length(const uint popID)
Realf * get_data(const uint popID)
Population & get_population(const uint popID)
std::array< Real, CellParams::N_SPATIAL_CELL_PARAMS > parameters
void setReservation(const uint popID, const vmesh::LocalID reservationsize, bool force=false)
vmesh::GlobalID get_velocity_block(const uint popID, vmesh::GlobalID blockIndices[3]) const
ARCH_HOSTDEV vmesh::LocalID size() const
size_t size(bool dummy=0) const
const std::vector< CellID > & getLocalCells()
fsgrid::FsGrid< FS_STENCIL_WIDTH > FieldSolverGrid
__host__ gpuStream_t gpu_getStream()
ObjectWrapper & getObjectWrapper()
Logger & write(Logger &logger)
@ N_VELOCITY_BLOCK_PARAMS
void averageCellData(const dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const vector< CellID > cellList, SpatialCell *to, const uint popID, const creal fluffiness)
std::span< std::array< Real, fsgrids::bfield::N_BFIELD > > perbspan
std::span< technical > technicalspan
std::span< std::array< Real, bgbfield::N_BGB > > bgbspan
Project * createProject()
ARCH_HOSTDEV MeshWrapper * getMeshWrapper()
projects::Project * project
std::vector< species::Species > particleSpecies
static std::vector< uint > amrBoxHalfWidthX
static Real anisotropyRefineThreshold
static Real vorticityCoarsenThreshold
static std::vector< Real > refinementMinZ
static Real alpha1RefineThreshold
static Real alpha2RefineThreshold
static int amrMaxSpatialRefLevel
static std::vector< Real > refinementMinY
static int refineBoxNumber
static std::vector< uint > amrBoxHalfWidthY
static bool useAnisotropy
static std::vector< Real > refinementMaxY
static Real alpha2CoarsenThreshold
static std::string projectName
static std::vector< Realf > amrBoxCenterY
static std::vector< Real > refinementMaxX
static int amrMaxAllowedSpatialRefLevel
static Real vorticityRefineThreshold
static Real alpha1CoarsenThreshold
static std::vector< Realf > amrBoxCenterX
static std::vector< uint > amrBoxHalfWidthZ
static std::vector< Real > refinementMinX
static std::vector< int > amrBoxMaxLevel
static Real anisotropyCoarsenThreshold
static std::vector< Realf > amrBoxCenterZ
static int anisotropyMaxReflevel
static std::vector< Real > refinementMaxZ
std::vector< vmesh::MeshParameters > * velocityMeshesCreation