Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/geocel/Types.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 geocel/Types.hh
0006 //! Shared (VecGeom + ORANGE) geometry type definitions.
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <type_traits>
0011 
0012 #include "corecel/OpaqueId.hh"
0013 #include "corecel/Types.hh"
0014 #include "corecel/cont/Array.hh"
0015 #include "corecel/sys/ThreadId.hh"
0016 
0017 namespace celeritas
0018 {
0019 //---------------------------------------------------------------------------//
0020 // TYPE ALIASES
0021 //---------------------------------------------------------------------------//
0022 
0023 //! Two-dimensional cartesian coordinates
0024 using Real2 = Array<real_type, 2>;
0025 
0026 //! Two-dimensional extents
0027 using Size2 = Array<size_type, 2>;
0028 
0029 //! Alias for a small square dense matrix
0030 template<class T, std::size_t N>
0031 using SquareMatrix = Array<Array<T, N>, N>;
0032 
0033 //! Alias for a small square dense matrix
0034 using SquareMatrixReal3 = SquareMatrix<real_type, 3>;
0035 
0036 //---------------------------------------------------------------------------//
0037 
0038 //! Opaque index for mapping volume-specific "sensitive detector" objects
0039 using DetectorId = OpaqueId<struct Detector_>;
0040 
0041 //! Identifier for a material fill
0042 using GeoMatId = OpaqueId<struct GeoMaterial_>;
0043 
0044 //! Combined boundary/interface surface identifier
0045 using SurfaceId = OpaqueId<struct Surface_, unsigned int>;
0046 
0047 //! Identifier for a canonical geometry volume that may be repeated
0048 using VolumeId = OpaqueId<struct Volume_, unsigned int>;
0049 
0050 //! Identifier for an instance of a geometry volume (aka physical/placed)
0051 using VolumeInstanceId = OpaqueId<struct VolumeInstance_, unsigned int>;
0052 
0053 //! Type-safe depth in the canonical volume graph (zero for world)
0054 using VolumeLevelId = OpaqueId<struct VolumeLevel_, unsigned int>;
0055 
0056 //! Identifier for a unique volume in global space (aka touchable)
0057 using VolumeUniqueInstanceId = OpaqueId<struct VolumeInstance_, ull_int>;
0058 
0059 //---------------------------------------------------------------------------//
0060 //!@{
0061 //! \name Geometry-specific implementation details
0062 
0063 //! Implementation detail surface (for surface-based geometries)
0064 using ImplSurfaceId = OpaqueId<struct ImplSurface_>;
0065 
0066 //! Implementation detail: "global" volume index internal to a geometry
0067 using ImplVolumeId = OpaqueId<struct ImplVolumeId_>;
0068 
0069 //!@}
0070 //---------------------------------------------------------------------------//
0071 // ENUMERATIONS
0072 //---------------------------------------------------------------------------//
0073 /*!
0074  * Enumeration for cartesian axes.
0075  */
0076 enum class Axis
0077 {
0078     x,  //!< X axis/I index coordinate
0079     y,  //!< Y axis/J index coordinate
0080     z,  //!< Z axis/K index coordinate
0081     size_  //!< Sentinel value for looping over axes
0082 };
0083 
0084 //---------------------------------------------------------------------------//
0085 /*!
0086  * Geometry state as a track moves across boundaries through the geometry.
0087  *
0088  * The "incoming" (incident) and "outgoing" (exiting) states are relative to
0089  * the \em boundary (surface) that the track is on, \em not the volume.
0090  *
0091  * \note The numeric values of the enumeration are chosen to optimize the free
0092  * functions \c is_valid (invalid values are strictly negative) and \c
0093  * is_on_boundary (values on the boundary are strictly positive).
0094  */
0095 enum class GeoStatus : signed char
0096 {
0097     error = -2,  //!< Unrecoverable error occurred
0098     invalid = -1,  //!< Unusable but allowable state
0099     interior = 0,  //!< In a volume, not on a boundary
0100     boundary_inc = 1,  //!< On a boundary, pointing into surface
0101     boundary_out = 2,  //!< On a boundary, pointing away from surface
0102 };
0103 
0104 //---------------------------------------------------------------------------//
0105 // STRUCTS
0106 //---------------------------------------------------------------------------//
0107 /*!
0108  * Data required to initialize a geometry state.
0109  */
0110 struct GeoTrackInitializer
0111 {
0112     Real3 pos{0, 0, 0};
0113     Real3 dir{0, 0, 0};
0114     TrackSlotId parent;
0115 
0116     //! True if assigned
0117     explicit CELER_FUNCTION operator bool() const
0118     {
0119         return dir[0] != 0 || dir[1] != 0 || dir[2] != 0;
0120     }
0121 
0122     // Constructors
0123     inline CELER_FUNCTION GeoTrackInitializer();
0124     inline CELER_FUNCTION GeoTrackInitializer(Real3, Real3);
0125     inline CELER_FUNCTION GeoTrackInitializer(Real3, Real3, TrackSlotId);
0126 };
0127 
0128 //---------------------------------------------------------------------------//
0129 /*!
0130  * Result of a propagation step.
0131  *
0132  * The boundary flag means that the geometry is step limiting, but the surface
0133  * crossing must be called externally.
0134  */
0135 struct Propagation
0136 {
0137     real_type distance{0};  //!< Distance traveled
0138     bool boundary{false};  //!< True if hit a boundary before given distance
0139     bool looping{false};  //!< True if track is looping in the field propagator
0140 };
0141 
0142 //---------------------------------------------------------------------------//
0143 // INLINE DEFINITIONS
0144 //---------------------------------------------------------------------------//
0145 //! Default constructor
0146 CELER_FUNCTION GeoTrackInitializer::GeoTrackInitializer() = default;
0147 
0148 //! Construct with an invalid parent ID
0149 CELER_FUNCTION GeoTrackInitializer::GeoTrackInitializer(Real3 p, Real3 d)
0150     : GeoTrackInitializer(p, d, {})
0151 {
0152 }
0153 
0154 //! Construct with position, direction, and parent ID
0155 CELER_FUNCTION GeoTrackInitializer::GeoTrackInitializer(
0156     Real3 p, Real3 d, TrackSlotId p_id)
0157     : pos(p), dir(d), parent(p_id)
0158 {
0159 }
0160 
0161 //---------------------------------------------------------------------------//
0162 // HELPER FUNCTIONS (HOST)
0163 //---------------------------------------------------------------------------//
0164 
0165 // Get a string corresponding to a geometry track state
0166 char const* to_cstring(GeoStatus value);
0167 
0168 //---------------------------------------------------------------------------//
0169 // HELPER FUNCTIONS
0170 //---------------------------------------------------------------------------//
0171 //! Convert Axis enum value to int
0172 CELER_CONSTEXPR_FUNCTION int to_int(Axis a)
0173 {
0174     return static_cast<int>(a);
0175 }
0176 
0177 //---------------------------------------------------------------------------//
0178 //! Convert int to Axis enum value
0179 inline CELER_FUNCTION Axis to_axis(int a)
0180 {
0181     CELER_EXPECT(a >= 0 && a < 3);
0182     return static_cast<Axis>(a);
0183 }
0184 
0185 //---------------------------------------------------------------------------//
0186 //! Get the lowercase name of the axis.
0187 inline constexpr char to_char(Axis ax)
0188 {
0189     return "xyz\a"[static_cast<int>(ax)];
0190 }
0191 
0192 //---------------------------------------------------------------------------//
0193 //! Whether the geometry state is usable
0194 CELER_CONSTEXPR_FUNCTION bool is_valid(GeoStatus s)
0195 {
0196     return static_cast<std::underlying_type_t<GeoStatus>>(s) >= 0;
0197 }
0198 
0199 //---------------------------------------------------------------------------//
0200 //! Whether the geometry is on a boundary
0201 CELER_CONSTEXPR_FUNCTION bool is_on_boundary(GeoStatus s)
0202 {
0203     return static_cast<std::underlying_type_t<GeoStatus>>(s) > 0;
0204 }
0205 
0206 //---------------------------------------------------------------------------//
0207 /*!
0208  * Change whether a boundary crossing is reentrant or exiting.
0209  */
0210 [[nodiscard]] CELER_CONSTEXPR_FUNCTION GeoStatus flip_boundary(GeoStatus orig)
0211 {
0212     return orig == GeoStatus::boundary_inc ? GeoStatus::boundary_out
0213                                            : GeoStatus::boundary_inc;
0214 }
0215 
0216 //---------------------------------------------------------------------------//
0217 //! Whether a volume is outside the canonical geometry extents
0218 CELER_CONSTEXPR_FUNCTION bool is_outside(VolumeId v)
0219 {
0220     return !v;
0221 }
0222 
0223 //---------------------------------------------------------------------------//
0224 }  // namespace celeritas