Back to home page

EIC code displayed by LXR

 
 

    


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

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/TrackInitData.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Types.hh"
0011 #include "corecel/cont/Range.hh"
0012 #include "corecel/data/Collection.hh"
0013 #include "corecel/data/CollectionAlgorithms.hh"
0014 #include "corecel/data/CollectionBuilder.hh"
0015 #include "corecel/sys/Device.hh"
0016 #include "corecel/sys/ThreadId.hh"
0017 #include "celeritas/Types.hh"
0018 #include "celeritas/optical/TrackInitializer.hh"
0019 
0020 namespace celeritas
0021 {
0022 namespace optical
0023 {
0024 //---------------------------------------------------------------------------//
0025 /*!
0026  * Persistent data for optical track initialization.
0027  */
0028 template<Ownership W, MemSpace M>
0029 struct TrackInitParamsData
0030 {
0031     size_type capacity{0};  //!< Optical primary buffer storage size
0032 
0033     //// METHODS ////
0034 
0035     //! Whether the data are assigned
0036     explicit CELER_FUNCTION operator bool() const { return capacity > 0; }
0037 
0038     //! Assign from another set of data
0039     template<Ownership W2, MemSpace M2>
0040     TrackInitParamsData& operator=(TrackInitParamsData<W2, M2> const& other)
0041     {
0042         CELER_EXPECT(other);
0043         capacity = other.capacity;
0044         return *this;
0045     }
0046 };
0047 
0048 //---------------------------------------------------------------------------//
0049 /*!
0050  * Storage for dynamic data used to initialize new optical photon tracks.
0051  *
0052  * - \c initializers stores the data for track initializers and secondaries
0053  *   waiting to be turned into new tracks and can be any size up to \c
0054  *   capacity.
0055  * - \c vacancies stores the \c TrackSlotid of the tracks that have been
0056  *   killed; the size will be <= the number of track states.
0057  */
0058 template<Ownership W, MemSpace M>
0059 struct TrackInitStateData
0060 {
0061     //// TYPES ////
0062 
0063     template<class T>
0064     using StateItems = StateCollection<T, W, M>;
0065     template<class T>
0066     using Items = Collection<T, W, M>;
0067 
0068     //// DATA ////
0069 
0070     Items<TrackInitializer> initializers;
0071     StateItems<TrackSlotId> vacancies;
0072 
0073     //// METHODS ////
0074 
0075     //! Whether the data are assigned
0076     explicit CELER_FUNCTION operator bool() const
0077     {
0078         return !initializers.empty() && !vacancies.empty();
0079     }
0080 
0081     //! Assign from another set of data
0082     template<Ownership W2, MemSpace M2>
0083     TrackInitStateData& operator=(TrackInitStateData<W2, M2>& other)
0084     {
0085         CELER_EXPECT(other);
0086 
0087         initializers = other.initializers;
0088         vacancies = other.vacancies;
0089 
0090         return *this;
0091     }
0092 };
0093 
0094 //---------------------------------------------------------------------------//
0095 /*!
0096  * Resize and initialize data.
0097  *
0098  * Here \c size is the number of track states, and the "capacity" is the
0099  * maximum number of initializers that can be buffered.
0100  */
0101 template<MemSpace M>
0102 void resize(TrackInitStateData<Ownership::value, M>* data,
0103             HostCRef<TrackInitParamsData> const& params,
0104             StreamId stream,
0105             size_type size)
0106 {
0107     CELER_EXPECT(params);
0108     CELER_EXPECT(size > 0);
0109 
0110     resize(&data->initializers, params.capacity);
0111     resize(&data->vacancies, size);
0112 
0113     // Initialize vacancies to mark all track slots as empty
0114     fill_sequence(&data->vacancies, stream);
0115 
0116     CELER_ENSURE(*data);
0117 }
0118 
0119 //---------------------------------------------------------------------------//
0120 
0121 }  // namespace optical
0122 }  // namespace celeritas