File indexing completed on 2026-10-26 09:34:37
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <cmath>
0010
0011 #include "corecel/Types.hh"
0012 #include "corecel/cont/Array.hh"
0013 #include "corecel/random/data/DistributionData.hh"
0014 #include "corecel/random/distribution/UniformRealDistribution.hh"
0015
0016 namespace celeritas
0017 {
0018
0019
0020
0021
0022 template<class RealType = ::celeritas::real_type>
0023 class UniformBoxDistribution
0024 {
0025 public:
0026
0027
0028 using real_type = RealType;
0029 using result_type = Array<real_type, 3>;
0030 using RecordT = UniformBoxDistributionRecord;
0031
0032
0033 public:
0034
0035 inline CELER_FUNCTION UniformBoxDistribution(result_type lower,
0036 result_type upper);
0037
0038
0039 explicit CELER_FUNCTION UniformBoxDistribution(RecordT const& record)
0040 : UniformBoxDistribution(record.lower, record.upper)
0041 {
0042 }
0043
0044
0045 template<class Generator>
0046 inline CELER_FUNCTION result_type operator()(Generator& rng);
0047
0048 private:
0049 using UniformRealDist = UniformRealDistribution<real_type>;
0050
0051 Array<UniformRealDist, 3> sample_pos_;
0052 };
0053
0054
0055
0056
0057
0058
0059
0060 template<class RealType>
0061 CELER_FUNCTION UniformBoxDistribution<RealType>::UniformBoxDistribution(
0062 result_type lower, result_type upper)
0063 : sample_pos_{UniformRealDist{lower[0], upper[0]},
0064 UniformRealDist{lower[1], upper[1]},
0065 UniformRealDist{lower[2], upper[2]}}
0066 {
0067 CELER_EXPECT(lower[0] <= upper[0]);
0068 CELER_EXPECT(lower[1] <= upper[1]);
0069 CELER_EXPECT(lower[2] <= upper[2]);
0070 }
0071
0072
0073
0074
0075
0076 template<class RealType>
0077 template<class Generator>
0078 CELER_FUNCTION auto UniformBoxDistribution<RealType>::operator()(Generator& rng)
0079 -> result_type
0080 {
0081 result_type result;
0082 for (int i = 0; i < 3; ++i)
0083 {
0084 result[i] = sample_pos_[i](rng);
0085 }
0086 return result;
0087 }
0088
0089
0090 }