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 "corecel/OpaqueId.hh"
0011 #include "corecel/Types.hh"
0012 #include "corecel/cont/Array.hh"
0013 #include "corecel/sys/ThreadId.hh"
0014 
0015 namespace celeritas
0016 {
0017 //---------------------------------------------------------------------------//
0018 // TYPE ALIASES
0019 //---------------------------------------------------------------------------//
0020 
0021 //! Three-dimensional cartesian coordinates
0022 using Real3 = Array<real_type, 3>;
0023 
0024 //! Two-dimensional cartesian coordinates
0025 using Real2 = Array<real_type, 2>;
0026 
0027 //! Two-dimensional extents
0028 using Size2 = Array<size_type, 2>;
0029 
0030 //! Alias for a small square dense matrix
0031 template<class T, size_type N>
0032 using SquareMatrix = Array<Array<T, N>, N>;
0033 
0034 //! Alias for a small square dense matrix
0035 using SquareMatrixReal3 = SquareMatrix<real_type, 3>;
0036 
0037 //---------------------------------------------------------------------------//
0038 
0039 //! Type-safe "level", i.e., depth of embedded unit/scene/volume
0040 using LevelId = OpaqueId<struct Level_>;
0041 
0042 //! Identifier for a material fill
0043 using GeoMatId = OpaqueId<struct GeoMaterial_>;
0044 
0045 //! Combined boundary/interface surface identifier
0046 using SurfaceId = OpaqueId<struct Surface_, unsigned int>;
0047 
0048 //! Identifier for a geometry volume that may be repeated
0049 using VolumeId = OpaqueId<struct Volume_, unsigned int>;
0050 
0051 //! Identifier for an instance of a geometry volume (aka physical/placed)
0052 using VolumeInstanceId = OpaqueId<struct VolumeInstance_, unsigned int>;
0053 
0054 //! Identifier for a unique volume in global space (aka touchable)
0055 using VolumeUniqueInstanceId = OpaqueId<struct VolumeInstance_, ull_int>;
0056 
0057 //---------------------------------------------------------------------------//
0058 //!{ Geometry-specific implementation details used by
0059 
0060 //! Implementation detail surface (for surface-based geometries)
0061 using ImplSurfaceId = OpaqueId<struct Surface_>;
0062 
0063 //! Implementation detail "global" volume index
0064 using ImplVolumeId = VolumeId;
0065 
0066 //! Identifier for a unique volume in global space (aka touchable)
0067 using ImplVolumeUniqueInstanceId = VolumeUniqueInstanceId;
0068 
0069 //---------------------------------------------------------------------------//
0070 // ENUMERATIONS
0071 //---------------------------------------------------------------------------//
0072 /*!
0073  * Enumeration for cartesian axes.
0074  */
0075 enum class Axis
0076 {
0077     x,  //!< X axis/I index coordinate
0078     y,  //!< Y axis/J index coordinate
0079     z,  //!< Z axis/K index coordinate
0080     size_  //!< Sentinel value for looping over axes
0081 };
0082 
0083 //---------------------------------------------------------------------------//
0084 // STRUCTS
0085 //---------------------------------------------------------------------------//
0086 /*!
0087  * Data required to initialize a geometry state.
0088  */
0089 struct GeoTrackInitializer
0090 {
0091     Real3 pos{0, 0, 0};
0092     Real3 dir{0, 0, 0};
0093     TrackSlotId parent;
0094 
0095     //! True if assigned
0096     explicit CELER_FUNCTION operator bool() const
0097     {
0098         return dir[0] != 0 || dir[1] != 0 || dir[2] != 0;
0099     }
0100 
0101     // Constructors
0102     inline CELER_FUNCTION GeoTrackInitializer();
0103     inline CELER_FUNCTION GeoTrackInitializer(Real3, Real3);
0104     inline CELER_FUNCTION GeoTrackInitializer(Real3, Real3, TrackSlotId);
0105 };
0106 
0107 //---------------------------------------------------------------------------//
0108 /*!
0109  * Result of a propagation step.
0110  *
0111  * The boundary flag means that the geometry is step limiting, but the surface
0112  * crossing must be called externally.
0113  */
0114 struct Propagation
0115 {
0116     real_type distance{0};  //!< Distance traveled
0117     bool boundary{false};  //!< True if hit a boundary before given distance
0118     bool looping{false};  //!< True if track is looping in the field propagator
0119 };
0120 
0121 //---------------------------------------------------------------------------//
0122 // INLINE DEFINITIONS
0123 //---------------------------------------------------------------------------//
0124 //! Default constructor
0125 CELER_FUNCTION GeoTrackInitializer::GeoTrackInitializer() = default;
0126 
0127 //! Construct with an invalid parent ID
0128 CELER_FUNCTION GeoTrackInitializer::GeoTrackInitializer(Real3 pos, Real3 dir)
0129     : GeoTrackInitializer(pos, dir, {})
0130 {
0131 }
0132 
0133 //! Construct with position, direction, and parent ID
0134 CELER_FUNCTION GeoTrackInitializer::GeoTrackInitializer(Real3 pos,
0135                                                         Real3 dir,
0136                                                         TrackSlotId parent)
0137     : pos(pos), dir(dir), parent(parent)
0138 {
0139 }
0140 
0141 //---------------------------------------------------------------------------//
0142 // HELPER FUNCTIONS
0143 //---------------------------------------------------------------------------//
0144 //! Convert Axis enum value to int
0145 CELER_CONSTEXPR_FUNCTION int to_int(Axis a)
0146 {
0147     return static_cast<int>(a);
0148 }
0149 
0150 //---------------------------------------------------------------------------//
0151 //! Convert int to Axis enum value
0152 inline CELER_FUNCTION Axis to_axis(int a)
0153 {
0154     CELER_EXPECT(a >= 0 && a < 3);
0155     return static_cast<Axis>(a);
0156 }
0157 
0158 //---------------------------------------------------------------------------//
0159 //! Get the lowercase name of the axis.
0160 inline constexpr char to_char(Axis ax)
0161 {
0162     return "xyz\a"[static_cast<int>(ax)];
0163 }
0164 
0165 //---------------------------------------------------------------------------//
0166 }  // namespace celeritas