diff --git a/applications/solvers/DNS/dnsFoam/dnsFoam.C b/applications/solvers/DNS/dnsFoam/dnsFoam.C index 87720db898..cf5da63f97 100644 --- a/applications/solvers/DNS/dnsFoam/dnsFoam.C +++ b/applications/solvers/DNS/dnsFoam/dnsFoam.C @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) fft::reverseTransform ( K/(mag(K) + 1.0e-6) ^ forceGen.newField(), K.nn() - ) + )*recRootN ); #include "globalProperties.H" diff --git a/applications/solvers/DNS/dnsFoam/readTurbulenceProperties.H b/applications/solvers/DNS/dnsFoam/readTurbulenceProperties.H index 0d6b417d5a..0b44eed10c 100644 --- a/applications/solvers/DNS/dnsFoam/readTurbulenceProperties.H +++ b/applications/solvers/DNS/dnsFoam/readTurbulenceProperties.H @@ -19,3 +19,10 @@ Kmesh K(mesh); UOprocess forceGen(K, runTime.deltaTValue(), turbulenceProperties); + + label ntot = 1; + forAll(K.nn(), idim) + { + ntot *= K.nn()[idim]; + } + const scalar recRootN = 1.0/Foam::sqrt(scalar(ntot)); diff --git a/applications/utilities/postProcessing/noise/noise.C b/applications/utilities/postProcessing/noise/noise.C index 61653947ea..a97edc1854 100644 --- a/applications/utilities/postProcessing/noise/noise.C +++ b/applications/utilities/postProcessing/noise/noise.C @@ -55,8 +55,8 @@ Usage } - // Input file - inputFile "postProcessing/faceSource1/surface/patch/patch.case"; + // Input files list + files ("postProcessing/faceSource1/surface/patch/patch.case";) // Surface reader reader ensight; diff --git a/src/OpenFOAM/primitives/random/Random/Random.C b/src/OpenFOAM/primitives/random/Random/Random.C index 307fcb0eb1..523155c251 100644 --- a/src/OpenFOAM/primitives/random/Random/Random.C +++ b/src/OpenFOAM/primitives/random/Random/Random.C @@ -121,7 +121,24 @@ Foam::scalar Foam::Random::position template<> Foam::label Foam::Random::position(const label& start, const label& end) { - return start + round(scalar01()*(end - start)); + #ifdef FULLDEBUG + if (start > end) + { + FatalErrorInFunction + << "start index " << start << " > end index " << end << nl + << abort(FatalError); + } + #endif + + // Extend the upper sampling range by 1 and floor the result. + // Since the range is non-negative, can use integer truncation + // instead using floor(). + + const label val = start + label(scalar01()*(end - start + 1)); + + // Rare case when scalar01() returns exactly 1.000 and the truncated + // value would be out of range. + return min(val, end); } @@ -200,12 +217,12 @@ Foam::scalar Foam::Random::globalPosition if (Pstream::master()) { - value = scalar01()*(end - start); + value = position(start, end); } Pstream::scatter(value); - return start + value; + return value; } @@ -220,12 +237,12 @@ Foam::label Foam::Random::globalPosition if (Pstream::master()) { - value = round(scalar01()*(end - start)); + value = position