Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:27

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 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 celeritas/optical/CoreTrackData.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Assert.hh"
0011 #include "corecel/data/Collection.hh"
0012 #include "celeritas/Types.hh"
0013 #include "celeritas/geo/GeoData.hh"
0014 #include "celeritas/random/RngData.hh"
0015 
0016 #include "CoreTrackDataFwd.hh"
0017 #include "MaterialData.hh"
0018 #include "ParticleData.hh"
0019 #include "SimData.hh"
0020 #include "TrackInitData.hh"
0021 #include "Types.hh"
0022 
0023 namespace celeritas
0024 {
0025 namespace optical
0026 {
0027 //---------------------------------------------------------------------------//
0028 // XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX
0029 // IMPLEMENT ME!
0030 
0031 template<Ownership W, MemSpace M>
0032 struct PhysicsParamsData
0033 {
0034     explicit CELER_FUNCTION operator bool() const { return true; }
0035 };
0036 template<Ownership W, MemSpace M>
0037 struct PhysicsStateData
0038 {
0039     explicit CELER_FUNCTION operator bool() const { return true; }
0040 
0041     //! Assign from another set of data
0042     template<Ownership W2, MemSpace M2>
0043     PhysicsStateData& operator=(PhysicsStateData<W2, M2>&)
0044     {
0045         return *this;
0046     }
0047 };
0048 
0049 template<MemSpace M>
0050 inline void resize(PhysicsStateData<Ownership::value, M>*,
0051                    HostCRef<PhysicsParamsData> const&,
0052                    size_type)
0053 {
0054 }
0055 
0056 // XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX  XXX
0057 //---------------------------------------------------------------------------//
0058 /*!
0059  * Memspace-independent core variables.
0060  */
0061 struct CoreScalars
0062 {
0063     // TODO: maybe replace with a surface crossing manager to handle boundary
0064     // conditions (see CoreParams.cc)
0065     ActionId boundary_action;
0066 
0067     StreamId::size_type max_streams{0};
0068 
0069     //! True if assigned and valid
0070     explicit CELER_FUNCTION operator bool() const
0071     {
0072         return boundary_action && max_streams > 0;
0073     }
0074 };
0075 
0076 //---------------------------------------------------------------------------//
0077 /*!
0078  * Immutable problem data.
0079  */
0080 template<Ownership W, MemSpace M>
0081 struct CoreParamsData
0082 {
0083     GeoParamsData<W, M> geometry;
0084     MaterialParamsData<W, M> material;
0085     PhysicsParamsData<W, M> physics;
0086     RngParamsData<W, M> rng;
0087     TrackInitParamsData<W, M> init;
0088 
0089     CoreScalars scalars;
0090 
0091     //! True if all params are assigned
0092     explicit CELER_FUNCTION operator bool() const
0093     {
0094         return geometry && material && physics && rng && init && scalars;
0095     }
0096 
0097     //! Assign from another set of data
0098     template<Ownership W2, MemSpace M2>
0099     CoreParamsData& operator=(CoreParamsData<W2, M2> const& other)
0100     {
0101         CELER_EXPECT(other);
0102         geometry = other.geometry;
0103         material = other.material;
0104         physics = other.physics;
0105         rng = other.rng;
0106         init = other.init;
0107         scalars = other.scalars;
0108         return *this;
0109     }
0110 };
0111 
0112 //---------------------------------------------------------------------------//
0113 /*!
0114  * Thread-local state data.
0115  */
0116 template<Ownership W, MemSpace M>
0117 struct CoreStateData
0118 {
0119     template<class T>
0120     using Items = StateCollection<T, W, M>;
0121 
0122     GeoStateData<W, M> geometry;
0123     // TODO: should we cache the material ID?
0124     ParticleStateData<W, M> particle;
0125     PhysicsStateData<W, M> physics;
0126     RngStateData<W, M> rng;
0127     SimStateData<W, M> sim;
0128     TrackInitStateData<W, M> init;
0129 
0130     //! Unique identifier for "thread-local" data.
0131     StreamId stream_id;
0132 
0133     //! Number of state elements
0134     CELER_FUNCTION size_type size() const { return geometry.size(); }
0135 
0136     //! Whether the data are assigned
0137     explicit CELER_FUNCTION operator bool() const
0138     {
0139         return geometry && particle && physics && rng && sim && init
0140                && stream_id;
0141     }
0142 
0143     //! Assign from another set of data
0144     template<Ownership W2, MemSpace M2>
0145     CoreStateData& operator=(CoreStateData<W2, M2>& other)
0146     {
0147         CELER_EXPECT(other);
0148         geometry = other.geometry;
0149         particle = other.particle;
0150         physics = other.physics;
0151         rng = other.rng;
0152         sim = other.sim;
0153         init = other.init;
0154         stream_id = other.stream_id;
0155         return *this;
0156     }
0157 };
0158 
0159 //---------------------------------------------------------------------------//
0160 /*!
0161  * Resize states in host code.
0162  *
0163  * Initialize threads to track slots mapping.
0164  * Resize core states using parameter data, stream ID, and track slots.
0165  */
0166 template<MemSpace M>
0167 void resize(CoreStateData<Ownership::value, M>* state,
0168             HostCRef<CoreParamsData> const& params,
0169             StreamId stream_id,
0170             size_type size);
0171 
0172 //---------------------------------------------------------------------------//
0173 }  // namespace optical
0174 }  // namespace celeritas