low-level API

Grid generation

cem_gridtools.gridgen(x, y, beta, ni, nj, ulidx=0)

This is the low-level interface function to the gridgen-c library.

For general use, see cem_gridtools.cem_gridtools.CGrid.gen_grid()

Parameters
  • x (array) – x boundary points

  • y (array) – y boundary values

  • b (array) – beta values (corner status)

  • ni (int) – Number of required grid points in the i-direction

  • nj (int) – Number of required grid points in the j-direction

  • ulidx (int) – The idx of the upper left corner of the grid

Returns

(gx,gy) output 2d arrays

Return type

tuple

import numpy
from cem_gridtools.gridgen import gridgen
# Note that the ordering is important to make a 'simple' shape
x = numpy.array([0, 1, 1, 0], dtype='d')
y = numpy.array([0, 0, 1, 1], dtype='d')
beta = numpy.ones(x.shape, dtype='d')
(gx,gy) = gridgen(x,y,beta,3,2,0)

Interpolation

cem_gridtools.grid_interp.init(x, y, z, rule)

Initialises the interpolation routine with the given source data

Parameters
  • x (array) – x values of input data

  • y (array) – y values of input data

  • z (array) – input data values

  • rule (str) – interpolation type (“nn_sibson, nn_non_sibson”)

Returns

handle of interpolant

Return type

void pointer

cem_gridtools.grid_interp.on_point(h, x, y)

Perform the interpolation on the given point

Parameters
  • h – handle from output of the init function

  • x (float) – target x value

  • y (float) – target y value

Returns

interpolated value

Return type

float

import numpy
from cem_gridtools.grid_interp import init,on_point
x = numpy.array([0, 1,   0.4], dtype='d')
y = numpy.array([0, 0.2, 0.8], dtype='d')
z = numpy.array([1, 2, 3], dtype='d')
H = init(x,y,z,"nn_sibson")
# Now interpolate on any point
v = on_point(H, 0.5, 0.2)