Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-10 10:05:47

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/optical/gen/detail/OpticalGeneratorBase.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 #include "corecel/data/AuxInterface.hh"
0011 #include "corecel/data/AuxStateVec.hh"
0012 #include "corecel/math/Algorithms.hh"
0013 #include "corecel/sys/ActionInterface.hh"
0014 #include "celeritas/optical/action/ActionInterface.hh"
0015 #include "celeritas/phys/GeneratorInterface.hh"
0016 
0017 namespace celeritas
0018 {
0019 namespace detail
0020 {
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * Common interface for generating optical photons.
0024  */
0025 class OpticalGeneratorBase
0026     : virtual public optical::OpticalStepActionInterface,
0027       virtual public AuxParamsInterface,
0028       virtual public GeneratorInterface
0029 {
0030   public:
0031     // Construct from IDs, unique label, and description
0032     OpticalGeneratorBase(ActionId id,
0033                          AuxId aux_id,
0034                          GeneratorId gen_id,
0035                          std::string_view label,
0036                          std::string_view description) noexcept(!CELERITAS_DEBUG);
0037 
0038     //!@{
0039     //! \name Aux interface
0040 
0041     //! Index of this class instance in its registry
0042     AuxId aux_id() const final { return aux_id_; }
0043     //!@}
0044 
0045     //!@{
0046     //! \name Action interface
0047 
0048     //! ID of the action
0049     ActionId action_id() const final { return sad_.action_id(); }
0050     //! Short name for the action
0051     std::string_view label() const final { return sad_.label(); }
0052     //! Description of the action
0053     std::string_view description() const final { return sad_.description(); }
0054     //!@}
0055 
0056     //!@{
0057     //! \name StepAction interface
0058 
0059     //! Dependency ordering of the action
0060     StepActionOrder order() const final { return StepActionOrder::generate; }
0061     //!@}
0062 
0063     //!@{
0064     //! \name Generator interface
0065 
0066     //! ID of the generator
0067     GeneratorId generator_id() const final { return gen_id_; }
0068     // Get generator counters (mutable)
0069     GeneratorStateBase& counters(AuxStateVec&) const final;
0070     // Get generator counters
0071     GeneratorStateBase const& counters(AuxStateVec const&) const final;
0072     //!@}
0073 
0074     // Update the generator and state counters
0075     template<MemSpace M>
0076     inline void update_counters(optical::CoreState<M>&) const;
0077 
0078   private:
0079     StaticActionData sad_;
0080     AuxId aux_id_;
0081     GeneratorId gen_id_;
0082 };
0083 
0084 //---------------------------------------------------------------------------//
0085 // INLINE DEFINITIONS
0086 //---------------------------------------------------------------------------//
0087 /*!
0088  * Update the generator and state counters.
0089  */
0090 template<MemSpace M>
0091 void OpticalGeneratorBase::update_counters(optical::CoreState<M>& state) const
0092 {
0093     CELER_EXPECT(state.aux());
0094 
0095     auto& counters = state.counters();
0096     auto& gen_counters = this->counters(*state.aux());
0097 
0098     // Calculate the number of new tracks generated at this step
0099     size_type num_gen
0100         = min(counters.num_vacancies, gen_counters.counters.num_pending);
0101 
0102     // Update the optical core state counters
0103     counters.num_pending -= num_gen;
0104     counters.num_generated += num_gen;
0105     counters.num_vacancies -= num_gen;
0106 
0107     // Update the generator counters and statistics
0108     gen_counters.counters.num_pending -= num_gen;
0109     gen_counters.counters.num_generated += num_gen;
0110     gen_counters.accum.num_generated += num_gen;
0111 
0112     // Update the number of active tracks. This must be done even if no new
0113     // tracks were generated
0114     counters.num_active = state.size() - counters.num_vacancies;
0115 }
0116 
0117 //---------------------------------------------------------------------------//
0118 }  // namespace detail
0119 }  // namespace celeritas