File indexing completed on 2025-02-22 10:31:25
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include "corecel/Assert.hh"
0011 #include "corecel/Macros.hh"
0012 #include "corecel/Types.hh"
0013 #include "celeritas/Types.hh"
0014 #include "celeritas/grid/XsCalculator.hh"
0015 #include "celeritas/phys/PhysicsData.hh"
0016 #include "celeritas/random/distribution/GenerateCanonical.hh"
0017
0018 namespace celeritas
0019 {
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 class TabulatedElementSelector
0030 {
0031 public:
0032
0033
0034 using Energy = Quantity<XsGridData::EnergyUnits>;
0035 using GridValues
0036 = Collection<ValueGrid, Ownership::const_reference, MemSpace::native>;
0037 using GridIdValues
0038 = Collection<ValueGridId, Ownership::const_reference, MemSpace::native>;
0039 using Values
0040 = Collection<real_type, Ownership::const_reference, MemSpace::native>;
0041
0042
0043 public:
0044
0045 inline CELER_FUNCTION TabulatedElementSelector(ValueTable const& table,
0046 GridValues const& grids,
0047 GridIdValues const& ids,
0048 Values const& reals,
0049 Energy energy);
0050
0051
0052 template<class Engine>
0053 inline CELER_FUNCTION ElementComponentId operator()(Engine& rng) const;
0054
0055 private:
0056 ValueTable const& table_;
0057 GridValues const& grids_;
0058 GridIdValues const& ids_;
0059 Values const& reals_;
0060 Energy const energy_;
0061 };
0062
0063
0064
0065
0066
0067
0068
0069 CELER_FUNCTION
0070 TabulatedElementSelector::TabulatedElementSelector(ValueTable const& table,
0071 GridValues const& grids,
0072 GridIdValues const& ids,
0073 Values const& reals,
0074 Energy energy)
0075 : table_(table), grids_(grids), ids_(ids), reals_(reals), energy_(energy)
0076 {
0077 CELER_EXPECT(table);
0078 }
0079
0080
0081
0082
0083
0084 template<class Engine>
0085 CELER_FUNCTION ElementComponentId
0086 TabulatedElementSelector::operator()(Engine& rng) const
0087 {
0088 size_type i = 0;
0089 real_type u = generate_canonical(rng);
0090 for (; i < table_.grids.size() - 1; ++i)
0091 {
0092 ValueGridId grid_id = ids_[table_.grids[i]];
0093 CELER_ASSERT(grid_id < grids_.size());
0094 XsCalculator calc_xs(grids_[grid_id], reals_);
0095 if (calc_xs(energy_) > u)
0096 break;
0097 }
0098 return ElementComponentId{i};
0099 }
0100
0101
0102 }