Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-28 08:39:02

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/user/detail/ActionDiagnosticExecutor.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Assert.hh"
0010 #include "corecel/Macros.hh"
0011 #include "corecel/math/Atomics.hh"
0012 #include "celeritas/global/CoreTrackView.hh"
0013 
0014 #include "../ParticleTallyData.hh"
0015 
0016 namespace celeritas
0017 {
0018 namespace detail
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Tally tracks that are active, have errors, *or* are killed.
0023  */
0024 struct ActionDiagnosticCondition
0025 {
0026     CELER_FUNCTION bool operator()(SimTrackView const& sim) const
0027     {
0028         return sim.status() != TrackStatus::inactive;
0029     }
0030 };
0031 
0032 //---------------------------------------------------------------------------//
0033 /*!
0034  * Tally post-step actions by particle type.
0035  */
0036 struct ActionDiagnosticExecutor
0037 {
0038     inline CELER_FUNCTION void
0039     operator()(celeritas::CoreTrackView const& track);
0040 
0041     NativeCRef<ParticleTallyParamsData> const params;
0042     NativeRef<ParticleTallyStateData> const state;
0043 };
0044 
0045 //---------------------------------------------------------------------------//
0046 CELER_FUNCTION void
0047 ActionDiagnosticExecutor::operator()(CoreTrackView const& track)
0048 {
0049     CELER_EXPECT(params);
0050     CELER_EXPECT(state);
0051 
0052     using BinId = ItemId<size_type>;
0053 
0054     auto action = track.sim().post_step_action();
0055     CELER_ASSERT(action);
0056     auto particle = track.particle().particle_id();
0057     CELER_ASSERT(particle);
0058 
0059     BinId bin{particle.unchecked_get() * params.num_bins
0060               + action.unchecked_get()};
0061     CELER_ASSERT(bin < state.counts.size());
0062     celeritas::atomic_add(&state.counts[bin], size_type(1));
0063 }
0064 
0065 //---------------------------------------------------------------------------//
0066 }  // namespace detail
0067 }  // namespace celeritas