From 53a2f90d5fe71dcd741bba5631b0121069ca66ab Mon Sep 17 00:00:00 2001 From: Christian Sendlinger Date: Wed, 13 Mar 2024 11:05:13 +0100 Subject: [PATCH] fixed guard against very low energies in drift mover --- src/simulation/mover.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/simulation/mover.cpp b/src/simulation/mover.cpp index 23359bf..0174c3b 100755 --- a/src/simulation/mover.cpp +++ b/src/simulation/mover.cpp @@ -165,10 +165,14 @@ void DriftMover::move(particle::Particle* particle, bool changed_position_bin = false; bool changed_energy_bin = false; bool left_simulation_domain = false; + // if particle too slow -> timestep > maximum time the particle lives + // -> add maximal timestep to time in bin and stop moving the particle + bool died_in_bin = false; + const double max_time_alive = particle->specie()->terminator()->maxTimeAlive(); while ( !(changed_position_bin || changed_energy_bin || left_simulation_domain) && - (leftover_distance > 0.)) { + (leftover_distance > 0.) && !(died_in_bin)) { old_position = particle->position(); old_velocity = particle->velocity(); @@ -197,7 +201,7 @@ void DriftMover::move(particle::Particle* particle, // should be a very rare case (but has happend) const double timestep = std::min( stepsize / (v_parallel_norm + v_perp_norm + v_drift_norm), - particle->specie()->terminator()->maxTimeAlive()); + max_time_alive); const blitz::TinyVector movement_parallel = v_parallel * timestep; @@ -244,6 +248,9 @@ void DriftMover::move(particle::Particle* particle, const auto new_position = particle->position(); + died_in_bin = + particle->specie()->terminator()->reachedMaxTimeAlive(particle); + changed_position_bin = particle->specie()->dynamicDensityField()->changedPositionBin( old_position, new_position);