-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathstochastic_heat2d.cpp
1127 lines (1037 loc) · 24.1 KB
/
stochastic_heat2d.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <cmath>
# include <ctime>
# include <cstring>
using namespace std;
# include "stochastic_heat2d.hpp"
void boundary ( int nx, int ny, double x[], double y[],
int n, double a[], double u[] );
//****************************************************************************80
double diffusivity_2d_bnt ( double dc0, double omega[], double x, double y )
//****************************************************************************80
//
// Purpose:
//
// DIFFUSIVITY_2D_BNT evaluates a 2D stochastic diffusivity function.
//
// Discussion:
//
// The 2D diffusion equation has the form
//
// - Del ( DC(X,Y) Del U(X,Y) ) = F(X,Y)
//
// where DC(X,Y) is a function called the diffusivity.
//
// In the stochastic version of the problem, the diffusivity function
// includes the influence of stochastic parameters:
//
// - Del ( DC(X,Y;OMEGA) Del U(X,Y;OMEGA) ) = F(X,Y).
//
// In this function, the domain is the rectangle [-1.5,0]x[-0.4,0.8].
//
// The four stochastic parameters OMEGA(1:4) are assumed to be independent
// identically distributed random variables with mean value zero and
// variance 1. The distribution is typically taken to be Gaussian or
// uniform.
//
// A collocation approach to this problem would then use the roots of
// Hermite or Legendre polynomials.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 06 August 2013
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Ivo Babuska, Fabio Nobile, Raul Tempone,
// A stochastic collocation method for elliptic partial differential equations
// with random input data,
// SIAM Journal on Numerical Analysis,
// Volume 45, Number 3, 2007, pages 1005-1034.
//
// Parameters:
//
// Input, double DC0, the constant term in the expansion of the
// diffusion coefficient. Take DC0 = 10.
//
// Input, double OMEGA[4], the stochastic parameters.
//
// Input, double X, Y, the points where the diffusion
// coefficient is to be evaluated.
//
// Output, double DIFFUSIVITY_2D_BNT, the value of the diffusion
// coefficient at (X,Y).
//
{
double arg;
double dc;
double pi = 3.141592653589793;
arg = omega[0] * cos ( pi * x )
+ omega[1] * sin ( pi * x )
+ omega[2] * cos ( pi * y )
+ omega[3] * sin ( pi * y );
arg = exp ( - 0.125 ) * arg;
dc = dc0 + exp ( arg );
return dc;
}
//****************************************************************************80
void interior ( double omega[], int nx, int ny, double x[], double y[],
double f ( double x, double y ), int n, double a[], double rhs[] )
//****************************************************************************80
//
// Purpose:
//
// INTERIOR sets up the matrix and right hand side at interior nodes.
//
// Discussion:
//
// Nodes are assigned a single index K, which increases as:
//
// (NY-1)*NX+1 (NY-1)*NX+2 ... NY * NX
// .... .... ... .....
// NX+1 NX+2 ... 2 * NX
// 1 2 ... NX
//
// Therefore, the neighbors of an interior node numbered C are
//
// C+NY
// |
// C-1 --- C --- C+1
// |
// C-NY
//
// If we number rows from bottom I = 1 to top I = NY
// and columns from left J = 1 to right J = NX, then the relationship
// between the single index K and the row and column indices I and J is:
// K = ( I - 1 ) * NX + J
// and
// J = 1 + mod ( K - 1, NX )
// I = 1 + ( K - J ) / NX
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 04 September 2013
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, double OMEGA[4], the stochastic coefficients.
//
// Input, int NX, NY, the number of grid points in X and Y.
//
// Input, double X[NX], Y[NY], the coordinates of grid lines.
//
// Input, double function F ( double X, double Y ), evaluates the heat
// source term.
//
// Input, int N, the number of nodes.
//
// Output, double A[N*N], the system matrix, with the entries for
// the interior nodes filled in.
//
// Output, double RHS[N], the system right hand side, with the
// entries for the interior nodes filled in.
//
{
double dc0;
double dce;
double dcn;
double dcs;
double dcw;
double dx;
double dy;
int ic;
int in;
int is;
int jc;
int je;
int jw;
int kc;
int ke;
int kn;
int ks;
int kw;
double xce;
double xcw;
double ycn;
double ycs;
dc0 = 1.0;
//
// For now, assume X and Y are equally spaced.
//
dx = x[1] - x[0];
dy = y[1] - y[0];
for ( ic = 1; ic < ny - 1; ic++ )
{
for ( jc = 1; jc < nx - 1; jc++ )
{
in = ic + 1;
is = ic - 1;
je = jc + 1;
jw = jc - 1;
kc = ic * nx + jc;
ke = kc + 1;
kw = kc - 1;
kn = kc + nx;
ks = kc - nx;
xce = 0.5 * ( x[jc] + x[je] );
dce = diffusivity_2d_bnt ( dc0, omega, xce, y[ic] );
xcw = 0.5 * ( x[jc] + x[jw] );
dcw = diffusivity_2d_bnt ( dc0, omega, xcw, y[ic] );
ycn = 0.5 * ( y[ic] + y[in] );
dcn = diffusivity_2d_bnt ( dc0, omega, x[jc], ycn );
ycs = 0.5 * ( y[ic] + y[is] );
dcs = diffusivity_2d_bnt ( dc0, omega, x[jc], ycs );
a[kc+kc*n] = ( dce + dcw ) / dx / dx + ( dcn + dcs ) / dy / dy;
a[kc+ke*n] = - dce / dx / dx;
a[kc+kw*n] = - dcw / dx / dx;
a[kc+kn*n] = - dcn / dy / dy;
a[kc+ks*n] = - dcs / dy / dy;
rhs[kc] = f ( x[jc], y[ic] );
}
}
return;
}
//****************************************************************************80
double r8_uniform_01 ( int &seed )
//****************************************************************************80
//
// Purpose:
//
// R8_UNIFORM_01 returns a unit pseudorandom R8.
//
// Discussion:
//
// This routine implements the recursion
//
// seed = ( 16807 * seed ) mod ( 2^31 - 1 )
// u = seed / ( 2^31 - 1 )
//
// The integer arithmetic never requires more than 32 bits,
// including a sign bit.
//
// If the initial seed is 12345, then the first three computations are
//
// Input Output R8_UNIFORM_01
// SEED SEED
//
// 12345 207482415 0.096616
// 207482415 1790989824 0.833995
// 1790989824 2035175616 0.947702
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 09 April 2012
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Paul Bratley, Bennett Fox, Linus Schrage,
// A Guide to Simulation,
// Second Edition,
// Springer, 1987,
// ISBN: 0387964673,
// LC: QA76.9.C65.B73.
//
// Bennett Fox,
// Algorithm 647:
// Implementation and Relative Efficiency of Quasirandom
// Sequence Generators,
// ACM Transactions on Mathematical Software,
// Volume 12, Number 4, December 1986, pages 362-376.
//
// Pierre L'Ecuyer,
// Random Number Generation,
// in Handbook of Simulation,
// edited by Jerry Banks,
// Wiley, 1998,
// ISBN: 0471134031,
// LC: T57.62.H37.
//
// Peter Lewis, Allen Goodman, James Miller,
// A Pseudo-Random Number Generator for the System/360,
// IBM Systems Journal,
// Volume 8, Number 2, 1969, pages 136-143.
//
// Parameters:
//
// Input/output, int &SEED, the "seed" value. Normally, this
// value should not be 0. On output, SEED has been updated.
//
// Output, double R8_UNIFORM_01, a new pseudorandom variate,
// strictly between 0 and 1.
//
{
int i4_huge = 2147483647;
int k;
double r;
if ( seed == 0 )
{
cerr << "\n";
cerr << "R8_UNIFORM_01 - Fatal error!\n";
cerr << " Input value of SEED = 0.\n";
exit ( 1 );
}
k = seed / 127773;
seed = 16807 * ( seed - k * 127773 ) - k * 2836;
if ( seed < 0 )
{
seed = seed + i4_huge;
}
r = ( double ) ( seed ) * 4.656612875E-10;
return r;
}
//****************************************************************************80
void r8mat_fs ( int n, double a[], double x[] )
//****************************************************************************80
//
// Purpose:
//
// R8MAT_FS factors and solves a system with one right hand side.
//
// Discussion:
//
// This routine differs from R8MAT_FSS in two ways:
// * only one right hand side is allowed;
// * the input matrix A is not modified.
//
// This routine uses partial pivoting, but no pivot vector is required.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 21 January 2013
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int N, the order of the matrix.
// N must be positive.
//
// Input, double A[N*N], the coefficient matrix of the linear system.
//
// Input/output, double X[N], on input, the right hand side of the
// linear system. On output, the solution of the linear system.
//
{
double *a2;
int i;
int ipiv;
int j;
int jcol;
double piv;
double t;
a2 = new double[n*n];
for ( j = 0; j < n; j++ )
{
for ( i = 0; i < n; i++ )
{
a2[i+j*n] = a[i+j*n];
}
}
for ( jcol = 1; jcol <= n; jcol++ )
{
//
// Find the maximum element in column I.
//
piv = fabs ( a2[jcol-1+(jcol-1)*n] );
ipiv = jcol;
for ( i = jcol+1; i <= n; i++ )
{
if ( piv < fabs ( a2[i-1+(jcol-1)*n] ) )
{
piv = fabs ( a2[i-1+(jcol-1)*n] );
ipiv = i;
}
}
if ( piv == 0.0 )
{
cerr << "\n";
cerr << "R8MAT_FS - Fatal error!\n";
cerr << " Zero pivot on step " << jcol << "\n";
exit ( 1 );
}
//
// Switch rows JCOL and IPIV, and X.
//
if ( jcol != ipiv )
{
for ( j = 1; j <= n; j++ )
{
t = a2[jcol-1+(j-1)*n];
a2[jcol-1+(j-1)*n] = a2[ipiv-1+(j-1)*n];
a2[ipiv-1+(j-1)*n] = t;
}
t = x[jcol-1];
x[jcol-1] = x[ipiv-1];
x[ipiv-1] = t;
}
//
// Scale the pivot row.
//
t = a2[jcol-1+(jcol-1)*n];
a2[jcol-1+(jcol-1)*n] = 1.0;
for ( j = jcol+1; j <= n; j++ )
{
a2[jcol-1+(j-1)*n] = a2[jcol-1+(j-1)*n] / t;
}
x[jcol-1] = x[jcol-1] / t;
//
// Use the pivot row to eliminate lower entries in that column.
//
for ( i = jcol+1; i <= n; i++ )
{
if ( a2[i-1+(jcol-1)*n] != 0.0 )
{
t = - a2[i-1+(jcol-1)*n];
a2[i-1+(jcol-1)*n] = 0.0;
for ( j = jcol+1; j <= n; j++ )
{
a2[i-1+(j-1)*n] = a2[i-1+(j-1)*n] + t * a2[jcol-1+(j-1)*n];
}
x[i-1] = x[i-1] + t * x[jcol-1];
}
}
}
//
// Back solve.
//
for ( jcol = n; 2 <= jcol; jcol-- )
{
for ( i = 1; i < jcol; i++ )
{
x[i-1] = x[i-1] - a2[i-1+(jcol-1)*n] * x[jcol-1];
}
}
delete [] a2;
return;
}
//****************************************************************************80
double r8mat_max ( int m, int n, double a[] )
//****************************************************************************80
//
// Purpose:
//
// R8MAT_MAX returns the maximum entry of an R8MAT.
//
// Discussion:
//
// An R8MAT is a doubly dimensioned array of R8 values, stored as a vector
// in column-major order.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 21 May 2011
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int M, the number of rows in A.
//
// Input, int N, the number of columns in A.
//
// Input, double A[M*N], the M by N matrix.
//
// Output, double R8MAT_MAX, the maximum entry of A.
//
{
int i;
int j;
double value;
value = a[0+0*m];
for ( j = 0; j < n; j++ )
{
for ( i = 0; i < m; i++ )
{
if ( value < a[i+j*m] )
{
value = a[i+j*m];
}
}
}
return value;
}
//****************************************************************************80
double r8mat_mean ( int m, int n, double a[] )
//****************************************************************************80
//
// Purpose:
//
// R8MAT_MEAN returns the mean of an R8MAT.
//
// Discussion:
//
// An R8MAT is a doubly dimensioned array of R8 values, stored as a vector
// in column-major order.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 03 September 2013
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int M, the number of rows in A.
//
// Input, int N, the number of columns in A.
//
// Input, double A[M*N], the M by N matrix.
//
// Output, double R8MAT_MEAN, the mean of A.
//
{
int i;
int j;
double value;
value = 0.0;
for ( j = 0; j < n; j++ )
{
for ( i = 0; i < m; i++ )
{
value = value + a[i+j*m];
}
}
value = value / ( double ) ( m * n );
return value;
}
//****************************************************************************80
double *r8vec_linspace_new ( int n, double a_first, double a_last )
//****************************************************************************80
//
// Purpose:
//
// R8VEC_LINSPACE_NEW creates a vector of linearly spaced values.
//
// Discussion:
//
// An R8VEC is a vector of R8's.
//
// 4 points evenly spaced between 0 and 12 will yield 0, 4, 8, 12.
//
// In other words, the interval is divided into N-1 even subintervals,
// and the endpoints of intervals are used as the points.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 29 March 2011
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int N, the number of entries in the vector.
//
// Input, double A_FIRST, A_LAST, the first and last entries.
//
// Output, double R8VEC_LINSPACE_NEW[N], a vector of linearly spaced data.
//
{
double *a;
int i;
a = new double[n];
if ( n == 1 )
{
a[0] = ( a_first + a_last ) / 2.0;
}
else
{
for ( i = 0; i < n; i++ )
{
a[i] = ( ( double ) ( n - 1 - i ) * a_first
+ ( double ) ( i ) * a_last )
/ ( double ) ( n - 1 );
}
}
return a;
}
//****************************************************************************80
void r8vec_mesh_2d ( int nx, int ny, double xvec[], double yvec[],
double xmat[], double ymat[] )
//****************************************************************************80
//
// Purpose:
//
// R8VEC_MESH_2D creates a 2D mesh from X and Y vectors.
//
// Discussion:
//
// An R8VEC is a vector of R8's.
//
// NX = 2
// XVEC = ( 1, 2, 3 )
// NY = 3
// YVEC = ( 4, 5 )
//
// XMAT = (
// 1, 2, 3
// 1, 2, 3 )
//
// YMAT = (
// 4, 4, 4
// 5, 5, 5 )
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 26 July 2013
//
// Parameters:
//
// Input, int NX, NY, the number of X and Y values.
//
// Input, double XVEC[NX], YVEC[NY], the X and Y coordinate
// values.
//
// Output, double XMAT[NX*NY], YMAT[NX*NY], the coordinate
// values of points on an NX by NY mesh.
//
{
int i;
int j;
for ( j = 0; j < ny; j++ )
{
for ( i = 0; i < nx; i++ )
{
xmat[i+j*nx] = xvec[i];
}
}
for ( j = 0; j < ny; j++ )
{
for ( i = 0; i < nx; i++ )
{
ymat[i+j*nx] = yvec[j];
}
}
return;
}
//****************************************************************************80
double *r8vec_normal_01_new ( int n, int &seed )
//****************************************************************************80
//
// Purpose:
//
// R8VEC_NORMAL_01_NEW returns a unit pseudonormal R8VEC.
//
// Discussion:
//
// An R8VEC is a vector of R8's.
//
// The standard normal probability distribution function (PDF) has
// mean 0 and standard deviation 1.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 06 August 2013
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int N, the number of values desired.
//
// Input/output, int &SEED, a seed for the random number generator.
//
// Output, double R8VEC_NORMAL_01_NEW[N], a sample of the standard normal PDF.
//
// Local parameters:
//
// Local, double R[N+1], is used to store some uniform random values.
// Its dimension is N+1, but really it is only needed to be the
// smallest even number greater than or equal to N.
//
// Local, int X_LO, X_HI, records the range of entries of
// X that we need to compute.
//
{
int i;
int m;
const double pi = 3.141592653589793;
double *r;
double *x;
int x_hi;
int x_lo;
x = new double[n];
//
// Record the range of X we need to fill in.
//
x_lo = 1;
x_hi = n;
//
// If we need just one new value, do that here to avoid null arrays.
//
if ( x_hi - x_lo + 1 == 1 )
{
r = r8vec_uniform_01_new ( 2, seed );
x[x_hi-1] = sqrt ( -2.0 * log ( r[0] ) ) * cos ( 2.0 * pi * r[1] );
delete [] r;
}
//
// If we require an even number of values, that's easy.
//
else if ( ( x_hi - x_lo + 1 ) % 2 == 0 )
{
m = ( x_hi - x_lo + 1 ) / 2;
r = r8vec_uniform_01_new ( 2*m, seed );
for ( i = 0; i <= 2*m-2; i = i + 2 )
{
x[x_lo+i-1] = sqrt ( -2.0 * log ( r[i] ) ) * cos ( 2.0 * pi * r[i+1] );
x[x_lo+i ] = sqrt ( -2.0 * log ( r[i] ) ) * sin ( 2.0 * pi * r[i+1] );
}
delete [] r;
}
//
// If we require an odd number of values, we generate an even number,
// and handle the last pair specially, storing one in X(N), and
// saving the other for later.
//
else
{
x_hi = x_hi - 1;
m = ( x_hi - x_lo + 1 ) / 2 + 1;
r = r8vec_uniform_01_new ( 2*m, seed );
for ( i = 0; i <= 2*m-4; i = i + 2 )
{
x[x_lo+i-1] = sqrt ( -2.0 * log ( r[i] ) ) * cos ( 2.0 * pi * r[i+1] );
x[x_lo+i ] = sqrt ( -2.0 * log ( r[i] ) ) * sin ( 2.0 * pi * r[i+1] );
}
i = 2*m - 2;
x[x_lo+i-1] = sqrt ( -2.0 * log ( r[i] ) ) * cos ( 2.0 * pi * r[i+1] );
delete [] r;
}
return x;
}
//****************************************************************************80
void r8vec_print ( int n, double a[], string title )
//****************************************************************************80
//
// Purpose:
//
// R8VEC_PRINT prints an R8VEC.
//
// Discussion:
//
// An R8VEC is a vector of R8's.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 16 August 2004
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int N, the number of components of the vector.
//
// Input, double A[N], the vector to be printed.
//
// Input, string TITLE, a title.
//
{
int i;
cout << "\n";
cout << title << "\n";
cout << "\n";
for ( i = 0; i < n; i++ )
{
cout << " " << setw(8) << i
<< ": " << setw(14) << a[i] << "\n";
}
return;
}
//****************************************************************************80
double *r8vec_uniform_01_new ( int n, int &seed )
//****************************************************************************80
//
// Purpose:
//
// R8VEC_UNIFORM_01_NEW returns a new unit pseudorandom R8VEC.
//
// Discussion:
//
// This routine implements the recursion
//
// seed = ( 16807 * seed ) mod ( 2^31 - 1 )
// u = seed / ( 2^31 - 1 )
//
// The integer arithmetic never requires more than 32 bits,
// including a sign bit.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 19 August 2004
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Paul Bratley, Bennett Fox, Linus Schrage,
// A Guide to Simulation,
// Second Edition,
// Springer, 1987,
// ISBN: 0387964673,
// LC: QA76.9.C65.B73.
//
// Bennett Fox,
// Algorithm 647:
// Implementation and Relative Efficiency of Quasirandom
// Sequence Generators,
// ACM Transactions on Mathematical Software,
// Volume 12, Number 4, December 1986, pages 362-376.
//
// Pierre L'Ecuyer,
// Random Number Generation,
// in Handbook of Simulation,
// edited by Jerry Banks,
// Wiley, 1998,
// ISBN: 0471134031,
// LC: T57.62.H37.
//
// Peter Lewis, Allen Goodman, James Miller,
// A Pseudo-Random Number Generator for the System/360,
// IBM Systems Journal,
// Volume 8, Number 2, 1969, pages 136-143.
//
// Parameters:
//
// Input, int N, the number of entries in the vector.
//
// Input/output, int &SEED, a seed for the random number generator.
//
// Output, double R8VEC_UNIFORM_01_NEW[N], the vector of pseudorandom values.
//
{
int i;
int i4_huge = 2147483647;
int k;
double *r;
if ( seed == 0 )
{
cerr << "\n";
cerr << "R8VEC_UNIFORM_01_NEW - Fatal error!\n";
cerr << " Input value of SEED = 0.\n";
exit ( 1 );
}
r = new double[n];
for ( i = 0; i < n; i++ )
{
k = seed / 127773;
seed = 16807 * ( seed - k * 127773 ) - k * 2836;
if ( seed < 0 )
{
seed = seed + i4_huge;
}
r[i] = ( double ) ( seed ) * 4.656612875E-10;
}
return r;
}
//****************************************************************************80
double *stochastic_heat2d ( double omega[], int nx, int ny, double x[],
double y[], double f ( double x, double y ) )
//****************************************************************************80
//
// Purpose:
//
// STOCHASTIC_HEAT2D solves the steady 2D heat equation.
//
// Discussion:
//
// Nodes are assigned a singled index K, which increases as:
//
// (NY-1)*NX+1 (NY-1)*NX+2 ... NY * NX
// .... .... ... .....
// NX+1 NX+2 ... 2 * NX
// 1 2 ... NX
//
// Therefore, the neighbors of an interior node numbered C are
//
// C+NY