Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-12 08:36:34

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/Types.hh
0006 //! \brief Type definitions for simulation management
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <cstdint>
0011 
0012 #include "corecel/Config.hh"
0013 // IWYU pragma: begin_exports
0014 #include "corecel/Assert.hh"
0015 #include "corecel/Macros.hh"
0016 #include "corecel/OpaqueId.hh"
0017 #include "corecel/Types.hh"
0018 #include "corecel/sys/ThreadId.hh"
0019 #include "geocel/Types.hh"
0020 // IWYU pragma: end_exports
0021 
0022 namespace celeritas
0023 {
0024 //---------------------------------------------------------------------------//
0025 // TYPE ALIASES
0026 //---------------------------------------------------------------------------//
0027 
0028 //! Opaque index to ElementRecord in the global vector of elements
0029 using ElementId = OpaqueId<struct ElementRecord>;
0030 
0031 //! Zero-indexed counter for the initiating event for a track
0032 using EventId = OpaqueId<struct Event_>;
0033 
0034 //! Unique identifier for an event used by external applications
0035 using UniqueEventId = OpaqueId<struct Event_, std::uint64_t>;
0036 
0037 //! Opaque index to IsotopeRecord in a vector
0038 using IsotopeId = OpaqueId<struct IsotopeRecord>;
0039 
0040 //! Opaque index of a material modified by physics options
0041 using PhysMatId = OpaqueId<struct PhysicsMaterial_>;
0042 
0043 //! Opaque index of model in the list of physics processes
0044 using ModelId = OpaqueId<struct Model_>;
0045 
0046 //! Opaque index to a material with optical properties
0047 using OptMatId = OpaqueId<struct OpticalMaterial_>;
0048 
0049 //! Opaque index to ParticleRecord in a vector: represents a particle type
0050 using ParticleId = OpaqueId<struct Particle_>;
0051 
0052 //! Unique ID (for an event) of a track among all primaries
0053 using PrimaryId = OpaqueId<struct Primary_>;
0054 
0055 //! Opaque index of physics process
0056 using ProcessId = OpaqueId<struct Process_>;
0057 
0058 //! Unique ID (for an event) of a track among all primaries and secondaries
0059 using TrackId = OpaqueId<struct Track_>;
0060 
0061 //---------------------------------------------------------------------------//
0062 // (detailed type aliases)
0063 //---------------------------------------------------------------------------//
0064 
0065 //! Opaque index of particle-nucleon cascade channel
0066 using ChannelId = OpaqueId<struct Channel_>;
0067 
0068 //! Opaque index for mapping volume-specific "sensitive detector" objects
0069 using DetectorId = OpaqueId<struct Detector_>;
0070 
0071 //! Opaque index to one elemental component datum in a particular material
0072 using ElementComponentId = OpaqueId<struct MatElementComponent>;
0073 
0074 //! Opaque index to one isotopic component datum in a particular element
0075 using IsotopeComponentId = OpaqueId<struct ElIsotopeComponent>;
0076 
0077 //! Opaque index of a process applicable to a single particle type
0078 using ParticleProcessId = OpaqueId<ProcessId>;
0079 
0080 //! Opaque index of a model applicable to a single particle type
0081 using ParticleModelId = OpaqueId<ModelId>;
0082 
0083 //! Opaque index of electron subshell
0084 using SubshellId = OpaqueId<struct Subshell_>;
0085 
0086 //! Opaque index of a uniform grid
0087 using UniformGridId = OpaqueId<struct UniformGridRecord>;
0088 
0089 //! Opaque index of a cross section grid
0090 using XsGridId = OpaqueId<struct XsGridRecord>;
0091 
0092 //---------------------------------------------------------------------------//
0093 // ENUMERATIONS
0094 //---------------------------------------------------------------------------//
0095 //! Physical state of matter
0096 enum class MatterState
0097 {
0098     unspecified = 0,
0099     solid,
0100     liquid,
0101     gas,
0102     size_
0103 };
0104 
0105 //---------------------------------------------------------------------------//
0106 /*!
0107  * Whether a track slot is alive, inactive, or dying inside a step iteration.
0108  *
0109  * Each track slot has a state marking its transition between death and life.
0110  *
0111  * - A track slot starts as \c inactive . If not filled with a new track, it is
0112  *   inactive for the rest of the step iteration.
0113  * - When it is populated with a new particle, it is \c initializing . If an
0114  *   error occurs during initialization it is \c errored .
0115  * - During the pre-step setup, a non-errored active track slot is marked as \c
0116  *   alive .
0117  * - During along-step or post-step a track can be marked as \c errored or
0118  *   \c killed .
0119  */
0120 enum class TrackStatus : std::uint_least8_t
0121 {
0122     inactive = 0,  //!< No tracking in this thread slot
0123     initializing,  //!< Before pre-step, after initialization
0124     alive,  //!< Track is active and alive
0125     begin_dying_,
0126     errored = begin_dying_,  //!< Track failed during this step
0127     killed,  //!< Killed physically inside the step
0128     size_
0129 };
0130 
0131 //---------------------------------------------------------------------------//
0132 //! Differentiate between result data at the beginning and end of a step.
0133 enum class StepPoint
0134 {
0135     pre,
0136     post,
0137     size_
0138 };
0139 
0140 //---------------------------------------------------------------------------//
0141 /*!
0142  * Change the ordering or thread mapping of track slots.
0143  *
0144  * There are three categories of track sorting:
0145  * 1. No sorting is performed and new tracks are inserted in the nearest empty
0146  *    track slot. (\c none )
0147  * 2. The location of new track slots is biased during track initialization:
0148  *    charged and neutral tracks are inserted at opposite sides of the track
0149  *    slot vacancies. (\c init_charge )
0150  * 3. Tracks are \em reindexed one or more times per step so that the layout
0151  *    in memory is unchanged but an additional indirection maps threads onto
0152  *    different track slots based on particle attributes (\c reindex_status,
0153  *    \c reindex_particle_type ), actions (\c reindex_along_step_action,
0154  *    \c reindex_step_limit_action, \c reindex_both_action ).
0155  * 4. As a control to measure the cost of indirection, the track slots can be
0156  *    reindexed randomly at the beginning of execution (\c reindex_shuffle ).
0157  */
0158 enum class TrackOrder
0159 {
0160     none,  //!< Don't do any sorting: tracks are in an arbitrary order
0161     begin_layout_,
0162     //! Partition data layout of new tracks by charged vs neutral
0163     init_charge = begin_layout_,
0164     end_layout_,
0165     begin_reindex_ = end_layout_,
0166     //!< Shuffle at the start of the simulation
0167     reindex_shuffle = begin_reindex_,
0168     reindex_status,  //!< Partition by active/inactive status
0169     reindex_particle_type,  //!< Sort by particle type
0170     begin_reindex_action_,
0171     //! Sort only by the along-step action id
0172     reindex_along_step_action = begin_reindex_action_,
0173     reindex_step_limit_action,  //!< Sort only by the step limit action id
0174     reindex_both_action,  //!< Sort by along-step id, then post-step ID
0175     end_reindex_action_,
0176     end_reindex_ = end_reindex_action_,
0177     size_ = end_reindex_
0178 };
0179 
0180 //---------------------------------------------------------------------------//
0181 //! Algorithm used to calculate the multiple scattering step limit
0182 enum class MscStepLimitAlgorithm
0183 {
0184     minimal,
0185     safety,
0186     safety_plus,
0187     distance_to_boundary,
0188     size_,
0189 };
0190 
0191 //---------------------------------------------------------------------------//
0192 //! Nuclear form factor model for Coulomb scattering
0193 enum class NuclearFormFactorType
0194 {
0195     none,
0196     flat,
0197     exponential,
0198     gaussian,
0199     size_
0200 };
0201 
0202 //---------------------------------------------------------------------------//
0203 //! Optical photon wavelength shifting time model
0204 enum class WlsTimeProfile
0205 {
0206     delta,  //!< Delta function
0207     exponential,  //!< Exponential decay
0208     size_
0209 };
0210 
0211 //---------------------------------------------------------------------------//
0212 //! Interpolation for physics grids
0213 enum class InterpolationType
0214 {
0215     linear,
0216     poly_spline,  //!< Piecewise polynomial interpolation
0217     cubic_spline,  //!< Cubic spline interpolation with \f$ C^2 \f$ continuity
0218     size_
0219 };
0220 
0221 //---------------------------------------------------------------------------//
0222 //! Cylindrical coordinates indices
0223 enum class CylAxis
0224 {
0225     r = 0,
0226     phi,
0227     z,
0228     size_
0229 };
0230 
0231 //---------------------------------------------------------------------------//
0232 // HELPER STRUCTS
0233 //---------------------------------------------------------------------------//
0234 //! Step length and limiting action to take
0235 struct StepLimit
0236 {
0237     real_type step{};
0238     ActionId action{};
0239 
0240     //! Whether a step limit has been determined
0241     explicit CELER_FUNCTION operator bool() const
0242     {
0243         CELER_ASSERT(step >= 0);
0244         return static_cast<bool>(action);
0245     }
0246 };
0247 
0248 //---------------------------------------------------------------------------//
0249 // HELPER FUNCTIONS
0250 //---------------------------------------------------------------------------//
0251 
0252 //! Whether a track is in a consistent, valid state
0253 CELER_CONSTEXPR_FUNCTION bool is_track_valid(TrackStatus status)
0254 {
0255     return status != TrackStatus::inactive && status != TrackStatus::errored;
0256 }
0257 
0258 //---------------------------------------------------------------------------//
0259 // HELPER FUNCTIONS (HOST)
0260 //---------------------------------------------------------------------------//
0261 
0262 // Get a string corresponding to a material state
0263 char const* to_cstring(MatterState);
0264 
0265 // Get a string corresponding to a track stats
0266 char const* to_cstring(TrackStatus);
0267 
0268 // Get a string corresponding to a track ordering policy
0269 char const* to_cstring(TrackOrder);
0270 
0271 // Get a string corresponding to the MSC step limit algorithm
0272 char const* to_cstring(MscStepLimitAlgorithm value);
0273 
0274 // Get a string corresponding to the nuclear form factor model
0275 char const* to_cstring(NuclearFormFactorType value);
0276 
0277 // Get a string corresponding to the interpolation method
0278 char const* to_cstring(InterpolationType value);
0279 
0280 //---------------------------------------------------------------------------//
0281 }  // namespace celeritas