Function tabulation

We often have the need for tabulated functions in the code. Especially for the collision algorithms. Collision cross-sections can be defined in an extremely broad range, where it can be highly nonlinear in a very small part of the range. To solve that problem we have used nonlinear tabulation. Basic idea is to define manually ranges for tabulation so that certain parts of the function’s domain can have a controllable resolution.

struct FuncTable

Tabulated function, linear and nonlinear tabulation is available.

Public Functions

int loadData(const std::string &fileName)

Loads data from the defined file name and based on the object type.

Returns

int Zero on success

Public Members

int type

Type 0:linear, 1:nonlinear.

int colCnt

Row count Column count (index increase by 1, is column increase)

int rowCnt

Row count.

std::vector<double> ranges

Vector of ranges.

std::vector<int> nbins

Vector of number of points per range.

std::vector<double> idx

Vector of 1/dx per range.

std::vector<double> xVec

X values.

std::vector<double> yVec

Y values.

std::function<double(double)> eval

Function to run the evaluation based on type.

For every collision cross-section, we use a single FuncTable object parfis::GasCollision::xSecFtab. We calculate the collision frequencies for every cross-section in another FuncTable object parfis::GasCollision::freqFtab. In the end, we combine all of the collisional frequencies in a single FuncTable object with multiple rows and columns parfis::SimData::gasCollisionProbVec.

For the example given in the demo notebook Generating simple cross sections, we have set the following ranges and bins for one specie with two collisional cross cross-sections:

ranges = [   1,   10,  100, 1000, 10000, 114000]
nbins =  [1000, 1000, 1000, 1000,  1000,   1000]

The resulting generated FuncTable objects have the following members defining the data format:

xSecFtab.type = 1
xSecFtab.colCnt = 6000
xSecFtab.rowCnt = 1

freqFtab.type = 1
freqFtab.colCnt = 6000
freqFtab.rowCnt = 1

gasCollisionProbVec[0].type = 1
gasCollisionProbVec[0].colCnt = 2
gasCollisionProbVec[0].rowCnt = 6000

We can see that the unrolling of the matrix format in the probability vector is different than the cross-section and collision frequency FuncTable. This vector format is more convenient for us. Once we have found the particle value on the x-axis (squared speed) we can easily go through all of the collision probabilities because they are located in successive memory addresses.

Wrapper for the python module

The function tabulation has a wrapper for Python which on the python side is given as:

struct PyFuncTable

Wrapper for the FuncTable structure to be used by ctypes in python.

Public Functions

inline PyFuncTable &operator=(const FuncTable &ftab)

Overload of the equal operator for easier manipulation.

Public Members

int type

Type 0:linear, 1:nonlinear.

int colCnt

Column count (index increase by 1, is column increase)

int rowCnt

Row count.

PyVec<double> ranges

Vector of ranges.

PyVec<int> nbins

Vector of number of points per range.

PyVec<double> idx

Vector of 1/dx per range.

PyVec<double> xVec

X values.

PyVec<double> yVec

Y values.