Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:11:38

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