source: issm/oecreview/Archive/25834-26739/ISSM-26577-26578.diff@ 26740

Last change on this file since 26740 was 26740, checked in by Mathieu Morlighem, 3 years ago

CHG: added 25834-26739

File size: 7.6 KB
RevLine 
[26740]1Index: ../trunk-jpl/test/Archives/Archive134.arch
2===================================================================
3Cannot display: file marked as a binary type.
4svn:mime-type = application/octet-stream
5Index: ../trunk-jpl/src/c/shared/Random/randomgenerator.cpp
6===================================================================
7--- ../trunk-jpl/src/c/shared/Random/randomgenerator.cpp (revision 26577)
8+++ ../trunk-jpl/src/c/shared/Random/randomgenerator.cpp (revision 26578)
9@@ -8,70 +8,71 @@
10 #undef M_PI
11 #define M_PI 3.141592653589793238462643
12
13+namespace rdngen{
14+ uniform_distribution_rnd::uniform_distribution_rnd(){/*{{{*/
15
16-uniform_distribution_rnd::uniform_distribution_rnd(){/*{{{*/
17+ a = 1103515245; // BSD Formula
18+ c = 12345; // BSD Formula
19+ m = 2147483648; // BSD Formula
20+ _seed = 0;
21+ lbound = 0.0;
22+ ubound = 1.0;
23+ return;
24+ }
25+ /*}}}*/
26+ uniform_distribution_rnd::uniform_distribution_rnd(double lower,double upper){/*{{{*/
27
28- a = 1103515245; // BSD Formula
29- c = 12345; // BSD Formula
30- m = 2147483648; // BSD Formula
31- _seed = 0;
32- lbound = 0.0;
33- ubound = 1.0;
34- return;
35-}
36- /*}}}*/
37-uniform_distribution_rnd::uniform_distribution_rnd(double lower,double upper){/*{{{*/
38+ a = 1103515245; // BSD Formula
39+ c = 12345; // BSD Formula
40+ m = 2147483648; // BSD Formula
41+ _seed = 0;
42+ lbound = lower;
43+ ubound = upper;
44+ return;
45+ }
46+ /*}}}*/
47+ uniform_distribution_rnd::~uniform_distribution_rnd(){}
48+ void uniform_distribution_rnd::seed( unsigned int s ) { _seed = s; }
49+ unsigned int uniform_distribution_rnd::get_seed() { return _seed; }
50+ double uniform_distribution_rnd::generator() {
51+ _seed = ( a * _seed + c ) % m ;
52+ return (ubound-lbound)*(double) _seed/ m + lbound;
53+ }
54
55- a = 1103515245; // BSD Formula
56- c = 12345; // BSD Formula
57- m = 2147483648; // BSD Formula
58- _seed = 0;
59- lbound = lower;
60- ubound = upper;
61- return;
62-}
63- /*}}}*/
64-uniform_distribution_rnd::~uniform_distribution_rnd(){}
65-void uniform_distribution_rnd::seed( unsigned int s ) { _seed = s; }
66-unsigned int uniform_distribution_rnd::get_seed() { return _seed; }
67-double uniform_distribution_rnd::generator() {
68- _seed = ( a * _seed + c ) % m ;
69- return (ubound-lbound)*(double) _seed/ m + lbound;
70-}
71
72+ normal_distribution_rnd::normal_distribution_rnd(){/*{{{*/
73
74-normal_distribution_rnd::normal_distribution_rnd(){/*{{{*/
75+ _seed = 0;
76+ mean = 0;
77+ sdev = 1.0;
78+ return;
79+ }
80+ /*}}}*/
81+ normal_distribution_rnd::normal_distribution_rnd(double m,double s){/*{{{*/
82
83- _seed = 0;
84- mean = 0;
85- sdev = 1.0;
86- return;
87-}
88-/*}}}*/
89-normal_distribution_rnd::normal_distribution_rnd(double m,double s){/*{{{*/
90+ _seed = 0;
91+ mean = m;
92+ sdev = s;
93+ return;
94+ }
95+ /*}}}*/
96+ normal_distribution_rnd::~normal_distribution_rnd(){}
97+ void normal_distribution_rnd::seed( unsigned int s ) { _seed = s; }
98+ double normal_distribution_rnd::generator(){/*{{{*/
99
100- _seed = 0;
101- mean = m;
102- sdev = s;
103- return;
104-}
105- /*}}}*/
106-normal_distribution_rnd::~normal_distribution_rnd(){}
107-void normal_distribution_rnd::seed( unsigned int s ) { _seed = s; }
108-double normal_distribution_rnd::generator(){/*{{{*/
109+ uniform_distribution_rnd unifdistri;
110+ unifdistri.seed(_seed);
111
112- uniform_distribution_rnd unifdistri;
113- unifdistri.seed(_seed);
114+ double u1 = unifdistri.generator();
115+ double u2 = unifdistri.generator();
116
117- double u1 = unifdistri.generator();
118- double u2 = unifdistri.generator();
119+ double R = sqrt(-2*log(u1));
120+ double theta = 2*M_PI*u2;
121
122- double R = sqrt(-2*log(u1));
123- double theta = 2*M_PI*u2;
124+ seed(unifdistri.get_seed());
125
126- seed(unifdistri.get_seed());
127+ return mean + sdev * (R*cos(theta));
128
129- return mean + sdev * (R*cos(theta));
130-
131- }
132- /*}}}*/
133+ }
134+ /*}}}*/
135+}
136Index: ../trunk-jpl/src/c/shared/Random/randomgenerator.h
137===================================================================
138--- ../trunk-jpl/src/c/shared/Random/randomgenerator.h (revision 26577)
139+++ ../trunk-jpl/src/c/shared/Random/randomgenerator.h (revision 26578)
140@@ -8,49 +8,51 @@
141 #undef M_PI
142 #define M_PI 3.141592653589793238462643
143
144-class uniform_distribution_rnd
145-{
146+namespace rdngen{
147+ class uniform_distribution_rnd
148+ {
149
150- private:
151+ private:
152
153- unsigned int a; //multiplier of the linear congruential generator
154- unsigned int c; //increment of the linear congruential generator
155- unsigned int m; // modulo of the linear congruential generator
156- unsigned int _seed; // seed value
157- double lbound; // lower bound of uniform distribution
158- double ubound; // upper bound of uniform distribution
159+ unsigned int a; //multiplier of the linear congruential generator
160+ unsigned int c; //increment of the linear congruential generator
161+ unsigned int m; // modulo of the linear congruential generator
162+ unsigned int _seed; // seed value
163+ double lbound; // lower bound of uniform distribution
164+ double ubound; // upper bound of uniform distribution
165
166- public:
167+ public:
168
169- /*constructors, destructors: */
170- uniform_distribution_rnd();
171- uniform_distribution_rnd(double a_1, double a_2);
172- ~uniform_distribution_rnd();
173+ /*constructors, destructors: */
174+ uniform_distribution_rnd();
175+ uniform_distribution_rnd(double a_1, double a_2);
176+ ~uniform_distribution_rnd();
177
178- void seed( unsigned int s );
179- unsigned int get_seed();
180- double generator();
181+ void seed( unsigned int s );
182+ unsigned int get_seed();
183+ double generator();
184
185-};
186+ };
187
188-class normal_distribution_rnd
189-{
190+ class normal_distribution_rnd
191+ {
192
193- private:
194- unsigned int _seed; // seed value
195- double mean; // mean value
196- double sdev; // standard deviation
197+ private:
198+ unsigned int _seed; // seed value
199+ double mean; // mean value
200+ double sdev; // standard deviation
201
202- public:
203+ public:
204
205- /*constructors, destructors: */
206- normal_distribution_rnd();
207- normal_distribution_rnd(double m,double s);
208- ~normal_distribution_rnd();
209+ /*constructors, destructors: */
210+ normal_distribution_rnd();
211+ normal_distribution_rnd(double m,double s);
212+ ~normal_distribution_rnd();
213
214- void seed( unsigned int s );
215- double generator();
216+ void seed( unsigned int s );
217+ double generator();
218
219-};
220+ };
221
222+}
223 #endif //ifndef _RANDOMGENERATOR_H_
224Index: ../trunk-jpl/src/c/solutionsequences/solutionsequence_sampling.cpp
225===================================================================
226--- ../trunk-jpl/src/c/solutionsequences/solutionsequence_sampling.cpp (revision 26577)
227+++ ../trunk-jpl/src/c/solutionsequences/solutionsequence_sampling.cpp (revision 26578)
228@@ -17,7 +17,7 @@
229 double rdnumber;
230
231 /*Define seed*/
232- //normal_distribution_rnd distribution;
233+ rdngen::normal_distribution_rnd distribution;
234 if(seed<0){
235 std::random_device rd;
236 seed = rd();
237@@ -28,7 +28,7 @@
238 ISSM_MPI_Comm_rank(ISSM_MPI_COMM_WORLD,&my_rank);
239 seed = seed + 783728*my_rank; // change default seed for parallel simulations (by considering an arbitrary shif based on the rank number)
240 }
241- //distribution.seed(seed);
242+ distribution.seed(seed);
243
244 int *local_indices = NULL;
245 IssmDouble *local_vector = NULL;
246@@ -37,7 +37,7 @@
247 int M;
248 ppf->GetLocalSize(&M);
249 for(int i=0;i<M;i++){
250- rdnumber = 1.0;//distribution.rnd();
251+ rdnumber = distribution.generator();
252 ppf->SetValue(local_indices[i],rdnumber,INS_VAL);
253 }
254 ppf->Assemble();
Note: See TracBrowser for help on using the repository browser.