Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 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/optical/action/detail/InitTracksExecutor.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Assert.hh"
0011 #include "corecel/Macros.hh"
0012 #include "celeritas/Types.hh"
0013 #include "celeritas/optical/CoreTrackData.hh"
0014 #include "celeritas/optical/CoreTrackView.hh"
0015 #include "celeritas/track/CoreStateCounters.hh"
0016 
0017 namespace celeritas
0018 {
0019 namespace optical
0020 {
0021 namespace detail
0022 {
0023 //---------------------------------------------------------------------------//
0024 /*!
0025  * Initialize the track states.
0026  *
0027  * The track initializers are created from either primary particles or
0028  * secondaries. The new tracks are inserted into the vacancies in the track
0029  * vector.
0030  */
0031 struct InitTracksExecutor
0032 {
0033     //// TYPES ////
0034 
0035     using ParamsPtr = CRefPtr<CoreParamsData, MemSpace::native>;
0036     using StatePtr = RefPtr<CoreStateData, MemSpace::native>;
0037 
0038     //// DATA ////
0039 
0040     ParamsPtr params;
0041     StatePtr state;
0042     CoreStateCounters counters;
0043 
0044     //// FUNCTIONS ////
0045 
0046     // Initialize track states
0047     inline CELER_FUNCTION void operator()(TrackSlotId tid) const;
0048 
0049     CELER_FORCEINLINE_FUNCTION void operator()(ThreadId tid) const
0050     {
0051         return (*this)(TrackSlotId{tid.unchecked_get()});
0052     }
0053 };
0054 
0055 //---------------------------------------------------------------------------//
0056 /*!
0057  * Initialize the track states.
0058  */
0059 CELER_FUNCTION void InitTracksExecutor::operator()(TrackSlotId tid) const
0060 {
0061     CELER_EXPECT(tid < counters.num_initializers);
0062     CELER_EXPECT(tid < counters.num_vacancies);
0063 
0064     // Create the view to the new track to be initialized
0065     CoreTrackView vacancy{*params, *state, state->init.vacancies[tid]};
0066 
0067     // Get the initializer from the back of the vector and initialize the track
0068     vacancy = state->init.initializers[ItemId<TrackInitializer>(
0069         counters.num_initializers - tid.get() - 1)];
0070 }
0071 
0072 //---------------------------------------------------------------------------//
0073 }  // namespace detail
0074 }  // namespace optical
0075 }  // namespace celeritas