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/OffloadGatherAction.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <vector>
0011 
0012 #include "corecel/Macros.hh"
0013 #include "corecel/data/AuxInterface.hh"
0014 #include "corecel/data/Collection.hh"
0015 #include "celeritas/global/ActionInterface.hh"
0016 
0017 #include "OffloadData.hh"
0018 
0019 #include "detail/OffloadGatherTraits.hh"
0020 
0021 namespace celeritas
0022 {
0023 class CoreParams;
0024 
0025 //---------------------------------------------------------------------------//
0026 /*!
0027  * Collect state data needed to create optical distribution data.
0028  *
0029  * This action is templated on the step action order so that it can be used to
0030  * collect both pre-step data and pre-post-step data.
0031  *
0032  * The pre-step action stores the optical material ID and other
0033  * beginning-of-step properties so that optical photons can be generated
0034  * between the start and end points of the step.
0035  *
0036  * The pre-post-step action stores the particle's speed and energy deposition
0037  * following the continuous energy loss but before the particle undergoes a
0038  * discrete interaction. These must be cached for scintillation, which offloads
0039  * the distribution data post-step rather than pre-post-step because it also
0040  * requires the local energy deposition from the interaction.
0041  *
0042  * \sa OffloadGatherExecutor
0043  */
0044 template<StepActionOrder S>
0045 class OffloadGatherAction final : public CoreStepActionInterface,
0046                                   public AuxParamsInterface
0047 {
0048   public:
0049     //!@{
0050     //! \name Type aliases
0051     using TraitsT = detail::OffloadGatherTraits<S>;
0052     //!@}
0053 
0054   public:
0055     // Construct and add to core params
0056     static std::shared_ptr<OffloadGatherAction> make_and_insert(
0057         CoreParams const&);
0058 
0059     // Construct with action ID and storage
0060     OffloadGatherAction(ActionId id, AuxId aux_id);
0061 
0062     //!@{
0063     //! \name Aux interface
0064 
0065     //! Index of this class instance in its registry
0066     AuxId aux_id() const final { return aux_id_; }
0067     // Build state data for a stream
0068     UPState create_state(MemSpace, StreamId, size_type) const final;
0069     //!@}
0070 
0071     //!@{
0072     //! \name Action interface
0073 
0074     //! ID of the model
0075     ActionId action_id() const final { return action_id_; }
0076     //! Short name for the action
0077     std::string_view label() const final { return TraitsT::label; }
0078     //! Description of the action
0079     std::string_view description() const final { return TraitsT::description; }
0080     //!@}
0081 
0082     //!@{
0083     //! \name StepAction interface
0084 
0085     //! Dependency ordering of the action
0086     StepActionOrder order() const final { return S; }
0087     // Launch kernel with host data
0088     void step(CoreParams const&, CoreStateHost&) const final;
0089     // Launch kernel with device data
0090     void step(CoreParams const&, CoreStateDevice&) const final;
0091     //!@}
0092 
0093   private:
0094     //// TYPES ////
0095 
0096     using Executor = typename TraitsT::Executor;
0097 
0098     //// HELPER FUNCTIONS ////
0099 
0100     typename TraitsT::template Data<Ownership::reference, MemSpace::device>&
0101     get_step_data(CoreState<MemSpace::device>& state) const;
0102 
0103     //// DATA ////
0104 
0105     ActionId action_id_;
0106     AuxId aux_id_;
0107 };
0108 
0109 //---------------------------------------------------------------------------//
0110 // EXPLICIT INSTANTIATION
0111 //---------------------------------------------------------------------------//
0112 
0113 extern template class OffloadGatherAction<StepActionOrder::pre>;
0114 extern template class OffloadGatherAction<StepActionOrder::pre_post>;
0115 
0116 //---------------------------------------------------------------------------//
0117 }  // namespace celeritas