Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-14 08:21:55

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     Items<size_type> num_steps;  //!< Total number of steps taken
0042 
0043     //// METHODS ////
0044 
0045     //! Check whether the interface is assigned
0046     explicit CELER_FUNCTION operator bool() const
0047     {
0048         return !time.empty() && !step_length.empty() && !status.empty()
0049                && !post_step_action.empty() && !num_steps.empty();
0050     }
0051 
0052     //! State size
0053     CELER_FUNCTION size_type size() const { return status.size(); }
0054 
0055     //! Assign from another set of data
0056     template<Ownership W2, MemSpace M2>
0057     SimStateData& operator=(SimStateData<W2, M2>& other)
0058     {
0059         CELER_EXPECT(other);
0060         time = other.time;
0061         step_length = other.step_length;
0062         status = other.status;
0063         post_step_action = other.post_step_action;
0064         num_steps = other.num_steps;
0065         return *this;
0066     }
0067 };
0068 
0069 //---------------------------------------------------------------------------//
0070 /*!
0071  * Resize simulation states and set \c alive to be false.
0072  */
0073 template<MemSpace M>
0074 inline void resize(SimStateData<Ownership::value, M>* data, size_type size)
0075 {
0076     CELER_EXPECT(size > 0);
0077 
0078     resize(&data->time, size);
0079     resize(&data->step_length, size);
0080 
0081     resize(&data->status, size);
0082     fill(TrackStatus::inactive, &data->status);
0083 
0084     resize(&data->post_step_action, size);
0085     resize(&data->num_steps, size);
0086 
0087     CELER_ENSURE(*data);
0088 }
0089 
0090 //---------------------------------------------------------------------------//
0091 }  // namespace optical
0092 }  // namespace celeritas