Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-01 10:03:38

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