Back to home page

EIC code displayed by LXR

 
 

    


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

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/optical/SimData.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <vector>
0011 
0012 #include "corecel/Macros.hh"
0013 #include "corecel/Types.hh"
0014 #include "corecel/data/Collection.hh"
0015 #include "corecel/data/CollectionAlgorithms.hh"
0016 #include "corecel/data/CollectionBuilder.hh"
0017 #include "celeritas/Quantities.hh"
0018 #include "celeritas/Types.hh"
0019 
0020 namespace celeritas
0021 {
0022 namespace optical
0023 {
0024 //---------------------------------------------------------------------------//
0025 /*!
0026  * Storage for dynamic simulation data.
0027  */
0028 template<Ownership W, MemSpace M>
0029 struct SimStateData
0030 {
0031     //// TYPES ////
0032 
0033     template<class T>
0034     using Items = celeritas::StateCollection<T, W, M>;
0035 
0036     //// DATA ////
0037 
0038     Items<real_type> time;  //!< Time elapsed in lab frame since start of event
0039     Items<real_type> step_length;
0040     Items<TrackStatus> status;
0041     Items<ActionId> post_step_action;
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();
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         return *this;
0065     }
0066 };
0067 
0068 //---------------------------------------------------------------------------//
0069 /*!
0070  * Resize simulation states and set \c alive to be false.
0071  */
0072 template<MemSpace M>
0073 inline void resize(SimStateData<Ownership::value, M>* data, size_type size)
0074 {
0075     CELER_EXPECT(size > 0);
0076 
0077     resize(&data->time, size);
0078     resize(&data->step_length, size);
0079 
0080     resize(&data->status, size);
0081     fill(TrackStatus::inactive, &data->status);
0082 
0083     resize(&data->post_step_action, size);
0084 
0085     CELER_ENSURE(*data);
0086 }
0087 
0088 //---------------------------------------------------------------------------//
0089 }  // namespace optical
0090 }  // namespace celeritas