Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-14 08:50:58

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 corecel/random/distribution/RadialDistribution.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <cmath>
0010 
0011 #include "corecel/Assert.hh"
0012 #include "corecel/Macros.hh"
0013 #include "corecel/Types.hh"
0014 
0015 #include "GenerateCanonical.hh"
0016 
0017 namespace celeritas
0018 {
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Sample from a uniform radial distribution.
0022  */
0023 template<class RealType = ::celeritas::real_type>
0024 class RadialDistribution
0025 {
0026   public:
0027     //!@{
0028     //! \name Type aliases
0029     using real_type = RealType;
0030     using result_type = real_type;
0031     //!@}
0032 
0033   public:
0034     // Constructor
0035     explicit inline CELER_FUNCTION RadialDistribution(real_type radius);
0036 
0037     // Sample a random number according to the distribution
0038     template<class Generator>
0039     inline CELER_FUNCTION result_type operator()(Generator& rng);
0040 
0041     //// ACCESSORS ////
0042 
0043     //! Get the sampling radius
0044     inline CELER_FUNCTION real_type radius() const { return radius_; }
0045 
0046   private:
0047     RealType radius_;
0048 };
0049 
0050 //---------------------------------------------------------------------------//
0051 // INLINE DEFINITIONS
0052 //---------------------------------------------------------------------------//
0053 /*!
0054  * Construct with defaults.
0055  */
0056 template<class RealType>
0057 CELER_FUNCTION
0058 RadialDistribution<RealType>::RadialDistribution(real_type radius)
0059     : radius_(radius)
0060 {
0061     CELER_EXPECT(radius_ > 0);
0062 }
0063 
0064 //---------------------------------------------------------------------------//
0065 /*!
0066  * Sample a random number according to the distribution.
0067  */
0068 template<class RealType>
0069 template<class Generator>
0070 CELER_FUNCTION auto
0071 RadialDistribution<RealType>::operator()(Generator& rng) -> result_type
0072 {
0073     return std::cbrt(generate_canonical<RealType>(rng)) * radius_;
0074 }
0075 //---------------------------------------------------------------------------//
0076 }  // namespace celeritas