Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
vlasovmover.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 <cstdlib>
24#include <iostream>
25#include <vector>
26#include <stdint.h>
27
28#ifdef _OPENMP
29 #include <omp.h>
30#endif
31
32#include <zoltan.h>
33#include <dccrg.hpp>
34#include <phiprof.hpp>
35
36#include "vlasovmover.h"
37#include "../grid.h"
38#include "../definitions.h"
39#include "../object_wrapper.h"
40#include "../mpiconversion.h"
41
42#include "arch_moments.h"
43
44#include "cpu_trans_pencils.hpp"
45#include "cpu_acc_transform.hpp" // for updateAccelerationMaxdt
46#ifdef USE_GPU
47#include "gpu_moments.h"
48#include "gpu_acc_semilag.hpp"
49#include "gpu_trans_map_amr.hpp"
50#else
51#include "cpu_acc_semilag.hpp"
52#include "cpu_trans_map_amr.hpp"
53#endif
54
55using namespace spatial_cell;
56
66 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
67 const vector<CellID>& local_propagated_cells,
68 const vector<CellID>& remoteTargetCellsx,
69 const vector<CellID>& remoteTargetCellsy,
70 const vector<CellID>& remoteTargetCellsz,
71 vector<uint>& nPencils,
72 const Realf dt,
73 const uint popID,
74 Real &time
75) {
76
77 double t1;
78
79 int myRank;
80 MPI_Comm_rank(MPI_COMM_WORLD,&myRank);
81
82 phiprof::Timer btzTimer {"barrier-trans-pre-z", {"Barriers","MPI"}};
83 MPI_Barrier(MPI_COMM_WORLD);
84 btzTimer.stop();
85
86 // ------------- SLICE - map dist function in Z --------------- //
87 if(P::zcells_ini > 1){
88
89 phiprof::Timer transTimer {"transfer-stencil-data-z", {"MPI"}};
90 //updateRemoteVelocityBlockLists(mpiGrid,popID,VLASOV_SOLVER_Z);
92 mpiGrid.update_copies_of_remote_neighbors(Neighborhoods::VLASOV_SOLVER_Z);
93 transTimer.stop();
94
95 // bt=phiprof::initializeTimer("barrier-trans-pre-trans_map_1d-z","Barriers","MPI");
96 // phiprof::start(bt);
97 // MPI_Barrier(MPI_COMM_WORLD);
98 // phiprof::stop(bt);
99
100 t1 = MPI_Wtime();
101 phiprof::Timer computeTimer {"compute-mapping-z"};
102 trans_map_1d_amr(mpiGrid,local_propagated_cells, remoteTargetCellsz, nPencils, 2, dt,popID); // map along z//
103 computeTimer.stop();
104 time += MPI_Wtime() - t1;
105
106 phiprof::Timer btTimer {"barrier-trans-pre-update_remote-z", {"Barriers","MPI"}};
107 MPI_Barrier(MPI_COMM_WORLD);
108 btTimer.stop();
109
110 phiprof::Timer updateRemoteTimer {"update_remote-z", {"MPI"}};
111 update_remote_mapping_contribution_amr(mpiGrid, 2,+1,popID);
112 update_remote_mapping_contribution_amr(mpiGrid, 2,-1,popID);
113 updateRemoteTimer.stop();
114
115 }
116
117 phiprof::Timer btxTimer {"barrier-trans-pre-x", {"Barriers","MPI"}};
118 MPI_Barrier(MPI_COMM_WORLD);
119 btxTimer.stop();
120
121 // ------------- SLICE - map dist function in X --------------- //
122 if(P::xcells_ini > 1){
123
124 phiprof::Timer transTimer {"transfer-stencil-data-x", {"MPI"}};
125 //updateRemoteVelocityBlockLists(mpiGrid,popID,VLASOV_SOLVER_X);
127 mpiGrid.update_copies_of_remote_neighbors(Neighborhoods::VLASOV_SOLVER_X);
128 transTimer.stop();
129
130 // bt=phiprof::initializeTimer("barrier-trans-pre-trans_map_1d-x","Barriers","MPI");
131 // phiprof::start(bt);
132 // MPI_Barrier(MPI_COMM_WORLD);
133 // phiprof::stop(bt);
134
135 t1 = MPI_Wtime();
136 phiprof::Timer computeTimer {"compute-mapping-x"};
137 trans_map_1d_amr(mpiGrid,local_propagated_cells, remoteTargetCellsx, nPencils, 0,dt,popID); // map along x//
138 computeTimer.stop();
139 time += MPI_Wtime() - t1;
140
141 phiprof::Timer btTimer {"barrier-trans-pre-update_remote-x", {"Barriers","MPI"}};
142 MPI_Barrier(MPI_COMM_WORLD);
143 btTimer.stop();
144
145 phiprof::Timer updateRemoteTimer {"update_remote-x", {"MPI"}};
146 update_remote_mapping_contribution_amr(mpiGrid, 0,+1,popID);
147 update_remote_mapping_contribution_amr(mpiGrid, 0,-1,popID);
148 updateRemoteTimer.stop();
149
150 }
151
152 phiprof::Timer btyTimer {"barrier-trans-pre-y", {"Barriers","MPI"}};
153 MPI_Barrier(MPI_COMM_WORLD);
154 btyTimer.stop();
155
156 // ------------- SLICE - map dist function in Y --------------- //
157 if(P::ycells_ini > 1) {
158
159 phiprof::Timer transTimer {"transfer-stencil-data-y", {"MPI"}};
160 //updateRemoteVelocityBlockLists(mpiGrid,popID,VLASOV_SOLVER_Y);
162 mpiGrid.update_copies_of_remote_neighbors(Neighborhoods::VLASOV_SOLVER_Y);
163 transTimer.stop();
164
165 // bt=phiprof::initializeTimer("barrier-trans-pre-trans_map_1d-y","Barriers","MPI");
166 // phiprof::start(bt);
167 // MPI_Barrier(MPI_COMM_WORLD);
168 // phiprof::stop(bt);
169
170 t1 = MPI_Wtime();
171 phiprof::Timer computeTimer {"compute-mapping-y"};
172 trans_map_1d_amr(mpiGrid,local_propagated_cells, remoteTargetCellsy, nPencils, 1,dt,popID); // map along y//
173 computeTimer.stop();
174 time += MPI_Wtime() - t1;
175
176 phiprof::Timer btTimer {"barrier-trans-pre-update_remote-y", {"Barriers","MPI"}};
177 MPI_Barrier(MPI_COMM_WORLD);
178 btTimer.stop();
179
180 phiprof::Timer updateRemoteTimer {"update_remote-y", {"MPI"}};
181 update_remote_mapping_contribution_amr(mpiGrid, 1,+1,popID);
182 update_remote_mapping_contribution_amr(mpiGrid, 1,-1,popID);
183 updateRemoteTimer.stop();
184
185 }
186
187 phiprof::Timer btpostimer {"barrier-trans-post-trans",{"Barriers","MPI"}};
188 MPI_Barrier(MPI_COMM_WORLD);
189 btpostimer.stop();
190
191 // MPI_Barrier(MPI_COMM_WORLD);
192 // bailout(true, "", __FILE__, __LINE__);
193}
194
206 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
207 const vector<CellID>& local_propagated_cells,
208 vector<uint>& nPencils,
209 const creal dt,
210 const uint popID,
211 Real &time
212 ) {
213
214 // Ghost translation, need all cell information, not just for a single direction.
215 // No need for remote target cells; pass a dummy list.
216 const vector<CellID> dummy_cells;
217
219 // Need to re-do in case block lists of boundary cells change after
220 // the block adjustment just after ACC.
221
222 phiprof::Timer prepreBarrierTimer {"MPI barrier-pre-trans-comm"};
223 MPI_Barrier(MPI_COMM_WORLD);
224 prepreBarrierTimer.stop();
225
226 phiprof::Timer transferTimer {"transfer-stencil-data-all",{"MPI"}};
228 mpiGrid.update_copies_of_remote_neighbors(Neighborhoods::VLASOV_SOLVER_GHOST);
229 transferTimer.stop();
230
231 phiprof::Timer preBarrierTimer {"MPI barrier-pre-trans"};
232 MPI_Barrier(MPI_COMM_WORLD);
233 preBarrierTimer.stop();
234
235 //#warning TODO: Implement also 2D / non-AMR ghost translation?
236 // ------------- SLICE - map dist function in Z --------------- //
237 phiprof::Timer mappingZTimer {"compute-mapping-z"};
238 trans_map_1d_amr(mpiGrid,local_propagated_cells, dummy_cells, nPencils, 2, dt,popID); // map along z//
239 mappingZTimer.stop();
240
241 // ------------- SLICE - map dist function in X --------------- //
242 phiprof::Timer mappingXTimer {"compute-mapping-x"};
243 trans_map_1d_amr(mpiGrid,local_propagated_cells, dummy_cells, nPencils, 0,dt,popID); // map along x//
244 mappingXTimer.stop();
245
246 // ------------- SLICE - map dist function in Y --------------- //
247 phiprof::Timer mappingYTimer {"compute-mapping-y"};
248 trans_map_1d_amr(mpiGrid,local_propagated_cells, dummy_cells, nPencils, 1,dt,popID); // map along y//
249 mappingYTimer.stop();
250
251 phiprof::Timer postBarrierTimer {"MPI barrier-post-trans"};
252 MPI_Barrier(MPI_COMM_WORLD);
253 postBarrierTimer.stop();
254 return;
255}
256
268 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
269 const Real dt) {
270 typedef Parameters P;
271
272 phiprof::Timer semilagTimer {"semilag-trans"};
273
274 //double t1 = MPI_Wtime();
275
276 const vector<CellID>& localCells = getLocalCells();
277 vector<CellID> remoteTargetCellsx;
278 vector<CellID> remoteTargetCellsy;
279 vector<CellID> remoteTargetCellsz;
280 vector<CellID> local_propagated_cells;
281 vector<uint> nPencils;
282 Real time=0.0;
283
284 // If dt=0 we are either initializing or distribution functions are not translated.
285 // In both cases go to the end of this function and calculate the moments.
286 if (dt == 0.0) {
287 calculateMoments_R(mpiGrid,localCells,true,true);
288 return;
289 }
290
291 phiprof::Timer computeTimer {"compute_cell_lists"};
293 remoteTargetCellsx = mpiGrid.get_remote_cells_on_process_boundary(Neighborhoods::VLASOV_SOLVER_TARGET_X);
294 remoteTargetCellsy = mpiGrid.get_remote_cells_on_process_boundary(Neighborhoods::VLASOV_SOLVER_TARGET_Y);
295 remoteTargetCellsz = mpiGrid.get_remote_cells_on_process_boundary(Neighborhoods::VLASOV_SOLVER_TARGET_Z);
296 }
297
298 // Figure out which spatial cells are translated,
299 // result independent of particle species.
300 // If performing ghost translation, this is used for LB.
301 for (size_t c=0; c<localCells.size(); ++c) {
302 if (do_translate_cell(mpiGrid[localCells[c]])) {
303 local_propagated_cells.push_back(localCells[c]);
304 }
305 }
306
307 if (P::prepareForRebalance == true) {
308 // One more element to count the sums
309 nPencils.resize(local_propagated_cells.size()+1, 0);
310 }
311 computeTimer.stop();
312
313 // Translate all particle species
314 for (uint popID=0; popID<getObjectWrapper().particleSpecies.size(); ++popID) {
315 string profName = "translate "+getObjectWrapper().particleSpecies[popID].name;
316 phiprof::Timer timer {profName};
319 // All-local ghost translation with coalesced communication
320 // Not yet implemented for non-AMR solver
322 mpiGrid,
323 local_propagated_cells, // Used for LB
324 nPencils,
325 (Realf)dt,
326 popID,
327 time
328 );
329 } else {
330 // Classic method with included remote contribution through MPI
332 mpiGrid,
333 local_propagated_cells,
334 remoteTargetCellsx,
335 remoteTargetCellsy,
336 remoteTargetCellsz,
337 nPencils,
338 (Realf)dt,
339 popID,
340 time
341 );
342 }
343 }
344
346 // clear weight on all local cells
347 for (size_t c=0; c<localCells.size(); ++c) {
348 SpatialCell* SC = mpiGrid[localCells[c]];
350 }
351 for (size_t c=0; c<local_propagated_cells.size(); ++c) {
352 // Gather total blocks in cell
353 SpatialCell* SC = mpiGrid[local_propagated_cells[c]];
354 Real counter = 0;
355 for (uint popID=0; popID<getObjectWrapper().particleSpecies.size(); ++popID) {
356 counter += SC->get_number_of_velocity_blocks(popID);
357 }
358
359 // int accelerationsteps = 0; // Account for time spent in acceleration as well
360 // if (mpiGrid[local_propagated_cells[c]]->sysBoundaryFlag == sysboundarytype::NOT_SYSBOUNDARY) {
361 // accelerationsteps = 3;
362 // }
364 // Set sysb cells to a small weight
365 SC->parameters[CellParams::LBWEIGHTCOUNTER] = counter * 0.5;
366 } else {
367 if (P::amrMaxSpatialRefLevel == 0) {
368 SC->parameters[CellParams::LBWEIGHTCOUNTER] = 3 * counter;
369 } else {
370 // SC->parameters[CellParams::LBWEIGHTCOUNTER] = nPencils[c] * counter;
371 SC->parameters[CellParams::LBWEIGHTCOUNTER] = 3 * counter;
372 // SC->parameters[CellParams::LBWEIGHTCOUNTER] += (nPencils[c]+accelerationsteps) * counter;
373 // SC->parameters[CellParams::LBWEIGHTCOUNTER] += time / localCells.size();
374 }
375 }
376 }
377 }
378
379 // Mapping complete, update moments and maximum dt limits //
380 calculateMoments_R(mpiGrid,localCells,true);
381}
382
383/*
384 --------------------------------------------------
385 Acceleration (velocity space propagation)
386 --------------------------------------------------
387*/
388
397
398uint getAccelerationSubcycles(const SpatialCell* spatial_cell, const Real dt, const uint popID)
399{
400 return max( convert<uint>(ceil(dt / spatial_cell->get_max_v_dt(popID))), 1u);
401}
402
410void calculateAcceleration(const uint popID,const uint globalMaxSubcycles,const uint step,
411 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
412 const std::vector<CellID>& acceleratedCells,
413 const Real dt) {
414 // Set active population
416
417 // Calculate velocity moments, these are needed to
418 // calculate the transforms used in the accelerations.
419 // Calculated moments are stored in the "_V" variables.
420 calculateMoments_V(mpiGrid, acceleratedCells, false);
421
422 // set seed, initialise generator and get value. The order is the same
423 // for all cells, but varies with timestep.
424 std::default_random_engine rndState;
425 rndState.seed(P::tstep);
426 uint map_order = std::uniform_int_distribution<>(0,2)(rndState);
427
428 // Calculate length of step for each cell
429 #pragma omp parallel for
430 for (size_t c=0; c<acceleratedCells.size(); ++c) {
431 const CellID cellID = acceleratedCells[c];
432 const Real maxVdt = mpiGrid[cellID]->get_max_v_dt(popID);
433
444
445 Real thisSubcycleDt;
446 if( (step + 1) * maxVdt > fabs(dt)) {
447 thisSubcycleDt = max(fabs(dt) - step * maxVdt, 0.0);
448 } else{
449 thisSubcycleDt = maxVdt;
450 }
451 if (dt<0) {
452 thisSubcycleDt = -thisSubcycleDt;
453 }
454 spatial_cell::Population& pop = mpiGrid[cellID]->get_population(popID);
455 pop.subcycleDt = thisSubcycleDt;
456 }
457
458 // Semi-Lagrangian acceleration for all cells
459#ifdef USE_GPU
460 gpu_accelerate_cells(mpiGrid,acceleratedCells,popID,map_order);
461#else
462 cpu_accelerate_cells(mpiGrid,acceleratedCells,popID,map_order);
463#endif
464
472 if (step < (globalMaxSubcycles - 1)) {
473 adjustVelocityBlocks(mpiGrid, acceleratedCells, false, popID);
474 }
475}
476
481void calculateAcceleration(dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
482 const Real dt
483 ) {
484 typedef Parameters P;
485 const vector<CellID>& cells = getLocalCells();
486
487 int myRank;
488 MPI_Comm_rank(MPI_COMM_WORLD,&myRank);
489
490 if (dt == 0.0 && P::tstep > 0) {
491
492 // Even if acceleration is turned off we need to adjust velocity blocks
493 // because the boundary conditions may have altered the velocity space,
494 // and to update changes in no-content blocks during translation.
495 for (uint popID=0; popID<getObjectWrapper().particleSpecies.size(); ++popID) {
496 adjustVelocityBlocks(mpiGrid, cells, true, popID);
497 }
498 } else {
499 // Fairly ugly but no goto
500 phiprof::Timer accTimer {"semilag-acc"};
501
502 // Accelerate all particle species
503 for (uint popID=0; popID<getObjectWrapper().particleSpecies.size(); ++popID) {
504 int maxSubcycles=0;
505 int globalMaxSubcycles;
506
507 // Set active population
509
510 // Iterate through all local cells and collect cells to propagate.
511 // Ghost cells (spatial cells at the boundary of the simulation
512 // volume) do not need to be propagated:
513 phiprof::Timer gatherTimer {"Gather subcycles and propagated cells"};
514 vector<CellID> acceleratedCells;
515 #pragma omp parallel for
516 for (size_t c=0; c<cells.size(); ++c) {
517 SpatialCell* SC = mpiGrid[cells[c]];
518 const vmesh::VelocityMesh* vmesh = SC->get_velocity_mesh(popID);
519 // disregard boundary cells, in preparation for acceleration
521 // Include inflow-Maxwellian
523 uint blockCount = vmesh->size();
524 if (blockCount != 0){
525 //do not propagate spatial cells with no blocks
526 #pragma omp critical
527 {
528 acceleratedCells.push_back(cells[c]);
529 }
530 }
531 //prepare for acceleration, updates max dt for each cell, it
532 //needs to be set to somthing sensible for _all_ cells, even if
533 //they are not propagated
534 updateAccelerationMaxdt(SC, popID);
535 //update max subcycles for all cells in this process
536 maxSubcycles = max((int)getAccelerationSubcycles(SC, dt, popID), maxSubcycles);
538 pop.ACCSUBCYCLES = getAccelerationSubcycles(SC, dt, popID);
539 }
540 }
541 gatherTimer.stop();
542
543 // Compute global maximum for number of subcycles
544 MPI_Allreduce(&maxSubcycles, &globalMaxSubcycles, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
545
546 // TODO: move subcycling to lower level call in order to optimize GPU memory calls
547 // substep global max times
548 for(uint step=0; step<(uint)globalMaxSubcycles; ++step) {
549 if(step > 0) {
550 // prune list of cells to propagate to only contained those which are now subcycled
551 vector<CellID> temp;
552 for (const auto& cell: acceleratedCells) {
553 if (step < getAccelerationSubcycles(mpiGrid[cell], dt, popID) ) {
554 temp.push_back(cell);
555 }
556 }
557 acceleratedCells.swap(temp);
558 }
559 // Accelerate population over one subcycle step
560 calculateAcceleration(popID,(uint)globalMaxSubcycles,step,mpiGrid,acceleratedCells,dt);
561 } // for-loop over acceleration substeps
562
563 // final adjust for all cells, also updating full remote block lists
564 adjustVelocityBlocks(mpiGrid, cells, true, popID);
565 } // for-loop over particle species
566 }
567
568 // Recalculate "_V" velocity moments
569 calculateMoments_V(mpiGrid,cells,true,(dt==0));
570
571 // Set CellParams::MAXVDT to be the minimum dt of all per-species values
572 #pragma omp parallel for
573 for (size_t c=0; c<cells.size(); ++c) {
574 SpatialCell* cell = mpiGrid[cells[c]];
575 cell->parameters[CellParams::MAXVDT] = numeric_limits<Real>::max();
576 for (uint popID=0; popID<getObjectWrapper().particleSpecies.size(); ++popID) {
578 = min(cell->get_max_v_dt(popID), cell->parameters[CellParams::MAXVDT]);
579 }
580 }
581}
582
583/*--------------------------------------------------
584 Functions for computing moments
585 --------------------------------------------------*/
586
588 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
589 const int cp_rhom,
590 const int cp_vx,
591 const int cp_vy,
592 const int cp_vz,
593 const int cp_rhoq,
594 const int cp_p11,
595 const int cp_p22,
596 const int cp_p33,
597 const int cp_p23,
598 const int cp_p13,
599 const int cp_p12
600) {
601 const vector<CellID>& cells = getLocalCells();
602
603 //Iterate through all local cells
604 #pragma omp parallel for
605 for (size_t c=0; c<cells.size(); ++c) {
606 const CellID cellID = cells[c];
607 SpatialCell* SC = mpiGrid[cellID];
608 SC->parameters[cp_rhom ] = 0.5* ( SC->parameters[CellParams::RHOM_R] + SC->parameters[CellParams::RHOM_V] );
609 SC->parameters[cp_vx] = 0.5* ( SC->parameters[CellParams::VX_R] + SC->parameters[CellParams::VX_V] );
610 SC->parameters[cp_vy] = 0.5* ( SC->parameters[CellParams::VY_R] + SC->parameters[CellParams::VY_V] );
611 SC->parameters[cp_vz] = 0.5* ( SC->parameters[CellParams::VZ_R] + SC->parameters[CellParams::VZ_V] );
612 SC->parameters[cp_rhoq ] = 0.5* ( SC->parameters[CellParams::RHOQ_R] + SC->parameters[CellParams::RHOQ_V] );
613 SC->parameters[cp_p11] = 0.5* ( SC->parameters[CellParams::P_11_R] + SC->parameters[CellParams::P_11_V] );
614 SC->parameters[cp_p22] = 0.5* ( SC->parameters[CellParams::P_22_R] + SC->parameters[CellParams::P_22_V] );
615 SC->parameters[cp_p33] = 0.5* ( SC->parameters[CellParams::P_33_R] + SC->parameters[CellParams::P_33_V] );
616 SC->parameters[cp_p23] = 0.5* ( SC->parameters[CellParams::P_23_R] + SC->parameters[CellParams::P_23_V] );
617 SC->parameters[cp_p13] = 0.5* ( SC->parameters[CellParams::P_13_R] + SC->parameters[CellParams::P_13_V] );
618 SC->parameters[cp_p12] = 0.5* ( SC->parameters[CellParams::P_12_R] + SC->parameters[CellParams::P_12_V] );
619
620 for (uint popID=0; popID<getObjectWrapper().particleSpecies.size(); ++popID) {
622 pop.RHO = 0.5 * ( pop.RHO_R + pop.RHO_V );
623 for (int i = 0; i < 3; i++) {
624 pop.V[i] = 0.5 * ( pop.V_R[i] + pop.V_V[i] );
625 }
626 for (int i = 0; i < 6; i++) {
627 pop.P[i] = 0.5 * ( pop.P_R[i] + pop.P_V[i] );
628 }
629 }
630 }
631}
632
633void calculateInitialVelocityMoments(dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid) {
634 const vector<CellID>& cells = getLocalCells();
635 phiprof::Timer timer {"Calculate moments"};
636
637 // Iterate through all local cells (incl. system boundary cells):
638 // Setting the GPU device inside the moment call itself, because
639 // it's being called from so many different projects etc
640 #pragma omp parallel for
641 for (size_t c=0; c<cells.size(); ++c) {
642 const CellID cellID = cells[c];
643 SpatialCell* SC = mpiGrid[cellID];
644 calculateCellMoments(SC,true,false);
645 // WARNING the following is sane as this function is only called by initializeGrid.
646 // We need initialized _DT2 values for the dt=0 field propagation done in the beginning.
647 // Later these will be set properly.
659 } // for-loop over spatial cells
660}
for i
Definition Dispersion.m:24
dt
Definition Dispersion.m:39
Constants c
Definition Dispersion.m:45
void calculateCellMoments(spatial_cell::SpatialCell *cell, const bool &computeSecond, const bool &computePopulationMomentsOnly, const bool &doNotSkip)
void calculateMoments_R(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells, const bool &computeSecond, const bool initialCompute)
void calculateMoments_V(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells, const bool &computeSecond, const bool initialCompute)
vmesh::LocalID get_number_of_velocity_blocks(const uint popID) const
vmesh::VelocityMesh * get_velocity_mesh(const size_t &popID)
static bool setCommunicatedSpecies(const uint popID)
static void set_mpi_transfer_type(const uint64_t type, bool atSysBoundaries=false)
const Real & get_max_v_dt(const uint popID) const
Population & get_population(const uint popID)
std::array< Real, CellParams::N_SPATIAL_CELL_PARAMS > parameters
const std::vector< CellID > & getLocalCells()
Definition main.cpp:39
void cpu_accelerate_cells(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &acceleratedCells, const uint popID, const uint map_order)
void updateAccelerationMaxdt(SpatialCell *spatial_cell, const uint popID)
bool trans_map_1d_amr(const dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const vector< CellID > &localPropagatedCells, const vector< CellID > &remoteTargetCells, std::vector< uint > &nPencils, const uint dimension, const Realf dt, const uint popID)
void update_remote_mapping_contribution_amr(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const uint dimension, int direction, const uint popID)
bool do_translate_cell(const SpatialCell *const SC)
Parameters P
float Real
Definition definitions.h:41
uint64_t CellID
Definition definitions.h:54
T convert(const T &number)
Definition definitions.h:56
float Realf
Definition definitions.h:33
const float creal
Definition definitions.h:42
void gpu_accelerate_cells(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &acceleratedCells, const uint popID, const uint map_order)
Propagates the distribution function in velocity space of given list of real space cells using a semi...
int myRank
Definition gpu_base.cpp:48
__global__ void const Realf const uint *__restrict__ const uint *__restrict__ const vmesh::GlobalID *__restrict__ const uint const uint nPencils
bool adjustVelocityBlocks(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const vector< CellID > &cellsToAdjust, bool doPrepareToReceiveBlocks, const uint popID)
Definition grid.cpp:830
void updateRemoteVelocityBlockLists(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const uint popID, const uint neighborhood)
Definition grid.cpp:919
ObjectWrapper & getObjectWrapper()
Definition main.cpp:33
@ LBWEIGHTCOUNTER
Definition common.h:198
@ VLASOV_SOLVER_Z
Definition common.h:80
@ VLASOV_SOLVER_TARGET_X
Definition common.h:81
@ VLASOV_SOLVER_X
Definition common.h:78
@ VLASOV_SOLVER_TARGET_Z
Definition common.h:83
@ VLASOV_SOLVER_TARGET_Y
Definition common.h:82
@ VLASOV_SOLVER_Y
Definition common.h:79
@ VLASOV_SOLVER_GHOST
Definition common.h:98
static const uint64_t VEL_BLOCK_DATA
std::vector< species::Species > particleSpecies
static uint zcells_ini
Definition parameters.h:50
static bool vlasovSolverGhostTranslate
Definition parameters.h:63
static int amrMaxSpatialRefLevel
Definition parameters.h:190
static bool prepareForRebalance
Definition parameters.h:167
static uint ycells_ini
Definition parameters.h:49
static uint xcells_ini
Definition parameters.h:48
static uint tstep
Definition parameters.h:73
static bool vlasovAccelerateMaxwellianBoundaries
Definition parameters.h:158
static ARCH_HOSTDEV VecSimple< T > min(VecSimple< T > const &l, VecSimple< T > const &r)
static ARCH_HOSTDEV VecSimple< T > max(VecSimple< T > const &l, VecSimple< T > const &r)
void calculateInterpolatedVelocityMoments(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const int cp_rhom, const int cp_vx, const int cp_vy, const int cp_vz, const int cp_rhoq, const int cp_p11, const int cp_p22, const int cp_p33, const int cp_p23, const int cp_p13, const int cp_p12)
Compute real-time 1st order accurate moments from the moments after propagation in velocity and spati...
uint getAccelerationSubcycles(const SpatialCell *spatial_cell, const Real dt, const uint popID)
void calculateAcceleration(const uint popID, const uint globalMaxSubcycles, const uint step, dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &acceleratedCells, const Real dt)
void calculateInitialVelocityMoments(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid)
Compute 0th, 1st and 2nd velocity moments (RHO,VX,VY,VZ,P_11,P_22,P_33 and *_DT2) for all cells in th...
void calculateSpatialGhostTranslation(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const vector< CellID > &local_propagated_cells, vector< uint > &nPencils, const creal dt, const uint popID, Real &time)
void calculateSpatialTranslation(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const vector< CellID > &local_propagated_cells, const vector< CellID > &remoteTargetCellsx, const vector< CellID > &remoteTargetCellsy, const vector< CellID > &remoteTargetCellsz, vector< uint > &nPencils, const Realf dt, const uint popID, Real &time)