Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:08:57

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 celeritas/em/data/SeltzerBergerData.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011 #include "corecel/cont/Range.hh"
0012 #include "corecel/data/Collection.hh"
0013 #include "corecel/grid/TwodGridData.hh"
0014 #include "celeritas/Quantities.hh"
0015 #include "celeritas/Types.hh"
0016 
0017 #include "ElectronBremsData.hh"
0018 
0019 namespace celeritas
0020 {
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * Seltzer-Berger differential cross section tables for a single element.
0024  *
0025  * The 2D grid data is organized by log E on the x axis and fractional exiting
0026  * energy (0 to 1) on the y axis. The values are in millibarns, but their
0027  * magnitude isn't important since we always take ratios.
0028  *
0029  * \c argmax is the y index of the largest cross section at a given incident
0030  * energy point.
0031  *
0032  * \todo We could use way smaller integers for argmax, even i/j here, because
0033  * these tables are so small.
0034  */
0035 struct SBElementTableData
0036 {
0037     using EnergyUnits = units::LogMev;
0038     using XsUnits = units::Millibarn;
0039 
0040     TwodGridData grid;  //!< Cross section grid and data
0041     ItemRange<size_type> argmax;  //!< Y index of the largest XS for each
0042                                   //!< energy
0043 
0044     explicit CELER_FUNCTION operator bool() const
0045     {
0046         return grid && argmax.size() == grid.x.size();
0047     }
0048 };
0049 
0050 //---------------------------------------------------------------------------//
0051 /*!
0052  * Bremsstrahlung differential cross section (DCS) data for SB sampling.
0053  *
0054  * The value grids are organized per element ID, and each 2D grid is:
0055  * - x: logarithm of the energy [MeV] of the incident charged dparticle
0056  * - y: ratio of exiting photon energy to incident particle energy
0057  * - value: differential cross section (microbarns)
0058  */
0059 template<Ownership W, MemSpace M>
0060 struct SeltzerBergerTableData
0061 {
0062     //// MEMBER FUNCTIONS ////
0063 
0064     template<class T>
0065     using Items = Collection<T, W, M>;
0066     template<class T>
0067     using ElementItems = Collection<T, W, M, ElementId>;
0068 
0069     //// MEMBER DATA ////
0070 
0071     Items<real_type> reals;
0072     Items<size_type> sizes;
0073     ElementItems<SBElementTableData> elements;
0074 
0075     //// MEMBER FUNCTIONS ////
0076 
0077     //! Whether the data is assigned
0078     explicit CELER_FUNCTION operator bool() const
0079     {
0080         return !reals.empty() && !sizes.empty() && !elements.empty();
0081     }
0082 
0083     //! Assign from another set of data
0084     template<Ownership W2, MemSpace M2>
0085     SeltzerBergerTableData&
0086     operator=(SeltzerBergerTableData<W2, M2> const& other)
0087     {
0088         CELER_EXPECT(other);
0089         reals = other.reals;
0090         sizes = other.sizes;
0091         elements = other.elements;
0092         return *this;
0093     }
0094 };
0095 
0096 //---------------------------------------------------------------------------//
0097 /*!
0098  * Device data for sampling SeltzerBergerInteractor.
0099  */
0100 template<Ownership W, MemSpace M>
0101 struct SeltzerBergerData
0102 {
0103     using MevMass = units::MevMass;
0104     using Energy = units::MevEnergy;
0105 
0106     //// MEMBER DATA ////
0107 
0108     //! IDs in a separate struct for readability/easier copying
0109     ElectronBremIds ids;
0110 
0111     //! Electron mass [MeV / c^2]
0112     MevMass electron_mass;
0113 
0114     //! High energy limit of the model
0115     Energy high_energy_limit;
0116 
0117     // Differential cross section storage
0118     SeltzerBergerTableData<W, M> differential_xs;
0119 
0120     //// MEMBER FUNCTIONS ////
0121 
0122     //! Whether the data is assigned
0123     explicit CELER_FUNCTION operator bool() const
0124     {
0125         return ids && electron_mass > zero_quantity() && differential_xs;
0126     }
0127 
0128     //! Assign from another set of data
0129     template<Ownership W2, MemSpace M2>
0130     SeltzerBergerData& operator=(SeltzerBergerData<W2, M2> const& other)
0131     {
0132         CELER_EXPECT(other);
0133         ids = other.ids;
0134         electron_mass = other.electron_mass;
0135         high_energy_limit = other.high_energy_limit;
0136         differential_xs = other.differential_xs;
0137         return *this;
0138     }
0139 };
0140 
0141 using SeltzerBergerDeviceRef = DeviceCRef<SeltzerBergerData>;
0142 using SeltzerBergerHostRef = HostCRef<SeltzerBergerData>;
0143 using SeltzerBergerRef = NativeCRef<SeltzerBergerData>;
0144 
0145 //---------------------------------------------------------------------------//
0146 }  // namespace celeritas