Back to home page

EIC code displayed by LXR

 
 

    


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

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