Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:09:16

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/user/ParticleTallyData.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 #include "corecel/data/Collection.hh"
0011 
0012 namespace celeritas
0013 {
0014 //---------------------------------------------------------------------------//
0015 /*!
0016  * Shared diagnostic attributes.
0017  */
0018 template<Ownership W, MemSpace M>
0019 struct ParticleTallyParamsData
0020 {
0021     //// DATA ////
0022 
0023     //! Number of tally bins
0024     size_type num_bins{0};
0025     //! Number of particle types
0026     size_type num_particles{0};
0027 
0028     //// METHODS ////
0029 
0030     //! Whether the data is assigned
0031     explicit CELER_FUNCTION operator bool() const
0032     {
0033         return num_bins > 0 && num_particles > 0;
0034     }
0035 
0036     //! Assign from another set of data
0037     template<Ownership W2, MemSpace M2>
0038     ParticleTallyParamsData&
0039     operator=(ParticleTallyParamsData<W2, M2> const& other)
0040     {
0041         CELER_EXPECT(other);
0042         num_bins = other.num_bins;
0043         num_particles = other.num_particles;
0044         return *this;
0045     }
0046 };
0047 
0048 //---------------------------------------------------------------------------//
0049 /*!
0050  * State data for accumulating results for each particle type.
0051  *
0052  * \c counts is indexed as particle_id * num_bins + bin_index.
0053  */
0054 template<Ownership W, MemSpace M>
0055 struct ParticleTallyStateData
0056 {
0057     //// TYPES ////
0058 
0059     template<class T>
0060     using Items = Collection<T, W, M>;
0061 
0062     //// DATA ////
0063 
0064     Items<size_type> counts;
0065 
0066     //// METHODS ////
0067 
0068     //! Number of states
0069     CELER_FUNCTION size_type size() const { return counts.size(); }
0070 
0071     //! Whether the data is assigned
0072     explicit CELER_FUNCTION operator bool() const { return !counts.empty(); }
0073 
0074     //! Assign from another set of states
0075     template<Ownership W2, MemSpace M2>
0076     ParticleTallyStateData& operator=(ParticleTallyStateData<W2, M2>& other)
0077     {
0078         CELER_EXPECT(other);
0079         counts = other.counts;
0080         return *this;
0081     }
0082 };
0083 
0084 //---------------------------------------------------------------------------//
0085 // HELPER FUNCTIONS
0086 //---------------------------------------------------------------------------//
0087 // Resize based on number of bins and particle types
0088 template<MemSpace M>
0089 void resize(ParticleTallyStateData<Ownership::value, M>* state,
0090             HostCRef<ParticleTallyParamsData> const& params,
0091             StreamId,
0092             size_type);
0093 
0094 //---------------------------------------------------------------------------//
0095 }  // namespace celeritas