Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
project.cpp
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2010-2016 Finnish Meteorological Institute
4 *
5 * For details of usage, see the COPYING file and read the "Rules of the Road"
6 * at http://www.physics.helsinki.fi/vlasiator/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#include "project.h"
24#include <cstdlib>
25#include "../common.h"
26#include "../parameters.h"
27#include "../readparameters.h"
29#include "../logger.h"
30#include "../object_wrapper.h"
32
33#include "Alfven/Alfven.h"
34#include "Diffusion/Diffusion.h"
37#include "Firehose/Firehose.h"
40#include "Harris/Harris.h"
41#include "KHB/KHB.h"
42#include "Larmor/Larmor.h"
44#include "MultiPeak/MultiPeak.h"
45#include "Riemann1/Riemann1.h"
46#include "Shock/Shock.h"
47#include "IPShock/IPShock.h"
48#include "Template/Template.h"
49#include "test_fp/test_fp.h"
50#include "testHall/testHall.h"
54#include "Shocktest/Shocktest.h"
55#include "LossCone/LossCone.h"
57
58#ifdef DEBUG_VLASIATOR
59 #define DEBUG_REFINE
60#endif
61
62using namespace std;
63
64extern Logger logFile;
65
67
68namespace projects {
72
74
102
104 typedef Readparameters RP;
105 RP::get("Project_common.seed", this->seed);
106 }
107
114
115 // Basic error checking
116 bool success = true;
117
118 baseClassInitialized = success;
119 return success;
120 }
121
125
130 int rank;
131 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
132 if (rank == MASTER_RANK) {
133 cerr << "(Project.cpp) WARNING: Base class 'setCellBackgroundField' in " << __FILE__ << ":" << __LINE__ << " called." << endl;
134 }
135 exit(1);
136 }
137
138 void Project::hook(cuint& stage, const dccrg::Dccrg<spatial_cell::SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
140 fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) const {}
141
142 void Project::setupBeforeSetCell(const std::vector<CellID>& cells) {
143 // Dummy implementation.
144 return;
145 }
146
147 /* Setting up the v-space for the cell
148 this is called within a threaded region, so we can use non-threadsafe methods
149 */
151 // Set up cell parameters:
152 calcCellParameters(cell,0.0);
153 for (uint popID=0; popID<getObjectWrapper().particleSpecies.size(); ++popID) {
154 this->setVelocitySpace(popID,cell);
155 // Verify current mesh and blocks
156 #ifdef DEBUG_VLASIATOR
157 cuint vmeshSize = cell->get_velocity_mesh(popID)->size();
158 cuint vbcSize = cell->get_velocity_blocks(popID)->size();
159 if (vmeshSize != vbcSize) {
160 printf("ERROR: population vmesh %ul and blockcontainer %ul sizes do not match!\n",vmeshSize,vbcSize);
161 }
162 cell->get_velocity_mesh(popID)->check();
163 #endif
164 }
165
166 // Passing true for the doNotSkip argument as we want to calculate
167 // the moment no matter what when this function is called.
168 calculateCellMoments(cell,true,false,true);
169 }
170
171 /*
172 Brute force function, returns all possible velocity blocks. Much preferred to use
173 projectTriAxisSearch
174 */
176 const vmesh::LocalID* vblocks_ini = cell->get_velocity_grid_length(popID);
178
179 const uint blocksCount = vblocks_ini[0]*vblocks_ini[1]*vblocks_ini[2];
180
181 #ifdef USE_GPU
182 // Host-pinned memory buffer
183 vmesh::GlobalID *GIDbuffer;
184 CHK_ERR( gpuMallocHost((void**)&GIDbuffer,blocksCount*sizeof(vmesh::GlobalID)) );
185 cell->dev_resize_vmesh(popID,blocksCount);
186 #else
187 vmesh->setNewSize(blocksCount);
188 vmesh::GlobalID *GIDbuffer = vmesh->getGrid()->data();
189 #endif
190
191 vmesh::LocalID LID = 0;
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) {
195 vmesh::LocalID blockIndices[3];
196 blockIndices[0] = iv;
197 blockIndices[1] = jv;
198 blockIndices[2] = kv;
199 const vmesh::GlobalID GID = cell->get_velocity_block(popID,blockIndices);
200 GIDbuffer[LID] = GID;
201 LID++;
202 }
203 }
204 }
205 cell->get_population(popID).N_blocks = LID;
206
207 #ifdef USE_GPU
208 vmesh::GlobalID *GIDtarget = vmesh->getGrid()->data();
209 gpuStream_t stream = gpu_getStream();
210 CHK_ERR( gpuMemcpyAsync(GIDtarget, GIDbuffer, blocksCount*sizeof(vmesh::GlobalID), gpuMemcpyHostToDevice, stream));
211 CHK_ERR( gpuStreamSynchronize(stream) );
212 CHK_ERR( gpuFreeHost(GIDbuffer));
213 #endif
214
215 return LID;
216 }
217
220 logFile << "(PROJECT): Loaded particle populations are:" << endl;
221
222 for (uint popID=0; popID<getObjectWrapper().particleSpecies.size(); ++popID) {
224 logFile << "Population #" << popID << endl;
225 logFile << "\t name : '" << spec.name << "'" << endl;
226 logFile << "\t charge : '" << spec.charge << "'" << endl;
227 logFile << "\t mass : '" << spec.mass << "'" << endl;
228 logFile << "\t sparse threshold : '" << spec.sparseMinValue << "'" << endl;
229 logFile << "\t velocity mesh : '" << vmesh::getMeshWrapper()->velocityMeshesCreation->at(spec.velocityMesh).name << "'" << endl;
230 logFile << endl;
231 }
232 logFile << write;
233 }
234
235 void Project::setVelocitySpace(const uint popID,SpatialCell* cell) const {
236 // Find list of blocks to initialize. The project.cpp version returns
237 // all possible blocks, projectTriAxisSearch provides a more educated guess.
238
239 const uint nRequested = this->findBlocksToInitialize(cell,popID);
240 // stores in vmesh->getGrid() (localToGlobalMap)
241 // with count in cell->get_population(popID).N_blocks
242
243 // Set and apply the reservation value
244 #ifdef USE_GPU
245 cell->setReservation(popID,nRequested,true); // Force to this value
246 cell->applyReservation(popID);
247 #endif
248
249 // Resize and populate mesh
250 cell->prepare_to_receive_blocks(popID);
251
252 // Call project-specific fill function, which loops over all requested blocks,
253 // fills v-space into target
254 const Realf nullsum = fillPhaseSpace(cell, popID, nRequested);
255 if (rescalesDensity(popID) == true) {
256 rescaleDensity(cell,popID);
257 }
258 return;
259 }
260
264 bool Project::rescalesDensity(const uint popID) const {
265 return false;
266 }
267
272 void Project::rescaleDensity(spatial_cell::SpatialCell* cell,const uint popID) const {
273 // Re-scale densities
274 Real sum = 0.0;
275 Realf* data = cell->get_data(popID);
276 const Real* blockParams = cell->get_block_parameters(popID);
277 for (vmesh::LocalID blockLID=0; blockLID<cell->get_number_of_velocity_blocks(popID); ++blockLID) {
278 Real tmp = 0.0;
279 for (unsigned int i=0; i<WID3; ++i) {
280 tmp += data[blockLID*WID3+i];
281 }
282 const Real DV3 = blockParams[BlockParams::DVX]*blockParams[BlockParams::DVY]*blockParams[BlockParams::DVZ];
283 sum += tmp*DV3;
285 }
286
287 const Real correctSum = getCorrectNumberDensity(cell,popID);
288 const Real ratio = correctSum / sum;
289
290 for (size_t i=0; i<cell->get_number_of_velocity_blocks(popID)*WID3; ++i) {
291 data[i] *= ratio;
292 }
293 }
294
297 int rank;
298 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
299 if (rank == MASTER_RANK) {
300 cerr << "(Project.cpp) WARNING: Base class 'calcCellParameters' in " << __FILE__ << ":" << __LINE__ << " called." << endl;
301 }
302 exit(1);
303 }
304
309 cerr << "ERROR: Project::getCorrectNumberDensity called instead of derived class function!" << endl;
310 exit(1);
311 return 0.0;
312 }
313
317 Real Project::getRandomNumber(std::default_random_engine& randGen) const {
318 return std::uniform_real_distribution<>(0,1)(randGen);
319 }
320
326 void Project::setRandomSeed(CellID seedModifier, std::default_random_engine& randGen) const {
327 randGen.seed(this->seed+seedModifier);
328 }
329
336 void Project::setRandomCellSeed(spatial_cell::SpatialCell* cell, std::default_random_engine& randGen) const {
337 const creal x = cell->parameters[CellParams::XCRD];
338 const creal y = cell->parameters[CellParams::YCRD];
339 const creal z = cell->parameters[CellParams::ZCRD];
340 const creal dx = cell->parameters[CellParams::DX];
341 const creal dy = cell->parameters[CellParams::DY];
342 const creal dz = cell->parameters[CellParams::DZ];
343
344 const CellID cellID = (int) ((x - Parameters::xmin) / dx) +
345 (int) ((y - Parameters::ymin) / dy) * Parameters::xcells_ini +
347 setRandomSeed(cellID, randGen);
348 }
349
350 /*
351 Refine cells of mpiGrid. Each project that wants refinement should implement this function.
352 Base class function uses AMR box half width parameters
353 */
354 bool Project::refineSpatialCells( dccrg::Dccrg<spatial_cell::SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid ) const {
355 phiprof::Timer refineSCTimer {"Project: refine spatial cells"};
356 int myRank;
357 MPI_Comm_rank(MPI_COMM_WORLD,&myRank);
358
359 if(myRank == MASTER_RANK) {
360 std::cout << "Maximum refinement level is " << mpiGrid.mapping.get_maximum_refinement_level() << std::endl;
361 }
362
363 std::vector<bool> refineSuccess;
364
365 for (int level = 0; level < mpiGrid.mapping.get_maximum_refinement_level(); level++) {
366 int refineCount = 0;
367 for (int n = 0; n < P::amrBoxNumber; n++) {
368 if (level < P::amrBoxMaxLevel[n]) {
369 const int maxloop = pow(2, level+1);
370 #pragma omp parallel for schedule(guided) collapse(3)
371 for (int i = 0; i < maxloop * (int)P::amrBoxHalfWidthX[n]; ++i) {
372 for (int j = 0; j < maxloop * (int)P::amrBoxHalfWidthY[n]; ++j) {
373 for (int k = 0; k < maxloop * (int)P::amrBoxHalfWidthZ[n]; ++k) {
374
375 std::array<double,3> xyz;
376 xyz[0] = P::amrBoxCenterX[n] + (0.5 + i - pow(2, level)*P::amrBoxHalfWidthX[n]) * P::dx_ini / pow(2, level);
377 xyz[1] = P::amrBoxCenterY[n] + (0.5 + j - pow(2, level)*P::amrBoxHalfWidthY[n]) * P::dy_ini / pow(2, level);
378 xyz[2] = P::amrBoxCenterZ[n] + (0.5 + k - pow(2, level)*P::amrBoxHalfWidthZ[n]) * P::dz_ini / pow(2, level);
379
380 #pragma omp critical
381 {
382 if (mpiGrid.refine_completely_at(xyz)) {
383 refineCount++;
384 #ifdef DEBUG_REFINE
385 CellID myCell = mpiGrid.get_existing_cell(xyz);
386 std::cout << "Rank " << myRank << " is refining cell " << myCell << std::endl;
387 #endif
388 } // if
389 }
390 } // box z
391 } // box y
392 } // box x
393 } // if (P::amrBoxMaxLevel <= level)
394 } // box number
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();
399 #ifdef DEBUG_REFINE
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 << " ";
404 }
405 std::cout << endl;
406 }
407 #endif
408
409 // Don't do LB, as this function is called only before v-spaces have been created
410 // mpiGrid.balance_load();
411 }
412 if(myRank == MASTER_RANK) {
413 std::cout << "Finished level of refinement " << level+1 << endl;
414 }
415
416 } // refinement levels
417 return true;
418 }
419
420
424
425 bool Project::shouldRefineCell(dccrg::Dccrg<spatial_cell::SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid, CellID id, Real r_max2) const {
426 // Evaluate possible refinement for this cell
427
428 // Cells too far from the ionosphere should not be refined but
429 // induced refinement still possible just beyond this r_max2 limit.
430
431 std::array<double,3> xyz {mpiGrid.get_center(id)};
432 SpatialCell* cell {mpiGrid[id]};
433 int refLevel {mpiGrid.get_refinement_level(id)};
434 Real r2 {pow(xyz[0], 2) + pow(xyz[1], 2) + pow(xyz[2], 2)};
435
436 bool alpha1ShouldRefine = (P::useAlpha1 && cell->parameters[CellParams::AMR_ALPHA1] > P::alpha1RefineThreshold);
437 bool alpha2ShouldRefine = (P::useAlpha2 && cell->parameters[CellParams::AMR_ALPHA2] > P::alpha2RefineThreshold);
438 bool vorticityShouldRefine = (P::useVorticity && cell->parameters[CellParams::AMR_VORTICITY] > P::vorticityRefineThreshold);
440
441 bool shouldRefine {
442 (r2 < r_max2) && (
443 alpha1ShouldRefine ||
444 alpha2ShouldRefine ||
445 vorticityShouldRefine ||
446 anisotropyShouldRefine
447 )
448 };
449
450 if (P::refineBoxNumber > 0) {
451 bool outsideAllRefineBoxes = true;
452 for (int i = 0; i < P::refineBoxNumber; i++) {
453 if (
454 // If this cell is planned to be refined and is inside any of the refinement boxes, then go ahead with refinement.
455 // Induced refinement still possible just beyond that limit.
456 (xyz[0] >= P::refinementMinX.at(i)) && (xyz[0] <= P::refinementMaxX.at(i))
457 && (xyz[1] >= P::refinementMinY.at(i)) && (xyz[1] <= P::refinementMaxY.at(i))
458 && (xyz[2] >= P::refinementMinZ.at(i)) && (xyz[2] <= P::refinementMaxZ.at(i))) {
459 outsideAllRefineBoxes = false;
460 break;
461 }
462 }
463
464 shouldRefine = shouldRefine && !outsideAllRefineBoxes;
465 }
466
467 return shouldRefine;
468 }
469
470 bool Project::shouldUnrefineCell(dccrg::Dccrg<spatial_cell::SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid, CellID id, Real r_max2) const {
471 // Evaluate possible unrefinement for this cell
472
473 // Cells too far from the ionosphere should be unrefined but
474 // induced refinement still possible just beyond this r_max2 limit.
475
476 std::array<double,3> xyz {mpiGrid.get_center(id)};
477 SpatialCell* cell {mpiGrid[id]};
478 int refLevel {mpiGrid.get_refinement_level(id)};
479 Real r2 {pow(xyz[0], 2) + pow(xyz[1], 2) + pow(xyz[2], 2)};
480
481 bool alpha1ShouldUnrefine = (!P::useAlpha1 || cell->parameters[CellParams::AMR_ALPHA1] < P::alpha1CoarsenThreshold);
482 bool alpha2ShouldUnrefine = (!P::useAlpha2 || cell->parameters[CellParams::AMR_ALPHA2] < P::alpha2CoarsenThreshold);
483 bool vorticityShouldUnrefine = (!P::useVorticity || cell->parameters[CellParams::AMR_VORTICITY] < P::vorticityCoarsenThreshold);
485
486 bool shouldUnrefine {
487 (r2 > r_max2) || (
488 alpha1ShouldUnrefine &&
489 alpha2ShouldUnrefine &&
490 vorticityShouldUnrefine &&
491 anisotropyShouldUnrefine
492 )
493 };
494
495 if (P::refineBoxNumber > 0) {
496 bool outsideAllRefineBoxes = true;
497 for (int i = 0; i < P::refineBoxNumber; i++) {
498 if (
499 // If this cell is planned to remain at the current refinement level, but is outside all the allowed refinement regions,
500 // attempt to unrefine it instead. (If it is already at the lowest refinement level, DCCRG should not go belly-up.)
501 // Induced refinement still possible just beyond that limit.
502 (xyz[0] >= P::refinementMinX.at(i)) && (xyz[0] <= P::refinementMaxX.at(i))
503 && (xyz[1] >= P::refinementMinY.at(i)) && (xyz[1] <= P::refinementMaxY.at(i))
504 && (xyz[2] >= P::refinementMinZ.at(i)) && (xyz[2] <= P::refinementMaxZ.at(i))) {
505 outsideAllRefineBoxes = false;
506 break;
507 }
508 }
509
510 shouldUnrefine = shouldUnrefine || outsideAllRefineBoxes;
511 }
512
513 return shouldUnrefine;
514 }
515
516 uint64_t Project::adaptRefinement( dccrg::Dccrg<spatial_cell::SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid ) const {
517 phiprof::Timer refinesTimer {"Set refines"};
518 int myRank;
519 MPI_Comm_rank(MPI_COMM_WORLD,&myRank);
520
521 uint64_t refines {0};
523 if (myRank == MASTER_RANK) {
524 std::cout << "WARNING All refinement indices disabled" << std::endl;
525 }
526 return refines;
527 }
528
529 const std::vector<CellID> cells {getLocalCells()};
530 Real r_max2 {pow(P::refineRadius, 2)};
531
532 #pragma omp parallel for
533 for (uint cid = 0; cid < cells.size(); ++cid) {
534 CellID id = cells[cid];
535 int refLevel {mpiGrid.get_refinement_level(id)};
536
537 if (!canRefine(mpiGrid[id])) {
538 // Skip refining, touching boundaries during runtime breaks everything
539 #pragma omp critical
540 {
541 mpiGrid.dont_refine(id);
542 mpiGrid.dont_unrefine(id);
543 }
544 } else {
545 // Evaluate possible refinement or unrefinement for this cell
546 bool shouldRefine = shouldRefineCell(mpiGrid, id, r_max2);
547 bool shouldUnrefine = shouldUnrefineCell(mpiGrid, id, r_max2);
548
549 // Finally, check neighbors
550 int refined_neighbors {0};
551 int coarser_neighbors {0};
552 for (const auto& [neighbor, dir] : mpiGrid.get_face_neighbors_of(id)) {
553 // Evaluate all face neighbors of the current cell
554 bool shouldRefineNeighbor = shouldRefineCell(mpiGrid, neighbor, r_max2);
555 bool shouldUnrefineNeighbor = shouldUnrefineCell(mpiGrid, neighbor, r_max2);
556 int neighborRef {mpiGrid.get_refinement_level(neighbor)};
557
558 if (neighborRef > refLevel && !shouldUnrefineNeighbor) {
559 ++refined_neighbors;
560 } else if (neighborRef < refLevel && !shouldRefineNeighbor) {
561 ++coarser_neighbors;
562 } else if (shouldRefineNeighbor) {
563 // If neighbor refines, 4 of its children will be this cells refined neighbors
564 refined_neighbors += 4;
565 } else if (shouldUnrefineNeighbor) {
566 ++coarser_neighbors;
567 }
568 }
569 ; // CUDA compilation does not like the start of a new region with nothing, so a null semicolon is here.
570 #pragma omp critical
571 {
572 if ((shouldRefine || refined_neighbors > 12) && refLevel < P::amrMaxAllowedSpatialRefLevel) {
573 // Refine a cell if a majority of its neighbors are refined or about to be
574 // Increment count of refined cells only if we're actually refining
575 refines += mpiGrid.refine_completely(id) && refLevel < P::amrMaxSpatialRefLevel;
576 } else if (refLevel > 0 && shouldUnrefine && coarser_neighbors > 0) {
577 // Unrefine a cell only if any of its neighbors is unrefined or about to be
578 // refLevel check prevents dont_refine() being set
579 mpiGrid.unrefine_completely(id);
580 } else {
581 // Ensure no cells above both unrefine thresholds are unrefined
582 mpiGrid.dont_unrefine(id);
583 }
584 }
585 }
586 }
587
588 return refines;
589 }
590
591 bool Project::forceRefinement( dccrg::Dccrg<spatial_cell::SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid, int n ) const {
592 int myRank;
593 MPI_Comm_rank(MPI_COMM_WORLD,&myRank);
594 if (myRank == MASTER_RANK) {
595 cerr << "(Project.cpp) Base class 'forceRefinement' in " << __FILE__ << ":" << __LINE__ << " called. Function is not implemented for project." << endl;
596 }
597
598 return false;
599 }
600
601 bool Project::filterRefined( dccrg::Dccrg<spatial_cell::SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid ) const {
602 int myRank;
603 MPI_Comm_rank(MPI_COMM_WORLD,&myRank);
604
605 const vector<CellID>& cells = getLocalCells();
606 std::map<CellID, SpatialCell> cellsMap;
607 for (CellID id : cells) {
608 if (mpiGrid[id]->parameters[CellParams::RECENTLY_REFINED]) {
609 cellsMap.insert({id, *mpiGrid[id]});
610 }
611 }
612
613 for (auto cellPair : cellsMap) {
614 CellID id = cellPair.first;
615 // To preserve the mean, we must only consider refined cells
616 int refLevel = mpiGrid.get_refinement_level(id);
617 std::vector<CellID> refinedNeighbors;
618 for (auto& neighbor : *mpiGrid.get_neighbors_of(id, Neighborhoods::NEAREST)) {
619 if (mpiGrid[neighbor.first]->parameters[CellParams::RECENTLY_REFINED] && mpiGrid.get_refinement_level(neighbor.first) == refLevel) {
620 refinedNeighbors.push_back(neighbor.first);
621 }
622 }
623
624 if (refinedNeighbors.size() == 7) {
625 continue; // Simple heuristic, in these cases all neighbors are from the same parent cell, ergo are identical
626 }
627
628 // In boxcar filter, we take the average of each of the neighbors and the cell itself. For each missing neighbour, add the cell one more time
629 Real fluffiness = (Real) refinedNeighbors.size() / 27.0;
630 for (uint popID=0; popID<getObjectWrapper().particleSpecies.size(); ++popID) {
631 SBC::averageCellData(mpiGrid, refinedNeighbors, &cellPair.second, popID, fluffiness);
632 }
633
634 calculateCellMoments(&cellPair.second, true, false);
635 }
636
637 for (auto cellPair : cellsMap) {
638 *mpiGrid[cellPair.first] = cellPair.second;
639 mpiGrid[cellPair.first]->parameters[CellParams::RECENTLY_REFINED] = 0;
640 }
641
642 if (myRank == MASTER_RANK) {
643 std::cout << "Filtered refined cells!" << std::endl;
644 }
645
646 return true;
647 }
648
650 Project* rvalue = NULL;
651 if(Parameters::projectName == "") {
652 cerr << "No project specified! Please set 'project' parameter!" << endl;
653 abort();
654 }
655 if(Parameters::projectName == "Alfven") {
656 rvalue = new projects::Alfven;
657 }
658 if(Parameters::projectName == "Diffusion") {
659 rvalue = new projects::Diffusion;
660 }
661 if(Parameters::projectName == "Dispersion") {
662 rvalue = new projects::Dispersion;
663 }
664 if(Parameters::projectName == "Distributions") {
665 rvalue = new projects::Distributions;
666 }
667 if(Parameters::projectName == "Firehose") {
668 rvalue = new projects::Firehose;
669 }
670 if(Parameters::projectName == "Flowthrough") {
671 rvalue = new projects::Flowthrough;
672 }
673 if(Parameters::projectName == "Fluctuations") {
674 rvalue = new projects::Fluctuations;
675 }
676 if(Parameters::projectName == "Harris") {
677 rvalue = new projects::Harris;
678 }
679 if(Parameters::projectName == "KHB") {
680 rvalue = new projects::KHB;
681 }
682 if(Parameters::projectName == "Larmor") {
683 rvalue = new projects::Larmor;
684 }
685 if(Parameters::projectName == "Magnetosphere") {
686 rvalue = new projects::Magnetosphere;
687 }
688 if(Parameters::projectName == "MultiPeak") {
689 rvalue = new projects::MultiPeak;
690 }
691 if(Parameters::projectName == "Riemann1") {
692 rvalue = new projects::Riemann1;
693 }
694 if(Parameters::projectName == "Shock") {
695 rvalue = new projects::Shock;
696 }
697 if(Parameters::projectName == "IPShock") {
698 rvalue = new projects::IPShock;
699 }
700 if(Parameters::projectName == "Template") {
701 rvalue = new projects::Template;
702 }
703 if(Parameters::projectName == "test_fp") {
704 rvalue = new projects::test_fp;
705 }
706 if(Parameters::projectName == "testHall") {
707 rvalue = new projects::TestHall;
708 }
709 if(Parameters::projectName == "verificationLarmor") {
710 rvalue = new projects::verificationLarmor;
711 }
712 if(Parameters::projectName == "Shocktest") {
713 rvalue = new projects::Shocktest;
714 }
715 if(Parameters::projectName == "LossCone") {
716 rvalue = new projects::LossCone;
717 }
718
719
720 if (rvalue == NULL) {
721 cerr << "Unknown project name!" << endl;
722 abort();
723 }
724
725 getObjectWrapper().project = rvalue;
726 return rvalue;
727}
728
729} // namespace projects
for i
Definition Dispersion.m:24
dx
Definition Dispersion.m:38
#define gpuStream_t
#define gpuStreamSynchronize
#define gpuMemcpyHostToDevice
#define CHK_ERR(err)
#define gpuMemcpyAsync
#define gpuMallocHost
#define gpuFreeHost
void calculateCellMoments(spatial_cell::SpatialCell *cell, const bool &computeSecond, const bool &computePopulationMomentsOnly, const bool &doNotSkip)
static void addParameters(void)
Definition Alfven.cpp:52
static void addParameters(void)
Definition Diffusion.cpp:46
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
Definition Firehose.cpp:43
static void addParameters(void)
static void addParameters(void)
static void addParameters(void)
Definition Harris.cpp:43
static void addParameters(void)
Definition IPShock.cpp:53
static void addParameters(void)
Definition KHB.cpp:41
static void addParameters(void)
Definition Larmor.cpp:47
static void addParameters(void)
Definition LossCone.cpp:47
static void addParameters(void)
static void addParameters(void)
Definition MultiPeak.cpp:52
void printPopulations()
Definition project.cpp:219
virtual void setupBeforeSetCell(const std::vector< CellID > &cells)
Definition project.cpp:142
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.
Definition project.cpp:591
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,...
Definition project.cpp:516
virtual bool canRefine(spatial_cell::SpatialCell *cell) const
Definition project.cpp:421
Real getRandomNumber(std::default_random_engine &randGen) const
Definition project.cpp:317
virtual Real getCorrectNumberDensity(spatial_cell::SpatialCell *cell, const uint popID) const
Definition project.cpp:308
virtual bool initialize()
Definition project.cpp:113
virtual void getParameters()
Definition project.cpp:103
virtual uint findBlocksToInitialize(spatial_cell::SpatialCell *cell, const uint popID) const
Prepares a list of blocks to loop through when initialising.
Definition project.cpp:175
virtual bool shouldRefineCell(dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, CellID id, Real r_max2) const
Definition project.cpp:425
static char rngStateBuffer[256]
Definition project.h:224
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid)
Definition project.cpp:127
virtual bool refineSpatialCells(dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid) const
Definition project.cpp:354
static void addParameters()
Definition project.cpp:75
virtual bool rescalesDensity(const uint popID) const
Definition project.cpp:264
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t)
Definition project.cpp:296
void rescaleDensity(spatial_cell::SpatialCell *cell, const uint popID) const
Definition project.cpp:272
virtual bool shouldUnrefineCell(dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, CellID id, Real r_max2) const
Definition project.cpp:470
void setRandomSeed(uint64_t seedModifier, std::default_random_engine &randGen) const
Definition project.cpp:326
virtual ~Project()
Definition project.cpp:73
virtual void hook(cuint &stage, const dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, fsgrids::perbspan perb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) const
Definition project.cpp:138
void setRandomCellSeed(spatial_cell::SpatialCell *cell, std::default_random_engine &randGen) const
Definition project.cpp:336
void setVelocitySpace(const uint popID, spatial_cell::SpatialCell *cell) const
Sets the distribution function in a cell.
Definition project.cpp:235
bool baseClassInitialized
Definition project.h:226
virtual bool filterRefined(dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid) const
Boxcar filters spatial cells that were recently refined.
Definition project.cpp:601
void setCell(spatial_cell::SpatialCell *cell)
Set the perturbed fields and distribution of a cell according to the default simulation settings....
Definition project.cpp:150
static void addParameters(void)
Definition Riemann1.cpp:43
static void addParameters(void)
Definition Shock.cpp:42
static void addParameters(void)
Definition Shocktest.cpp:48
static void addParameters(void)
Definition Template.cpp:42
static void addParameters(void)
Definition testHall.cpp:52
static void addParameters(void)
Definition test_fp.cpp:58
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()
Definition main.cpp:39
#define MASTER_RANK
Definition common.h:67
const int WID3
Definition common.h:517
const uint32_t cuint
Definition definitions.h:50
float Real
Definition definitions.h:41
uint64_t CellID
Definition definitions.h:54
float Realf
Definition definitions.h:33
fsgrid::FsGrid< FS_STENCIL_WIDTH > FieldSolverGrid
Definition definitions.h:78
const float creal
Definition definitions.h:42
int myRank
Definition gpu_base.cpp:48
Logger logFile
Definition main.cpp:25
__host__ gpuStream_t gpu_getStream()
Definition gpu_base.cpp:244
const int j
const int k
ObjectWrapper & getObjectWrapper()
Definition main.cpp:33
Logger & write(Logger &logger)
Definition logger.cpp:193
@ N_VELOCITY_BLOCK_PARAMS
Definition common.h:115
@ RECENTLY_REFINED
Definition common.h:224
@ AMR_ALPHA2
Definition common.h:221
@ P_ANISOTROPY
Definition common.h:222
@ AMR_ALPHA1
Definition common.h:220
@ AMR_VORTICITY
Definition common.h:223
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
Definition common.h:434
std::span< technical > technicalspan
Definition common.h:452
std::span< std::array< Real, bgbfield::N_BGB > > bgbspan
Definition common.h:444
Project * createProject()
Definition project.cpp:649
uint32_t LocalID
Definition definitions.h:60
uint32_t GlobalID
Definition definitions.h:59
ARCH_HOSTDEV MeshWrapper * getMeshWrapper()
projects::Project * project
std::vector< species::Species > particleSpecies
static std::vector< uint > amrBoxHalfWidthX
Definition parameters.h:227
static Real anisotropyRefineThreshold
Definition parameters.h:207
static Real refineRadius
Definition parameters.h:212
static Real dz_ini
Definition parameters.h:46
static Real vorticityCoarsenThreshold
Definition parameters.h:205
static std::vector< Real > refinementMinZ
Definition parameters.h:221
static Real dx_ini
Definition parameters.h:44
static Real alpha1RefineThreshold
Definition parameters.h:197
static Real alpha2RefineThreshold
Definition parameters.h:200
static int amrMaxSpatialRefLevel
Definition parameters.h:190
static std::vector< Real > refinementMinY
Definition parameters.h:220
static int refineBoxNumber
Definition parameters.h:218
static std::vector< uint > amrBoxHalfWidthY
Definition parameters.h:228
static bool useAnisotropy
Definition parameters.h:206
static std::vector< Real > refinementMaxY
Definition parameters.h:223
static Real ymin
Definition parameters.h:40
static int amrBoxNumber
Definition parameters.h:226
static bool useAlpha1
Definition parameters.h:196
static Real alpha2CoarsenThreshold
Definition parameters.h:201
static std::string projectName
Definition parameters.h:182
static std::vector< Realf > amrBoxCenterY
Definition parameters.h:231
static std::vector< Real > refinementMaxX
Definition parameters.h:222
static uint ycells_ini
Definition parameters.h:49
static int amrMaxAllowedSpatialRefLevel
Definition parameters.h:191
static Real vorticityRefineThreshold
Definition parameters.h:204
static Real alpha1CoarsenThreshold
Definition parameters.h:198
static uint xcells_ini
Definition parameters.h:48
static Real xmin
Definition parameters.h:38
static std::vector< Realf > amrBoxCenterX
Definition parameters.h:230
static std::vector< uint > amrBoxHalfWidthZ
Definition parameters.h:229
static Real zmin
Definition parameters.h:42
static std::vector< Real > refinementMinX
Definition parameters.h:219
static std::vector< int > amrBoxMaxLevel
Definition parameters.h:233
static Real dy_ini
Definition parameters.h:45
static Real anisotropyCoarsenThreshold
Definition parameters.h:208
static std::vector< Realf > amrBoxCenterZ
Definition parameters.h:232
static bool useAlpha2
Definition parameters.h:199
static int anisotropyMaxReflevel
Definition parameters.h:209
static std::vector< Real > refinementMaxZ
Definition parameters.h:224
static bool useVorticity
Definition parameters.h:203
std::vector< vmesh::MeshParameters > * velocityMeshesCreation