Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:35

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/SBTableInserter.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/data/CollectionBuilder.hh"
0010 #include "celeritas/em/data/SeltzerBergerData.hh"
0011 #include "celeritas/grid/TwodGridBuilder.hh"
0012 #include "celeritas/io/ImportSBTable.hh"
0013 
0014 namespace celeritas
0015 {
0016 namespace detail
0017 {
0018 //---------------------------------------------------------------------------//
0019 /*!
0020  * Construct Seltzer-Berger differential cross section data from imported data.
0021  */
0022 class SBTableInserter
0023 {
0024   public:
0025     //!@{
0026     //! \name Type aliases
0027     using Data = HostVal<SeltzerBergerTableData>;
0028     //!@}
0029 
0030   public:
0031     // Construct with pointer to host data
0032     explicit inline SBTableInserter(Data* data);
0033 
0034     // Construct differential cross section table for a single element
0035     inline void operator()(ImportSBTable const& inp);
0036 
0037   private:
0038     using Values = Collection<real_type, Ownership::value, MemSpace::host>;
0039 
0040     TwodGridBuilder build_grid_;
0041     CollectionBuilder<size_type> argmax_;
0042     CollectionBuilder<SBElementTableData, MemSpace::host, ElementId> elements_;
0043     Values const& reals_;
0044 };
0045 
0046 //---------------------------------------------------------------------------//
0047 // INLINE DEFINITIONS
0048 //---------------------------------------------------------------------------//
0049 /*!
0050  * Construct with data.
0051  */
0052 SBTableInserter::SBTableInserter(Data* data)
0053     : build_grid_{&data->reals}
0054     , argmax_{&data->sizes}
0055     , elements_{&data->elements}
0056     , reals_(data->reals)
0057 {
0058     CELER_EXPECT(data);
0059 }
0060 
0061 //---------------------------------------------------------------------------//
0062 /*!
0063  * Construct differential cross section tables for a single element.
0064  *
0065  * Here, x is the log of scaled incident energy (E / MeV), y is the scaled
0066  * exiting energy (E_gamma / E_inc), and values are the cross sections.
0067  */
0068 void SBTableInserter::operator()(ImportSBTable const& inp)
0069 {
0070     CELER_EXPECT(inp);
0071 
0072     SBElementTableData table;
0073     table.grid = build_grid_(inp);
0074 
0075     size_type const num_x = inp.x.size();
0076     size_type const num_y = inp.y.size();
0077 
0078     // Find the location of the highest cross section at each incident E
0079     std::vector<size_type> argmax(num_x);
0080     for (size_type i : range(num_x))
0081     {
0082         // Get the xs data for the given incident energy coordinate
0083         real_type const* iter = &reals_[table.grid.at(i, 0)];
0084 
0085         // Search for the highest cross section value
0086         size_type max_el = std::max_element(iter, iter + num_y) - iter;
0087         CELER_ASSERT(max_el < num_y);
0088         // Save it!
0089         argmax[i] = max_el;
0090     }
0091     table.argmax = argmax_.insert_back(argmax.begin(), argmax.end());
0092 
0093     // Add the table
0094     elements_.push_back(table);
0095 
0096     CELER_ENSURE(table.grid.x.size() == num_x);
0097     CELER_ENSURE(table.grid.y.size() == num_y);
0098     CELER_ENSURE(table.argmax.size() == num_x);
0099     CELER_ENSURE(table.grid);
0100 }
0101 
0102 //---------------------------------------------------------------------------//
0103 }  // namespace detail
0104 }  // namespace celeritas