Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/celeritas/track/StatusChecker.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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