Skip to content

Commit afa4a27

Browse files
author
fournier2
committed
Improve performance
1 parent 58311e8 commit afa4a27

1 file changed

Lines changed: 6 additions & 23 deletions

File tree

src/tracers/tracers.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ TaskStatus InjectTracers(MeshBlockData<Real> *mbd, parthenon::SimTime &tm) {
276276
auto tracer_pkg = pmb->packages.Get("tracers");
277277
auto hydro_pkg = pmb->packages.Get("Hydro");
278278
auto mbar_over_kb = hydro_pkg->Param<Real>("mbar_over_kb");
279-
280279
// Getting the number of independent populations of tracers
281280
auto n_populations = tracer_pkg->Param<int>("n_populations");
282281
auto rmax = tracer_pkg->Param<Real>("rmax");
@@ -329,12 +328,6 @@ TaskStatus InjectTracers(MeshBlockData<Real> *mbd, parthenon::SimTime &tm) {
329328
PARTHENON_FAIL("No injection criteria has been set.");
330329
}
331330

332-
// Generating a new random seed at each call
333-
std::srand(std::time(nullptr));
334-
int rng_seed = std::rand();
335-
336-
RNGPool rng_pool(pmb->gid + rng_seed);
337-
338331
// Check number of dimensions
339332
auto ndim = pmb->pmy_mesh->ndim;
340333

@@ -358,8 +351,8 @@ TaskStatus InjectTracers(MeshBlockData<Real> *mbd, parthenon::SimTime &tm) {
358351

359352
// Simple test case: first calculate the number of cells fulfilling the criteria.
360353
// (modulo some stochastic factor)
361-
// To be discussed: currently assumes that only one tracer is added per timestep.
362-
// (otherwise p_injection > 1 if injection_timescale = O(tm.dt)).
354+
// To be discussed: currently assumes that only one tracer is added per timestep and
355+
// per cell. (otherwise p_injection > 1 if injection_timescale = O(tm.dt)).
363356
int npart = 0; // Number of particles to be injected at current timestep.
364357
Real p_injection = std::min(1.0, injection_num_target * tm.dt / injection_timescale);
365358

@@ -424,24 +417,14 @@ TaskStatus InjectTracers(MeshBlockData<Real> *mbd, parthenon::SimTime &tm) {
424417

425418
if (rnd < p_injection) {
426419

427-
auto rng = rng_pool.get_state();
428-
429420
int thread_id = Kokkos::atomic_fetch_add(&counter(), 1);
430421
int swarm_idx = injected_particles_context.GetNewParticleIndex(thread_id);
431422

432-
// Get the current cell sizes
433-
const Real dx_cell = coords.Dxc<1>(i);
434-
const Real dy_cell = coords.Dxc<2>(j);
435-
const Real dz_cell = coords.Dxc<3>(k);
436-
437-
const Real rx = 0.5 - rng.drand();
438-
const Real ry = 0.5 - rng.drand();
439-
const Real rz = 0.5 - rng.drand();
440-
441-
x(swarm_idx) = x_cell + dx_cell * rx;
442-
y(swarm_idx) = y_cell + dy_cell * ry;
423+
// Setting the position of the tracers
424+
x(swarm_idx) = x_cell;
425+
y(swarm_idx) = y_cell;
443426
if (ndim == 3) {
444-
z(swarm_idx) = z_cell + dz_cell * rz;
427+
z(swarm_idx) = z_cell;
445428
}
446429

447430
id(swarm_idx) = 1;

0 commit comments

Comments
 (0)