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/PrimaryGeneratorAction.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 
0011 #include "corecel/Macros.hh"
0012 #include "corecel/data/AuxInterface.hh"
0013 #include "corecel/data/AuxStateVec.hh"
0014 #include "celeritas/inp/Events.hh"
0015 #include "celeritas/optical/action/ActionInterface.hh"
0016 #include "celeritas/phys/GeneratorInterface.hh"
0017 
0018 #include "OpticalGeneratorBase.hh"
0019 #include "../GeneratorData.hh"
0020 #include "../OffloadData.hh"
0021 
0022 namespace celeritas
0023 {
0024 class CoreParams;
0025 
0026 namespace detail
0027 {
0028 //---------------------------------------------------------------------------//
0029 /*!
0030  * Generate optical primaries from user-configurable distributions.
0031  *
0032  * This reproducibly samples and initializes optical photons directly in track
0033  * slots.
0034  */
0035 class PrimaryGeneratorAction final : public OpticalGeneratorBase
0036 {
0037   public:
0038     //!@{
0039     //! \name Type aliases
0040     using Input = inp::OpticalPrimaryGenerator;
0041     //!@}
0042 
0043   public:
0044     // Construct and add to core params
0045     static std::shared_ptr<PrimaryGeneratorAction>
0046     make_and_insert(::celeritas::CoreParams const&,
0047                     optical::CoreParams const&,
0048                     Input&&);
0049 
0050     // Construct with IDs and distributions
0051     PrimaryGeneratorAction(ActionId, AuxId, GeneratorId, Input);
0052 
0053     //!@{
0054     //! \name Aux interface
0055 
0056     // Build state data for a stream
0057     UPState create_state(MemSpace, StreamId, size_type) const final;
0058     //!@}
0059 
0060     //!@{
0061     //! \name StepAction interface
0062 
0063     // Launch kernel with host data
0064     void step(optical::CoreParams const&, CoreStateHost&) const final;
0065     // Launch kernel with device data
0066     void step(optical::CoreParams const&, CoreStateDevice&) const final;
0067     //!@}
0068 
0069     // Set the number of pending tracks
0070     template<MemSpace M>
0071     inline void queue_primaries(optical::CoreState<M>&) const;
0072 
0073   private:
0074     //// DATA ////
0075 
0076     PrimaryDistributionData data_;
0077 
0078     //// HELPER FUNCTIONS ////
0079 
0080     template<MemSpace M>
0081     void step_impl(optical::CoreParams const&, optical::CoreState<M>&) const;
0082 
0083     void generate(optical::CoreParams const&, CoreStateHost&) const;
0084     void generate(optical::CoreParams const&, CoreStateDevice&) const;
0085 };
0086 
0087 //---------------------------------------------------------------------------//
0088 // INLINE DEFINITIONS
0089 //---------------------------------------------------------------------------//
0090 /*!
0091  * Set the number of pending tracks.
0092  *
0093  * The number of tracks to generate must be set at the beginning of each event
0094  * before the optical loop is launched.
0095  *
0096  * \todo Currently this is only called during testing, but it *must* be done at
0097  * the beginning of each event once this action is integrated into the stepping
0098  * loop. Refactor/replace this.
0099  */
0100 template<MemSpace M>
0101 void PrimaryGeneratorAction::queue_primaries(optical::CoreState<M>& state) const
0102 {
0103     CELER_EXPECT(state.aux());
0104     auto& aux_state = this->counters(*state.aux());
0105     aux_state.counters.num_pending = data_.num_photons;
0106     state.counters().num_pending = data_.num_photons;
0107 }
0108 
0109 //---------------------------------------------------------------------------//
0110 }  // namespace detail
0111 }  // namespace celeritas