PLUTO  4.4-patch2
Macros | Functions
input_data.c File Reference

Provide basic functionality for reading input data files. More...

#include "pluto.h"

Macros

#define ID_NZ_MAX   4
 

Functions

int InputDataOpen (char *data_fname, char *grid_fname, char *endianity, long int offset, int vpos)
 
void InputDataClose (int indx)
 
void InputDataGridSize (int indx, int *size)
 
double InputDataInterpolate (int indx, double x1, double x2, double x3)
 
void InputDataReadSlice (int indx, int kslice)
 

Detailed Description

Collects a number of functions for opening, reading and interpolating initial conditions from user-supplied binary data file(s). The geometry and dimensions of the input grid can be different from the actual grid employed by PLUTO, as long as the coordinate geometry transformation has been implemented. The input grid and data files should employ the same format and conventions employed by PLUTO. Specifically:

InputDataOpen() initializes the inputData structure for a given input field (e.g. density) iby reading grid size and coordinates, geometry, precision, endianity, etc..

InputDataInterpolate() is used to interpolate the given field from the input coordinates to the desired coordinate location using bi- or tri-linear interpolation to fill the data array.

The input data is stored in a buffer by reading ID_NZ_MAX planes at a time to save computational memory. The value of ID_NZ_MAX can be changed from your personal definitions.h. This task is performed in the InputDataReadSlice() function.

Authors
A. Mignone (migno.nosp@m.ne@t.nosp@m.o.inf.nosp@m.n.it)
Date
Nov 10, 2020

Macro Definition Documentation

◆ ID_NZ_MAX

#define ID_NZ_MAX   4

Maximum size (in the 3rd dimension) of the input buffer.

Function Documentation

◆ InputDataClose()

void InputDataClose ( int  indx)

Free memory and reset structure.

◆ InputDataGridSize()

void InputDataGridSize ( int  indx,
int *  size 
)

Return the size of the input data array, from the grid file.

Parameters
[in]indxinput data array element (handle)
[in]sizean array of integer containing the array size [nx1,nx2,nx3]

◆ InputDataInterpolate()

double InputDataInterpolate ( int  indx,
double  x1,
double  x2,
double  x3 
)

Perform bi- or tri-linear interpolation on external dataset to compute vs[] at the given point {x1,x2,x3}.

Parameters
[in]indxinput data array element (handle)
[in]x1coordinate point at which at interpolates are desired
[in]x2coordinate point at which at interpolates are desired
[in]x3coordinate point at which at interpolates are desired
Returns
The interpolated value.

The function performs the following tasks.

  • Convert PLUTO coordinates to input grid geometry if necessary.
  • Make sure point (x1,x2,x3) does not fall outside input grid range. Limit to input grid edge otherwise.
  • Use table lookup by binary search to find the indices il, jl and kl such that grid points of PLUTO fall between [il, il+1], [jl, jl+1], [kl, kl+1].
  • Define normalized coordinates between [0,1]:
    • x[il+1] < x1[i] < x[il+1] ==> 0 < xx < 1
    • y[jl+1] < x2[j] < y[jl+1] ==> 0 < yy < 1
    • z[kl+1] < x3[k] < z[kl+1] ==> 0 < zz < 1
  • Read data from disk (1 or 2 planes)
  • Perform bi- or tri-linear interpolation.

◆ InputDataOpen()

int InputDataOpen ( char *  data_fname,
char *  grid_fname,
char *  endianity,
long int  offset,
int  vpos 
)

Initialize access to input data file by assigning values to grid-related information (geometry, number of points, etc...). This function should be called just once for input-data initialization.

Parameters
[in]data_fnamethe name of the input binary data file
[in]grid_fnamethe name of the corresponding grid file
[in]endianityan input string ("little" or "big") giving the byte-order of how the input data file was originally written. If an empty string is supplied, no change is made.
[in]offsetan integer specifying the offset of the variable (in units of double or float) in the file.
[in]vposthe variable position with respect to the cell center (CENTER / X1FACE / X2FACE / X3FACE).
Returns
The index of the id_stack[] array

0. Find the 1st available (NULL pointer) element in the stack

  1. Scan grid data file and try to determine the grid geometry (id->geom). Search for tag "GEOMETRY:" and read the word that follows.
  2. Move file pointer to the first line of grid.out that does not begin with a "\c #".
  3. Read number of points, allocate grid arrays and store input grid coordinates into structure members id->nx1, id->x1, etc... In the case of a staggered direction [i] refers to the left interface and we increment by 1 the number of points.
  4. Check if binary data file exists and allocate memory buffer id->Vin
  5. Set endianity (id->swap_endian)
  6. Set data size (id->dsize) by looking at the file extension (dbl or flt).
  7. Compute offset (id->offset in bytes) and initialize id->klast (last read plane) to -1

◆ InputDataReadSlice()

void InputDataReadSlice ( int  indx,
int  kslice 
)

Read ID_NZ_MAX slices from disk starting at the kslice vertical index.

Parameters
[in]indxthe structure index (file handle)
[in]kslicethe starting slice