Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:59:58

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/vg/VecgeomData.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Config.hh"
0010 
0011 #include "corecel/Macros.hh"
0012 #include "corecel/Types.hh"
0013 #include "corecel/data/Collection.hh"
0014 #include "corecel/data/CollectionBuilder.hh"
0015 #include "corecel/sys/ThreadId.hh"
0016 #include "geocel/Types.hh"
0017 
0018 #include "detail/VecgeomNavCollection.hh"
0019 #include "detail/VecgeomTraits.hh"
0020 
0021 namespace celeritas
0022 {
0023 //---------------------------------------------------------------------------//
0024 // PARAMS
0025 //---------------------------------------------------------------------------//
0026 /*!
0027  * Persistent data used by VecGeom implementation.
0028  */
0029 template<Ownership W, MemSpace M>
0030 struct VecgeomParamsData
0031 {
0032     using PlacedVolumeT = typename detail::VecgeomTraits<M>::PlacedVolume;
0033 
0034     PlacedVolumeT const* world_volume = nullptr;
0035     LevelId::size_type max_depth = 0;
0036 
0037     //! Whether the interface is initialized
0038     explicit CELER_FUNCTION operator bool() const
0039     {
0040         return world_volume != nullptr && max_depth > 0;
0041     }
0042 
0043     //! Assign from another set of data
0044     template<Ownership W2, MemSpace M2>
0045     VecgeomParamsData& operator=(VecgeomParamsData<W2, M2>& other)
0046     {
0047         static_assert(M2 == M && W2 == Ownership::value
0048                           && W == Ownership::reference,
0049                       "Only supported assignment is from value to reference");
0050         CELER_EXPECT(other);
0051         world_volume = other.world_volume;
0052         max_depth = other.max_depth;
0053         return *this;
0054     }
0055 };
0056 
0057 //---------------------------------------------------------------------------//
0058 // STATE
0059 //---------------------------------------------------------------------------//
0060 /*!
0061  * Interface for VecGeom state information.
0062  */
0063 template<Ownership W, MemSpace M>
0064 struct VecgeomStateData
0065 {
0066     //// TYPES ////
0067 
0068     template<class T>
0069     using Items = celeritas::StateCollection<T, W, M>;
0070 
0071     //// DATA ////
0072 
0073     // Collections
0074     Items<Real3> pos;
0075     Items<Real3> dir;
0076 #ifdef VECGEOM_USE_SURF
0077     Items<long> next_surface;
0078 #endif
0079 
0080     // Wrapper for NavStatePool, vector, or void*
0081     detail::VecgeomNavCollection<W, M> vgstate;
0082     detail::VecgeomNavCollection<W, M> vgnext;
0083 
0084     //// METHODS ////
0085 
0086     //! True if sizes are consistent and states are assigned
0087     explicit CELER_FUNCTION operator bool() const
0088     {
0089         return this->size() > 0 && dir.size() == this->size()
0090 #ifdef VECGEOM_USE_SURF
0091                && next_surface.size() == this->size()
0092 #endif
0093                && vgstate && vgnext;
0094     }
0095 
0096     //! State size
0097     CELER_FUNCTION TrackSlotId::size_type size() const { return pos.size(); }
0098 
0099     //! Assign from another set of data
0100     template<Ownership W2, MemSpace M2>
0101     VecgeomStateData& operator=(VecgeomStateData<W2, M2>& other)
0102     {
0103         static_assert(M2 == M && W == Ownership::reference,
0104                       "Only supported assignment is from the same memspace to "
0105                       "a reference");
0106         CELER_EXPECT(other);
0107         pos = other.pos;
0108         dir = other.dir;
0109 #ifdef VECGEOM_USE_SURF
0110         next_surface = other.next_surface;
0111 #endif
0112         vgstate = other.vgstate;
0113         vgnext = other.vgnext;
0114         return *this;
0115     }
0116 };
0117 
0118 //---------------------------------------------------------------------------//
0119 /*!
0120  * Resize geometry states.
0121  */
0122 template<MemSpace M>
0123 void resize(VecgeomStateData<Ownership::value, M>* data,
0124             HostCRef<VecgeomParamsData> const& params,
0125             size_type size)
0126 {
0127     CELER_EXPECT(data);
0128     CELER_EXPECT(size > 0);
0129     CELER_EXPECT(params.max_depth > 0);
0130 
0131     resize(&data->pos, size);
0132     resize(&data->dir, size);
0133 #ifdef VECGEOM_USE_SURF
0134     resize(&data->next_surface, size);
0135 #endif
0136     data->vgstate.resize(params.max_depth, size);
0137     data->vgnext.resize(params.max_depth, size);
0138 
0139     CELER_ENSURE(data);
0140 }
0141 
0142 //---------------------------------------------------------------------------//
0143 }  // namespace celeritas