Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-07 10:01:43

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/OffloadData.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <vector>
0010 
0011 #include "corecel/Macros.hh"
0012 #include "corecel/Types.hh"
0013 #include "corecel/data/Collection.hh"
0014 #include "corecel/data/CollectionBuilder.hh"
0015 #include "celeritas/Quantities.hh"
0016 #include "celeritas/Types.hh"
0017 #include "celeritas/phys/GeneratorCounters.hh"
0018 
0019 namespace celeritas
0020 {
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * Cumulative statistics of optical tracking.
0024  */
0025 struct OpticalAccumStats
0026 {
0027     using size_type = std::size_t;
0028     using OpticalBufferSize = GeneratorCounters<size_type>;
0029 
0030     std::vector<OpticalBufferSize> generators;
0031 
0032     size_type steps{0};
0033     size_type step_iters{0};
0034     size_type flushes{0};
0035 };
0036 
0037 //---------------------------------------------------------------------------//
0038 /*!
0039  * Pre-step data needed to generate optical photon distributions.
0040  *
0041  * If the optical material is not set, the other properties are invalid.
0042  */
0043 struct OffloadPreStepData
0044 {
0045     units::LightSpeed speed;
0046     Real3 pos{};
0047     real_type time{};
0048     OptMatId material;
0049 
0050     //! Check whether the data are assigned
0051     explicit CELER_FUNCTION operator bool() const
0052     {
0053         return material && speed > zero_quantity();
0054     }
0055 };
0056 
0057 //---------------------------------------------------------------------------//
0058 /*!
0059  * Pre-step data that is cached and used to generate optical distributions.
0060  */
0061 template<Ownership W, MemSpace M>
0062 struct OffloadStepStateData
0063 {
0064     //// TYPES ////
0065 
0066     template<class T>
0067     using StateItems = StateCollection<T, W, M>;
0068 
0069     //// DATA ////
0070 
0071     // Pre-step data for generating optical photon distributions
0072     StateItems<OffloadPreStepData> step;
0073 
0074     //// METHODS ////
0075 
0076     //! Number of states
0077     CELER_FUNCTION size_type size() const { return step.size(); }
0078 
0079     //! Whether all data are assigned and valid
0080     explicit CELER_FUNCTION operator bool() const { return !step.empty(); }
0081 
0082     //! Assign from another set of data
0083     template<Ownership W2, MemSpace M2>
0084     OffloadStepStateData& operator=(OffloadStepStateData<W2, M2>& other)
0085     {
0086         CELER_EXPECT(other);
0087         step = other.step;
0088         return *this;
0089     }
0090 };
0091 
0092 //---------------------------------------------------------------------------//
0093 /*!
0094  * Resize optical step states.
0095  */
0096 template<MemSpace M>
0097 void resize(OffloadStepStateData<Ownership::value, M>* state,
0098             StreamId,
0099             size_type size)
0100 {
0101     CELER_EXPECT(size > 0);
0102     resize(&state->step, size);
0103     CELER_ENSURE(*state);
0104 }
0105 
0106 //---------------------------------------------------------------------------//
0107 }  // namespace celeritas