Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:31

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/track/ExtendFromPrimariesAction.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/cont/Span.hh"
0011 #include "corecel/data/AuxInterface.hh"
0012 #include "corecel/data/Collection.hh"
0013 #include "celeritas/global/ActionInterface.hh"
0014 #include "celeritas/phys/Primary.hh"
0015 
0016 namespace celeritas
0017 {
0018 //---------------------------------------------------------------------------//
0019 struct Primary;
0020 
0021 template<MemSpace M>
0022 struct PrimaryStateData;
0023 class CoreStateInterface;
0024 
0025 //---------------------------------------------------------------------------//
0026 /*!
0027  * Create track initializers from queued host primary particles.
0028  *
0029  * \todo Change "generate" step order to be at the end of the loop
0030  * alongside create secondaries, and execute the action immediately after
0031  * adding primaries.
0032  */
0033 class ExtendFromPrimariesAction final : public CoreStepActionInterface,
0034                                         public AuxParamsInterface
0035 
0036 {
0037   public:
0038     // Construct and add to core params
0039     static std::shared_ptr<ExtendFromPrimariesAction>
0040     make_and_insert(CoreParams const& core);
0041 
0042     // Hacky helper function (DEPRECATED) to get the primary action from core
0043     // params
0044     static std::shared_ptr<ExtendFromPrimariesAction const>
0045     find_action(CoreParams const& core);
0046 
0047     // Construct with explicit ids
0048     ExtendFromPrimariesAction(ActionId action_id, AuxId aux_id);
0049 
0050     // Add user-provided primaries on host
0051     void insert(CoreParams const& params,
0052                 CoreStateInterface& state,
0053                 Span<Primary const> host_primaries) const;
0054 
0055     //!@{
0056     //! \name Metadata interface
0057     //! Label for the auxiliary data and action
0058     std::string_view label() const final { return sad_.label(); }
0059     // Description of the action
0060     std::string_view description() const final { return sad_.description(); }
0061     //!@}
0062 
0063     //!@{
0064     //! \name Step action interface
0065     //! ID of the action
0066     ActionId action_id() const final { return sad_.action_id(); }
0067     //! Dependency ordering of the action
0068     StepActionOrder order() const final { return StepActionOrder::generate; }
0069     // Perform a host action within a step
0070     void step(CoreParams const& params, CoreStateHost& state) const final;
0071     // Perform a device action within a step
0072     void step(CoreParams const& params, CoreStateDevice& state) const final;
0073     //!@}
0074 
0075     //!@{
0076     //! \name Aux params interface
0077     //! Index of this class instance in its registry
0078     AuxId aux_id() const final { return aux_id_; }
0079     // Build state data for a stream
0080     UPState create_state(MemSpace m, StreamId id, size_type size) const final;
0081     //!@}
0082 
0083   private:
0084     StaticActionData sad_;
0085     AuxId aux_id_;
0086 
0087     template<MemSpace M>
0088     void
0089     insert_impl(CoreState<M>& state, Span<Primary const> host_primaries) const;
0090 
0091     template<MemSpace M>
0092     void step_impl(CoreParams const&, CoreState<M>&) const;
0093 
0094     void process_primaries(CoreParams const&,
0095                            CoreStateHost&,
0096                            PrimaryStateData<MemSpace::host> const&) const;
0097     void process_primaries(CoreParams const&,
0098                            CoreStateDevice&,
0099                            PrimaryStateData<MemSpace::device> const&) const;
0100 };
0101 
0102 template<MemSpace M>
0103 struct PrimaryStateData : public AuxStateInterface
0104 {
0105     // "Resizable" storage
0106     Collection<Primary, Ownership::value, M> storage;
0107     size_type count{0};
0108 
0109     //! Access valid range of primaries
0110     auto primaries()
0111     {
0112         return this->storage[ItemRange<Primary>{ItemId<Primary>{this->count}}];
0113     }
0114 
0115     //! Access valid range of primaries (const)
0116     auto primaries() const
0117     {
0118         return this->storage[ItemRange<Primary>{ItemId<Primary>{this->count}}];
0119     }
0120 };
0121 
0122 //---------------------------------------------------------------------------//
0123 }  // namespace celeritas