Changeset 26554
- Timestamp:
- 11/08/21 14:41:51 (3 years ago)
- Location:
- issm/trunk-jpl
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/solutionsequences/solutionsequence_sampling.cpp
r26514 r26554 8 8 #include "../modules/modules.h" 9 9 #include "../analyses/analyses.h" 10 #include "../shared/Random/randomgenerator.h" 10 11 #include <random> 11 12 #undef M_PI13 #define M_PI 3.14159265358979323846264314 15 double lcg(long long* seed){/*{{{*/16 17 18 int N = 5;19 long long M = 1LL<<32;20 long long a = 1812433253;21 long long c = 1;22 23 for(int i=0;i<N;i++){24 *seed = a * *seed + c;25 *seed = *seed%M;26 }27 28 return ((double) *seed) / ((double) M);29 30 }31 32 double BoxMuller(long long* pseed){33 34 double u1 = lcg(pseed);35 double u2 = lcg(pseed);36 37 double R = sqrt(-2*log(u1));38 double theta = 2*M_PI*u2;39 40 return R*cos(theta);41 42 }43 12 44 13 void GaussianVector(Vector<IssmDouble>* ppf,int seed){/*{{{*/ … … 49 18 50 19 /*Define seed*/ 20 normal_distribution_rnd distribution; 51 21 if(seed<0){ 52 22 std::random_device rd; … … 59 29 seed = seed + 783728*my_rank; // change default seed for parallel simulations (by considering an arbitrary shif based on the rank number) 60 30 } 61 62 long long seedbis; 63 seedbis = (long long) seed; 31 distribution.seed(seed); 64 32 65 33 int *local_indices = NULL; … … 70 38 ppf->GetLocalSize(&M); 71 39 for(int i=0;i<M;i++){ 72 rdnumber = BoxMuller(&seedbis);40 rdnumber = distribution.rnd(); 73 41 ppf->SetValue(local_indices[i],rdnumber,INS_VAL); 74 42 }
Note:
See TracChangeset
for help on using the changeset viewer.