Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:11:00

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/ParticleData.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011 #include "corecel/cont/Array.hh"
0012 #include "corecel/data/Collection.hh"
0013 #include "corecel/data/CollectionBuilder.hh"
0014 #include "celeritas/Types.hh"
0015 
0016 namespace celeritas
0017 {
0018 namespace optical
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Storage for dynamic particle data.
0023  */
0024 template<Ownership W, MemSpace M>
0025 struct ParticleStateData
0026 {
0027     //// TYPES ////
0028 
0029     using Real3 = Array<real_type, 3>;
0030     template<class T>
0031     using Items = celeritas::StateCollection<T, W, M>;
0032 
0033     //// DATA ////
0034 
0035     Items<real_type> energy;  //! Kinetic energy [MeV]
0036     Items<Real3> polarization;
0037 
0038     //// METHODS ////
0039 
0040     //! Check whether the interface is assigned
0041     explicit CELER_FUNCTION operator bool() const
0042     {
0043         return !energy.empty() && !polarization.empty();
0044     }
0045 
0046     //! State size
0047     CELER_FUNCTION size_type size() const { return energy.size(); }
0048 
0049     //! Assign from another set of data
0050     template<Ownership W2, MemSpace M2>
0051     ParticleStateData& operator=(ParticleStateData<W2, M2>& other)
0052     {
0053         CELER_EXPECT(other);
0054         energy = other.energy;
0055         polarization = other.polarization;
0056         return *this;
0057     }
0058 };
0059 
0060 //---------------------------------------------------------------------------//
0061 /*!
0062  * Resize particle states.
0063  */
0064 template<MemSpace M>
0065 inline void resize(ParticleStateData<Ownership::value, M>* data, size_type size)
0066 {
0067     CELER_EXPECT(size > 0);
0068     resize(&data->energy, size);
0069     resize(&data->polarization, size);
0070     CELER_ENSURE(*data);
0071 }
0072 
0073 //---------------------------------------------------------------------------//
0074 }  // namespace optical
0075 }  // namespace celeritas