Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2022-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/global/ActionSequence.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <memory>
0011 #include <type_traits>
0012 #include <vector>
0013 
0014 #include "corecel/Types.hh"
0015 
0016 #include "ActionGroups.hh"
0017 #include "ActionInterface.hh"
0018 
0019 namespace celeritas
0020 {
0021 //---------------------------------------------------------------------------//
0022 class ActionRegistry;
0023 class StatusChecker;
0024 
0025 //---------------------------------------------------------------------------//
0026 /*!
0027  * Sequence of step actions to invoke as part of a single step.
0028  *
0029  * TODO accessors here are used by diagnostic output from celer-sim etc.;
0030  * perhaps make this public or add a diagnostic output for it?
0031  *
0032  * \todo Refactor action times as "aux data" and as an end-gather action so
0033  * that this class can merge across states. Currently there's one sequence per
0034  * stepper which isn't right.
0035  */
0036 class ActionSequence
0037 {
0038   public:
0039     //!@{
0040     //! \name Type aliases
0041     using ActionGroupsT = ActionGroups<CoreParams, CoreState>;
0042     using VecDouble = std::vector<double>;
0043     //!@}
0044 
0045   public:
0046     //! Construction/execution options
0047     struct Options
0048     {
0049         bool action_times{false};  //!< Call DeviceSynchronize and add timer
0050     };
0051 
0052   public:
0053     // Construct from an action registry and sequence options
0054     ActionSequence(ActionRegistry const&, Options options);
0055 
0056     //// INVOCATION ////
0057 
0058     // Call beginning-of-run actions.
0059     template<MemSpace M>
0060     void begin_run(CoreParams const& params, CoreState<M>& state);
0061 
0062     // Launch all actions with the given memory space.
0063     template<MemSpace M>
0064     void step(CoreParams const&, CoreState<M>& state);
0065 
0066     //// ACCESSORS ////
0067 
0068     //! Whether synchronization is taking place
0069     bool action_times() const { return options_.action_times; }
0070 
0071     //! Get the ordered vector of actions in the sequence
0072     ActionGroupsT const& actions() const { return actions_; }
0073 
0074     //! Get the corresponding accumulated time, if 'sync' or host called
0075     VecDouble const& accum_time() const { return accum_time_; }
0076 
0077   private:
0078     ActionGroupsT actions_;
0079     Options options_;
0080     VecDouble accum_time_;
0081     std::shared_ptr<StatusChecker const> status_checker_;
0082 };
0083 
0084 //---------------------------------------------------------------------------//
0085 }  // namespace celeritas