File indexing completed on 2025-09-17 08:59:57
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <cmath>
0010
0011 #include "corecel/Constants.hh"
0012 #include "corecel/Types.hh"
0013 #include "corecel/cont/Array.hh"
0014 #include "corecel/math/ArrayUtils.hh"
0015 #include "corecel/random/distribution/UniformRealDistribution.hh"
0016
0017 namespace celeritas
0018 {
0019
0020
0021
0022
0023 template<class RealType = ::celeritas::real_type>
0024 class IsotropicDistribution
0025 {
0026 public:
0027
0028
0029 using real_type = RealType;
0030 using result_type = Array<real_type, 3>;
0031
0032
0033 public:
0034
0035 inline CELER_FUNCTION IsotropicDistribution();
0036
0037
0038 template<class Generator>
0039 inline CELER_FUNCTION result_type operator()(Generator& rng);
0040
0041 private:
0042 UniformRealDistribution<real_type> sample_costheta_;
0043 UniformRealDistribution<real_type> sample_phi_;
0044 };
0045
0046
0047
0048
0049
0050
0051
0052 template<class RealType>
0053 CELER_FUNCTION IsotropicDistribution<RealType>::IsotropicDistribution()
0054 : sample_costheta_(-1, 1), sample_phi_(0, real_type(2 * constants::pi))
0055 {
0056 }
0057
0058
0059
0060
0061
0062 template<class RealType>
0063 template<class Generator>
0064 CELER_FUNCTION auto
0065 IsotropicDistribution<RealType>::operator()(Generator& rng) -> result_type
0066 {
0067 real_type const costheta = sample_costheta_(rng);
0068 real_type const phi = sample_phi_(rng);
0069 return from_spherical(costheta, phi);
0070 }
0071
0072
0073 }