Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:54:48

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/optical/SimData.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <vector>
0010 
0011 #include "corecel/Macros.hh"
0012 #include "corecel/Types.hh"
0013 #include "corecel/data/Collection.hh"
0014 #include "corecel/data/CollectionAlgorithms.hh"
0015 #include "corecel/data/CollectionBuilder.hh"
0016 #include "celeritas/Quantities.hh"
0017 #include "celeritas/Types.hh"
0018 
0019 namespace celeritas
0020 {
0021 namespace optical
0022 {
0023 //---------------------------------------------------------------------------//
0024 /*!
0025  * Storage for dynamic simulation data.
0026  */
0027 template<Ownership W, MemSpace M>
0028 struct SimStateData
0029 {
0030     //// TYPES ////
0031 
0032     template<class T>
0033     using Items = celeritas::StateCollection<T, W, M>;
0034 
0035     //// DATA ////
0036 
0037     Items<real_type> time;  //!< Time elapsed in lab frame since start of event
0038     Items<real_type> step_length;
0039     Items<TrackStatus> status;
0040     Items<ActionId> post_step_action;
0041 
0042     //// METHODS ////
0043 
0044     //! Check whether the interface is assigned
0045     explicit CELER_FUNCTION operator bool() const
0046     {
0047         return !time.empty() && !step_length.empty() && !status.empty()
0048                && !post_step_action.empty();
0049     }
0050 
0051     //! State size
0052     CELER_FUNCTION size_type size() const { return status.size(); }
0053 
0054     //! Assign from another set of data
0055     template<Ownership W2, MemSpace M2>
0056     SimStateData& operator=(SimStateData<W2, M2>& other)
0057     {
0058         CELER_EXPECT(other);
0059         time = other.time;
0060         step_length = other.step_length;
0061         status = other.status;
0062         post_step_action = other.post_step_action;
0063         return *this;
0064     }
0065 };
0066 
0067 //---------------------------------------------------------------------------//
0068 /*!
0069  * Resize simulation states and set \c alive to be false.
0070  */
0071 template<MemSpace M>
0072 inline void resize(SimStateData<Ownership::value, M>* data, size_type size)
0073 {
0074     CELER_EXPECT(size > 0);
0075 
0076     resize(&data->time, size);
0077     resize(&data->step_length, size);
0078 
0079     resize(&data->status, size);
0080     fill(TrackStatus::inactive, &data->status);
0081 
0082     resize(&data->post_step_action, size);
0083 
0084     CELER_ENSURE(*data);
0085 }
0086 
0087 //---------------------------------------------------------------------------//
0088 }  // namespace optical
0089 }  // namespace celeritas