Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-15 09:05:02

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/field/LinearPropagator.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/math/Algorithms.hh"
0010 #include "geocel/Types.hh"
0011 
0012 namespace celeritas
0013 {
0014 //---------------------------------------------------------------------------//
0015 /*!
0016  * Propagate (move) a particle in a straight line.
0017  */
0018 template<class GTV>
0019 class LinearPropagator
0020 {
0021   public:
0022     //!@{
0023     //! \name Type aliases
0024     using result_type = Propagation;
0025     //!@}
0026 
0027   public:
0028     //! Construct from a geo track view
0029     CELER_FUNCTION LinearPropagator(GTV&& track)
0030         : geo_(::celeritas::forward<GTV>(track))
0031     {
0032     }
0033 
0034     // Move track to next volume boundary.
0035     inline CELER_FUNCTION result_type operator()();
0036 
0037     // Move track up to a user-provided distance, up to the next boundary
0038     inline CELER_FUNCTION result_type operator()(real_type dist);
0039 
0040     //! Whether it's possible to have tracks that are looping
0041     static CELER_CONSTEXPR_FUNCTION bool tracks_can_loop() { return false; }
0042 
0043   private:
0044     GTV geo_;
0045 };
0046 
0047 //---------------------------------------------------------------------------//
0048 // DEDUCTION GUIDES
0049 //---------------------------------------------------------------------------//
0050 template<class GTV>
0051 CELER_FUNCTION LinearPropagator(GTV&&) -> LinearPropagator<GTV>;
0052 
0053 //---------------------------------------------------------------------------//
0054 /*!
0055  * Move track to next volume boundary.
0056  */
0057 template<class GTV>
0058 CELER_FUNCTION auto LinearPropagator<GTV>::operator()() -> result_type
0059 {
0060     CELER_EXPECT(!geo_.is_outside());
0061 
0062     result_type result = geo_.find_next_step();
0063     CELER_ASSERT(result.boundary);
0064     geo_.move_to_boundary();
0065 
0066     return result;
0067 }
0068 
0069 //---------------------------------------------------------------------------//
0070 /*!
0071  * Move track by a user-provided distance up to the next boundary.
0072  */
0073 template<class GTV>
0074 CELER_FUNCTION auto LinearPropagator<GTV>::operator()(real_type dist)
0075     -> result_type
0076 {
0077     CELER_EXPECT(dist > 0);
0078 
0079     result_type result = geo_.find_next_step(dist);
0080 
0081     if (result.boundary)
0082     {
0083         geo_.move_to_boundary();
0084     }
0085     else
0086     {
0087         CELER_ASSERT(dist == result.distance);
0088         geo_.move_internal(dist);
0089     }
0090 
0091     return result;
0092 }
0093 
0094 //---------------------------------------------------------------------------//
0095 }  // namespace celeritas