diff --git a/src/celeritas/alongstep/detail/FluctELoss.hh b/src/celeritas/alongstep/detail/FluctELoss.hh index f2c33b967a..3f1d5c9b12 100644 --- a/src/celeritas/alongstep/detail/FluctELoss.hh +++ b/src/celeritas/alongstep/detail/FluctELoss.hh @@ -81,9 +81,8 @@ CELER_FUNCTION bool FluctELoss::is_applicable(CoreTrackView const& track) const if (track.make_sim_view().status() == TrackStatus::errored) return false; - // Energy loss grid ID will be 'false' if inapplicable - auto ppid = track.make_physics_view().eloss_ppid(); - return static_cast(ppid); + // Energy loss grid ID is 'false' + return static_cast(track.make_physics_view().energy_loss_grid()); } //---------------------------------------------------------------------------// diff --git a/src/celeritas/alongstep/detail/MeanELoss.hh b/src/celeritas/alongstep/detail/MeanELoss.hh index ea9042ad0e..5b979686eb 100644 --- a/src/celeritas/alongstep/detail/MeanELoss.hh +++ b/src/celeritas/alongstep/detail/MeanELoss.hh @@ -53,9 +53,8 @@ CELER_FUNCTION bool MeanELoss::is_applicable(CoreTrackView const& track) const if (track.make_sim_view().status() == TrackStatus::errored) return false; - // Energy loss grid ID will be 'false' if inapplicable - auto ppid = track.make_physics_view().eloss_ppid(); - return static_cast(ppid); + // Energy loss grid ID is 'false' + return static_cast(track.make_physics_view().energy_loss_grid()); } //---------------------------------------------------------------------------// diff --git a/src/celeritas/em/msc/detail/UrbanMscHelper.hh b/src/celeritas/em/msc/detail/UrbanMscHelper.hh index d55ac470a9..8a442fc271 100644 --- a/src/celeritas/em/msc/detail/UrbanMscHelper.hh +++ b/src/celeritas/em/msc/detail/UrbanMscHelper.hh @@ -17,7 +17,6 @@ #include "celeritas/grid/EnergyLossCalculator.hh" #include "celeritas/grid/InverseRangeCalculator.hh" #include "celeritas/grid/RangeCalculator.hh" -#include "celeritas/grid/ValueGridType.hh" #include "celeritas/grid/XsCalculator.hh" #include "celeritas/phys/ParticleTrackView.hh" #include "celeritas/phys/PhysicsTrackView.hh" @@ -145,10 +144,8 @@ CELER_FUNCTION real_type UrbanMscHelper::calc_msc_mfp(Energy energy) const CELER_FUNCTION auto UrbanMscHelper::calc_inverse_range(real_type step) const -> Energy { - auto range_gid - = physics_.value_grid(ValueGridType::range, physics_.eloss_ppid()); - auto range_to_energy - = physics_.make_calculator(range_gid); + auto range_to_energy = physics_.make_calculator( + physics_.range_grid()); return range_to_energy(step); } @@ -172,11 +169,9 @@ UrbanMscHelper::calc_end_energy(real_type step) const -> Energy real_type range = physics_.dedx_range(); if (step <= range * shared_.params.dtrl()) { - auto eloss_gid = physics_.value_grid(ValueGridType::energy_loss, - physics_.eloss_ppid()); // Assume constant energy loss rate over the step real_type dedx = physics_.make_calculator( - eloss_gid)(particle_.energy()); + physics_.energy_loss_grid())(particle_.energy()); return particle_.energy() - Energy{step * dedx}; } diff --git a/src/celeritas/phys/Model.hh b/src/celeritas/phys/Model.hh index 90906a5561..6d3241b3b0 100644 --- a/src/celeritas/phys/Model.hh +++ b/src/celeritas/phys/Model.hh @@ -16,7 +16,6 @@ #include "celeritas/Types.hh" #include "celeritas/global/ActionInterface.hh" // IWYU pragma: export #include "celeritas/grid/ValueGridBuilder.hh" -#include "celeritas/grid/ValueGridType.hh" #include "Applicability.hh" // IWYU pragma: export diff --git a/src/celeritas/phys/PhysicsData.hh b/src/celeritas/phys/PhysicsData.hh index 797b0f3086..d761188a5b 100644 --- a/src/celeritas/phys/PhysicsData.hh +++ b/src/celeritas/phys/PhysicsData.hh @@ -16,7 +16,6 @@ #include "celeritas/em/data/AtomicRelaxationData.hh" #include "celeritas/em/data/EPlusGGData.hh" #include "celeritas/em/data/LivermorePEData.hh" -#include "celeritas/grid/ValueGridType.hh" #include "celeritas/grid/XsGridData.hh" #include "celeritas/neutron/data/NeutronElasticData.hh" @@ -118,22 +117,20 @@ struct IntegralXsProcess /*! * Processes for a single particle type. * - * Each index should be accessed with type ParticleProcessId. The "tables" are - * a fixed-size number of ItemRange references to ValueTables. The first index - * of the table (hard-coded) corresponds to ValueGridType; the second index is - * a ParticleProcessId. So the cross sections for ParticleProcessId{2} would - * be \code tables[ValueGridType::macro_xs][2] \endcode. This - * awkward access is encapsulated by the PhysicsTrackView. \c integral_xs will - * only be assigned if the integral approach is used and the particle has - * continuous-discrete processes. + * Each index should be accessed with type ParticleProcessId. \c macro_xs + * stores the cross section tables for each process, while \c energy_loss and + * \c range are the process-integrated dE/dx and range for the particle. \c + * integral_xs will only be assigned if the integral approach is used and the + * particle has continuous-discrete processes. */ struct ProcessGroup { ItemRange processes; //!< Processes that apply [ppid] - ValueGridArray> tables; //!< [vgt][ppid] - ItemRange integral_xs; //!< [ppid] ItemRange models; //!< Model applicability [ppid] - ParticleProcessId eloss_ppid{}; //!< Process with de/dx and range tables + ItemRange integral_xs; //!< [ppid] + ItemRange macro_xs; //!< [ppid] + ValueTableId energy_loss; //!< Process-integrated energy loss + ValueTableId range; //!< Process-integrated range bool has_at_rest{}; //!< Whether the particle type has an at-rest process //! True if assigned and valid @@ -306,16 +303,16 @@ struct PhysicsParamsScalars /*! * Persistent shared physics data. * - * This includes macroscopic cross section, energy loss, and range tables - * ordered by [particle][process][material][energy]. + * This includes macroscopic cross section tables ordered by + * [particle][process][material][energy] and process-integrated energy loss and + * range tables ordered by [particle][material][energy]. * * So the first applicable process (ProcessId{0}) for an arbitrary particle * (ParticleId{1}) in material 2 (MaterialId{2}) will have the following * ID and cross section grid: \code ProcessId proc_id = params.particle[1].processes[0]; const UniformGridData& grid - = - params.particle[1].table[int(ValueGridType::macro_xs)][0].material[2].log_energy; + = params.particle[1].macro_xs[0].material[2].log_energy; * \endcode */ template diff --git a/src/celeritas/phys/PhysicsParams.cc b/src/celeritas/phys/PhysicsParams.cc index c91a3d3ac9..4574aad00a 100644 --- a/src/celeritas/phys/PhysicsParams.cc +++ b/src/celeritas/phys/PhysicsParams.cc @@ -454,6 +454,7 @@ void PhysicsParams::build_xs(Options const& opts, using UPGridBuilder = Process::UPConstGridBuilder; using Energy = Applicability::Energy; + using VGT = ValueGridType; ValueGridInserter insert_grid(&data->reals, &data->value_grids); auto value_tables = make_builder(&data->value_tables); @@ -477,12 +478,11 @@ void PhysicsParams::build_xs(Options const& opts, = data->model_groups[process_groups.models]; CELER_ASSERT(processes.size() == model_groups.size()); - // Material-dependent physics tables, one per particle-process - ValueGridArray> temp_tables; - for (auto& vec : temp_tables) - { - vec.resize(processes.size()); - } + // Material-dependent physics tables, one cross section table per + // particle-process and one dedx/range table per particle + std::vector xs_table(processes.size()); + ValueTable eloss_table; + ValueTable range_table; // Processes with dE/dx and macro xs tables std::vector temp_integral_xs(processes.size()); @@ -501,11 +501,9 @@ void PhysicsParams::build_xs(Options const& opts, Process const& proc = *this->process(processes[pp_idx]); // Grid IDs for each grid type, each material - ValueGridArray> temp_grid_ids; - for (auto& vec : temp_grid_ids) - { - vec.resize(mats.size()); - } + std::vector xs_grid_ids(mats.size()); + std::vector eloss_grid_ids(mats.size()); + std::vector range_grid_ids(mats.size()); // Energy of maximum cross section for each material std::vector energy_max_xs; @@ -517,9 +515,9 @@ void PhysicsParams::build_xs(Options const& opts, } // Loop over materials - for (auto mat_id : range(MaterialId{mats.size()})) + for (auto mat_idx : range(MaterialId::size_type{mats.size()})) { - applic.material = mat_id; + applic.material = MaterialId(mat_idx); // Construct step limit builders auto builders = proc.step_limits(applic); @@ -532,11 +530,10 @@ void PhysicsParams::build_xs(Options const& opts, "have at least one)"); // Construct grids - for (auto vgt : range(ValueGridType::size_)) - { - temp_grid_ids[vgt][mat_id.get()] - = build_grid(builders[vgt]); - } + xs_grid_ids[mat_idx] = build_grid(builders[VGT::macro_xs]); + eloss_grid_ids[mat_idx] + = build_grid(builders[VGT::energy_loss]); + range_grid_ids[mat_idx] = build_grid(builders[VGT::range]); if (processes[pp_idx] == data->hardwired.positron_annihilation) { @@ -547,11 +544,10 @@ void PhysicsParams::build_xs(Options const& opts, { // Annihilation cross section is maximum at zero and // decreases with increasing energy - energy_max_xs[mat_id.get()] = 0; + energy_max_xs[mat_idx] = 0; } } - else if (auto grid_id - = temp_grid_ids[ValueGridType::macro_xs][mat_id.get()]) + else if (auto grid_id = xs_grid_ids[mat_idx]) { auto const& grid_data = data->value_grids[grid_id]; auto data_ref = make_const_ref(*data); @@ -579,37 +575,39 @@ void PhysicsParams::build_xs(Options const& opts, } } CELER_ASSERT(e_max > 0); - energy_max_xs[mat_id.get()] = e_max; + energy_max_xs[mat_idx] = e_max; } } - - // Index of the energy loss process that stores the de/dx and - // range tables - if (temp_grid_ids[ValueGridType::energy_loss][mat_id.get()] - && temp_grid_ids[ValueGridType::range][mat_id.get()]) - { - // Only one particle-process should have energy loss tables - CELER_ASSERT(!process_groups.eloss_ppid - || pp_idx == process_groups.eloss_ppid.get()); - process_groups.eloss_ppid = ParticleProcessId{pp_idx}; - } } - // Outer loop over grid types - for (auto vgt : range(ValueGridType::size_)) - { - if (!std::any_of(temp_grid_ids[vgt].begin(), - temp_grid_ids[vgt].end(), - [](ValueGridId id) { return bool(id); })) - { - continue; - } + // Check if any material has value grids + auto has_grids = [](std::vector const& vec_id) { + return std::any_of(vec_id.begin(), + vec_id.end(), + [](ValueGridId id) { return bool(id); }); + }; - // Construct value grid table - ValueTable& temp_table = temp_tables[vgt][pp_idx]; - temp_table.grids = value_grid_ids.insert_back( - temp_grid_ids[vgt].begin(), temp_grid_ids[vgt].end()); - CELER_ASSERT(temp_table.grids.size() == mats.size()); + // Construct value grid tables + if (has_grids(xs_grid_ids)) + { + xs_table[pp_idx].grids = value_grid_ids.insert_back( + xs_grid_ids.begin(), xs_grid_ids.end()); + CELER_ASSERT(xs_table[pp_idx].grids.size() == mats.size()); + } + if (has_grids(eloss_grid_ids)) + { + CELER_VALIDATE(!eloss_table && !range_table, + << "more than one process for particle ID " + << particle_id.get() + << " has energy loss tables"); + + CELER_ASSERT(has_grids(range_grid_ids)); + eloss_table.grids = value_grid_ids.insert_back( + eloss_grid_ids.begin(), eloss_grid_ids.end()); + range_table.grids = value_grid_ids.insert_back( + range_grid_ids.begin(), range_grid_ids.end()); + CELER_ASSERT(eloss_table.grids.size() == mats.size() + && range_table.grids.size() == mats.size()); } // Store the energies of the maximum cross sections @@ -627,11 +625,10 @@ void PhysicsParams::build_xs(Options const& opts, temp_integral_xs.begin(), temp_integral_xs.end()); // Construct value tables - for (auto vgt : range(ValueGridType::size_)) - { - process_groups.tables[vgt] = value_tables.insert_back( - temp_tables[vgt].begin(), temp_tables[vgt].end()); - } + process_groups.macro_xs + = value_tables.insert_back(xs_table.begin(), xs_table.end()); + process_groups.energy_loss = value_tables.push_back(eloss_table); + process_groups.range = value_tables.push_back(range_table); } } diff --git a/src/celeritas/phys/PhysicsStepUtils.hh b/src/celeritas/phys/PhysicsStepUtils.hh index 4120a955d9..ce7d583a1b 100644 --- a/src/celeritas/phys/PhysicsStepUtils.hh +++ b/src/celeritas/phys/PhysicsStepUtils.hh @@ -18,7 +18,6 @@ #include "celeritas/grid/InverseRangeCalculator.hh" #include "celeritas/grid/RangeCalculator.hh" #include "celeritas/grid/SplineXsCalculator.hh" -#include "celeritas/grid/ValueGridType.hh" #include "celeritas/grid/XsCalculator.hh" #include "celeritas/mat/MaterialTrackView.hh" #include "celeritas/random/Selector.hh" @@ -42,8 +41,6 @@ calc_physics_step_limit(MaterialTrackView const& material, { CELER_EXPECT(physics.has_interaction_mfp()); - using VGT = ValueGridType; - /*! \todo For particles with decay, macro XS calculation will incorporate * decay probability, dividing decay constant by speed to become 1/len to * compete with interactions. @@ -86,9 +83,8 @@ calc_physics_step_limit(MaterialTrackView const& material, else { limit.step = physics.interaction_mfp() / total_macro_xs; - if (auto ppid = physics.eloss_ppid()) + if (auto grid_id = physics.range_grid()) { - auto grid_id = physics.value_grid(VGT::range, ppid); auto calc_range = physics.make_calculator(grid_id); real_type range = calc_range(particle.energy()); // Save range for the current step and reuse it elsewhere @@ -180,20 +176,17 @@ calc_mean_energy_loss(ParticleTrackView const& particle, real_type step) { CELER_EXPECT(step > 0); - CELER_EXPECT(physics.eloss_ppid()); using Energy = ParticleTrackView::Energy; - using VGT = ValueGridType; static_assert(Energy::unit_type::value() == EnergyLossCalculator::Energy::unit_type::value(), "Incompatible energy types"); - auto ppid = physics.eloss_ppid(); Energy const pre_step_energy = particle.energy(); // Calculate the sum of energy loss rate over all processes. Energy eloss; { - auto grid_id = physics.value_grid(VGT::energy_loss, ppid); + auto grid_id = physics.energy_loss_grid(); CELER_ASSERT(grid_id); size_type order = physics.scalars().spline_eloss_order; @@ -218,7 +211,7 @@ calc_mean_energy_loss(ParticleTrackView const& particle, // approximation is probably wrong. Use the definition of the range as // the integral of 1/loss to back-calculate the actual energy loss // along the curve given the actual step. - auto grid_id = physics.value_grid(VGT::range, ppid); + auto grid_id = physics.range_grid(); CELER_ASSERT(grid_id); // Use the range limit stored from calc_physics_step_limit diff --git a/src/celeritas/phys/PhysicsTrackView.hh b/src/celeritas/phys/PhysicsTrackView.hh index cdec923bba..f1fb88deff 100644 --- a/src/celeritas/phys/PhysicsTrackView.hh +++ b/src/celeritas/phys/PhysicsTrackView.hh @@ -95,9 +95,14 @@ class PhysicsTrackView // Process ID for the given within-particle process index inline CELER_FUNCTION ProcessId process(ParticleProcessId) const; - // Get table, null if not present for this particle/material/type - inline CELER_FUNCTION ValueGridId value_grid(ValueGridType table, - ParticleProcessId) const; + // Get macro xs table, null if not present for this particle/material + inline CELER_FUNCTION ValueGridId macro_xs_grid(ParticleProcessId) const; + + // Get energy loss table, null if not present for this particle/material + inline CELER_FUNCTION ValueGridId energy_loss_grid() const; + + // Get range table, null if not present for this particle/material + inline CELER_FUNCTION ValueGridId range_grid() const; // Get data for processes that use the integral approach inline CELER_FUNCTION IntegralXsProcess const& @@ -164,9 +169,6 @@ class PhysicsTrackView inline CELER_FUNCTION ModelId hardwired_model(ParticleProcessId ppid, Energy energy) const; - // Particle-process ID of the process with the de/dx and range tables - inline CELER_FUNCTION ParticleProcessId eloss_ppid() const; - private: PhysicsParamsRef const& params_; PhysicsStateRef const& states_; @@ -179,6 +181,7 @@ class PhysicsTrackView CELER_FORCEINLINE_FUNCTION PhysicsTrackState& state(); CELER_FORCEINLINE_FUNCTION PhysicsTrackState const& state() const; CELER_FORCEINLINE_FUNCTION ProcessGroup const& process_group() const; + inline CELER_FUNCTION ValueGridId value_grid(ValueTableId) const; }; //---------------------------------------------------------------------------// @@ -333,35 +336,31 @@ CELER_FUNCTION ProcessId PhysicsTrackView::process(ParticleProcessId ppid) const //---------------------------------------------------------------------------// /*! - * Return value grid data for the given table type and process if available. - * - * If the result is not null, it can be used to instantiate a - * grid Calculator. - * - * If the result is null, it's likely because the process doesn't have the - * associated value (e.g. if the table type is "energy_loss" and the process is - * not a slowing-down process). + * Return macro xs value grid data for the given process if available. */ CELER_FUNCTION auto -PhysicsTrackView::value_grid(ValueGridType table_type, - ParticleProcessId ppid) const -> ValueGridId +PhysicsTrackView::macro_xs_grid(ParticleProcessId ppid) const -> ValueGridId { - CELER_EXPECT(int(table_type) < int(ValueGridType::size_)); CELER_EXPECT(ppid < this->num_particle_processes()); - ValueTableId table_id - = this->process_group().tables[table_type][ppid.get()]; - - CELER_ASSERT(table_id); - ValueTable const& table = params_.value_tables[table_id]; - if (!table) - return {}; // No table for this process + return this->value_grid(this->process_group().macro_xs[ppid.get()]); +} - CELER_EXPECT(material_ < table.grids.size()); - auto grid_id_ref = table.grids[material_.get()]; - if (!grid_id_ref) - return {}; // No table for this particular material +//---------------------------------------------------------------------------// +/*! + * Return the energy loss grid data if available. + */ +CELER_FUNCTION auto PhysicsTrackView::energy_loss_grid() const -> ValueGridId +{ + return this->value_grid(this->process_group().energy_loss); +} - return params_.value_grid_ids[grid_id_ref]; +//---------------------------------------------------------------------------// +/*! + * Return the range grid data if available. + */ +CELER_FUNCTION auto PhysicsTrackView::range_grid() const -> ValueGridId +{ + return this->value_grid(this->process_group().range); } //---------------------------------------------------------------------------// @@ -430,7 +429,7 @@ CELER_FUNCTION real_type PhysicsTrackView::calc_xs(ParticleProcessId ppid, result = calc_xs(energy); } } - else if (auto grid_id = this->value_grid(ValueGridType::macro_xs, ppid)) + else if (auto grid_id = this->macro_xs_grid(ppid)) { // Calculate cross section from the tabulated data auto calc_xs = this->make_calculator(grid_id); @@ -499,15 +498,6 @@ CELER_FUNCTION ModelId PhysicsTrackView::hardwired_model(ParticleProcessId ppid, return {}; } -//---------------------------------------------------------------------------// -/*! - * Particle-process ID of the process with the de/dx and range tables. - */ -CELER_FUNCTION ParticleProcessId PhysicsTrackView::eloss_ppid() const -{ - return this->process_group().eloss_ppid; -} - //---------------------------------------------------------------------------// /*! * Models that apply to the given process ID. @@ -695,6 +685,33 @@ CELER_FUNCTION T PhysicsTrackView::make_calculator(ValueGridId id, //---------------------------------------------------------------------------// // IMPLEMENTATION HELPER FUNCTIONS //---------------------------------------------------------------------------// +/*! + * Return value grid data for the given table ID if available. + * + * If the result is not null, it can be used to instantiate a + * grid Calculator. + * + * If the result is null, it's likely because the process doesn't have the + * associated value (e.g. if the table type is "energy_loss" and the process is + * not a slowing-down process). + */ +CELER_FUNCTION auto PhysicsTrackView::value_grid(ValueTableId table_id) const + -> ValueGridId +{ + CELER_EXPECT(table_id); + + ValueTable const& table = params_.value_tables[table_id]; + if (!table) + return {}; // No table for this process + + CELER_EXPECT(material_ < table.grids.size()); + auto grid_id_ref = table.grids[material_.get()]; + if (!grid_id_ref) + return {}; // No table for this particular material + + return params_.value_grid_ids[grid_id_ref]; +} + //! Get the thread-local state (mutable) CELER_FUNCTION PhysicsTrackState& PhysicsTrackView::state() { diff --git a/test/celeritas/em/MscTestBase.cc b/test/celeritas/em/MscTestBase.cc index d04b83adc8..eab460f15a 100644 --- a/test/celeritas/em/MscTestBase.cc +++ b/test/celeritas/em/MscTestBase.cc @@ -78,8 +78,7 @@ MscTestBase::make_phys_view(ParticleTrackView const& par, phys_view = PhysicsTrackInitializer{}; // Calculate and store the energy loss (dedx) range limit - auto ppid = phys_view.eloss_ppid(); - auto grid_id = phys_view.value_grid(ValueGridType::range, ppid); + auto grid_id = phys_view.range_grid(); auto calc_range = phys_view.make_calculator(grid_id); real_type range = calc_range(par.energy()); phys_view.dedx_range(range); diff --git a/test/celeritas/phys/Physics.test.cc b/test/celeritas/phys/Physics.test.cc index afea841c62..0ada6b34f6 100644 --- a/test/celeritas/phys/Physics.test.cc +++ b/test/celeritas/phys/Physics.test.cc @@ -142,7 +142,7 @@ TEST_F(PhysicsParamsTest, output) GTEST_SKIP() << "Test results are based on CGS units"; } EXPECT_JSON_EQ( - R"json({"_category":"internal","_label":"physics","models":{"label":["mock-model-1","mock-model-2","mock-model-3","mock-model-4","mock-model-5","mock-model-6","mock-model-7","mock-model-8","mock-model-9","mock-model-10","mock-model-11"],"process_id":[0,0,1,2,2,2,3,3,4,4,5]},"options":{"fixed_step_limiter":0.0,"linear_loss_limit":0.01,"lowest_electron_energy":[0.001,"MeV"],"max_step_over_range":0.2,"min_eprime_over_e":0.8,"min_range":0.1,"spline_eloss_order":1},"processes":{"label":["scattering","absorption","purrs","hisses","meows","barks"]},"sizes":{"integral_xs":8,"model_groups":8,"model_ids":11,"process_groups":5,"process_ids":8,"reals":257,"value_grid_ids":89,"value_grids":89,"value_tables":35}})json", + R"json({"_category":"internal","_label":"physics","models":{"label":["mock-model-1","mock-model-2","mock-model-3","mock-model-4","mock-model-5","mock-model-6","mock-model-7","mock-model-8","mock-model-9","mock-model-10","mock-model-11"],"process_id":[0,0,1,2,2,2,3,3,4,4,5]},"options":{"fixed_step_limiter":0.0,"linear_loss_limit":0.01,"lowest_electron_energy":[0.001,"MeV"],"max_step_over_range":0.2,"min_eprime_over_e":0.8,"min_range":0.1,"spline_eloss_order":1},"processes":{"label":["scattering","absorption","purrs","hisses","meows","barks"]},"sizes":{"integral_xs":8,"model_groups":8,"model_ids":11,"process_groups":5,"process_ids":8,"reals":257,"value_grid_ids":89,"value_grids":89,"value_tables":29}})json", to_string(out)); } @@ -413,6 +413,10 @@ TEST_F(PhysicsTrackViewHostTest, value_grids) { std::vector grid_ids; + auto id_to_int = [](ValueGridId vgid) { + return vgid ? static_cast(vgid.unchecked_get()) : -1; + }; + for (char const* particle : {"gamma", "celeriton", "anti-celeriton"}) { for (auto mat_id : range(MaterialId{this->material()->size()})) @@ -423,23 +427,20 @@ TEST_F(PhysicsTrackViewHostTest, value_grids) for (auto pp_id : range(ParticleProcessId{phys.num_particle_processes()})) { - for (ValueGridType vgt : range(ValueGridType::size_)) - { - auto id = phys.value_grid(vgt, pp_id); - grid_ids.push_back(id ? static_cast(id.get()) : -1); - } + grid_ids.push_back(id_to_int(phys.macro_xs_grid(pp_id))); } + grid_ids.push_back(id_to_int(phys.energy_loss_grid())); + grid_ids.push_back(id_to_int(phys.range_grid())); } } // Grid IDs should be unique if they exist. Gammas should have fewer // because there aren't any slowing down/range limiters. - static int const expected_grid_ids[] - = {0, -1, -1, 4, -1, -1, 1, -1, -1, 5, -1, -1, 2, -1, -1, 6, -1, - -1, 3, -1, -1, 7, -1, -1, 8, -1, -1, 12, 13, 14, 24, -1, -1, 9, - -1, -1, 15, 16, 17, 25, -1, -1, 10, -1, -1, 18, 19, 20, 26, -1, -1, - 11, -1, -1, 21, 22, 23, 27, -1, -1, 28, 29, 30, 40, -1, -1, 31, 32, - 33, 41, -1, -1, 34, 35, 36, 42, -1, -1, 37, 38, 39, 43, -1, -1}; + static int const expected_grid_ids[] = { + 0, 4, -1, -1, 1, 5, -1, -1, 2, 6, -1, -1, 3, 7, -1, -1, 8, 12, + 24, 13, 14, 9, 15, 25, 16, 17, 10, 18, 26, 19, 20, 11, 21, 27, 22, 23, + 28, 40, 29, 30, 31, 41, 32, 33, 34, 42, 35, 36, 37, 43, 38, 39, + }; EXPECT_VEC_EQ(expected_grid_ids, grid_ids); } @@ -455,7 +456,7 @@ TEST_F(PhysicsTrackViewHostTest, calc_xs) PhysicsTrackView const phys = this->make_track_view(particle, mat_id); auto scat_ppid = this->find_ppid(phys, "scattering"); - auto id = phys.value_grid(ValueGridType::macro_xs, scat_ppid); + auto id = phys.macro_xs_grid(scat_ppid); ASSERT_TRUE(id); auto calc_xs = phys.make_calculator(id); xs.push_back(to_inv_cm(calc_xs(MevEnergy{1.0}))); @@ -482,14 +483,12 @@ TEST_F(PhysicsTrackViewHostTest, calc_eloss_range) { PhysicsTrackView const phys = this->make_track_view(particle, MaterialId{0}); - auto ppid = phys.eloss_ppid(); - ASSERT_TRUE(ppid); - auto eloss_id = phys.value_grid(ValueGridType::energy_loss, ppid); + auto eloss_id = phys.energy_loss_grid(); ASSERT_TRUE(eloss_id); auto calc_eloss = phys.make_calculator(eloss_id); - auto range_id = phys.value_grid(ValueGridType::range, ppid); + auto range_id = phys.range_grid(); ASSERT_TRUE(range_id); auto calc_range = phys.make_calculator(range_id); for (real_type energy : {1e-6, 0.01, 1.0, 1e2}) @@ -661,7 +660,7 @@ TEST_F(PhysicsTrackViewHostTest, calc_spline_xs) PhysicsTrackView const phys = this->make_track_view(particle, mat_id); auto scat_ppid = this->find_ppid(phys, "scattering"); - auto id = phys.value_grid(ValueGridType::macro_xs, scat_ppid); + auto id = phys.macro_xs_grid(scat_ppid); ASSERT_TRUE(id); auto calc_xs = phys.make_calculator(id, 2); xs.push_back(to_inv_cm(calc_xs(MevEnergy{1.0}))); diff --git a/test/celeritas/phys/Physics.test.hh b/test/celeritas/phys/Physics.test.hh index 0f7d0032f0..e68faa3d97 100644 --- a/test/celeritas/phys/Physics.test.hh +++ b/test/celeritas/phys/Physics.test.hh @@ -61,7 +61,7 @@ inline CELER_FUNCTION real_type calc_step(PhysicsTrackView& phys, for (auto ppid : range(ParticleProcessId{phys.num_particle_processes()})) { real_type process_xs = 0; - if (auto id = phys.value_grid(ValueGridType::macro_xs, ppid)) + if (auto id = phys.macro_xs_grid(ppid)) { auto calc_xs = phys.make_calculator(id); process_xs = calc_xs(energy); @@ -82,13 +82,10 @@ inline CELER_FUNCTION real_type calc_step(PhysicsTrackView& phys, // Calc minimum range auto const inf = numeric_limits::infinity(); real_type step = inf; - for (auto ppid : range(ParticleProcessId{phys.num_particle_processes()})) + if (auto id = phys.range_grid()) { - if (auto id = phys.value_grid(ValueGridType::range, ppid)) - { - auto calc_range = phys.make_calculator(id); - step = min(step, calc_range(energy)); - } + auto calc_range = phys.make_calculator(id); + step = min(step, calc_range(energy)); } if (step != inf) { diff --git a/test/celeritas/phys/PhysicsStepUtils.test.cc b/test/celeritas/phys/PhysicsStepUtils.test.cc index 188c70dbff..2484376bb3 100644 --- a/test/celeritas/phys/PhysicsStepUtils.test.cc +++ b/test/celeritas/phys/PhysicsStepUtils.test.cc @@ -227,8 +227,7 @@ TEST_F(PhysicsStepUtilsTest, calc_mean_energy_loss) // input: cm; output: MeV auto calc_eloss = [&](PhysicsTrackView& phys, real_type step) -> real_type { // Calculate and store the energy loss range to PhysicsTrackView - auto ppid = phys.eloss_ppid(); - auto grid_id = phys.value_grid(ValueGridType::range, ppid); + auto grid_id = phys.range_grid(); auto calc_range = phys.make_calculator(grid_id); real_type range = calc_range(particle.energy()); phys.dedx_range(range); @@ -481,8 +480,7 @@ TEST_F(SplinePhysicsStepUtilsTest, calc_mean_energy_loss) // input: cm; output: MeV auto calc_eloss = [&](PhysicsTrackView& phys, real_type step) -> real_type { // Calculate and store the energy loss range to PhysicsTrackView - auto ppid = phys.eloss_ppid(); - auto grid_id = phys.value_grid(ValueGridType::range, ppid); + auto grid_id = phys.range_grid(); auto calc_range = phys.make_calculator(grid_id); real_type range = calc_range(particle.energy()); phys.dedx_range(range);