Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:49

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 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 corecel/sys/ActionGroups.t.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <algorithm>
0011 
0012 #include "corecel/cont/Range.hh"
0013 
0014 #include "ActionRegistry.hh"
0015 
0016 namespace celeritas
0017 {
0018 //---------------------------------------------------------------------------//
0019 /*!
0020  * Construct from an action registry.
0021  */
0022 template<class P, template<MemSpace M> class S>
0023 ActionGroups<P, S>::ActionGroups(ActionRegistry const& reg)
0024 {
0025     // Loop over all action IDs
0026     for (auto aidx : range(reg.num_actions()))
0027     {
0028         // Get abstract action shared pointer to determine type
0029         auto const& base = reg.action(ActionId{aidx});
0030         if (auto step_act = std::dynamic_pointer_cast<StepActionT const>(base))
0031         {
0032             // Add stepping action to our array
0033             step_actions_.push_back(std::move(step_act));
0034         }
0035     }
0036 
0037     // Loop over all mutable actions
0038     for (auto const& base : reg.mutable_actions())
0039     {
0040         if (auto brun = std::dynamic_pointer_cast<BeginRunActionT>(base))
0041         {
0042             // Add beginning-of-run to the array
0043             begin_run_.emplace_back(std::move(brun));
0044         }
0045     }
0046 
0047     // Sort actions by increasing order (and secondarily, increasing IDs)
0048     std::sort(step_actions_.begin(),
0049               step_actions_.end(),
0050               [](SPConstStepAction const& a, SPConstStepAction const& b) {
0051                   return OrderedAction{a->order(), a->action_id()}
0052                          < OrderedAction{b->order(), b->action_id()};
0053               });
0054 }
0055 
0056 //---------------------------------------------------------------------------//
0057 }  // namespace celeritas