File indexing completed on 2025-09-17 08:53:35
0001
0002
0003
0004
0005
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
0021
0022 class SBTableInserter
0023 {
0024 public:
0025
0026
0027 using Data = HostVal<SeltzerBergerTableData>;
0028
0029
0030 public:
0031
0032 explicit inline SBTableInserter(Data* data);
0033
0034
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
0048
0049
0050
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
0064
0065
0066
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
0079 std::vector<size_type> argmax(num_x);
0080 for (size_type i : range(num_x))
0081 {
0082
0083 real_type const* iter = &reals_[table.grid.at(i, 0)];
0084
0085
0086 size_type max_el = std::max_element(iter, iter + num_y) - iter;
0087 CELER_ASSERT(max_el < num_y);
0088
0089 argmax[i] = max_el;
0090 }
0091 table.argmax = argmax_.insert_back(argmax.begin(), argmax.end());
0092
0093
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 }
0104 }