Back to home page

EIC code displayed by LXR

 
 

    


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

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 celeritas/track/StatusChecker.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <string_view>
0011 
0012 #include "corecel/Types.hh"
0013 #include "corecel/data/AuxInterface.hh"
0014 #include "corecel/data/CollectionMirror.hh"
0015 #include "corecel/data/ParamsDataInterface.hh"
0016 #include "celeritas/Types.hh"
0017 #include "celeritas/global/ActionInterface.hh"
0018 
0019 #include "StatusCheckData.hh"
0020 
0021 namespace celeritas
0022 {
0023 //---------------------------------------------------------------------------//
0024 class ActionRegistry;
0025 class CoreParams;
0026 template<MemSpace>
0027 class CoreState;
0028 
0029 //---------------------------------------------------------------------------//
0030 /*!
0031  * Verify a consistent simulation state after performing an action.
0032  *
0033  * This is used as a debug option in the step executor to check that actions
0034  * and simulation state are consistent.
0035  *
0036  * Since this is called manually by the stepper, multiple times per step, it is
0037  * \em not an "explicit" action. It's meant to be used inside the \c
0038  * ActionSequence itself, called after every action.
0039  */
0040 class StatusChecker final : public AuxParamsInterface,
0041                             public CoreBeginRunActionInterface,
0042                             public ParamsDataInterface<StatusCheckParamsData>
0043 {
0044   public:
0045     // Construct with IDs
0046     StatusChecker(ActionId action_id, AuxId aux_id);
0047 
0048     //!@{
0049     //! \name Aux/action metadata interface
0050     //! Label for the auxiliary data and action
0051     std::string_view label() const final { return "status-check"; }
0052     // Description of the action
0053     std::string_view description() const final;
0054     //!@}
0055 
0056     //!@{
0057     //! \name Aux params interface
0058     //! Index of this class instance in its registry
0059     AuxId aux_id() const final { return aux_id_; }
0060     // Build state data for a stream
0061     UPState create_state(MemSpace m, StreamId id, size_type size) const final;
0062     //!@}
0063 
0064     //!@{
0065     //! \name Begin run interface
0066     //! Index of this class instance in its registry
0067     ActionId action_id() const final { return action_id_; }
0068     // Set host data at the beginning of a run
0069     void begin_run(CoreParams const&, CoreStateHost&) final;
0070     // Set device data at the beginning of a run
0071     void begin_run(CoreParams const&, CoreStateDevice&) final;
0072     //!@}
0073 
0074     //!@{
0075     //! \name Data interface
0076     //! Access data on host
0077     HostRef const& host_ref() const final { return data_.host_ref(); }
0078     //! Access data on device
0079     DeviceRef const& device_ref() const final { return data_.device_ref(); }
0080     //!@}
0081 
0082     // Execute *manually* with the last action's ID and the state
0083     template<MemSpace M>
0084     void
0085     step(ActionId prev_action, CoreParams const&, CoreState<M>& state) const;
0086 
0087   private:
0088     template<MemSpace M>
0089     using StatusStateRef = StatusCheckStateData<Ownership::reference, M>;
0090 
0091     //// DATA ////
0092 
0093     ActionId action_id_;
0094     AuxId aux_id_;
0095     CollectionMirror<StatusCheckParamsData> data_;
0096 
0097     //// HELPER FUNCTIONS ////
0098 
0099     void begin_run_impl(CoreParams const&);
0100 
0101     void launch_impl(CoreParams const&,
0102                      CoreState<MemSpace::host>&,
0103                      StatusStateRef<MemSpace::host> const&) const;
0104     void launch_impl(CoreParams const&,
0105                      CoreState<MemSpace::device>&,
0106                      StatusStateRef<MemSpace::device> const&) const;
0107 };
0108 
0109 //---------------------------------------------------------------------------//
0110 }  // namespace celeritas