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/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 "GeneratorTraits.hh"
0017 #include "../GeneratorData.hh"
0018 
0019 namespace celeritas
0020 {
0021 namespace optical
0022 {
0023 class MaterialParams;
0024 }  // namespace optical
0025 
0026 namespace detail
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 = 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 step_id;
0047         AuxId gen_id;
0048         AuxId optical_id;
0049         SPConstMaterial material;
0050         SPConstParams shared;
0051 
0052         explicit operator bool() const
0053         {
0054             return step_id && gen_id && optical_id && material && shared;
0055         }
0056     };
0057 
0058   public:
0059     // Construct and add to core params
0060     static std::shared_ptr<OffloadAction>
0061     make_and_insert(CoreParams const&, Input&&);
0062 
0063     // Construct with action ID, aux IDs, and optical properties
0064     OffloadAction(ActionId action_id, Input&&);
0065 
0066     //!@{
0067     //! \name Action interface
0068 
0069     //! ID of the action
0070     ActionId action_id() const final { return action_id_; }
0071     //! Short name for the action
0072     std::string_view label() const final { return TraitsT::label; }
0073     //! Description of the action
0074     std::string_view description() const final { return TraitsT::description; }
0075     //!@}
0076 
0077     //!@{
0078     //! \name StepAction interface
0079 
0080     //! Dependency ordering of the action
0081     StepActionOrder order() const final { return StepActionOrder::user_post; }
0082     // Launch kernel with host data
0083     void step(CoreParams const&, CoreStateHost&) const final;
0084     // Launch kernel with device data
0085     void step(CoreParams const&, CoreStateDevice&) const final;
0086     //!@}
0087 
0088     //// ACCESSORS ////
0089 
0090     //! Access shared data used by this offload physics
0091     SPConstParams const& params() const { return data_.shared; }
0092 
0093   private:
0094     //// TYPES ////
0095 
0096     using Executor = typename TraitsT::Executor;
0097 
0098     //// DATA ////
0099 
0100     ActionId action_id_;
0101     Input data_;
0102 
0103     //// HELPER FUNCTIONS ////
0104 
0105     template<MemSpace M>
0106     void step_impl(CoreParams const&, CoreState<M>&) const;
0107 
0108     void offload(CoreParams const&, CoreStateHost&) const;
0109     void offload(CoreParams const&, CoreStateDevice&) const;
0110 };
0111 
0112 //---------------------------------------------------------------------------//
0113 // EXPLICIT INSTANTIATION
0114 //---------------------------------------------------------------------------//
0115 
0116 extern template class OffloadAction<GeneratorType::cherenkov>;
0117 extern template class OffloadAction<GeneratorType::scintillation>;
0118 
0119 //---------------------------------------------------------------------------//
0120 }  // namespace detail
0121 }  // namespace celeritas