Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 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/phys/MacroXsCalculator.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Assert.hh"
0011 #include "corecel/Macros.hh"
0012 #include "corecel/Types.hh"
0013 #include "corecel/cont/Span.hh"
0014 #include "celeritas/Quantities.hh"
0015 #include "celeritas/UnitTypes.hh"
0016 #include "celeritas/mat/MaterialView.hh"
0017 
0018 namespace celeritas
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Calculates the macroscopic cross section.
0023  *
0024  * \tparam MicroXsT microscopic (element) cross section calculator
0025  */
0026 template<class MicroXsT>
0027 class MacroXsCalculator
0028 {
0029   public:
0030     //!@{
0031     //! \name Type aliases
0032     using ParamsRef = typename MicroXsT::ParamsRef;
0033     using Energy = typename MicroXsT::Energy;
0034     using MicroXs = units::BarnXs;
0035     using MacroXsUnits = units::Native;  // [1/len]
0036     //!@}
0037 
0038   public:
0039     // Construct with shared and material
0040     inline CELER_FUNCTION
0041     MacroXsCalculator(ParamsRef const& shared, MaterialView const& material);
0042 
0043     // Compute the macroscopic cross section on the fly at the given energy
0044     inline CELER_FUNCTION real_type operator()(Energy energy) const;
0045 
0046   private:
0047     ParamsRef const& shared_;
0048     Span<MatElementComponent const> elements_;
0049     real_type number_density_;
0050 };
0051 
0052 //---------------------------------------------------------------------------//
0053 // INLINE DEFINITIONS
0054 //---------------------------------------------------------------------------//
0055 /*!
0056  * Construct with shared and material data.
0057  */
0058 template<class MicroXsT>
0059 CELER_FUNCTION
0060 MacroXsCalculator<MicroXsT>::MacroXsCalculator(ParamsRef const& shared,
0061                                                MaterialView const& material)
0062     : shared_(shared)
0063     , elements_(material.elements())
0064     , number_density_(material.number_density())
0065 {
0066     CELER_EXPECT(!elements_.empty());
0067 }
0068 
0069 //---------------------------------------------------------------------------//
0070 /*!
0071  * Compute the macroscopic cross section on the fly at the given energy.
0072  */
0073 template<class MicroXsT>
0074 CELER_FUNCTION real_type
0075 MacroXsCalculator<MicroXsT>::operator()(Energy energy) const
0076 {
0077     real_type result = 0.;
0078     MicroXsT calc_micro_xs(shared_, energy);
0079     for (auto const& el_comp : elements_)
0080     {
0081         real_type micro_xs = value_as<MicroXs>(calc_micro_xs(el_comp.element));
0082         CELER_ASSERT(micro_xs >= 0);
0083         result += micro_xs * el_comp.fraction;
0084     }
0085     result = native_value_from(MicroXs{result}) * number_density_;
0086     CELER_ENSURE(result >= 0);
0087     return result;
0088 }
0089 
0090 //---------------------------------------------------------------------------//
0091 }  // namespace celeritas