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