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/GeneratorAction.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/optical/action/ActionInterface.hh"
0015 #include "celeritas/phys/GeneratorInterface.hh"
0016 
0017 #include "GeneratorTraits.hh"
0018 #include "OpticalGeneratorBase.hh"
0019 #include "../GeneratorData.hh"
0020 #include "../OffloadData.hh"
0021 
0022 namespace celeritas
0023 {
0024 class CoreParams;
0025 
0026 namespace optical
0027 {
0028 class MaterialParams;
0029 }  // namespace optical
0030 
0031 namespace detail
0032 {
0033 //---------------------------------------------------------------------------//
0034 /*!
0035  * Generate photons from optical distribution data.
0036  *
0037  * This samples and initializes optical photons directly in a track slot in a
0038  * reproducible way.  Multiple threads may generate initializers from a single
0039  * distribution.
0040  */
0041 template<GeneratorType G>
0042 class GeneratorAction final : public OpticalGeneratorBase
0043 {
0044   public:
0045     //!@{
0046     //! \name Type aliases
0047     using TraitsT = GeneratorTraits<G>;
0048     template<Ownership W, MemSpace M>
0049     using Data = typename TraitsT::template Data<W, M>;
0050     using SPConstParams = std::shared_ptr<typename TraitsT::Params const>;
0051     using SPConstMaterial = std::shared_ptr<optical::MaterialParams const>;
0052     //!@}
0053 
0054     //! Generator input data
0055     struct Input
0056     {
0057         SPConstMaterial material;
0058         SPConstParams shared;
0059         size_type capacity{};
0060 
0061         explicit operator bool() const
0062         {
0063             return material && shared && capacity > 0;
0064         }
0065     };
0066 
0067   public:
0068     // Construct and add to core params
0069     static std::shared_ptr<GeneratorAction>
0070     make_and_insert(::celeritas::CoreParams const&,
0071                     optical::CoreParams const&,
0072                     Input&&);
0073 
0074     // Construct with action ID, data IDs, and optical properties
0075     GeneratorAction(ActionId, AuxId, GeneratorId, Input&&);
0076 
0077     //!@{
0078     //! \name Aux interface
0079 
0080     // Build state data for a stream
0081     UPState create_state(MemSpace, StreamId, size_type) const final;
0082     //!@}
0083 
0084     //!@{
0085     //! \name StepAction interface
0086 
0087     // Launch kernel with host data
0088     void step(optical::CoreParams const&, CoreStateHost&) const final;
0089     // Launch kernel with device data
0090     void step(optical::CoreParams const&, CoreStateDevice&) const final;
0091     //!@}
0092 
0093   private:
0094     //// DATA ////
0095 
0096     Input data_;
0097 
0098     //// HELPER FUNCTIONS ////
0099 
0100     template<MemSpace M>
0101     void step_impl(optical::CoreParams const&, optical::CoreState<M>&) const;
0102 
0103     void generate(optical::CoreParams const&, CoreStateHost&) const;
0104     void generate(optical::CoreParams const&, CoreStateDevice&) const;
0105 };
0106 
0107 //---------------------------------------------------------------------------//
0108 // EXPLICIT INSTANTIATION
0109 //---------------------------------------------------------------------------//
0110 
0111 extern template class GeneratorAction<GeneratorType::cherenkov>;
0112 extern template class GeneratorAction<GeneratorType::scintillation>;
0113 
0114 //---------------------------------------------------------------------------//
0115 }  // namespace detail
0116 }  // namespace celeritas