Tabular data is handled by GetDP as simple lists, which can be defined either directly in the .pro
files, or in separate ASCII text files.
The following example shows how to use tables and how to interpolate the data depending on one or two variables using InterpolationLinear
, InterpolationAkima
, InterpolationBilinear
and related built-in functions:
- Geometry: Table.geo
- Problem definition: Table.pro
- 1D and 2D datasets: Table_1D.dat and Table_2D.dat
Structured 3D datasets can be handled in a similar way, using InterpolationTrilinear
. General datasets, based on arbitrary unstructured grids, can also be imported and interpolated by combining GmshRead
in the Resolution
operations with calls to ScalarField
, VectorField
and related functions.
Here is an excerpt from Table.pro
highlighting the important parts:
Function {
// 1D Tables: Value depends only on just one variable -> f(u) = (10 * u)^2
// -----------------------------------------------------------------------
// The list here consists of pairs of u and f. The u values have to be in in
// an ascending order. To make the list better readable the table here is
// written in that way that the values for u are in the first column and the
// values of f are in the second one. All values are separated by commas.
MyListA() = {
0,0,
0.1,1,
0.2,4,
0.3,9,
0.4,16,
0.5,25,
0.6,36,
0.7,49,
0.8,64,
0.9,81,
1,100
};
// Lists can also be loaded from a file. The structure is the same but the
// values are separated by spaces!
MyListB() = ListFromFile["Table_1D.txt"];
// The values for u and f can be in separate lists which then must be combined
// to one list before doing the interpolation.
uList() = { 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1 };
fList() = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 };
MyListC() = ListAlt[uList(), fList()];
// Now let's do the interpolation:
// - Linear interpolation between the table values
f_A[] = InterpolationLinear[$1]{MyListA()};
// - 1st derivative of the linearly interpolated table values
f_B[] = dInterpolationLinear[$1]{MyListB()};
// - Akima interpolation (3rd order spline interpolation, continuously differentiable)
// See also: http://www.iue.tuwien.ac.at/phd/rottinger/node60.html
f_C[] = InterpolationAkima[$1]{MyListC()};
// - 1st derivative of Akima interpolated values
f_D[] = dInterpolationAkima[$1]{MyListC()};
f_Analytic[] = ($1 * 10.0)^2;
// 2D Tables: Value depends on two variables -> g(u, v) = 50 * u + (10 * v)^2
// -----------------------------------------------------------------------
// The 2D table has the following elements (Nu = Number of u values; Nv =
// Number of v values)
// Nu Nv
// u(1) u(2) u(3) ... u(Nu)
// v(1) v(2) v(3) ... v(Nv)
// g(u(1),v(1)) g(u(2),v(1)) g(u(3),v(1)) ... g(u(Nu),v(1))
// g(u(1),v(2)) g(u(2),v(2)) g(u(3),v(2)) ... g(u(Nu),v(2))
// g(u(1),v(3)) g(u(2),v(3)) g(u(3),v(3)) ... g(u(Nu),v(3))
// ...
// g(u(1),v(Nv)) g(u(2),v(Nv)) g(u(3),v(Nv)) ... g(u(Nu),v(Nv))
MyList2D() = ListFromFile["Table_2D.txt"];
g_List[] = InterpolationBilinear[$1,$2]{MyList2D()};
g_Analytic[] = 50.0 * $1 + ($2 * 10.0)^2;
// The function "dInterpolationBilinear" is implemented since version 2.3.1
g_Derivative_List[] = dInterpolationBilinear[$1,$2]{MyList2D()};
g_Derivative_Analytic[] = Vector[ 50.0, $2 * 200.0, 0 ];
}
There is no special format for tabular data imported from separate files:
numbers should simply be separacted by white space (spaces, newlines, tabs are
all accepted). For example Table_1D.dat
contains:
0 0
0.1 1
0.2 4
0.3 9
0.4 16
0.5 25
0.6 36
0.7 49
0.8 64
0.9 81
1 100
and Table_2D.dat
contains:
6 11
0 0.2 0.4 0.6 0.8 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 10 20 30 40 50
1 11 21 31 41 51
4 14 24 34 44 54
9 19 29 39 49 59
16 26 36 46 56 66
25 35 45 55 65 75
36 46 56 66 76 86
49 59 69 79 89 99
64 74 84 94 104 114
81 91 101 111 121 131
100 110 120 130 140 150
Initially written by @AsamMich.