Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/celeritas/optical/TrackInitData.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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/TrackInitData.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Types.hh"
0010 #include "corecel/cont/Range.hh"
0011 #include "corecel/data/Collection.hh"
0012 #include "corecel/data/CollectionAlgorithms.hh"
0013 #include "corecel/data/CollectionBuilder.hh"
0014 #include "corecel/sys/Device.hh"
0015 #include "corecel/sys/ThreadId.hh"
0016 #include "celeritas/Types.hh"
0017 #include "celeritas/track/CoreStateCounters.hh"
0018 
0019 #include "TrackInitializer.hh"
0020 
0021 namespace celeritas
0022 {
0023 namespace optical
0024 {
0025 //---------------------------------------------------------------------------//
0026 /*!
0027  * Storage for dynamic data used to initialize new optical photon tracks.
0028  *
0029  * - \c initializers stores the data for track initializers and secondaries
0030  *   waiting to be turned into new tracks and can be any size up to \c
0031  *   capacity.
0032  * - \c vacancies stores the \c TrackSlotId of the tracks that have been
0033  *   killed; the size will be <= the number of track states.
0034  * - \c counters stores the number of tracks with a given status and is updated
0035  *   during each step of the simulation of an event.
0036  */
0037 template<Ownership W, MemSpace M>
0038 struct TrackInitStateData
0039 {
0040     //// TYPES ////
0041 
0042     template<class T>
0043     using StateItems = StateCollection<T, W, M>;
0044     template<class T>
0045     using Items = Collection<T, W, M>;
0046 
0047     //// DATA ////
0048 
0049     StateItems<TrackSlotId> vacancies;
0050 
0051     // Maintain the counters here to allow device-resident computation with
0052     // synchronization between host and device only at the end of a step or
0053     // when explicitly requested, such as in the tests
0054     Items<CoreStateCounters> counters;
0055 
0056     //// METHODS ////
0057 
0058     //! Whether the data are assigned
0059     explicit CELER_FUNCTION operator bool() const
0060     {
0061         return !vacancies.empty() && !counters.empty();
0062     }
0063 
0064     //! Assign from another set of data
0065     template<Ownership W2, MemSpace M2>
0066     TrackInitStateData& operator=(TrackInitStateData<W2, M2>& other)
0067     {
0068         CELER_EXPECT(other);
0069         vacancies = other.vacancies;
0070         counters = other.counters;
0071         return *this;
0072     }
0073 };
0074 
0075 //---------------------------------------------------------------------------//
0076 /*!
0077  * Resize and initialize data.
0078  *
0079  * Here \c size is the number of track states, and the "capacity" is the
0080  * maximum number of initializers that can be buffered.
0081  */
0082 template<MemSpace M>
0083 void resize(TrackInitStateData<Ownership::value, M>* data,
0084             StreamId stream,
0085             size_type size)
0086 {
0087     CELER_EXPECT(size > 0);
0088 
0089     // Initialize vacancies to mark all track slots as empty
0090     resize(&data->vacancies, size);
0091     fill_sequence(&data->vacancies, stream);
0092 
0093     // Initialize the counters for the step to zero
0094     resize(&data->counters, 1);
0095     fill(CoreStateCounters{}, &data->counters);
0096 
0097     CELER_ENSURE(*data);
0098 }
0099 
0100 //---------------------------------------------------------------------------//
0101 
0102 }  // namespace optical
0103 }  // namespace celeritas