Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:34

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2020-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file geocel/vg/VecgeomData.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Macros.hh"
0011 #include "corecel/Types.hh"
0012 #include "corecel/cont/Array.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     int 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 
0077     // Wrapper for NavStatePool, vector, or void*
0078     detail::VecgeomNavCollection<W, M> vgstate;
0079     detail::VecgeomNavCollection<W, M> vgnext;
0080 
0081     //// METHODS ////
0082 
0083     //! True if sizes are consistent and states are assigned
0084     explicit CELER_FUNCTION operator bool() const
0085     {
0086         return this->size() > 0 && dir.size() == this->size() && vgstate
0087                && vgnext;
0088     }
0089 
0090     //! State size
0091     CELER_FUNCTION TrackSlotId::size_type size() const { return pos.size(); }
0092 
0093     //! Assign from another set of data
0094     template<Ownership W2, MemSpace M2>
0095     VecgeomStateData& operator=(VecgeomStateData<W2, M2>& other)
0096     {
0097         static_assert(M2 == M && W == Ownership::reference,
0098                       "Only supported assignment is from the same memspace to "
0099                       "a reference");
0100         CELER_EXPECT(other);
0101         pos = other.pos;
0102         dir = other.dir;
0103         vgstate = other.vgstate;
0104         vgnext = other.vgnext;
0105         return *this;
0106     }
0107 };
0108 
0109 //---------------------------------------------------------------------------//
0110 /*!
0111  * Resize geometry states.
0112  */
0113 template<MemSpace M>
0114 void resize(VecgeomStateData<Ownership::value, M>* data,
0115             HostCRef<VecgeomParamsData> const& params,
0116             size_type size)
0117 {
0118     CELER_EXPECT(data);
0119     CELER_EXPECT(size > 0);
0120     CELER_EXPECT(params.max_depth > 0);
0121 
0122     resize(&data->pos, size);
0123     resize(&data->dir, size);
0124     data->vgstate.resize(params.max_depth, size);
0125     data->vgnext.resize(params.max_depth, size);
0126 
0127     CELER_ENSURE(data);
0128 }
0129 
0130 //---------------------------------------------------------------------------//
0131 }  // namespace celeritas