Back to home page

EIC code displayed by LXR

 
 

    


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

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/model/detail/LivermoreXsInserter.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/data/CollectionBuilder.hh"
0010 #include "celeritas/em/data/LivermorePEData.hh"
0011 #include "celeritas/grid/NonuniformGridBuilder.hh"
0012 #include "celeritas/io/ImportLivermorePE.hh"
0013 
0014 namespace celeritas
0015 {
0016 namespace detail
0017 {
0018 //---------------------------------------------------------------------------//
0019 /*!
0020  * Construct Livermore Photoelectric cross section data from imported data.
0021  */
0022 class LivermoreXsInserter
0023 {
0024   public:
0025     //!@{
0026     //! \name Type aliases
0027     using Data = HostVal<LivermorePEXsData>;
0028     //!@}
0029 
0030   public:
0031     // Construct with pointer to host data
0032     explicit inline LivermoreXsInserter(Data* data);
0033 
0034     // Construct cross section data for a single element
0035     inline void operator()(ImportLivermorePE const& inp);
0036 
0037   private:
0038     NonuniformGridBuilder build_grid_;
0039 
0040     CollectionBuilder<LivermoreSubshell> shells_;
0041     CollectionBuilder<LivermoreElement, MemSpace::host, ElementId> elements_;
0042 };
0043 
0044 //---------------------------------------------------------------------------//
0045 // INLINE DEFINITIONS
0046 //---------------------------------------------------------------------------//
0047 /*!
0048  * Construct with data.
0049  */
0050 LivermoreXsInserter::LivermoreXsInserter(Data* data)
0051     : build_grid_{&data->reals}
0052     , shells_{&data->shells}
0053     , elements_{&data->elements}
0054 {
0055     CELER_EXPECT(data);
0056 }
0057 
0058 //---------------------------------------------------------------------------//
0059 /*!
0060  * Construct cross section data for a single element.
0061  */
0062 void LivermoreXsInserter::operator()(ImportLivermorePE const& inp)
0063 {
0064     CELER_EXPECT(!inp.shells.empty());
0065     if constexpr (CELERITAS_DEBUG)
0066     {
0067         CELER_EXPECT(inp.thresh_lo <= inp.thresh_hi);
0068         for (auto const& shell : inp.shells)
0069         {
0070             CELER_EXPECT(shell.param_lo.size() == 6);
0071             CELER_EXPECT(shell.param_hi.size() == 6);
0072             CELER_EXPECT(shell.binding_energy <= inp.thresh_lo);
0073         }
0074     }
0075     using units::MevEnergy;
0076 
0077     LivermoreElement el;
0078 
0079     // Add tabulated total cross sections. High energy cross sections use
0080     // spline interpolation if enabled; low energy cross sections use linear.
0081     if (inp.xs_lo)
0082     {
0083         // Z < 3 have no low-energy cross sections
0084         el.xs_lo = build_grid_(inp.xs_lo);
0085     }
0086     el.xs_hi = build_grid_(inp.xs_hi);
0087 
0088     // Add energy thresholds for using low and high xs parameterization
0089     el.thresh_lo = MevEnergy(inp.thresh_lo);
0090     el.thresh_hi = MevEnergy(inp.thresh_hi);
0091 
0092     // Allocate subshell data
0093     std::vector<LivermoreSubshell> shells(inp.shells.size());
0094 
0095     // Add subshell data
0096     for (auto i : range(inp.shells.size()))
0097     {
0098         // Ionization energy
0099         shells[i].binding_energy = MevEnergy(inp.shells[i].binding_energy);
0100 
0101         // Tabulated subshell cross section
0102         shells[i].xs = build_grid_(inp.shells[i].xs);
0103 
0104         // Subshell cross section fit parameters
0105         std::copy(inp.shells[i].param_lo.begin(),
0106                   inp.shells[i].param_lo.end(),
0107                   shells[i].param[0].begin());
0108         std::copy(inp.shells[i].param_hi.begin(),
0109                   inp.shells[i].param_hi.end(),
0110                   shells[i].param[1].begin());
0111 
0112         CELER_ASSERT(shells[i]);
0113     }
0114     el.shells = shells_.insert_back(shells.begin(), shells.end());
0115 
0116     // Add the elemental data
0117     CELER_ASSERT(el);
0118     elements_.push_back(el);
0119 
0120     CELER_ENSURE(el.shells.size() == inp.shells.size());
0121 }
0122 
0123 //---------------------------------------------------------------------------//
0124 }  // namespace detail
0125 }  // namespace celeritas