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/StatusCheckData.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/data/Collection.hh"
0011 #include "corecel/data/CollectionAlgorithms.hh"
0012 #include "corecel/data/CollectionBuilder.hh"
0013 #include "celeritas/Types.hh"
0014 
0015 namespace celeritas
0016 {
0017 //---------------------------------------------------------------------------//
0018 /*!
0019  * Status check parameters.
0020  */
0021 template<Ownership W, MemSpace M>
0022 struct StatusCheckParamsData
0023 {
0024     //// DATA ////
0025 
0026     celeritas::Collection<StepActionOrder, W, M, ActionId> orders;
0027 
0028     static inline constexpr StepActionOrder implicit_order
0029         = StepActionOrder::size_;
0030 
0031     //// METHODS ////
0032 
0033     //! Whether the data are assigned
0034     explicit CELER_FUNCTION operator bool() const { return !orders.empty(); }
0035 
0036     //! Assign from another set of data
0037     template<Ownership W2, MemSpace M2>
0038     StatusCheckParamsData& operator=(StatusCheckParamsData<W2, M2> const& other)
0039     {
0040         CELER_EXPECT(other);
0041         orders = other.orders;
0042         return *this;
0043     }
0044 };
0045 
0046 //---------------------------------------------------------------------------//
0047 /*!
0048  * Store the previous state and action IDs.
0049  */
0050 template<Ownership W, MemSpace M>
0051 struct StatusCheckStateData
0052 {
0053     //// TYPES ////
0054 
0055     template<class T>
0056     using Items = celeritas::StateCollection<T, W, M>;
0057 
0058     //// DATA ////
0059 
0060     ActionId action;
0061     StepActionOrder order{StepActionOrder::size_};
0062 
0063     Items<TrackStatus> status;
0064     Items<ActionId> post_step_action;
0065     Items<ActionId> along_step_action;
0066 
0067     //// METHODS ////
0068 
0069     //! Check whether the interface is assigned
0070     explicit CELER_FUNCTION operator bool() const
0071     {
0072         return !status.empty() && !post_step_action.empty()
0073                && !along_step_action.empty();
0074     }
0075 
0076     //! State size
0077     CELER_FUNCTION TrackSlotId::size_type size() const
0078     {
0079         return status.size();
0080     }
0081 
0082     //! Assign from another set of data
0083     template<Ownership W2, MemSpace M2>
0084     StatusCheckStateData& operator=(StatusCheckStateData<W2, M2>& other)
0085     {
0086         CELER_EXPECT(other);
0087         action = other.action;
0088         order = other.order;
0089         status = other.status;
0090         post_step_action = other.post_step_action;
0091         along_step_action = other.along_step_action;
0092         return *this;
0093     }
0094 };
0095 
0096 //---------------------------------------------------------------------------//
0097 /*!
0098  * Resize simulation states and set \c alive to be false.
0099  */
0100 template<MemSpace M>
0101 void resize(StatusCheckStateData<Ownership::value, M>* data,
0102             HostCRef<StatusCheckParamsData> const&,
0103             StreamId,
0104             size_type size)
0105 {
0106     CELER_EXPECT(size > 0);
0107 
0108     resize(&data->status, size);
0109     fill(TrackStatus::inactive, &data->status);
0110     resize(&data->post_step_action, size);
0111     resize(&data->along_step_action, size);
0112 
0113     CELER_ENSURE(*data);
0114 }
0115 
0116 //---------------------------------------------------------------------------//
0117 }  // namespace celeritas