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/ActionInterface.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/sys/ActionInterface.hh"
0011 #include "celeritas/Types.hh"
0012 
0013 namespace celeritas
0014 {
0015 //---------------------------------------------------------------------------//
0016 class CoreParams;
0017 template<MemSpace M>
0018 class CoreState;
0019 
0020 //---------------------------------------------------------------------------//
0021 // TYPE ALIASES
0022 //---------------------------------------------------------------------------//
0023 //! Interface called at beginning of the core stepping loop
0024 using CoreBeginRunActionInterface
0025     = BeginRunActionInterface<CoreParams, CoreState>;
0026 
0027 //! Action interface for core stepping loop
0028 using CoreStepActionInterface = StepActionInterface<CoreParams, CoreState>;
0029 
0030 // TODO: Remove in v0.6
0031 using ActionOrder [[deprecated]] = StepActionOrder;
0032 
0033 // TODO: Remove in v0.6
0034 class [[deprecated]] ExplicitCoreActionInterface
0035     : public CoreStepActionInterface
0036 {
0037     //! Execute the action with host data
0038     void step(CoreParams const& params, CoreStateHost& state) const final
0039     {
0040         return this->execute(params, state);
0041     }
0042 
0043     //! Execute the action with device data
0044     void step(CoreParams const& params, CoreStateDevice& state) const final
0045     {
0046         return this->execute(params, state);
0047     }
0048 
0049     //! Execute the action with host data
0050     virtual void execute(CoreParams const&, CoreStateHost&) const = 0;
0051 
0052     //! Execute the action with device data
0053     virtual void execute(CoreParams const&, CoreStateDevice&) const = 0;
0054 };
0055 
0056 //---------------------------------------------------------------------------//
0057 // HELPER FUNCTIONS
0058 //---------------------------------------------------------------------------//
0059 /*!
0060  * Whether the TrackOrder will sort tracks by actions at the given step order.
0061  */
0062 inline constexpr bool
0063 is_action_sorted(StepActionOrder aorder, TrackOrder torder)
0064 {
0065     // CAUTION: check that this matches \c SortTracksAction::SortTracksAction
0066     return (aorder == StepActionOrder::post
0067             && torder == TrackOrder::reindex_step_limit_action)
0068            || (aorder == StepActionOrder::along
0069                && torder == TrackOrder::reindex_along_step_action)
0070            || (torder == TrackOrder::reindex_both_action
0071                && (aorder == StepActionOrder::post
0072                    || aorder == StepActionOrder::along));
0073 }
0074 
0075 //---------------------------------------------------------------------------//
0076 /*!
0077  * Whether track sorting (reindexing) is enabled.
0078  */
0079 inline constexpr bool is_action_sorted(TrackOrder torder)
0080 {
0081     auto to_int = [](TrackOrder v) {
0082         return static_cast<std::underlying_type_t<TrackOrder>>(v);
0083     };
0084     return to_int(torder) >= to_int(TrackOrder::begin_reindex_)
0085            && to_int(torder) < to_int(TrackOrder::end_reindex_);
0086 }
0087 
0088 //---------------------------------------------------------------------------//
0089 }  // namespace celeritas