Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:48

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 //! Opaque index of physics process
0053 using ProcessId = OpaqueId<struct Process_>;
0054 
0055 //! Unique ID (for an event) of a track among all primaries and secondaries
0056 using TrackId = OpaqueId<struct Track_>;
0057 
0058 //---------------------------------------------------------------------------//
0059 // (detailed type aliases)
0060 //---------------------------------------------------------------------------//
0061 
0062 //! Opaque index of particle-nucleon cascade channel
0063 using ChannelId = OpaqueId<struct Channel_>;
0064 
0065 //! Opaque index for mapping volume-specific "sensitive detector" objects
0066 using DetectorId = OpaqueId<struct Detector_>;
0067 
0068 //! Opaque index to one elemental component datum in a particular material
0069 using ElementComponentId = OpaqueId<struct MatElementComponent>;
0070 
0071 //! Opaque index to one isotopic component datum in a particular element
0072 using IsotopeComponentId = OpaqueId<struct ElIsotopeComponent>;
0073 
0074 //! Opaque index of a process applicable to a single particle type
0075 using ParticleProcessId = OpaqueId<ProcessId>;
0076 
0077 //! Opaque index of a model applicable to a single particle type
0078 using ParticleModelId = OpaqueId<ModelId>;
0079 
0080 //! Opaque index of electron subshell
0081 using SubshellId = OpaqueId<struct Subshell_>;
0082 
0083 //---------------------------------------------------------------------------//
0084 // ENUMERATIONS
0085 //---------------------------------------------------------------------------//
0086 //! Physical state of matter
0087 enum class MatterState
0088 {
0089     unspecified = 0,
0090     solid,
0091     liquid,
0092     gas,
0093     size_
0094 };
0095 
0096 //---------------------------------------------------------------------------//
0097 /*!
0098  * Whether a track slot is alive, inactive, or dying inside a step iteration.
0099  *
0100  * Each track slot has a state marking its transition between death and life.
0101  *
0102  * - A track slot starts as \c inactive . If not filled with a new track, it is
0103  *   inactive for the rest of the step iteration.
0104  * - When it is populated with a new particle, it is \c initializing . If an
0105  *   error occurs during initialization it is \c errored .
0106  * - During the pre-step setup, a non-errored active track slot is marked as \c
0107  *   alive .
0108  * - During along-step or post-step a track can be marked as \c errored or
0109  *   \c killed .
0110  */
0111 enum class TrackStatus : std::uint_least8_t
0112 {
0113     inactive = 0,  //!< No tracking in this thread slot
0114     initializing,  //!< Before pre-step, after initialization
0115     alive,  //!< Track is active and alive
0116     begin_dying_,
0117     errored = begin_dying_,  //!< Track failed during this step
0118     killed,  //!< Killed physically inside the step
0119     size_
0120 };
0121 
0122 //---------------------------------------------------------------------------//
0123 //! Differentiate between result data at the beginning and end of a step.
0124 enum class StepPoint
0125 {
0126     pre,
0127     post,
0128     size_
0129 };
0130 
0131 //---------------------------------------------------------------------------//
0132 /*!
0133  * Change the ordering or thread mapping of track slots.
0134  *
0135  * There are three categories of track sorting:
0136  * 1. No sorting is performed and new tracks are inserted in the nearest empty
0137  *    track slot. (\c none )
0138  * 2. The location of new track slots is biased during track initialization:
0139  *    charged and neutral tracks are inserted at opposite sides of the track
0140  *    slot vacancies. (\c init_charge )
0141  * 3. Tracks are \em reindexed one or more times per step so that the layout
0142  *    in memory is unchanged but an additional indirection maps threads onto
0143  *    different track slots based on particle attributes (\c reindex_status,
0144  *    \c reindex_particle_type ), actions (\c reindex_along_step_action,
0145  *    \c reindex_step_limit_action, \c reindex_both_action ).
0146  * 4. As a control to measure the cost of indirection, the track slots can be
0147  *    reindexed randomly at the beginning of execution (\c reindex_shuffle ).
0148  */
0149 enum class TrackOrder
0150 {
0151     none,  //!< Don't do any sorting: tracks are in an arbitrary order
0152     begin_layout_,
0153     //! Partition data layout of new tracks by charged vs neutral
0154     init_charge = begin_layout_,
0155     end_layout_,
0156     begin_reindex_ = end_layout_,
0157     //!< Shuffle at the start of the simulation
0158     reindex_shuffle = begin_reindex_,
0159     reindex_status,  //!< Partition by active/inactive status
0160     reindex_particle_type,  //!< Sort by particle type
0161     begin_reindex_action_,
0162     //! Sort only by the along-step action id
0163     reindex_along_step_action = begin_reindex_action_,
0164     reindex_step_limit_action,  //!< Sort only by the step limit action id
0165     reindex_both_action,  //!< Sort by along-step id, then post-step ID
0166     end_reindex_action_,
0167     end_reindex_ = end_reindex_action_,
0168     size_ = end_reindex_
0169 };
0170 
0171 //---------------------------------------------------------------------------//
0172 //! Algorithm used to calculate the multiple scattering step limit
0173 enum class MscStepLimitAlgorithm
0174 {
0175     minimal,
0176     safety,
0177     safety_plus,
0178     distance_to_boundary,
0179     size_,
0180 };
0181 
0182 //---------------------------------------------------------------------------//
0183 //! Nuclear form factor model for Coulomb scattering
0184 enum class NuclearFormFactorType
0185 {
0186     none,
0187     flat,
0188     exponential,
0189     gaussian,
0190     size_
0191 };
0192 
0193 //---------------------------------------------------------------------------//
0194 //! Interpolation for physics grids
0195 enum class InterpolationType
0196 {
0197     linear,
0198     poly_spline,  //!< Piecewise polynomial interpolation
0199     cubic_spline,  //!< Cubic spline interpolation with \f$ C^2 \f$ continuity
0200     size_
0201 };
0202 
0203 //---------------------------------------------------------------------------//
0204 //! Cylindrical coordinates indices
0205 enum class CylAxis
0206 {
0207     r = 0,
0208     phi,
0209     z,
0210     size_
0211 };
0212 
0213 //---------------------------------------------------------------------------//
0214 // HELPER STRUCTS
0215 //---------------------------------------------------------------------------//
0216 //! Step length and limiting action to take
0217 struct StepLimit
0218 {
0219     real_type step{};
0220     ActionId action{};
0221 
0222     //! Whether a step limit has been determined
0223     explicit CELER_FUNCTION operator bool() const
0224     {
0225         CELER_ASSERT(step >= 0);
0226         return static_cast<bool>(action);
0227     }
0228 };
0229 
0230 //---------------------------------------------------------------------------//
0231 // HELPER FUNCTIONS
0232 //---------------------------------------------------------------------------//
0233 
0234 //! Whether a track is in a consistent, valid state
0235 CELER_CONSTEXPR_FUNCTION bool is_track_valid(TrackStatus status)
0236 {
0237     return status != TrackStatus::inactive && status != TrackStatus::errored;
0238 }
0239 
0240 //---------------------------------------------------------------------------//
0241 // HELPER FUNCTIONS (HOST)
0242 //---------------------------------------------------------------------------//
0243 
0244 // Get a string corresponding to a material state
0245 char const* to_cstring(MatterState);
0246 
0247 // Get a string corresponding to a track stats
0248 char const* to_cstring(TrackStatus);
0249 
0250 // Get a string corresponding to a track ordering policy
0251 char const* to_cstring(TrackOrder);
0252 
0253 // Get a string corresponding to the MSC step limit algorithm
0254 char const* to_cstring(MscStepLimitAlgorithm value);
0255 
0256 // Get a string corresponding to the nuclear form factor model
0257 char const* to_cstring(NuclearFormFactorType value);
0258 
0259 // Get a string corresponding to the interpolation method
0260 char const* to_cstring(InterpolationType value);
0261 
0262 //---------------------------------------------------------------------------//
0263 }  // namespace celeritas