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/phys/detail/ParticleInserter.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/data/CollectionBuilder.hh"
0011 #include "celeritas/Units.hh"
0012 #include "celeritas/phys/ParticleData.hh"
0013 #include "celeritas/phys/ParticleParams.hh"
0014 
0015 namespace celeritas
0016 {
0017 namespace detail
0018 {
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Build particle parameters from user input.
0022  */
0023 class ParticleInserter
0024 {
0025   public:
0026     //!@{
0027     //! \name Type aliases
0028     using Data = HostVal<ParticleParamsData>;
0029     using Input = ParticleParams::ParticleInput;
0030     using Id = ParticleId;
0031     //!@}
0032 
0033   public:
0034     // Construct from host data to be built
0035     explicit inline ParticleInserter(Data* data);
0036 
0037     // Add a particle type
0038     inline Id operator()(Input const& inp);
0039 
0040   private:
0041     template<class T>
0042     using Builder = CollectionBuilder<T, MemSpace::host, ParticleId>;
0043 
0044     Builder<units::MevMass> mass_;
0045     Builder<units::ElementaryCharge> charge_;
0046     Builder<real_type> decay_constant_;
0047     Builder<MatterType> matter_;
0048 };
0049 
0050 //---------------------------------------------------------------------------//
0051 // INLINE DEFINITIONS
0052 //---------------------------------------------------------------------------//
0053 /*!
0054  * Construct from host data to be built.
0055  */
0056 ParticleInserter::ParticleInserter(Data* data)
0057     : mass_{&data->mass}
0058     , charge_{&data->charge}
0059     , decay_constant_{&data->decay_constant}
0060     , matter_{&data->matter}
0061 {
0062 }
0063 
0064 //---------------------------------------------------------------------------//
0065 /*!
0066  * Add a particle.
0067  */
0068 auto ParticleInserter::operator()(Input const& inp) -> Id
0069 {
0070     CELER_VALIDATE(inp.mass >= zero_quantity(),
0071                    << "invalid particle mass " << inp.mass.value());
0072     CELER_VALIDATE(inp.decay_constant >= 0,
0073                    << "invalid particle decay constant " << inp.decay_constant);
0074 
0075     auto result = mass_.push_back(inp.mass);
0076     charge_.push_back(inp.charge);
0077     decay_constant_.push_back(inp.decay_constant);
0078     matter_.push_back(inp.pdg_code.get() < 0 ? MatterType::antiparticle
0079                                              : MatterType::particle);
0080     return result;
0081 }
0082 
0083 //---------------------------------------------------------------------------//
0084 }  // namespace detail
0085 }  // namespace celeritas