wiki:Tables

Version 1 (modified by Jonathan, 11 years ago) ( diff )

BackLinksMenu()

Tables

Tables are used by a variety of other routines - cooling functions, opacity functions, etc… A table has a dimension dim, a size in each dimension npoints, lower and upper bounds and a cell spacing along each dimension xmin,xmax,dx, a data array data, and boundary types bc that specify what values to return when the lookup is outside the table bounds.

   TYPE TableDef
      INTEGER :: nPoints(3)=1
      REAL(KIND=qPREC) :: xmin(3), xmax(3), dx(3)
      REAL(KIND=qPREC), POINTER, DIMENSION(:,:,:) :: data
      INTEGER :: bc(3,2) = EXTEND_TABLE
      INTEGER :: dim=1
      LOGICAL :: Initialized=.false.
   END type TableDef

Currently there are three types of boundary conditions

EXTEND_TABLE=0
EXTRAPOLATE_TABLE=1
ZERO_TABLE=2

Extend table just uses the closest value in the table. Extrapolate table extrapolates values outside of the table. And Zero_table just returns '0' for outside the table.

The table object is agnostic to whether the data is arranged in log format or linear format. Conversions should occur outside of calls to the table lookup.

In this example, the table stores the log value of opacity on a grid of log T x log rho in cgs

 USE Tables
 TYPE(TableDef)  :: Planck_table
 CALL ReadTable("Planck.dat",Planck_Table, iErr)
 T=Temperature(q)
 rho=q(1)*rScale
 TableValue=10**(GetTableValue(Planck_Table,(/log10(T),log10(rho)/)))*rho*lScale

The linear multi-dimensional interpolation is done in steps. For 3D interpolation, 4 points are interpolated along the z direction, then 2 points are interpolated along y, and then 1 point is interpolated along x to give the value to return.

Tables are stored in data files with the following format

<dim>
<xmin(1)> <xmax(1)> <dx(1)> <bc(1,1)> <bc(1,2)>
<xmin(2)> <xmax(2)> <dx(2)> <bc(2,1)> <bc(2,2)> !if dim >= 2
<xmin(3)> <xmax(3)> <dx(3)> <bc(3,1)> <bc(3,2)> !if dim >= 3
111 112 113 114 115 116 117 ...
121 122 123 124 125 126 127...
...
...
211 212 213 214 215 216 217 ...
221 222 223 224 225 226 227 ...


So a 1D table would look something like

1
0 4 .2 0 0
2.534  ! and then 21 
2.76    ! lines of data
3.86    ! for values at 0, .2, .4, .6, ... 4
...
...

a 2D table would look something like

2
0 4 .2 0 0
2 10 .5 0 0
2.534  ! and then 21x17=357 
2.76    ! lines of data
3.86    
...
...

and a 3D table would look something like

3
0 4 .2 0 0
2 10 .5 0 0
6 9 1.0 0 0
2.534 2.535 2.536 2.537   ! and then 21x17=357 
2.76  2.767 2.768 2.769   ! lines of data where each line is 4 elements long
3.86  3.87  3.88  3.89    ! corresponding to z=6, 7, 8, and 9
...
...
Note: See TracWiki for help on using the wiki.