28 cout <<
"Simple interpolation cases\n" 29 <<
"--------------------------\n";
34 cout <<
"og:\n" << og <<
"\n";
35 cout <<
"ng:\n" << ng <<
"\n";
41 cout <<
"gp:\n" << gp <<
"\n";
50 cout <<
"itw:\n" << itw <<
"\n";
56 cout <<
"of:\n" << of <<
"\n";
63 cout <<
"nf:\n" << nf <<
"\n";
73 cout <<
"itw:\n" << itw <<
"\n";
76 Matrix of(og.nelem(), og.nelem(), 0);
79 cout <<
"of:\n" << of <<
"\n";
84 interp(nf, itw, of, gp, gp);
86 cout <<
"nf:\n" << nf <<
"\n";
93 Matrix itw(gp.nelem(), 64);
100 Tensor6 of(n, n, n, n, n, n, 0);
101 of(2, 2, 2, 2, 2, 2) = 10;
108 interp(nf, itw, of, gp, gp, gp, gp, gp, gp);
110 cout <<
"nf:\n" << nf <<
"\n";
113 cout <<
"Green 2D:\n" 117 Tensor3 itw(gp.nelem(), gp.nelem(), 4);
120 for (
Index i = 0;
i < itw.ncols(); ++
i)
121 cout <<
"itw " <<
i <<
":\n" 125 Matrix of(og.nelem(), og.nelem(), 0);
128 cout <<
"of:\n" << of <<
"\n";
131 Matrix nf(ng.nelem(), ng.nelem());
133 interp(nf, itw, of, gp, gp);
135 cout <<
"nf:\n" << nf <<
"\n";
138 cout <<
"Green 6D:\n" 159 of(2, 2, 2, 2, 2, 2) = 10;
161 cout <<
"Middle slice of of:\n" 166 ng.nelem(), ng.nelem(), ng.nelem(), ng.nelem(), ng.nelem(), ng.nelem());
168 interp(nf, itw, of, gp, gp, gp, gp, gp, gp);
170 cout <<
"Last slice of nf:\n" 176 cout <<
"Test whether for loop or iterator are quicker\n" 178 <<
"---------------------------------------------\n";
185 cout <<
"Test whether for loop or iterator are quicker\n" 187 <<
"---------------------------------------------\n";
193 for (; ai != ae; ++ai, ++
i) *ai = (
Numeric)
i;
200 cout <<
"Green type interpolation of all pages of a Tensor3\n";
205 Vector a_pgrid(1, 3, 1), a_rgrid(1, 3, 1), a_cgrid(1, 3, 1);
206 Tensor3 a(a_pgrid.nelem(), a_rgrid.nelem(), a_cgrid.
nelem());
216 Vector n_rgrid(1, 5, .5), n_cgrid(1, 5, .5);
217 Tensor3 n(a_pgrid.nelem(), n_rgrid.nelem(), n_cgrid.
nelem());
225 gridpos(n_rgp, a_rgrid, n_rgrid);
226 gridpos(n_cgp, a_cgrid, n_cgrid);
234 for (
Index i = 0;
i < a.npages(); ++
i) {
240 interp(np, itw, ap, n_rgp, n_cgp);
246 cout <<
"Original field:\n";
247 for (
Index i = 0;
i < a.npages(); ++
i)
250 cout <<
"Interpolated field:\n";
256 cout <<
"Very simple interpolation case\n";
261 cout <<
"Original grid:\n" << og <<
"\n";
262 cout <<
"New grid:\n" << ng <<
"\n";
268 cout <<
"Grid positions:\n" << gp;
271 Matrix itw(gp.nelem(), 2);
274 cout <<
"Interpolation weights:\n" << itw <<
"\n";
280 cout <<
"Original field:\n" << of <<
"\n";
287 cout <<
"New field:\n" << nf <<
"\n";
291 cout <<
"Simple extrapolation cases\n" 292 <<
"--------------------------\n";
295 Vector ng{0.9, 1.5, 3, 4.5, 5.1};
297 cout <<
"og:\n" << og <<
"\n";
298 cout <<
"ng:\n" << ng <<
"\n";
304 cout <<
"gp:\n" << gp <<
"\n";
310 Matrix itw(gp.nelem(), 2);
313 cout <<
"itw:\n" << itw <<
"\n";
317 for (
Index i = 0;
i < og.nelem(); ++
i)
320 cout <<
"of:\n" << of <<
"\n";
327 cout <<
"nf:\n" << nf <<
"\n";
334 Matrix itw(gp.nelem(), 4);
337 cout <<
"itw:\n" << itw <<
"\n";
340 Matrix of(og.nelem(), og.nelem(), 0);
343 cout <<
"of:\n" << of <<
"\n";
348 interp(nf, itw, of, gp, gp);
350 cout <<
"nf:\n" << nf <<
"\n";
357 Matrix itw(gp.nelem(), 64);
364 Tensor6 of(n, n, n, n, n, n, 0);
365 of(2, 2, 2, 2, 2, 2) = 10;
372 interp(nf, itw, of, gp, gp, gp, gp, gp, gp);
374 cout <<
"nf:\n" << nf <<
"\n";
377 cout <<
"Green 2D:\n" 381 Tensor3 itw(gp.nelem(), gp.nelem(), 4);
384 for (
Index i = 0;
i < itw.ncols(); ++
i)
385 cout <<
"itw " <<
i <<
":\n" 389 Matrix of(og.nelem(), og.nelem(), 0);
392 cout <<
"of:\n" << of <<
"\n";
395 Matrix nf(ng.nelem(), ng.nelem());
397 interp(nf, itw, of, gp, gp);
399 cout <<
"nf:\n" << nf <<
"\n";
402 cout <<
"Green 6D:\n" 423 of(2, 2, 2, 2, 2, 2) = 10;
425 cout <<
"Middle slice of of:\n" 430 ng.nelem(), ng.nelem(), ng.nelem(), ng.nelem(), ng.nelem(), ng.nelem());
432 interp(nf, itw, of, gp, gp, gp, gp, gp, gp);
434 cout <<
"Last slice of nf:\n" 442 Vector new_x(0, 21, +0.25);
456 y2[
i] =
pow(x[
i], 3) + 2;
462 Matrix itw(gp.nelem(), 2);
469 interp(y1_lin, itw, y1, gp);
470 interp(y2_lin, itw, y2, gp);
471 interp(y3_lin, itw, y3, gp);
473 cout <<
"y1_lin = [" << y1_lin <<
"];\n";
474 cout <<
"y2_lin = [" << y2_lin <<
"];\n";
475 cout <<
"y3_lin = [" << y3_lin <<
"];\n";
488 cout <<
"y1_cub = [" << y1_cub <<
"];\n";
489 cout <<
"y2_cub = [" << y2_cub <<
"];\n";
490 cout <<
"y3_cub = [" << y3_cub <<
"];\n";
504 interp(y1_new, itwp, y1, gpp);
505 interp(y2_new, itwp, y2, gpp);
506 interp(y3_new, itwp, y3, gpp);
508 cout <<
"y1_new = [" << y1_new <<
"];\n";
509 cout <<
"y2_new = [" << y2_new <<
"];\n";
510 cout <<
"y3_new = [" << y3_new <<
"];\n";
514 cout <<
"Very simple interpolation case for the " 515 <<
"new higher order polynomials.\n";
520 cout <<
"Original grid:\n" << og <<
"\n";
521 cout <<
"New grid:\n" << ng <<
"\n";
529 cout <<
"Grid positions:\n" << gp;
532 Matrix itw(gp.nelem(), order + 1);
535 cout <<
"Interpolation weights:\n" << itw <<
"\n";
541 cout <<
"Original field:\n" << of <<
"\n";
548 cout <<
"New field (order=" << order <<
"):\n" << nf <<
"\n";
550 cout <<
"All orders systematically:\n";
551 for (order = 0; order < 5; ++order) {
553 itw.resize(gp.nelem(), order + 1);
557 cout <<
"order " << order <<
": ";
558 for (
Index i = 0;
i < nf.nelem(); ++
i) cout << setw(8) << nf[
i] <<
" ";
INDEX Index
The type to use for all integer numbers and indices.
Numeric interp_poly(ConstVectorView x, ConstVectorView y, const Numeric &x_i, const GridPos &gp)
Polynomial interpolation.
Numeric interp(ConstVectorView itw, ConstVectorView a, const GridPos &tc)
Red 1D Interpolate.
This file contains basic functions to handle XML data files.
Header file for interpolation.cc.
Index nelem() const
Returns the number of elements.
This file contains the definition of Array.
Iterator1D begin()
Return iterator to first element.
Iterator1D end()
Return iterator behind last element.
void gridpos(ArrayOfGridPos &gp, ConstVectorView old_grid, ConstVectorView new_grid, const Numeric &extpolfac)
Set up a grid position Array.
NUMERIC Numeric
The type to use for all floating point numbers.
void gridpos_poly(ArrayOfGridPosPoly &gp, ConstVectorView old_grid, ConstVectorView new_grid, const Index order, const Numeric &extpolfac)
The maximum difference from 1 that we allow for a sum check.
Numeric pow(const Rational base, Numeric exp)
Power of.
This can be used to make arrays out of anything.
Header file for interpolation_poly.cc.
A constant view of a Matrix.
The iterator class for sub vectors.
void interpweights(VectorView itw, const GridPos &tc)
Red 1D interpolation weights.