GPU Expressions

NVidia Runtime Compiler (NVRTC) is a technology used by M-Star CFD to evaluate user expressions directly on a GPU accelerator. This is especially important for spatially dependent expressions that will be evaluated on the entire lattice. NVRTC itself uses C syntax and a simplified set of math functions.

This math equation

\[d = 0.00327 / e_{edr}^{0.4}\]

can be interpreted into C code as:

d = 0.00327 / powf(e, 0.4);

The M-Star CFD GUI will indicate the available input and output variables for a given expression. So for the above example, “d” is the diameter output variable, and “e” is the eddy dissipation rate input variable. This ties the particle diameter to the local fluid properties. Using this simple relation, we can acheive very compelling physical models.

Variables

Tip

Some variable names have changed. Please refer to Migrate UDF to version 3.3.* for more information.

Table 4 Universal Variables

Name

Units

Description

t

s

Current simulation time

dx

m

Local mesh spacing

dt

s

Local timestep

global var name

N/A

Global variables

Table 5 Cell Variables

Name

Units

Description

x, y, z

m

Position of current cell for UDFs that operate on a cell-by-cell basis

P

Pa

Pressure

v, vx, vy, vz

m/s

Fluid velocity

rho

kg/m^3

Fluid density

nu

m^2/s

Fluid viscosity

s

1/s

sxx, syy, szz, sxy, syz, sxz

1/s

ss

Pa

e

W/kg

T

K

age

s

f1, f2

N/A

Fluid volume fraction

isNear_StaticBodyName

boolean

produces a boolean for each static body

CustomVarName with x y z suffix if vector type

N/A

Custom variable

ScalarName

mol/L or fraction

mol/L for scalars, fraction for miscible scalars

kL_ParticleSetName

m/s

ssa_ParticleSetName

1/m

vf_ParticleSetName

fraction

Table 6 Particle Variables

Name

Units

Description

x_p, y_p, z_p

m

Position of current particle for UDFs that operate on a particle-by-particle basis

d_p, area_p, vol_p

m, m^2, m^3

if not superquadric,diameter, surface area, and volume of spherical particles. will add superquadrics info in future

v_p, vx_p, vy_p, vz_p

m/s

Particle velocity

a_p, ax_p, ay_p, az_p

m/s^2

if not tracer particle

w_p, wx_p, wy_p, wz_p

rad/s

if particle rotation is enabled

n_p

N/A

CustomParticleVarName_p

N/A

Custom particle variables

ScalarName_p, ScalarName_amount_p

mol/L or fraction for non-amount. mol or m^3 for amount, Two variables are provided: 1) concentration, and 2) the total amount in the particle.

tsb_p

s

Time since last particle breakup

Math API

The following is a summary of the available math API. For further detail, refer to NVRTC Math API

Table 7 NVRTC Math API

powf(x, y)

Evaluate power of x raised to the y power

acosf ( x )

Calculate the arc cosine of the input argument.

acoshf ( x )

Calculate the nonnegative arc hyperbolic cosine of the input argument.

asinf ( x )

Calculate the arc sine of the input argument.

asinhf ( x )

Calculate the arc hyperbolic sine of the input argument.

atan2f ( y, x )

Calculate the arc tangent of the ratio of first and second input arguments.

atanf ( x )

Calculate the arc tangent of the input argument.

atanhf ( x )

Calculate the arc hyperbolic tangent of the input argument.

cbrtf ( x )

Calculate the cube root of the input argument.

ceilf ( x )

Calculate ceiling of the input argument.

copysignf ( x, y )

Create value with given magnitude, copying sign of second value.

cosf ( x )

Calculate the cosine of the input argument.

coshf ( x )

Calculate the hyperbolic cosine of the input argument.

cospif ( x )

Calculate the cosine of the input argument × π .

cyl_bessel_i0f ( x )

Calculate the value of the regular modified cylindrical Bessel function of order 0 for the input argument.

cyl_bessel_i1f ( x )

Calculate the value of the regular modified cylindrical Bessel function of order 1 for the input argument.

erfcf ( x )

Calculate the complementary error function of the input argument.

erfcinvf ( y )

Calculate the inverse complementary error function of the input argument.

erfcxf ( x )

Calculate the scaled complementary error function of the input argument.

erff ( x )

Calculate the error function of the input argument.

erfinvf ( y )

Calculate the inverse error function of the input argument.

exp10f ( x )

Calculate the base 10 exponential of the input argument.

exp2f ( x )

Calculate the base 2 exponential of the input argument.

expf ( x )

Calculate the base e exponential of the input argument.

expm1f ( x )

Calculate the base e exponential of the input argument, minus 1.

fabsf ( x )

Calculate the absolute value of its argument.

fdimf ( x, y )

Compute the positive difference between x and y.

fdividef ( x, y )

Divide two ing point values.

floorf ( x )

Calculate the largest integer less than or equal to x.

fmaf ( x, y, z )

Compute x × y + z as a single operation.

fmaxf ( x, y )

Determine the maximum numeric value of the arguments.

fminf ( x, y )

Determine the minimum numeric value of the arguments.

fmodf ( x, y )

Calculate the ing-point remainder of x / y.

frexpf ( x, int* nptr )

Extract mantissa and exponent of a ing-point value.

hypotf ( x, y )

Calculate the square root of the sum of squares of two arguments.

nt ilogbf ( x )

Compute the unbiased integer exponent of the argument.

sfinite ( a )

Determine whether argument is finite.

sinf ( a )

Determine whether argument is infinite.

snan ( a )

Determine whether argument is a NaN.

j0f ( x )

Calculate the value of the Bessel function of the first kind of order 0 for the input argument.

j1f ( x )

Calculate the value of the Bessel function of the first kind of order 1 for the input argument.

jnf ( int n, x )

Calculate the value of the Bessel function of the first kind of order n for the input argument.

ldexpf ( x, int exp )

Calculate the value of x ⋅ 2 e x p .

lgammaf ( x )

Calculate the natural logarithm of the absolute value of the gamma function of the input argument.

ong long int llrintf ( x )

Round input to nearest integer value.

ong long int llroundf ( x )

Round to nearest integer value.

log10f ( x )

Calculate the base 10 logarithm of the input argument.

log1pf ( x )

Calculate the value of l o g e ( 1 + x ) .

log2f ( x )

Calculate the base 2 logarithm of the input argument.

logbf ( x )

Calculate the ing point representation of the exponent of the input argument.

logf ( x )

Calculate the natural logarithm of the input argument.

ong int lrintf ( x )

Round input to nearest integer value.

ong int lroundf ( x )

Round to nearest integer value.

modff ( x, * iptr )

Break down the input argument into fractional and integral parts.

nanf ( const char* tagp )

Returns “Not a Number” value.

nearbyintf ( x )

Round the input argument to the nearest integer.

nextafterf ( x, y )

Return next representable single-precision ing-point value afer argument.

norm3df ( a, b, c )

Calculate the square root of the sum of squares of three coordinates of the argument.

norm4df ( a, b, c, d )

Calculate the square root of the sum of squares of four coordinates of the argument.

normcdff ( y )

Calculate the standard normal cumulative distribution function.

normcdfinvf ( y )

Calculate the inverse of the standard normal cumulative distribution function.

normf ( int dim, const * a )

Calculate the square root of the sum of squares of any number of coordinates.

powf ( x, y )

Calculate the value of first argument to the power of second argument.

rcbrtf ( x )

Calculate reciprocal cube root function.

remainderf ( x, y )

Compute single-precision ing-point remainder.

remquof ( x, y, int* quo )

Compute single-precision ing-point remainder and part of quotient.

rhypotf ( x, y )

Calculate one over the square root of the sum of squares of two arguments.

rintf ( x )

Round input to nearest integer value in ing-point.

rnorm3df ( a, b, c )

Calculate one over the square root of the sum of squares of three coordinates of the argument.

rnorm4df ( a, b, c, d )

Calculate one over the square root of the sum of squares of four coordinates of the argument.

rnormf ( int dim, const * a )

Calculate the reciprocal of square root of the sum of squares of any number of coordinates.

roundf ( x )

Round to nearest integer value in ing-point.

rsqrtf ( x )

Calculate the reciprocal of the square root of the input argument.

scalblnf ( x, long int n )

Scale ing-point input by integer power of two.

scalbnf ( x, int n )

Scale ing-point input by integer power of two.

signbit ( a )

Return the sign bit of the input.

sincosf ( x, * sptr, * cptr )

Calculate the sine and cosine of the first input argument.

sincospif ( x, * sptr, * cptr )

Calculate the sine and cosine of the first input argument × π .

sinf ( x )

Calculate the sine of the input argument.

sinhf ( x )

Calculate the hyperbolic sine of the input argument.

sinpif ( x )

Calculate the sine of the input argument × π .

sqrtf ( x )

Calculate the square root of the input argument.

tanf ( x )

Calculate the tangent of the input argument.

tanhf ( x )

Calculate the hyperbolic tangent of the input argument.

tgammaf ( x )

Calculate the gamma function of the input argument.

truncf ( x )

Truncate input argument to the integral part.

y0f ( x )

Calculate the value of the Bessel function of the second kind of order 0 for the input argument.

y1f ( x )

Calculate the value of the Bessel function of the second kind of order 1 for the input argument.

ynf ( int n, x )

Calculate the value of the Bessel function of the second kind of order n for the input argument.