Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-12-01 10:04:53

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/xs/WentzelTransportXsCalculator.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Assert.hh"
0010 #include "corecel/Macros.hh"
0011 #include "corecel/Types.hh"
0012 #include "corecel/cont/Span.hh"
0013 #include "celeritas/mat/MaterialView.hh"
0014 
0015 #include "WentzelHelper.hh"
0016 
0017 namespace celeritas
0018 {
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Calculate the transport cross section for the Wentzel OK and VI model.
0022  *
0023  * \note This performs the same calculation as the Geant4 method
0024  * G4WentzelOKandVIxSection::ComputeTransportCrossSectionPerAtom.
0025  */
0026 class WentzelTransportXsCalculator
0027 {
0028   public:
0029     //!@{
0030     //! \name Type aliases
0031     using XsUnits = units::Native;  // [len^2]
0032     using Mass = units::MevMass;
0033     using MomentumSq = units::MevMomentumSq;
0034     //!@}
0035 
0036   public:
0037     // Construct with particle and precalculatad Wentzel data
0038     inline CELER_FUNCTION WentzelTransportXsCalculator(
0039         ParticleTrackView const& particle, WentzelHelper const& helper);
0040 
0041     // Calculate the transport cross section for the given angle [len^2]
0042     inline CELER_FUNCTION real_type operator()(real_type cos_thetamax) const;
0043 
0044   private:
0045     //// DATA ////
0046 
0047     AtomicNumber z_;
0048     real_type screening_coeff_;
0049     real_type cos_thetamax_elec_;
0050     real_type beta_sq_;
0051     real_type kin_factor_;
0052 
0053     //// HELPER FUNCTIONS ////
0054 
0055     // Calculate xs contribution from scattering off electrons or nucleus
0056     real_type calc_xs_contribution(real_type cos_thetamax) const;
0057 
0058     //! Limit on (1 - \c cos_thetamax) / \c screening_coeff
0059     static CELER_CONSTEXPR_FUNCTION real_type limit() { return 0.1; }
0060 };
0061 
0062 //---------------------------------------------------------------------------//
0063 // INLINE DEFINITIONS
0064 //---------------------------------------------------------------------------//
0065 /*!
0066  * Construct with particle and precalculatad Wentzel data.
0067  *
0068  * \c beta_sq should be calculated from the incident particle energy and mass.
0069  * \c screening_coeff and \c cos_thetamax_elec are calculated using the Wentzel
0070  * OK and VI model in \c WentzelHelper and depend on properties of the incident
0071  * particle, the energy cutoff in the current material, and the target element.
0072  */
0073 CELER_FUNCTION WentzelTransportXsCalculator::WentzelTransportXsCalculator(
0074     ParticleTrackView const& particle, WentzelHelper const& helper)
0075     : z_(helper.atomic_number())
0076     , screening_coeff_(2 * helper.screening_coefficient())
0077     , cos_thetamax_elec_(helper.cos_thetamax_electron())
0078     , beta_sq_(particle.beta_sq())
0079     , kin_factor_(helper.kin_factor())
0080 {
0081 }
0082 
0083 //---------------------------------------------------------------------------//
0084 /*!
0085  * Calculate the transport cross section for the given angle [len^2].
0086  */
0087 CELER_FUNCTION real_type WentzelTransportXsCalculator::operator()(
0088     real_type cos_thetamax) const
0089 {
0090     CELER_EXPECT(cos_thetamax <= 1);
0091 
0092     // Sum xs contributions from scattering off electrons and nucleus
0093     real_type xs_nuc = this->calc_xs_contribution(cos_thetamax);
0094     real_type xs_elec = cos_thetamax_elec_ > cos_thetamax
0095                             ? this->calc_xs_contribution(cos_thetamax_elec_)
0096                             : xs_nuc;
0097     real_type result = kin_factor_ * (xs_elec + z_.get() * xs_nuc);
0098 
0099     CELER_ENSURE(result >= 0);
0100     return result;
0101 }
0102 
0103 //---------------------------------------------------------------------------//
0104 /*!
0105  * Calculate contribution to xs from scattering off electrons or nucleus.
0106  */
0107 CELER_FUNCTION real_type WentzelTransportXsCalculator::calc_xs_contribution(
0108     real_type cos_thetamax) const
0109 {
0110     using namespace celeritas::literals;
0111 
0112     real_type result;
0113     real_type const spin = 0.5_r;
0114     real_type x = (1 - cos_thetamax) / screening_coeff_;
0115     if (x < WentzelTransportXsCalculator::limit())
0116     {
0117         real_type x_sq = ipow<2>(x);
0118         result = 0.5_r * x_sq
0119                  * ((1 - 4.0_r / 3.0_r * x + 1.5_r * x_sq)
0120                     - screening_coeff_ * spin * beta_sq_ * x
0121                           * (2.0_r / 3.0_r - x));
0122     }
0123     else
0124     {
0125         real_type x_1 = x / (1 + x);
0126         real_type log_x = std::log(1 + x);
0127         result = log_x - x_1
0128                  - screening_coeff_ * spin * beta_sq_ * (x + x_1 - 2 * log_x);
0129     }
0130     return clamp_to_nonneg(result);
0131 }
0132 
0133 //---------------------------------------------------------------------------//
0134 }  // namespace celeritas