![]() |
|
|||
File indexing completed on 2025-02-22 10:31:29
0001 //----------------------------------*-C++-*----------------------------------// 0002 // Copyright 2020-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/phys/ParticleData.hh 0007 //---------------------------------------------------------------------------// 0008 #pragma once 0009 0010 #include "corecel/Macros.hh" 0011 #include "corecel/data/Collection.hh" 0012 #include "corecel/data/CollectionBuilder.hh" 0013 #include "corecel/sys/ThreadId.hh" 0014 #include "celeritas/Quantities.hh" 0015 #include "celeritas/Types.hh" 0016 0017 namespace celeritas 0018 { 0019 //---------------------------------------------------------------------------// 0020 // PARAMS 0021 //---------------------------------------------------------------------------// 0022 0023 enum class MatterType : char 0024 { 0025 particle, 0026 antiparticle 0027 }; 0028 0029 //---------------------------------------------------------------------------// 0030 /*! 0031 * Access particle definitions on the device. 0032 * 0033 * Fundamental (static) properties of a particle type. Physical state of a 0034 * particle (kinetic energy, ...) is part of a ParticleState. This view is 0035 * created from \c ParticleParams. The size of the \c defs data member is the 0036 * number of particle types (accessed by \c ParticleId). 0037 * 0038 * \sa ParticleParams (owns the pointed-to data) 0039 * \sa ParticleTrackView (uses the pointed-to data in a kernel) 0040 */ 0041 template<Ownership W, MemSpace M> 0042 struct ParticleParamsData 0043 { 0044 //// TYPES //// 0045 0046 template<class T> 0047 using Items = Collection<T, W, M, ParticleId>; 0048 0049 //// DATA //// 0050 0051 Items<units::MevMass> mass; //!< Rest mass [MeV / c^2] 0052 Items<units::ElementaryCharge> charge; //!< Charge in units of [e] 0053 Items<real_type> decay_constant; //!< Decay constant [1/s] 0054 Items<MatterType> matter; //!< Antiparticle flag (negative PDG number) 0055 0056 //// METHODS //// 0057 0058 //! Whether the data is assigned 0059 explicit CELER_FUNCTION operator bool() const 0060 { 0061 return !mass.empty() && !charge.empty() && !decay_constant.empty() 0062 && !matter.empty(); 0063 } 0064 0065 //! Number of particles 0066 CELER_FUNCTION ParticleId::size_type size() const 0067 { 0068 return decay_constant.size(); 0069 } 0070 0071 //! Assign from another set of data 0072 template<Ownership W2, MemSpace M2> 0073 ParticleParamsData& operator=(ParticleParamsData<W2, M2> const& other) 0074 { 0075 CELER_EXPECT(other); 0076 mass = other.mass; 0077 charge = other.charge; 0078 decay_constant = other.decay_constant; 0079 matter = other.matter; 0080 return *this; 0081 } 0082 }; 0083 0084 //---------------------------------------------------------------------------// 0085 // STATE 0086 //---------------------------------------------------------------------------// 0087 /*! 0088 * Physical (dynamic) state of a particle track. 0089 * 0090 * The "physical state" is just about what differentiates this particle from 0091 * another (type, energy, polarization, ...) in the lab's inertial reference 0092 * frame. It does not include information about the particle's direction or 0093 * position, nor about path lengths or collisions. 0094 * 0095 * The energy is with respect to the lab frame. The particle state is 0096 * immutable: collisions and other interactions should return changes to the 0097 * particle state. 0098 */ 0099 0100 struct ParticleTrackInitializer 0101 { 0102 ParticleId particle_id; //!< Type of particle (electron, gamma, ...) 0103 units::MevEnergy energy; //!< Kinetic energy [MeV] 0104 0105 //! True if assigned and valid 0106 explicit CELER_FUNCTION operator bool() const 0107 { 0108 return particle_id && energy > zero_quantity(); 0109 } 0110 }; 0111 0112 //---------------------------------------------------------------------------// 0113 /*! 0114 * Data storage/access for particle properties. 0115 * 0116 * \sa ParticleTrackView (uses the pointed-to data in a kernel) 0117 */ 0118 template<Ownership W, MemSpace M> 0119 struct ParticleStateData 0120 { 0121 //// TYPES //// 0122 0123 template<class T> 0124 using Items = celeritas::StateCollection<T, W, M>; 0125 0126 //// DATA //// 0127 0128 Items<ParticleId> particle_id; //!< Type of particle (electron, gamma, 0129 //!< ...) 0130 Items<real_type> particle_energy; //!< Kinetic energy [MeV] 0131 0132 //// METHODS //// 0133 0134 //! Whether the interface is assigned 0135 explicit CELER_FUNCTION operator bool() const 0136 { 0137 return !particle_id.empty() && !particle_energy.empty(); 0138 } 0139 0140 //! State size 0141 CELER_FUNCTION TrackSlotId::size_type size() const 0142 { 0143 return particle_id.size(); 0144 } 0145 0146 //! Assign from another set of data 0147 template<Ownership W2, MemSpace M2> 0148 ParticleStateData& operator=(ParticleStateData<W2, M2>& other) 0149 { 0150 CELER_EXPECT(other); 0151 particle_id = other.particle_id; 0152 particle_energy = other.particle_energy; 0153 return *this; 0154 } 0155 }; 0156 0157 //---------------------------------------------------------------------------// 0158 /*! 0159 * Resize particle states in host code. 0160 */ 0161 template<MemSpace M> 0162 inline void resize(ParticleStateData<Ownership::value, M>* data, 0163 HostCRef<ParticleParamsData> const&, 0164 size_type size) 0165 { 0166 CELER_EXPECT(size > 0); 0167 resize(&data->particle_id, size); 0168 resize(&data->particle_energy, size); 0169 } 0170 0171 //---------------------------------------------------------------------------// 0172 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |