Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:11:41

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/optical/Runner.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 
0011 #include "celeritas/inp/StandaloneInput.hh"
0012 #include "celeritas/setup/StandaloneInput.hh"
0013 #include "celeritas/user/ActionTimes.hh"
0014 #include "celeritas/user/StepTimes.hh"
0015 
0016 #include "Transporter.hh"
0017 #include "gen/DirectGeneratorAction.hh"
0018 #include "gen/GeneratorAction.hh"
0019 #include "gen/PrimaryGeneratorAction.hh"
0020 
0021 namespace celeritas
0022 {
0023 namespace optical
0024 {
0025 class CoreStateBase;
0026 class CoreParams;
0027 
0028 //---------------------------------------------------------------------------//
0029 /*!
0030  * Manage execution of a standalone Celeritas optical stepping loop.
0031  *
0032  * Used by the \c celer-optical app and the \c LarStandaloneRunner .
0033  *
0034  * \note When parallelizing on the CPU using OpenMP, this class expects
0035  * track-level parallelism be enabled (transporting all tracks with a single
0036  * stream and state) rather than event-level parallelism (transporting events
0037  * on separate streams with one state per stream). Similarly on the GPU a
0038  * single stream and state will be used.
0039  */
0040 class Runner
0041 {
0042   public:
0043     //!@{
0044     //! \name Type aliases
0045     using Input = inp::OpticalStandaloneInput;
0046     using SPConstParams = std::shared_ptr<CoreParams const>;
0047     using SpanConstTrackInit = DirectGeneratorAction::SpanConstData;
0048     using SpanConstGenDist = GeneratorAction::SpanConstData;
0049     //!@}
0050 
0051     struct Result
0052     {
0053         CounterAccumStats counters;
0054         ActionTimes::MapStrDbl action_times;
0055         StepTimes::VecDbl step_times;
0056     };
0057 
0058   public:
0059     // Construct with optical problem input definition
0060     explicit Runner(Input&&);
0061 
0062     // Set the number of pending tracks for a primary generator
0063     void insert();
0064 
0065     // Insert track initializers
0066     void insert(SpanConstTrackInit);
0067 
0068     // Insert distributions for generating through scintillation or Cherenkov
0069     void insert(SpanConstGenDist);
0070 
0071     // Generate optical photons and transport to completion
0072     Result operator()();
0073 
0074     // Get and reset accumulated track counters
0075     CounterAccumStats exchange_counters();
0076 
0077     // Get and reset accumulated wall times for each action
0078     ActionTimes::MapStrDbl exchange_action_times();
0079 
0080     // Get and reset the wall time for each step iteration
0081     StepTimes::VecDbl exchange_step_times();
0082 
0083     //! Access the shared params
0084     SPConstParams const& params() const
0085     {
0086         return loaded_.problem.transporter->params();
0087     }
0088 
0089     //! Access the problem setup
0090     setup::OpticalProblemLoaded const& problem() const
0091     {
0092         return loaded_.problem;
0093     }
0094 
0095   private:
0096     setup::OpticalStandaloneLoaded loaded_;
0097     std::shared_ptr<CoreStateBase> state_;
0098 };
0099 
0100 //---------------------------------------------------------------------------//
0101 }  // namespace optical
0102 }  // namespace celeritas