forked from johannesgerer/jburkardt-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sparse_grid_open.html
541 lines (484 loc) · 16.9 KB
/
sparse_grid_open.html
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
<html>
<head>
<title>
SPARSE_GRID_OPEN - Sparse Grids Based on Open Quadrature Rules
</title>
</head>
<body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">
<h1 align = "center">
SPARSE_GRID_OPEN <br> Sparse Grids Based on Open Quadrature Rules
</h1>
<hr>
<p>
<b>SPARSE_GRID_OPEN</b>
is a C++ library which
computes the location of points on a sparse grid
based on an open quadrature rule.
</p>
<p>
One way of looking at the construction of sparse grids is to assume
that we start out by constructing a (very dense) product grid.
We will assume for now that the <b>order</b>, that is, the number of
points used in each component grid, is the same for all dimensions.
Moreover, we will assume that the order is a power of 2 minus one,
so that we have a natural relationship between the order and
the logarithm base 2 of the order plus 1:
</p>
<p>
<pre><b>
order = 2<sup>( level + 1 )</sup> - 1
</b></pre>
</p>
<p>
Thus, if we allow <b>level</b> to grow, the <b>order</b> roughly
doubles, as follows:
<table border = "1">
<tr><th>Level</th><th>Order</th></tr>
<tr><td> 0</td><td> 1</th></tr>
<tr><td> 1</td><td> 3</th></tr>
<tr><td> 2</td><td> 7</th></tr>
<tr><td> 3</td><td> 15</th></tr>
<tr><td> 4</td><td> 31</th></tr>
<tr><td> 5</td><td> 63</th></tr>
<tr><td> 6</td><td> 127</th></tr>
<tr><td> 7</td><td> 255</th></tr>
<tr><td> 8</td><td> 511</th></tr>
<tr><td> 9</td><td> 1023</th></tr>
<tr><td> 10</td><td> 2047</th></tr>
</table>
</p>
<p>
To keep things simple, let us begin by supposing we are selecting
points for a grid to be used in an interpolation or quadrature rule.
If you successively compute the locations of the points of each
level, you will probably see that the points of a level
are all included in the grid associated with the next level.
(This is not guaranteed for all rules; it's simply a property
of the way most such grids are defined!).
</p>
<p>
This <b>nesting</b> property is very useful. For one thing,
it means that when if we've computed a grid of one level, and now
proceed to the next, then all the information associated with
the current level (point location, the value of functions at those
points) is still useful for the next level, and will save us
some computation time as well. This also means that, when we
have reached a particular level, all the previous levels are
still available to us, with no extra storage. These considerations
make it possible, for instance, to do efficient and convenient
error estimation.
</p>
<p>
When we move to a problem whose geometry is two-dimensional or
more, we can still take the same approach. However, when working
in multidimensional geometry, it is usually not a good idea to
form a grid using the product of 1D grids, especially when we
are determining the order using the idea of levels. Especially
in this case, if we go to the next level in each dimension, the
total number of points would increase by a factor of roughly
2 to the spatial dimension. Just a few such steps in, say,
6 dimensions, and we would be far beyond our computational capacity.
</p>
<p>
Instead, in multidimensions, the idea is to construct a <i>sparse
grid</i>, which can be thought of in one of two ways:
<ul>
<li>
the sparse gird is a logical sum of low order product grids;
each product grid has a total level (sum of the levels of the
1d rules) that is less than or equal to <b>level_max</b>;
</li>
<li>
the sparse grid is a very sparse selection of points from the
very high order product grid formed by using rules of level
<b>level_max</b> in each dimension.
</li>
</ul>
</p>
<p><i>
(There is still a lot of explaining to do to get from the one-dimensional
levels to the N-dimensional levels and the selection of the low-level
product grids that sum up to the sparse grid...)
</i></p>
<p>
Once the grid indices of the sparse grid points have been selected,
there are a variety of schemes for distributing the points. We
concentrate on two sets of schemes:
<p>
<p>
Uniform (equally spaced) open rules of order N over [0,1]:
<ul>
<li>
Newton Cotes Open: [ 1, 2, 3,..., N ] / ( N + 1 );<br>
does not include boundaries. Point spacing is 1/(N+1)<br>
First and last points are distance 1/N to the boundary.
</li>
</ul>
</p>
<p>
The uniform schemes are easy to understand. However, it has
been observed that greater accuracy and stability can be achieved
by arranging the points in a nonuniform way that tends to move
points towards the boundary and away from the center.
A common scheme uses the cosine function to do this, and can
be naturally derived from the uniform schemes.
</p>
<p>
Nonuniform open rules of order N over [-1,1]:
<ul>
<li>
Fejer Type 2:<br>
Theta = pi * [ 1, 2, 3,..., N ] / ( N + 1 );<br>
Points = cos ( theta );<br>
does not include boundaries.<br>
Analogue to the Newton Cotes Open Rule.
</li>
<li>
Gauss-Patterson:<br>
Starting with midpoint rule, then the Gauss rule of order 3,<br>
incremented at each new level by intermediate points,<br>
does not include boundaries.
</li>
</ul>
</p>
<p>
Note that a standard Gauss-Legendre quadrature rule will not be suitable
for use in constructing sparse grids, because rules of successively
greater levels are not naturally nested.
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The code described and made available on this web page is distributed
under the
<a href = "gnu_lgpl.txt">GNU LGPL</a> license.
</p>
<h3 align = "center">
Languages:
</h3>
<p>
<b>SPARSE_GRID_OPEN</b> is available in
<a href = "../../cpp_src/sparse_grid_open/sparse_grid_open.html">a C++ version</a> and
<a href = "../../f_src/sparse_grid_open/sparse_grid_open.html">a FORTRAN90 version</a> and
<a href = "../../m_src/sparse_grid_open/sparse_grid_open.html">a MATLAB version</a>.
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../m_src/cc_display/cc_display.html">
CC_DISPLAY</a>,
a MATLAB program which
can compute and display Clenshaw Curtis grids in two dimensions,
as well as sparse grids formed from sums of Clenshaw Curtis grids.
</p>
<p>
<a href = "../../cpp_src/clenshaw_curtis/clenshaw_curtis.html">
CLENSHAW_CURTIS</a>,
a C++ library which
computes Clenshaw Curtis grids in multiple dimensions,
as well as sparse grids formed from sums of Clenshaw Curtis grids.
</p>
<p>
<a href = "../../datasets/quadrature_rules/quadrature_rules.html">
QUADRATURE_RULES</a>,
a dataset directory which
defines quadrature rules;
a number of examples of sparse grid quadrature rules are included.
</p>
<p>
<a href = "../../cpp_src/quadrule/quadrule.html">
QUADRULE</a>,
a C++ library which
defines quadrature rules for
various intervals and weight functions.
</p>
<p>
<a href = "../../cpp_src/sgmg/sgmg.html">
SGMG</a>,
a C++ library which
creates a sparse grid dataset based on a mixed set of 1D factor rules,
and experiments with the use of a linear growth rate for the quadrature rules.
</p>
<p>
<a href = "../../cpp_src/sgmga/sgmga.html">
SGMGA</a>,
a C++ library which
creates sparse grids based on a mixture of 1D quadrature rules,
allowing anisotropic weights for each dimension.
</p>
<p>
<a href = "../../c_src/smolpack/smolpack.html">
SMOLPACK</a>,
a C library which
implements Novak and Ritter's method for estimating the integral
of a function over a multidimensional hypercube using sparse grids.
</p>
<p>
<a href = "../../datasets/sparse_grid_cc/sparse_grid_cc.html">
SPARSE_GRID_CC</a>,
a dataset directory which
contains the abscissas of sparse
grids based on a Clenshaw Curtis rule.
</p>
<p>
<a href = "../../cpp_src/sparse_grid_closed/sparse_grid_closed.html">
SPARSE_GRID_CLOSED</a>,
a C++ library which
defines sparse grids based on closed nested quadrature rules.
</p>
<p>
<a href = "../../m_src/sparse_grid_display/sparse_grid_display.html">
SPARSE_GRID_DISPLAY</a>,
a MATLAB program which
can display a 2D or 3D sparse grid.
</p>
<p>
<a href = "../../datasets/sparse_grid_f2/sparse_grid_f2.html">
SPARSE_GRID_F2</a>,
a dataset directory which
contains the abscissas of sparse
grids based on a Fejer Type 2 rule.
</p>
<p>
<a href = "../../datasets/sparse_grid_gp/sparse_grid_gp.html">
SPARSE_GRID_GP</a>,
a dataset directory which
contains the abscissas of sparse
grids based on a Gauss Patterson rule.
</p>
<p>
<a href = "../../cpp_src/sparse_grid_hermite/sparse_grid_hermite.html">
SPARSE_GRID_HERMITE</a>,
a C++ library which
creates sparse grids based on Gauss-Hermite rules.
</p>
<p>
<a href = "../../cpp_src/sparse_grid_mixed/sparse_grid_mixed.html">
SPARSE_GRID_MIXED</a>,
a C++ library which
constructs a sparse grid using different rules in each spatial dimension.
</p>
<p>
<a href = "../../datasets/sparse_grid_ncc/sparse_grid_ncc.html">
SPARSE_GRID_NCC</a>,
a dataset directory which
contains the abscissas of sparse
grids based on a Newton Cotes closed rule.
</p>
<p>
<a href = "../../datasets/sparse_grid_nco/sparse_grid_nco.html">
SPARSE_GRID_NCO</a>,
a dataset directory which
contains the abscissas of sparse
grids based on a Newton Cotes open rule.
</p>
<p>
<a href = "../../m_src/sparse_grid_open_dataset/sparse_grid_open_dataset.html">
SPARSE_GRID_OPEN_DATASET</a>,
a MATLAB program which
creates a sparse grid dataset based on
open rules (Fejer 2, Gauss-Patterson, Newton-Cotes-Open).
</p>
<p>
<a href = "../../m_src/spinterp/spinterp.html">
SPINTERP</a>,
a MATLAB library which
carries out piecewise multilinear hierarchical sparse grid interpolation;
an earlier version of this software is ACM TOMS Algorithm 847,
by Andreas Klimke;
</p>
<p>
<a href = "../../m_src/toms847/toms847.html">
TOMS847</a>,
a MATLAB library which
carries out piecewise multilinear hierarchical sparse grid interpolation;
this library is commonly called SPINTERP (version 2.1);
this is ACM TOMS Algorithm 847,
by Andreas Klimke;
</p>
<h3 align = "center">
Reference:
</h3>
<p>
<ol>
<li>
Volker Barthelmann, Erich Novak, Klaus Ritter,<br>
High Dimensional Polynomial Interpolation on Sparse Grids,<br>
Advances in Computational Mathematics,<br>
Volume 12, Number 4, 2000, pages 273-288.
</li>
<li>
Thomas Gerstner, Michael Griebel,<br>
Numerical Integration Using Sparse Grids,<br>
Numerical Algorithms,<br>
Volume 18, Number 3-4, 1998, pages 209-232.
</li>
<li>
Albert Nijenhuis, Herbert Wilf,<br>
Combinatorial Algorithms for Computers and Calculators,<br>
Second Edition,<br>
Academic Press, 1978,<br>
ISBN: 0-12-519260-6,<br>
LC: QA164.N54.
</li>
<li>
Fabio Nobile, Raul Tempone, Clayton Webster,<br>
A Sparse Grid Stochastic Collocation Method for Partial Differential
Equations with Random Input Data,<br>
SIAM Journal on Numerical Analysis,<br>
Volume 46, Number 5, 2008, pages 2309-2345.
</li>
<li>
Sergey Smolyak,<br>
Quadrature and Interpolation Formulas for Tensor Products of
Certain Classes of Functions,<br>
Doklady Akademii Nauk SSSR,<br>
Volume 4, 1963, pages 240-243.
</li>
<li>
Dennis Stanton, Dennis White,<br>
Constructive Combinatorics,<br>
Springer, 1986,<br>
ISBN: 0387963472,<br>
LC: QA164.S79.
</li>
</ol>
</p>
<h3 align = "center">
Source Code:
</h3>
<p>
<ul>
<li>
<a href = "sparse_grid_open.cpp">sparse_grid_open.cpp</a>, the source code.
</li>
<li>
<a href = "sparse_grid_open.hpp">sparse_grid_open.hpp</a>, the include file.
</li>
<li>
<a href = "sparse_grid_open.sh">sparse_grid_open.sh</a>,
commands to compile the source code.
</li>
</ul>
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
<ul>
<li>
<a href = "sparse_grid_open_prb.cpp">sparse_grid_open_prb.cpp</a>,
a sample calling program.
</li>
<li>
<a href = "sparse_grid_open_prb.sh">sparse_grid_open_prb.sh</a>,
commands to compile and run the sample program.
</li>
<li>
<a href = "sparse_grid_open_prb_output.txt">sparse_grid_open_prb_output.txt</a>,
the output file.
</li>
</ul>
</p>
<h3 align = "center">
List of Routines:
</h3>
<p>
<ul>
<li>
<b>ABSCISSA_LEVEL_OPEN_ND:</b> first level at which given abscissa is generated.
</li>
<li>
<b>COMP_NEXT</b> computes the compositions of the integer N into K parts.
</li>
<li>
<b>F2_ABSCISSA</b> returns the I-th abscissa for the Fejer type 2 rule.
</li>
<li>
<b>GP_ABSCISSA</b> returns the I-th abscissa for a Gauss-Patterson rule.
</li>
<li>
<b>I4_CHOOSE</b> computes the binomial coefficient C(N,K).
</li>
<li>
<b>I4_MAX</b> returns the maximum of two I4's.
</li>
<li>
<b>I4_MIN</b> returns the minimum of two I4's.
</li>
<li>
<b>I4_MODP</b> returns the nonnegative remainder of I4 division.
</li>
<li>
<b>I4_POWER</b> returns the value of I^J.
</li>
<li>
<b>I4_TO_STRING</b> converts an I4 to a C++ string.
</li>
<li>
<b>I4VEC_PRODUCT</b> multiplies the entries of an I4VEC.
</li>
<li>
<b>INDEX_TO_LEVEL_OPEN</b> determines the level of a point given its index.
</li>
<li>
<b>LEVEL_TO_ORDER_OPEN</b> converts a level to an order for open rules.
</li>
<li>
<b>LEVELS_OPEN_INDEX</b> computes grids with 0 <= LEVEL <= LEVEL_MAX.
</li>
<li>
<b>MULTIGRID_INDEX1</b> returns an indexed multidimensional grid.
</li>
<li>
<b>MULTIGRID_SCALE_OPEN</b> renumbers a grid as a subgrid on a higher level.
</li>
<li>
<b>NCO_ABSCISSA</b> returns the I-th abscissa for the Newton Cotes open rule.
</li>
<li>
<b>R8_EPSILON</b> returns the R8 roundoff unit.
</li>
<li>
<b>R8_HUGE</b> returns a "huge" R8.
</li>
<li>
<b>R8MAT_WRITE</b> writes an R8MAT file.
</li>
<li>
<b>SPARSE_GRID_F2S_SIZE</b> sizes a sparse grid using Fejer Type 2 Slow rules.
</li>
<li>
<b>SPARSE_GRID_GPS_SIZE</b> sizes a sparse grid using Gauss-Patterson-Slow rules.
</li>
<li>
<b>SPARSE_GRID_OFN_SIZE</b> sizes a sparse grid using Open Fully Nested rules.
</li>
<li>
<b>SPARSE_GRID_ONN_SIZE</b> sizes a sparse grid using Open Non-Nested rules.
</li>
<li>
<b>SPARSE_GRID_OWN_SIZE</b> sizes a sparse grid using Open Weakly Nested rules.
</li>
<li>
<b>TIMESTAMP</b> prints the current YMDHMS date as a time stamp.
</li>
<li>
<b>VEC_COLEX_NEXT2</b> generates vectors in colex order.
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../cpp_src.html">
the C++ source codes</a>.
</p>
<hr>
<i>
Last revised on 12 January 2010.
</i>
<!-- John Burkardt -->
</body>
<!-- Initial HTML skeleton created by HTMLINDEX. -->
</html>