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