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 "celeritas/Constants.hh"
0015
0016 #include "UniformRealDistribution.hh"
0017
0018 namespace celeritas
0019 {
0020
0021
0022
0023
0024 template<class RealType = ::celeritas::real_type>
0025 class UniformBoxDistribution
0026 {
0027 public:
0028
0029
0030 using real_type = RealType;
0031 using result_type = Array<real_type, 3>;
0032
0033
0034 public:
0035
0036 inline CELER_FUNCTION
0037 UniformBoxDistribution(result_type lower, result_type upper);
0038
0039
0040 template<class Generator>
0041 inline CELER_FUNCTION result_type operator()(Generator& rng);
0042
0043 private:
0044 using UniformRealDist = UniformRealDistribution<real_type>;
0045
0046 Array<UniformRealDist, 3> sample_pos_;
0047 };
0048
0049
0050
0051
0052
0053
0054
0055 template<class RealType>
0056 CELER_FUNCTION
0057 UniformBoxDistribution<RealType>::UniformBoxDistribution(result_type lower,
0058 result_type upper)
0059 : sample_pos_{UniformRealDist{lower[0], upper[0]},
0060 UniformRealDist{lower[1], upper[1]},
0061 UniformRealDist{lower[2], upper[2]}}
0062 {
0063 CELER_EXPECT(lower[0] <= upper[0]);
0064 CELER_EXPECT(lower[1] <= upper[1]);
0065 CELER_EXPECT(lower[2] <= upper[2]);
0066 }
0067
0068
0069
0070
0071
0072 template<class RealType>
0073 template<class Generator>
0074 CELER_FUNCTION auto
0075 UniformBoxDistribution<RealType>::operator()(Generator& rng) -> result_type
0076 {
0077 result_type result;
0078 for (int i = 0; i < 3; ++i)
0079 {
0080 result[i] = sample_pos_[i](rng);
0081 }
0082 return result;
0083 }
0084
0085
0086 }