Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:32

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/user/detail/StepDiagnosticExecutor.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Assert.hh"
0011 #include "corecel/Macros.hh"
0012 #include "corecel/math/Algorithms.hh"
0013 #include "corecel/math/Atomics.hh"
0014 #include "celeritas/global/CoreTrackView.hh"
0015 
0016 #include "../ParticleTallyData.hh"
0017 
0018 namespace celeritas
0019 {
0020 namespace detail
0021 {
0022 //---------------------------------------------------------------------------//
0023 struct StepDiagnosticExecutor
0024 {
0025     inline CELER_FUNCTION void
0026     operator()(celeritas::CoreTrackView const& track);
0027 
0028     NativeCRef<ParticleTallyParamsData> const params;
0029     NativeRef<ParticleTallyStateData> const state;
0030 };
0031 
0032 //---------------------------------------------------------------------------//
0033 /*!
0034  * Collect distribution of steps per track for each particle type.
0035  */
0036 CELER_FUNCTION void
0037 StepDiagnosticExecutor::operator()(CoreTrackView const& track)
0038 {
0039     CELER_EXPECT(params);
0040     CELER_EXPECT(state);
0041 
0042     using BinId = ItemId<size_type>;
0043 
0044     // Tally the number of steps if the track was killed
0045     auto sim = track.make_sim_view();
0046     if (sim.status() == TrackStatus::killed)
0047     {
0048         // TODO: Add an ndarray-type class?
0049         auto get = [this](size_type i, size_type j) -> size_type& {
0050             size_type index = i * params.num_bins + j;
0051             CELER_ENSURE(index < state.counts.size());
0052             return state.counts[BinId(index)];
0053         };
0054 
0055         size_type num_steps
0056             = celeritas::min(sim.num_steps(), params.num_bins - 1);
0057         auto particle = track.make_particle_view().particle_id();
0058 
0059         // Increment the bin corresponding to the given particle and step count
0060         auto& bin = get(particle.get(), num_steps);
0061         atomic_add(&bin, size_type{1});
0062     }
0063 }
0064 
0065 //---------------------------------------------------------------------------//
0066 }  // namespace detail
0067 }  // namespace celeritas