Back to home page

EIC code displayed by LXR

 
 

    


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

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 celeritas/global/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/em/data/WentzelOKVIData.hh"
0014 #include "celeritas/geo/GeoData.hh"
0015 #include "celeritas/geo/GeoMaterialData.hh"
0016 #include "celeritas/mat/MaterialData.hh"
0017 #include "celeritas/phys/CutoffData.hh"
0018 #include "celeritas/phys/ParticleData.hh"
0019 #include "celeritas/phys/PhysicsData.hh"
0020 #include "celeritas/random/RngData.hh"
0021 #include "celeritas/track/SimData.hh"
0022 #include "celeritas/track/TrackInitData.hh"
0023 
0024 #include "CoreTrackDataFwd.hh"
0025 
0026 namespace celeritas
0027 {
0028 //---------------------------------------------------------------------------//
0029 /*!
0030  * Memspace-independent core variables.
0031  */
0032 struct CoreScalars
0033 {
0034     ActionId boundary_action;
0035     ActionId propagation_limit_action;
0036     ActionId tracking_cut_action;  //!< Deposit a track's energy locally
0037 
0038     // TODO: this is a hack until we improve the along-step interface
0039     ActionId along_step_user_action;
0040     ActionId along_step_neutral_action;
0041 
0042     StreamId::size_type max_streams{0};
0043 
0044     //! True if assigned and valid
0045     explicit CELER_FUNCTION operator bool() const
0046     {
0047         return boundary_action && propagation_limit_action
0048                && tracking_cut_action && along_step_user_action
0049                && along_step_neutral_action && max_streams > 0;
0050     }
0051 };
0052 
0053 //---------------------------------------------------------------------------//
0054 /*!
0055  * Immutable problem data.
0056  */
0057 template<Ownership W, MemSpace M>
0058 struct CoreParamsData
0059 {
0060     GeoParamsData<W, M> geometry;
0061     GeoMaterialParamsData<W, M> geo_mats;
0062     MaterialParamsData<W, M> materials;
0063     ParticleParamsData<W, M> particles;
0064     CutoffParamsData<W, M> cutoffs;
0065     PhysicsParamsData<W, M> physics;
0066     RngParamsData<W, M> rng;
0067     SimParamsData<W, M> sim;
0068     TrackInitParamsData<W, M> init;
0069     WentzelOKVIData<W, M> wentzel;
0070 
0071     CoreScalars scalars;
0072 
0073     //! True if all params are assigned
0074     explicit CELER_FUNCTION operator bool() const
0075     {
0076         return geometry && geo_mats && materials && particles && cutoffs
0077                && physics && rng && sim && init && scalars;
0078     }
0079 
0080     //! Assign from another set of data
0081     template<Ownership W2, MemSpace M2>
0082     CoreParamsData& operator=(CoreParamsData<W2, M2> const& other)
0083     {
0084         CELER_EXPECT(other);
0085         geometry = other.geometry;
0086         geo_mats = other.geo_mats;
0087         materials = other.materials;
0088         particles = other.particles;
0089         cutoffs = other.cutoffs;
0090         physics = other.physics;
0091         rng = other.rng;
0092         sim = other.sim;
0093         init = other.init;
0094         wentzel = other.wentzel;
0095         scalars = other.scalars;
0096         return *this;
0097     }
0098 };
0099 
0100 //---------------------------------------------------------------------------//
0101 /*!
0102  * Thread-local state data.
0103  *
0104  * TODO: standardize variable names
0105  */
0106 template<Ownership W, MemSpace M>
0107 struct CoreStateData
0108 {
0109     template<class T>
0110     using ThreadItems = Collection<T, W, M, ThreadId>;
0111 
0112     GeoStateData<W, M> geometry;
0113     MaterialStateData<W, M> materials;
0114     ParticleStateData<W, M> particles;
0115     PhysicsStateData<W, M> physics;
0116     RngStateData<W, M> rng;
0117     SimStateData<W, M> sim;
0118     TrackInitStateData<W, M> init;
0119 
0120     //! Indirection array for sorting (empty if unsorted)
0121     ThreadItems<TrackSlotId::size_type> track_slots;
0122 
0123     //! Unique identifier for "thread-local" data.
0124     StreamId stream_id;
0125 
0126     //! Number of state elements
0127     CELER_FUNCTION size_type size() const { return particles.size(); }
0128 
0129     //! Whether the data are assigned
0130     explicit CELER_FUNCTION operator bool() const
0131     {
0132         return geometry && materials && particles && physics && rng && sim
0133                && init && stream_id;
0134     }
0135 
0136     //! Assign from another set of data
0137     template<Ownership W2, MemSpace M2>
0138     CoreStateData& operator=(CoreStateData<W2, M2>& other)
0139     {
0140         CELER_EXPECT(other);
0141         geometry = other.geometry;
0142         materials = other.materials;
0143         particles = other.particles;
0144         physics = other.physics;
0145         rng = other.rng;
0146         sim = other.sim;
0147         init = other.init;
0148         track_slots = other.track_slots;
0149         stream_id = other.stream_id;
0150         return *this;
0151     }
0152 };
0153 
0154 //---------------------------------------------------------------------------//
0155 /*!
0156  * Resize states in host code.
0157  *
0158  * Initialize threads to track slots mapping.
0159  * Resize core states using parameter data, stream ID, and track slots.
0160  */
0161 template<MemSpace M>
0162 void resize(CoreStateData<Ownership::value, M>* state,
0163             HostCRef<CoreParamsData> const& params,
0164             StreamId stream_id,
0165             size_type size);
0166 
0167 //---------------------------------------------------------------------------//
0168 }  // namespace celeritas