Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-19 08:49:41

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file celeritas/alongstep/detail/TrackUpdater.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "celeritas/global/CoreTrackView.hh"
0010 
0011 #if !CELER_DEVICE_COMPILE
0012 #    include "corecel/io/Logger.hh"
0013 #endif
0014 
0015 namespace celeritas
0016 {
0017 namespace detail
0018 {
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Finish the step.
0022  *
0023  * TODO: we may need to save the pre-step speed and apply the time update using
0024  * an average here.
0025  */
0026 //---------------------------------------------------------------------------//
0027 struct TrackUpdater
0028 {
0029     inline CELER_FUNCTION void operator()(CoreTrackView& track);
0030 };
0031 
0032 //---------------------------------------------------------------------------//
0033 // INLINE DEFINITIONS
0034 //---------------------------------------------------------------------------//
0035 CELER_FUNCTION void TrackUpdater::operator()(CoreTrackView& track)
0036 {
0037     auto sim = track.sim();
0038 
0039     // The track errored within the along-step kernel
0040     if (sim.status() == TrackStatus::errored)
0041         return;
0042 
0043     // Increment the step counter
0044     sim.increment_num_steps();
0045 
0046     if (sim.status() == TrackStatus::alive)
0047     {
0048         CELER_ASSERT(sim.step_length() > 0 || track.particle().is_stopped());
0049         CELER_ASSERT(sim.post_step_action());
0050         auto phys = track.physics();
0051 
0052         if (sim.num_steps() == sim.max_steps()
0053             && sim.post_step_action() != track.tracking_cut_action())
0054         {
0055 #if !CELER_DEVICE_COMPILE
0056             CELER_LOG_LOCAL(error) << R"(Track exceeded maximum step count)";
0057 #endif
0058             track.apply_errored();
0059             return;
0060         }
0061         else if (sim.post_step_action() != phys.scalars().discrete_action()
0062                  && (!CELERITAS_DEBUG
0063                      || sim.post_step_action() != track.tracking_cut_action()))
0064         {
0065             // Reduce remaining mean free paths to travel. The 'discrete
0066             // action' case is launched separately and resets the
0067             // interaction MFP itself. In the unlikely case that a track is
0068             // about to be killed because it's looping (it's reached its
0069             // collision point but has undergone too many steps), it's OK to
0070             // set the interaction MFP to zero (but avoid during debug mode due
0071             // to the additional error checking).
0072             auto step = track.physics_step();
0073             real_type mfp = phys.interaction_mfp()
0074                             - sim.step_length() * step.macro_xs();
0075             CELER_ASSERT(mfp > 0);
0076             phys.interaction_mfp(mfp);
0077         }
0078     }
0079 }
0080 
0081 //---------------------------------------------------------------------------//
0082 }  // namespace detail
0083 }  // namespace celeritas