View Issue Details

IDProjectCategoryView StatusLast Update
0001568OpenFOAMBugpublic2015-03-13 13:02
Reportera.weber Assigned Tohenry  
PrioritynormalSeverityfeatureReproducibilityalways
Status resolvedResolutionfixed 
PlatformGNU/LinuxOSUbuntuOS Version14.10
Summary0001568: stochasticDispersionRAS: UTurb is not calculated spatially uniform
Descriptionusing

<< vector dir = 2.0*rnd.sample01<vector>() - vector::one;
            dir /= mag(dir) + SMALL;
....
UTurb = sigma*fac*dir; >>

will lead to a distribution of vectors according to a "cube-like" distribution, not to a uniform distribution on a sphere.

Additional Informationusing an appropriate random vector generator will solve this problem:

#1 use normal distributed random numbers:
e.g. http://stackoverflow.com/questions/9750908/how-to-generate-a-unit-vector-pointing-in-a-random-direction-with-isotropic-dist

#2 use the generation method with a spherical coordinate system:

<< const scalar theta = rndGen.template sample01<scalar>()*constant::mathematical::pi;
    const scalar phi = rndGen.template sample01<scalar>()*2.0*constant::mathematical::pi;

    vector dir = vector
        (
        sin(theta) * cos(phi),
        sin(theta) * sin(phi),
        cos(theta)
        );
    dir /= mag(dir); >>
TagsNo tags attached.

Activities

henry

2015-03-12 16:37

manager   ~0004094

The Foam::Random class already provides

        //- Return a normal Gaussian randon number
        // with zero mean and unity variance N(0, 1)
        scalar GaussNormal();

I assume this would be suitable for stochasticDispersionRAS in conjunction with the spherical transformation.

henry

2015-03-12 16:52

manager   ~0004095

Given the overhead of the GaussNormal method I think option #2 is preferable.

henry

2015-03-13 11:59

manager   ~0004108

Following the transformation from theta and phi to dir the normalization

dir /= mag(dir);

should not be needed an the vector should already be unit. Do you want the normalization in anyway to compensate for round-off error?

a.weber

2015-03-13 12:14

reporter   ~0004110

That's right. Normalization is not needed. My fault.

henry

2015-03-13 13:02

manager   ~0004112

Resolved by commit 19fbe17af23a10a14bd20dcfb693150e50e78474

Issue History

Date Modified Username Field Change
2015-03-12 15:32 a.weber New Issue
2015-03-12 16:37 henry Note Added: 0004094
2015-03-12 16:52 henry Note Added: 0004095
2015-03-13 11:59 henry Note Added: 0004108
2015-03-13 12:14 a.weber Note Added: 0004110
2015-03-13 13:02 henry Note Added: 0004112
2015-03-13 13:02 henry Status new => resolved
2015-03-13 13:02 henry Resolution open => fixed
2015-03-13 13:02 henry Assigned To => henry
2015-03-24 00:17 liuhuafei Issue cloned: 0001615