Back to home page

EIC code displayed by LXR

 
 

    


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

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/mat/ElementView.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Macros.hh"
0011 #include "celeritas/Quantities.hh"
0012 #include "celeritas/Types.hh"
0013 #include "celeritas/phys/AtomicNumber.hh"
0014 
0015 #include "IsotopeView.hh"
0016 #include "MaterialData.hh"
0017 
0018 namespace celeritas
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Access amalgamated data for an element.
0023  *
0024  * This encapsulates general data specific to an element instance. (We may
0025  * allow multiple element instances for an element eventually since they may
0026  * have various enriched abundances of component isotopes.) It also provides
0027  * access to ionization-related data, which in Geant4 is in a separate class.
0028  *
0029  * One use case of this class is after sampling an element in an EM model.
0030  *
0031  * The "derived quantities" may be calculated on-the-fly or stored in global
0032  * memory. As with the particle track view, assume that accessing them is
0033  * expensive and store them locally.
0034  */
0035 class ElementView
0036 {
0037   public:
0038     //!@{
0039     //! \name Type aliases
0040     using MaterialParamsRef = NativeCRef<MaterialParamsData>;
0041     using AmuMass = units::AmuMass;
0042     //!@}
0043 
0044   public:
0045     // Construct from shared material data and global element ID
0046     inline CELER_FUNCTION
0047     ElementView(MaterialParamsRef const& params, ElementId el_id);
0048 
0049     //// STATIC PROPERTIES ////
0050 
0051     // Atomic number Z
0052     CELER_FORCEINLINE_FUNCTION AtomicNumber atomic_number() const;
0053 
0054     //! Abundance-weighted atomic mass M [amu]
0055     CELER_FUNCTION AmuMass atomic_mass() const { return def_.atomic_mass; }
0056 
0057     // Number of isotopic components
0058     inline CELER_FUNCTION IsotopeComponentId::size_type num_isotopes() const;
0059 
0060     // View properties of a specific isotope
0061     inline CELER_FUNCTION IsotopeView
0062     make_isotope_view(IsotopeComponentId id) const;
0063 
0064     // ID of an isotope component of this element
0065     inline CELER_FUNCTION IsotopeId isotope_id(IsotopeComponentId id) const;
0066 
0067     // Advanced access to the element's isotopes (id/fraction)
0068     inline CELER_FUNCTION Span<ElIsotopeComponent const> isotopes() const;
0069 
0070     //// COMPUTED PROPERTIES ////
0071 
0072     //! Cube root of atomic number: Z^(1/3)
0073     CELER_FUNCTION real_type cbrt_z() const { return def_.cbrt_z; }
0074     //! Cube root of Z*(Z+1)
0075     CELER_FUNCTION real_type cbrt_zzp() const { return def_.cbrt_zzp; }
0076     //! log(z)
0077     CELER_FUNCTION real_type log_z() const { return def_.log_z; }
0078 
0079     // Coulomb correction factor [unitless]
0080     inline CELER_FUNCTION real_type coulomb_correction() const;
0081 
0082     // Mass radiation coefficient for Bremsstrahlung [len^2/mass]
0083     inline CELER_FUNCTION real_type mass_radiation_coeff() const;
0084 
0085   private:
0086     MaterialParamsRef const& params_;
0087     ElementRecord const& def_;
0088 };
0089 
0090 //---------------------------------------------------------------------------//
0091 // INLINE DEFINITIONS
0092 //---------------------------------------------------------------------------//
0093 /*!
0094  * Construct from shared material data and global element ID.
0095  */
0096 CELER_FUNCTION
0097 ElementView::ElementView(MaterialParamsRef const& params, ElementId el_id)
0098     : params_(params), def_(params.elements[el_id])
0099 {
0100     CELER_EXPECT(el_id < params.elements.size());
0101 }
0102 
0103 //---------------------------------------------------------------------------//
0104 /*!
0105  * Atomic number Z.
0106  *
0107  * Number of protons in an atom of this element.
0108  */
0109 CELER_FUNCTION AtomicNumber ElementView::atomic_number() const
0110 {
0111     return def_.atomic_number;
0112 }
0113 
0114 //---------------------------------------------------------------------------//
0115 /*!
0116  * Number of isotopes available for this element.
0117  */
0118 CELER_FUNCTION IsotopeComponentId::size_type ElementView::num_isotopes() const
0119 {
0120     return def_.isotopes.size();
0121 }
0122 
0123 //---------------------------------------------------------------------------//
0124 /*!
0125  * Get isotope properties for a given index.
0126  */
0127 CELER_FUNCTION IsotopeView
0128 ElementView::make_isotope_view(IsotopeComponentId id) const
0129 {
0130     CELER_EXPECT(id < this->num_isotopes());
0131     return IsotopeView(params_, this->isotope_id(id));
0132 }
0133 
0134 //---------------------------------------------------------------------------//
0135 /*!
0136  * ID of an isotope in this element.
0137  */
0138 CELER_FUNCTION IsotopeId ElementView::isotope_id(IsotopeComponentId id) const
0139 {
0140     CELER_EXPECT(id < this->num_isotopes());
0141     return this->isotopes()[id.get()].isotope;
0142 }
0143 
0144 //---------------------------------------------------------------------------//
0145 /*!
0146  * View the isotopic components (id/fraction) of this element.
0147  */
0148 CELER_FUNCTION Span<ElIsotopeComponent const> ElementView::isotopes() const
0149 {
0150     return params_.isocomponents[def_.isotopes];
0151 }
0152 
0153 //---------------------------------------------------------------------------//
0154 /*!
0155  * Coulomb correction term [unitless].
0156  *
0157  * Used by Bremsstrahlung and other physics processes, this constant is
0158  * calculated with greater precision than in Geant4 (which is accurate to only
0159  * 5 or 6 digits across the range of natural elements).
0160  */
0161 CELER_FUNCTION real_type ElementView::coulomb_correction() const
0162 {
0163     return def_.coulomb_correction;
0164 }
0165 
0166 //---------------------------------------------------------------------------//
0167 /*!
0168  * Mass radiation coefficient 1/X_0 for Bremsstrahlung [len^2/mass].
0169  *
0170  * The "radiation length" X_0 is "the mean distance over which a high-energy
0171  * electron loses all but 1/e of its energy by bremsstrahlung". See Review of
0172  * Particle Physics (2020), S34.4.2 (p541) for the semi-empirical calculation
0173  * of 1/X0.
0174  *
0175  * This quantity 1/X_0 is normalized by material density and is equivalent to
0176  * Geant4's \c G4Element::GetfRadTsai.
0177  */
0178 CELER_FUNCTION real_type ElementView::mass_radiation_coeff() const
0179 {
0180     return def_.mass_radiation_coeff;
0181 }
0182 
0183 //---------------------------------------------------------------------------//
0184 }  // namespace celeritas