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/OffloadAction.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/Collection.hh"
0014 #include "celeritas/global/ActionInterface.hh"
0015 
0016 #include "GeneratorData.hh"
0017 
0018 #include "detail/OffloadGatherTraits.hh"
0019 #include "detail/OffloadTraits.hh"
0020 
0021 namespace celeritas
0022 {
0023 namespace optical
0024 {
0025 class MaterialParams;
0026 }  // namespace optical
0027 
0028 //---------------------------------------------------------------------------//
0029 /*!
0030  * Generate optical distribution data.
0031  */
0032 template<GeneratorType G>
0033 class OffloadAction final : public CoreStepActionInterface
0034 {
0035   public:
0036     //!@{
0037     //! \name Type aliases
0038     using TraitsT = detail::OffloadTraits<G>;
0039     using SPConstParams = std::shared_ptr<typename TraitsT::Params const>;
0040     using SPConstMaterial = std::shared_ptr<optical::MaterialParams const>;
0041     //!@}
0042 
0043     //! Offload input data
0044     struct Input
0045     {
0046         AuxId pre_step_id;
0047         AuxId pre_post_step_id;
0048         AuxId gen_id;
0049         AuxId optical_id;
0050         SPConstMaterial material;
0051         SPConstParams shared;
0052 
0053         explicit operator bool() const
0054         {
0055             return pre_step_id && gen_id && optical_id && material && shared;
0056         }
0057     };
0058 
0059   public:
0060     // Construct and add to core params
0061     static std::shared_ptr<OffloadAction> make_and_insert(CoreParams const&,
0062                                                           Input&&);
0063 
0064     // Construct with action ID, aux IDs, and optical properties
0065     OffloadAction(ActionId action_id, Input&&);
0066 
0067     //!@{
0068     //! \name Action interface
0069 
0070     //! ID of the action
0071     ActionId action_id() const final { return action_id_; }
0072     //! Short name for the action
0073     std::string_view label() const final { return TraitsT::label; }
0074     //! Description of the action
0075     std::string_view description() const final { return TraitsT::description; }
0076     //!@}
0077 
0078     //!@{
0079     //! \name StepAction interface
0080 
0081     //! Dependency ordering of the action
0082     StepActionOrder order() const final { return TraitsT::order; }
0083     // Launch kernel with host data
0084     void step(CoreParams const&, CoreStateHost&) const final;
0085     // Launch kernel with device data
0086     void step(CoreParams const&, CoreStateDevice&) const final;
0087     //!@}
0088 
0089     //// ACCESSORS ////
0090 
0091     //! Access shared data used by this offload physics
0092     SPConstParams const& params() const { return data_.shared; }
0093 
0094   private:
0095     //// TYPES ////
0096 
0097     using PreTraitsT = detail::OffloadGatherTraits<StepActionOrder::pre>;
0098     using PostTraitsT = detail::OffloadGatherTraits<StepActionOrder::pre_post>;
0099     using Executor = typename TraitsT::Executor;
0100 
0101     //// DATA ////
0102 
0103     ActionId action_id_;
0104     Input data_;
0105 
0106     //// HELPER FUNCTIONS ////
0107 
0108     template<MemSpace M>
0109     void step_impl(CoreParams const&, CoreState<M>&) const;
0110 
0111     void offload(CoreParams const&, CoreStateHost&) const;
0112     void offload(CoreParams const&, CoreStateDevice&) const;
0113 
0114     template<MemSpace M>
0115     typename PreTraitsT::template Data<Ownership::reference, M>&
0116     get_pre_step_data(CoreState<M>& state) const;
0117 
0118     template<MemSpace M>
0119     typename PostTraitsT::template Data<Ownership::reference, M>&
0120     get_post_step_data(CoreState<M>& state) const;
0121 };
0122 
0123 //---------------------------------------------------------------------------//
0124 // EXPLICIT INSTANTIATION
0125 //---------------------------------------------------------------------------//
0126 
0127 extern template class OffloadAction<GeneratorType::cherenkov>;
0128 extern template class OffloadAction<GeneratorType::scintillation>;
0129 
0130 //---------------------------------------------------------------------------//
0131 }  // namespace celeritas