34template<
typename T,
bool useStored>
37 static_assert(!useStored,
"ERROR: no sequence provided");
40template<
typename T,
bool useStored>
42 : _storedSequence(sequence)
46template<
typename T,
bool useStored>
50 [[maybe_unused]] std::size_t count = 0;
54 std::ifstream filePre(filePathSequence.c_str(), std::ios::in);
57 writeSequence(1000,filePathSequence.c_str());
59 throw std::runtime_error(
"ERROR: Sequence not provided for Randomizer!");
63 std::ifstream file(filePathSequence.c_str(), std::ios::in);
65 while (std::getline(file, strVal))
67 _storedSequence.push_back(std::stod(strVal));
72#ifdef PARALLEL_MODE_MPI
78 _storedSequence.resize(count);
88template<
typename T,
bool useStored>
92 if constexpr (std::is_arithmetic<O>::value) {
93 O output = generateScalar();
97 for(
unsigned iDim=0; iDim<O::d; ++iDim){
98 output[iDim] = generateScalar();
104template<
typename T,
bool useStored>
107 T A = generateScalar();
108 T B = generateScalar();
110 T output = avg + x * stdDev;
114template<
typename T,
bool useStored>
117 T scalar = generateScalarNormal( avg, stdDev );
118 if (scalar<(avg-cutoff) || scalar>(avg+cutoff)){
119 scalar = generateScalarNormal(avg, stdDev, cutoff );
124template<
typename T,
bool useStored>
126 std::string filePathSequence,
131 std::ofstream writer;
132 writer.open( filePathSequence );
133 writer << std::setprecision(precision);
134 for (std::size_t i=0; i<numOfValues; ++i){
135 writer << generateScalarRandom() <<
" " << std::endl;
142template<
typename T,
bool useStored>
146 std::random_device rd;
148 std::mt19937 engine(rd());
151 std::uniform_real_distribution<T> distribution(0.0, 1.0);
154 return distribution(engine);
157template<
typename T,
bool useStored>
158T Randomizer<T,useStored>::generateScalarStored()
160 static_assert(useStored,
"ERROR: no sequence provided");
161 auto idx = _count%_storedSequence.size();
162 T scalar = _storedSequence[idx];
167template<
typename T,
bool useStored>
168T Randomizer<T,useStored>::generateScalar()
170 if constexpr (useStored){
171 return generateScalarStored();
173 T scalar = generateScalarRandom();
174#ifdef PARALLEL_MODE_MPI
void bCast(T *sendBuf, int sendCount, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Broadcast data from one processor to multiple processors.
int getRank() const
Returns the process ID.
void writeSequence(std::size_t numOfValues, std::string filePathSequence="./randomSequence.dat", int precision=5)
Write sequence to file for later retrieval.
T generateScalarNormal(T avg, T stdDev)
Generate scalar leading to normal distribution based on the Box-Muller approach.
O generate()
Generate scalar or vector filled with scalars.
Randomizer()
Constructor for (useStored=false)
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
ADf< T, DIM > log(const ADf< T, DIM > &a)
ADf< T, DIM > cos(const ADf< T, DIM > &a)
Top level namespace for all of OpenLB.