Index: ../trunk-jpl/test/Archives/Archive134.arch =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: ../trunk-jpl/src/c/shared/Random/randomgenerator.cpp =================================================================== --- ../trunk-jpl/src/c/shared/Random/randomgenerator.cpp (revision 26577) +++ ../trunk-jpl/src/c/shared/Random/randomgenerator.cpp (revision 26578) @@ -8,70 +8,71 @@ #undef M_PI #define M_PI 3.141592653589793238462643 +namespace rdngen{ + uniform_distribution_rnd::uniform_distribution_rnd(){/*{{{*/ -uniform_distribution_rnd::uniform_distribution_rnd(){/*{{{*/ + a = 1103515245; // BSD Formula + c = 12345; // BSD Formula + m = 2147483648; // BSD Formula + _seed = 0; + lbound = 0.0; + ubound = 1.0; + return; + } + /*}}}*/ + uniform_distribution_rnd::uniform_distribution_rnd(double lower,double upper){/*{{{*/ - a = 1103515245; // BSD Formula - c = 12345; // BSD Formula - m = 2147483648; // BSD Formula - _seed = 0; - lbound = 0.0; - ubound = 1.0; - return; -} - /*}}}*/ -uniform_distribution_rnd::uniform_distribution_rnd(double lower,double upper){/*{{{*/ + a = 1103515245; // BSD Formula + c = 12345; // BSD Formula + m = 2147483648; // BSD Formula + _seed = 0; + lbound = lower; + ubound = upper; + return; + } + /*}}}*/ + uniform_distribution_rnd::~uniform_distribution_rnd(){} + void uniform_distribution_rnd::seed( unsigned int s ) { _seed = s; } + unsigned int uniform_distribution_rnd::get_seed() { return _seed; } + double uniform_distribution_rnd::generator() { + _seed = ( a * _seed + c ) % m ; + return (ubound-lbound)*(double) _seed/ m + lbound; + } - a = 1103515245; // BSD Formula - c = 12345; // BSD Formula - m = 2147483648; // BSD Formula - _seed = 0; - lbound = lower; - ubound = upper; - return; -} - /*}}}*/ -uniform_distribution_rnd::~uniform_distribution_rnd(){} -void uniform_distribution_rnd::seed( unsigned int s ) { _seed = s; } -unsigned int uniform_distribution_rnd::get_seed() { return _seed; } -double uniform_distribution_rnd::generator() { - _seed = ( a * _seed + c ) % m ; - return (ubound-lbound)*(double) _seed/ m + lbound; -} + normal_distribution_rnd::normal_distribution_rnd(){/*{{{*/ -normal_distribution_rnd::normal_distribution_rnd(){/*{{{*/ + _seed = 0; + mean = 0; + sdev = 1.0; + return; + } + /*}}}*/ + normal_distribution_rnd::normal_distribution_rnd(double m,double s){/*{{{*/ - _seed = 0; - mean = 0; - sdev = 1.0; - return; -} -/*}}}*/ -normal_distribution_rnd::normal_distribution_rnd(double m,double s){/*{{{*/ + _seed = 0; + mean = m; + sdev = s; + return; + } + /*}}}*/ + normal_distribution_rnd::~normal_distribution_rnd(){} + void normal_distribution_rnd::seed( unsigned int s ) { _seed = s; } + double normal_distribution_rnd::generator(){/*{{{*/ - _seed = 0; - mean = m; - sdev = s; - return; -} - /*}}}*/ -normal_distribution_rnd::~normal_distribution_rnd(){} -void normal_distribution_rnd::seed( unsigned int s ) { _seed = s; } -double normal_distribution_rnd::generator(){/*{{{*/ + uniform_distribution_rnd unifdistri; + unifdistri.seed(_seed); - uniform_distribution_rnd unifdistri; - unifdistri.seed(_seed); + double u1 = unifdistri.generator(); + double u2 = unifdistri.generator(); - double u1 = unifdistri.generator(); - double u2 = unifdistri.generator(); + double R = sqrt(-2*log(u1)); + double theta = 2*M_PI*u2; - double R = sqrt(-2*log(u1)); - double theta = 2*M_PI*u2; + seed(unifdistri.get_seed()); - seed(unifdistri.get_seed()); + return mean + sdev * (R*cos(theta)); - return mean + sdev * (R*cos(theta)); - - } - /*}}}*/ + } + /*}}}*/ +} Index: ../trunk-jpl/src/c/shared/Random/randomgenerator.h =================================================================== --- ../trunk-jpl/src/c/shared/Random/randomgenerator.h (revision 26577) +++ ../trunk-jpl/src/c/shared/Random/randomgenerator.h (revision 26578) @@ -8,49 +8,51 @@ #undef M_PI #define M_PI 3.141592653589793238462643 -class uniform_distribution_rnd -{ +namespace rdngen{ + class uniform_distribution_rnd + { - private: + private: - unsigned int a; //multiplier of the linear congruential generator - unsigned int c; //increment of the linear congruential generator - unsigned int m; // modulo of the linear congruential generator - unsigned int _seed; // seed value - double lbound; // lower bound of uniform distribution - double ubound; // upper bound of uniform distribution + unsigned int a; //multiplier of the linear congruential generator + unsigned int c; //increment of the linear congruential generator + unsigned int m; // modulo of the linear congruential generator + unsigned int _seed; // seed value + double lbound; // lower bound of uniform distribution + double ubound; // upper bound of uniform distribution - public: + public: - /*constructors, destructors: */ - uniform_distribution_rnd(); - uniform_distribution_rnd(double a_1, double a_2); - ~uniform_distribution_rnd(); + /*constructors, destructors: */ + uniform_distribution_rnd(); + uniform_distribution_rnd(double a_1, double a_2); + ~uniform_distribution_rnd(); - void seed( unsigned int s ); - unsigned int get_seed(); - double generator(); + void seed( unsigned int s ); + unsigned int get_seed(); + double generator(); -}; + }; -class normal_distribution_rnd -{ + class normal_distribution_rnd + { - private: - unsigned int _seed; // seed value - double mean; // mean value - double sdev; // standard deviation + private: + unsigned int _seed; // seed value + double mean; // mean value + double sdev; // standard deviation - public: + public: - /*constructors, destructors: */ - normal_distribution_rnd(); - normal_distribution_rnd(double m,double s); - ~normal_distribution_rnd(); + /*constructors, destructors: */ + normal_distribution_rnd(); + normal_distribution_rnd(double m,double s); + ~normal_distribution_rnd(); - void seed( unsigned int s ); - double generator(); + void seed( unsigned int s ); + double generator(); -}; + }; +} #endif //ifndef _RANDOMGENERATOR_H_ Index: ../trunk-jpl/src/c/solutionsequences/solutionsequence_sampling.cpp =================================================================== --- ../trunk-jpl/src/c/solutionsequences/solutionsequence_sampling.cpp (revision 26577) +++ ../trunk-jpl/src/c/solutionsequences/solutionsequence_sampling.cpp (revision 26578) @@ -17,7 +17,7 @@ double rdnumber; /*Define seed*/ - //normal_distribution_rnd distribution; + rdngen::normal_distribution_rnd distribution; if(seed<0){ std::random_device rd; seed = rd(); @@ -28,7 +28,7 @@ ISSM_MPI_Comm_rank(ISSM_MPI_COMM_WORLD,&my_rank); seed = seed + 783728*my_rank; // change default seed for parallel simulations (by considering an arbitrary shif based on the rank number) } - //distribution.seed(seed); + distribution.seed(seed); int *local_indices = NULL; IssmDouble *local_vector = NULL; @@ -37,7 +37,7 @@ int M; ppf->GetLocalSize(&M); for(int i=0;iSetValue(local_indices[i],rdnumber,INS_VAL); } ppf->Assemble();