Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:52:19

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/WentzelMacroXsCalculator.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Assert.hh"
0010 #include "corecel/Macros.hh"
0011 #include "corecel/Types.hh"
0012 #include "celeritas/em/data/WentzelOKVIData.hh"
0013 #include "celeritas/em/data/WentzelVIMscData.hh"
0014 #include "celeritas/mat/MaterialView.hh"
0015 #include "celeritas/phys/ParticleTrackView.hh"
0016 
0017 #include "WentzelHelper.hh"
0018 
0019 namespace celeritas
0020 {
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * Calculate the total cross section for the Wentzel VI MSC model.
0024  *
0025  * \note This performs the same calculation of the total cross section (\c
0026  * xtsec) as the Geant4 method
0027  * G4WentzelVIModel::ComputeTransportXSectionPerVolume.
0028  */
0029 class WentzelMacroXsCalculator
0030 {
0031   public:
0032     //!@{
0033     //! \name Type aliases
0034     using Energy = units::MevEnergy;
0035     using XsUnits = units::Native;  // [1/len]
0036     //!@}
0037 
0038   public:
0039     // Construct with particle, material, and precalculatad Wentzel data
0040     inline CELER_FUNCTION
0041     WentzelMacroXsCalculator(ParticleTrackView const& particle,
0042                              MaterialView const& material,
0043                              NativeCRef<WentzelVIMscData> const& data,
0044                              NativeCRef<WentzelOKVIData> const& wentzel,
0045                              Energy cutoff);
0046 
0047     // Compute the total cross section for the given angle
0048     inline CELER_FUNCTION real_type operator()(real_type cos_theta) const;
0049 
0050   private:
0051     ParticleTrackView const& particle_;
0052     MaterialView const& material_;
0053     NativeCRef<WentzelOKVIData> const& wentzel_;
0054     CoulombIds const& ids_;
0055     Energy cutoff_;
0056 };
0057 
0058 //---------------------------------------------------------------------------//
0059 // INLINE DEFINITIONS
0060 //---------------------------------------------------------------------------//
0061 /*!
0062  * Construct with shared model and material data.
0063  */
0064 CELER_FUNCTION
0065 WentzelMacroXsCalculator::WentzelMacroXsCalculator(
0066     ParticleTrackView const& particle,
0067     MaterialView const& material,
0068     NativeCRef<WentzelVIMscData> const& data,
0069     NativeCRef<WentzelOKVIData> const& wentzel,
0070     Energy cutoff)
0071     : particle_(particle)
0072     , material_(material)
0073     , wentzel_(wentzel)
0074     , ids_(data.ids)
0075     , cutoff_(cutoff)
0076 {
0077 }
0078 
0079 //---------------------------------------------------------------------------//
0080 /*!
0081  * Compute the total cross section for the given angle.
0082  */
0083 CELER_FUNCTION real_type
0084 WentzelMacroXsCalculator::operator()(real_type cos_theta) const
0085 {
0086     real_type result = 0;
0087 
0088     for (auto elcomp_id : range(ElementComponentId(material_.num_elements())))
0089     {
0090         AtomicNumber z = material_.element_record(elcomp_id).atomic_number();
0091         WentzelHelper helper(particle_, material_, z, wentzel_, ids_, cutoff_);
0092 
0093         real_type cos_thetamax = helper.cos_thetamax_nuclear();
0094         if (cos_thetamax < cos_theta)
0095         {
0096             result += material_.elements()[elcomp_id.get()].fraction
0097                       * (helper.calc_xs_nuclear(cos_theta, cos_thetamax)
0098                          + helper.calc_xs_electron(cos_theta, cos_thetamax));
0099         }
0100     }
0101     result *= material_.number_density();
0102 
0103     CELER_ENSURE(result >= 0);
0104     return result;
0105 }
0106 
0107 //---------------------------------------------------------------------------//
0108 }  // namespace celeritas