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/StepDiagnostic.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <memory>
0011 #include <vector>
0012 
0013 #include "corecel/data/StreamStore.hh"
0014 #include "corecel/io/OutputInterface.hh"
0015 #include "celeritas/global/ActionInterface.hh"
0016 #include "celeritas/global/CoreTrackData.hh"
0017 
0018 #include "ParticleTallyData.hh"
0019 
0020 namespace celeritas
0021 {
0022 //---------------------------------------------------------------------------//
0023 class ParticleParams;
0024 
0025 //---------------------------------------------------------------------------//
0026 /*!
0027  * Tally post-step actions for each particle type.
0028  *
0029  * This adds an \c step-diagnostic entry to the \c result category of the
0030  * main Celeritas output that bins the total number of steps taken by a track,
0031  * grouped by particle type. The result is an integral over all events.
0032  */
0033 class StepDiagnostic final : public CoreStepActionInterface,
0034                              public OutputInterface
0035 {
0036   public:
0037     //!@{
0038     //! \name Type aliases
0039     using SPConstParticle = std::shared_ptr<ParticleParams const>;
0040     using VecVecCount = std::vector<std::vector<size_type>>;
0041     //!@}
0042 
0043   public:
0044     // Construct and add to core params
0045     static std::shared_ptr<StepDiagnostic>
0046     make_and_insert(CoreParams const& core, size_type max_bins);
0047 
0048     //! Construct with particle data
0049     StepDiagnostic(ActionId id,
0050                    SPConstParticle particle,
0051                    size_type max_bins,
0052                    size_type num_streams);
0053 
0054     //! Default destructor
0055     ~StepDiagnostic();
0056 
0057     //!@{
0058     //! \name ExplicitAction interface
0059     // Launch kernel with host data
0060     void step(CoreParams const&, CoreStateHost&) const final;
0061     // Launch kernel with device data
0062     void step(CoreParams const&, CoreStateDevice&) const final;
0063     //! ID of the action
0064     ActionId action_id() const final { return id_; }
0065     //! Short name for the action
0066     std::string_view label() const final { return "step-diagnostic"; }
0067     // Description of the action for user interaction
0068     std::string_view description() const final;
0069     //! Dependency ordering of the action
0070     StepActionOrder order() const final { return StepActionOrder::user_post; }
0071     //!@}
0072 
0073     //!@{
0074     //! \name Output interface
0075     //! Category of data to write
0076     Category category() const final { return Category::result; }
0077     // Write output to the given JSON object
0078     void output(JsonPimpl*) const final;
0079     //!@}
0080 
0081     // Get the diagnostic results accumulated over all streams
0082     VecVecCount calc_steps() const;
0083 
0084     // Size of diagnostic state data (number of bins times number of particles)
0085     size_type state_size() const;
0086 
0087     // Reset diagnostic results
0088     void clear();
0089 
0090   private:
0091     using StoreT = StreamStore<ParticleTallyParamsData, ParticleTallyStateData>;
0092 
0093     ActionId id_;
0094     size_type num_streams_;
0095     mutable StoreT store_;
0096 };
0097 
0098 //---------------------------------------------------------------------------//
0099 }  // namespace celeritas