Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-27 10:26:20

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/FieldTrackPropagator.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 #include "celeritas/field/DormandPrinceIntegrator.hh"
0011 #include "celeritas/field/MakeMagFieldPropagator.hh"
0012 #include "celeritas/global/CoreTrackView.hh"
0013 
0014 #if !CELER_DEVICE_COMPILE
0015 #    include "corecel/io/Logger.hh"
0016 #endif
0017 
0018 namespace celeritas
0019 {
0020 namespace detail
0021 {
0022 //---------------------------------------------------------------------------//
0023 /*!
0024  * Propagate a track in a mapped magnetic field.
0025  *
0026  * This class moves the track a single step based on the current sim step
0027  * length. It updates the particle with looping behavior if necessary.
0028  *
0029  * \tparam Field The field type (e.g., RZMapField, CylMapField, CartMapField)
0030  */
0031 template<class Field>
0032 struct FieldTrackPropagator
0033 {
0034     //!@{
0035     //! \name Type aliases
0036     using ParamsRef = typename Field::ParamsRef;
0037     //!@}
0038 
0039     //! Create propagator, execute propagation, and return result
0040     [[nodiscard]] CELER_FUNCTION Propagation operator()(
0041         CoreTrackView& track) const;
0042 
0043     //// DATA ////
0044 
0045     ParamsRef field;
0046 };
0047 
0048 //---------------------------------------------------------------------------//
0049 // INLINE DEFINITIONS
0050 //---------------------------------------------------------------------------//
0051 /*!
0052  * Create propagator, execute propagation, and return result.
0053  */
0054 template<class Field>
0055 inline CELER_FUNCTION Propagation FieldTrackPropagator<Field>::operator()(
0056     CoreTrackView& track) const
0057 {
0058     auto sim = track.sim();
0059     auto propagator = make_mag_field_propagator<DormandPrinceIntegrator>(
0060         Field{field}, field.options, track.particle(), track.geometry());
0061 
0062     Propagation p = propagator(sim.step_length());
0063 
0064     sim.update_looping(p.looping);
0065     if (p.looping)
0066     {
0067         sim.step_length(p.distance);
0068         auto particle = track.particle();
0069         if (particle.is_stable()
0070             && sim.is_looping(particle.particle_id(), particle.energy()))
0071         {
0072 #if !CELER_DEVICE_COMPILE
0073             CELER_LOG_LOCAL(debug)
0074                 << "Track " << track.track_slot_id().get()
0075                 << " (pid=" << particle.particle_id().get()
0076                 << ", E=" << particle.energy() << ") is looping after "
0077                 << sim.num_looping_steps() << " steps";
0078 #endif
0079             track.apply_cut();
0080         }
0081         else
0082         {
0083             sim.post_step_action(track.propagation_limit_action());
0084         }
0085     }
0086     return p;
0087 }
0088 
0089 //---------------------------------------------------------------------------//
0090 }  // namespace detail
0091 }  // namespace celeritas