Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:09:07

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 class ElementView
0035 {
0036   public:
0037     //!@{
0038     //! \name Type aliases
0039     using MaterialParamsRef = NativeCRef<MaterialParamsData>;
0040     using AmuMass = units::AmuMass;
0041     //!@}
0042 
0043   public:
0044     // Construct from shared material data and global element ID
0045     inline CELER_FUNCTION
0046     ElementView(MaterialParamsRef const& params, ElementId el_id);
0047 
0048     //// STATIC PROPERTIES ////
0049 
0050     // Atomic number Z
0051     CELER_FORCEINLINE_FUNCTION AtomicNumber atomic_number() const;
0052 
0053     //! Abundance-weighted atomic mass M [amu]
0054     CELER_FUNCTION AmuMass atomic_mass() const { return def_.atomic_mass; }
0055 
0056     // Number of isotopic components
0057     inline CELER_FUNCTION IsotopeComponentId::size_type num_isotopes() const;
0058 
0059     // View properties of a specific isotope
0060     inline CELER_FUNCTION IsotopeView isotope_record(IsotopeComponentId id) const;
0061 
0062     // ID of an isotope component of this element
0063     inline CELER_FUNCTION IsotopeId isotope_id(IsotopeComponentId id) const;
0064 
0065     // Advanced access to the element's isotopes (id/fraction)
0066     inline CELER_FUNCTION Span<ElIsotopeComponent const> isotopes() const;
0067 
0068     //// COMPUTED PROPERTIES ////
0069 
0070     //! Cube root of atomic number: Z^(1/3)
0071     CELER_FUNCTION real_type cbrt_z() const { return def_.cbrt_z; }
0072     //! Cube root of Z*(Z+1)
0073     CELER_FUNCTION real_type cbrt_zzp() const { return def_.cbrt_zzp; }
0074     //! log(z)
0075     CELER_FUNCTION real_type log_z() const { return def_.log_z; }
0076 
0077     // Coulomb correction factor [unitless]
0078     inline CELER_FUNCTION real_type coulomb_correction() const;
0079 
0080     // Mass radiation coefficient for Bremsstrahlung [len^2/mass]
0081     inline CELER_FUNCTION real_type mass_radiation_coeff() const;
0082 
0083   private:
0084     MaterialParamsRef const& params_;
0085     ElementRecord const& def_;
0086 };
0087 
0088 //---------------------------------------------------------------------------//
0089 // INLINE DEFINITIONS
0090 //---------------------------------------------------------------------------//
0091 /*!
0092  * Construct from shared material data and global element ID.
0093  */
0094 CELER_FUNCTION
0095 ElementView::ElementView(MaterialParamsRef const& params, ElementId el_id)
0096     : params_(params), def_(params.elements[el_id])
0097 {
0098     CELER_EXPECT(el_id < params.elements.size());
0099 }
0100 
0101 //---------------------------------------------------------------------------//
0102 /*!
0103  * Atomic number Z.
0104  *
0105  * Number of protons in an atom of this element.
0106  */
0107 CELER_FUNCTION AtomicNumber ElementView::atomic_number() const
0108 {
0109     return def_.atomic_number;
0110 }
0111 
0112 //---------------------------------------------------------------------------//
0113 /*!
0114  * Number of isotopes available for this element.
0115  */
0116 CELER_FUNCTION IsotopeComponentId::size_type ElementView::num_isotopes() const
0117 {
0118     return def_.isotopes.size();
0119 }
0120 
0121 //---------------------------------------------------------------------------//
0122 /*!
0123  * Get isotope properties for a given index.
0124  */
0125 CELER_FUNCTION IsotopeView ElementView::isotope_record(IsotopeComponentId id) const
0126 {
0127     CELER_EXPECT(id < this->num_isotopes());
0128     return IsotopeView(params_, this->isotope_id(id));
0129 }
0130 
0131 //---------------------------------------------------------------------------//
0132 /*!
0133  * ID of an isotope in this element.
0134  */
0135 CELER_FUNCTION IsotopeId ElementView::isotope_id(IsotopeComponentId id) const
0136 {
0137     CELER_EXPECT(id < this->num_isotopes());
0138     return this->isotopes()[id.get()].isotope;
0139 }
0140 
0141 //---------------------------------------------------------------------------//
0142 /*!
0143  * View the isotopic components (id/fraction) of this element.
0144  */
0145 CELER_FUNCTION Span<ElIsotopeComponent const> ElementView::isotopes() const
0146 {
0147     return params_.isocomponents[def_.isotopes];
0148 }
0149 
0150 //---------------------------------------------------------------------------//
0151 /*!
0152  * Coulomb correction term [unitless].
0153  *
0154  * Used by Bremsstrahlung and other physics processes, this constant is
0155  * calculated with greater precision than in Geant4 (which is accurate to only
0156  * 5 or 6 digits across the range of natural elements).
0157  */
0158 CELER_FUNCTION real_type ElementView::coulomb_correction() const
0159 {
0160     return def_.coulomb_correction;
0161 }
0162 
0163 //---------------------------------------------------------------------------//
0164 /*!
0165  * Mass radiation coefficient 1/X_0 for Bremsstrahlung [len^2/mass].
0166  *
0167  * The "radiation length" X_0 is "the mean distance over which a high-energy
0168  * electron loses all but 1/e of its energy by bremsstrahlung". See Review of
0169  * Particle Physics (2020), S34.4.2 (p541) for the semi-empirical calculation
0170  * of 1/X0.
0171  *
0172  * This quantity 1/X_0 is normalized by material density and is equivalent to
0173  * Geant4's \c G4Element::GetfRadTsai.
0174  */
0175 CELER_FUNCTION real_type ElementView::mass_radiation_coeff() const
0176 {
0177     return def_.mass_radiation_coeff;
0178 }
0179 
0180 //---------------------------------------------------------------------------//
0181 }  // namespace celeritas