Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
arch_dt.cpp
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2024-2025 University of Helsinki
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 <vector>
24#include "../definitions.h"
26#include "../object_wrapper.h"
27//#include <stdint.h>
28#include <dccrg.hpp>
29#include <dccrg_cartesian_geometry.hpp>
30
31//using namespace std;
32using namespace spatial_cell;
33
34void reduce_vlasov_dt(dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
35 const vector<CellID>& cells,
36 Real (&dtMaxLocal)[3]) {
37
38 phiprof::Timer computeTimestepTimer {"compute-vlasov-timestep"};
39 const Real HALF = 0.5;
40
41 for (vector<CellID>::const_iterator cell_id = cells.begin(); cell_id != cells.end(); ++cell_id) {
42 SpatialCell* cell = mpiGrid[*cell_id];
43 const Real dx = cell->parameters[CellParams::DX];
44 const Real dy = cell->parameters[CellParams::DY];
45 const Real dz = cell->parameters[CellParams::DZ];
46 cell->parameters[CellParams::MAXRDT] = numeric_limits<Real>::max();
47
48 for (uint popID = 0; popID < getObjectWrapper().particleSpecies.size(); ++popID) {
49 cell->set_max_r_dt(popID, numeric_limits<Real>::max());
50 const Real EPS = numeric_limits<Real>::min() * 1000;
51
52 const uint nBlocks = cell->get_number_of_velocity_blocks(popID);
53 if (nBlocks==0) {
54 continue;
55 }
56 #ifdef USE_GPU
57 const vmesh::VelocityBlockContainer *blockContainer = cell->dev_get_velocity_blocks(popID);
58 #else
59 const vmesh::VelocityBlockContainer *blockContainer = cell->get_velocity_blocks(popID);
60 #endif
61
62 Real threadMin = std::numeric_limits<Real>::max();
64 ARCH_LOOP_LAMBDA (uint i, const uint blockLID, Real *lthreadMin) -> void{
65 i = i * (WID - 1); // ie, i == 0, i == WID - 1
66 const Real* blockParams = blockContainer->getParameters();
67 const Real Vx =
69 (i + HALF) * blockParams[blockLID * BlockParams::N_VELOCITY_BLOCK_PARAMS + BlockParams::DVX] + EPS;
70 const Real Vy =
72 (i + HALF) * blockParams[blockLID * BlockParams::N_VELOCITY_BLOCK_PARAMS + BlockParams::DVY] + EPS;
73 const Real Vz =
75 (i + HALF) * blockParams[blockLID * BlockParams::N_VELOCITY_BLOCK_PARAMS + BlockParams::DVZ] + EPS;
76
77 const Real dt_max_cell = min({dx / fabs(Vx), dy / fabs(Vy), dz / fabs(Vz)});
78 lthreadMin[0] = min(dt_max_cell,lthreadMin[0]);
79 }, threadMin);
80 cell->set_max_r_dt(popID, threadMin);
82 } // end loop over popID
83
86 // spatial fluxes computed also for boundary cells
87 dtMaxLocal[0] = min(dtMaxLocal[0], cell->parameters[CellParams::MAXRDT]);
88 }
89
90 if (cell->parameters[CellParams::MAXVDT] != 0 &&
93 // acceleration only done on non-boundary cells
94 dtMaxLocal[1] = min(dtMaxLocal[1], cell->parameters[CellParams::MAXVDT]);
95 }
96 }
97}
for i
Definition Dispersion.m:24
dx
Definition Dispersion.m:38
#define ARCH_LOOP_LAMBDA
void reduce_vlasov_dt(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const vector< CellID > &cells, Real(&dtMaxLocal)[3])
Definition arch_dt.cpp:34
vmesh::LocalID get_number_of_velocity_blocks(const uint popID) const
vmesh::VelocityBlockContainer * get_velocity_blocks(const size_t &popID)
void set_max_r_dt(const uint popID, const Real &value)
const Real & get_max_r_dt(const uint popID) const
std::array< Real, CellParams::N_SPATIAL_CELL_PARAMS > parameters
vmesh::VelocityBlockContainer * dev_get_velocity_blocks(const size_t &popID)
#define WID
Definition common.h:514
float Real
Definition definitions.h:41
static creal EPS
Definition fs_common.h:61
const Real HALF
Definition fs_common.h:49
ObjectWrapper & getObjectWrapper()
Definition main.cpp:33
@ N_VELOCITY_BLOCK_PARAMS
Definition common.h:115
static void parallel_reduce(const uint(&limits)[NDim], Lambda loop_body, T &sum)
std::vector< species::Species > particleSpecies
static bool vlasovAccelerateMaxwellianBoundaries
Definition parameters.h:158
static ARCH_HOSTDEV VecSimple< T > min(VecSimple< T > const &l, VecSimple< T > const &r)