Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:44

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/PhysicsData.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Macros.hh"
0011 #include "corecel/data/Collection.hh"
0012 #include "corecel/data/CollectionBuilder.hh"
0013 #include "corecel/grid/NonuniformGridData.hh"
0014 #include "celeritas/Types.hh"
0015 
0016 #include "Types.hh"
0017 
0018 namespace celeritas
0019 {
0020 namespace optical
0021 {
0022 //---------------------------------------------------------------------------//
0023 // TYPE ALIASES
0024 //---------------------------------------------------------------------------//
0025 
0026 using ValueGrid = NonuniformGridRecord;
0027 using ValueGridId = OpaqueId<ValueGrid>;
0028 
0029 //---------------------------------------------------------------------------//
0030 /*!
0031  * Scalar quantities used by optical physics.
0032  */
0033 struct PhysicsParamsScalars
0034 {
0035     //! Number of optical models
0036     ModelId::size_type num_models{};
0037 
0038     //! Number of optical materials
0039     OptMatId::size_type num_materials{};
0040 
0041     //! Offset to create an ActionId from a ModelId
0042     ActionId::size_type model_to_action{};
0043 
0044     //! Whether data is assigned and valid
0045     explicit CELER_FUNCTION operator bool() const
0046     {
0047         return num_models > 0 && num_materials > 0 && model_to_action >= 1;
0048     }
0049 
0050     //! Undergo a discrete interaction
0051     CELER_FORCEINLINE_FUNCTION ActionId discrete_action() const
0052     {
0053         return ActionId{model_to_action - 1};
0054     }
0055 };
0056 
0057 //---------------------------------------------------------------------------//
0058 /*!
0059  * Persistent shared optical physics data.
0060  */
0061 template<Ownership W, MemSpace M>
0062 struct PhysicsParamsData
0063 {
0064     //!@{
0065     //! \name Type aliases
0066     template<class T>
0067     using Items = Collection<T, W, M>;
0068 
0069     template<class T>
0070     using ModelItems = Collection<T, W, M, ModelId>;
0071     //!@}
0072 
0073     //! Non-templated data
0074     PhysicsParamsScalars scalars;
0075 
0076     //! Optical model data
0077     Items<ValueGrid> grids;
0078 
0079     //! Backend storage
0080     Items<real_type> reals;
0081 
0082     //! Whether data is assigned and valid
0083     explicit CELER_FUNCTION operator bool() const
0084     {
0085         return static_cast<bool>(scalars) && !grids.empty() && !reals.empty();
0086     }
0087 
0088     //! Assign from another set of data
0089     template<Ownership W2, MemSpace M2>
0090     PhysicsParamsData<W, M>& operator=(PhysicsParamsData<W2, M2> const& other)
0091     {
0092         CELER_EXPECT(other);
0093         this->scalars = other.scalars;
0094         this->grids = other.grids;
0095         this->reals = other.reals;
0096         return *this;
0097     }
0098 };
0099 
0100 //---------------------------------------------------------------------------//
0101 /*!
0102  * Dynamic optical physics state data.
0103  */
0104 template<Ownership W, MemSpace M>
0105 struct PhysicsStateData
0106 {
0107     //!@{
0108     //! \name Type aliases
0109     template<class T>
0110     using Items = Collection<T, W, M>;
0111     template<class T>
0112     using StateItems = StateCollection<T, W, M>;
0113     //!@}
0114 
0115     //// Persistent State Data ////
0116 
0117     StateItems<real_type> interaction_mfp;
0118 
0119     //// Temporary State Data ////
0120 
0121     StateItems<real_type> macro_xs;  //! < Total macroscopic cross section
0122 
0123     //// Methods ////
0124 
0125     //! Whether data is assigned and valid
0126     explicit CELER_FUNCTION operator bool() const
0127     {
0128         return !interaction_mfp.empty();
0129     }
0130 
0131     //! State size
0132     CELER_FUNCTION size_type size() const { return interaction_mfp.size(); }
0133 
0134     //! Assign from another set of data
0135     template<Ownership W2, MemSpace M2>
0136     PhysicsStateData<W, M>& operator=(PhysicsStateData<W2, M2>& other)
0137     {
0138         CELER_EXPECT(other);
0139         interaction_mfp = other.interaction_mfp;
0140         macro_xs = other.macro_xs;
0141         return *this;
0142     }
0143 };
0144 
0145 //---------------------------------------------------------------------------//
0146 /*!
0147  * Resize the state in host code.
0148  */
0149 template<MemSpace M>
0150 inline void resize(PhysicsStateData<Ownership::value, M>* state, size_type size)
0151 {
0152     CELER_EXPECT(state);
0153     CELER_EXPECT(size > 0);
0154 
0155     resize(&state->interaction_mfp, size);
0156     resize(&state->macro_xs, size);
0157 
0158     CELER_ENSURE(*state);
0159 }
0160 
0161 //---------------------------------------------------------------------------//
0162 }  // namespace optical
0163 }  // namespace celeritas