Table of Contents


bodyfunc expression - used in generating bodyfunc(1falcON) functions: functions taking body, time and a set of up to 10 parameters and returning bool, int, real, or vector.


bodyfunc expressions are valid C (in fact C++) expressions that evaluate to either a bool, an integer, a real, or a vector. On construction of a bodyfunc, the C++ compiler is employed to to generate on the fly (as the user runs the program) the function together with type information and information on which body data are required, see bodyfunc(1falcON) .

List of body properties

The bodyfunc expression may contain the following sub-expressions for body properties.

Name      Type      Description

 constants and global properties
Pi    real    returns 3.14159265358979323846264338328
N    int    returns N, the total number of bodies
M    real    returns M, the total mass
t    real    returns t, the time of the snapshot
#d    real    parameter number d
 basic body properties
i    int    returns the index, between 0 and N-1
m    real    returns the mass
pos    vector    returns the position vector
vel    vector    returns the velocity vector
acc    vector    returns the acceleration vector
aux    real    returns an auxiliary real
pot    real    returns the potential
phi    real    returns the potential
eps    real    returns the individual softening length
key    int    returns the key, an auxiliary integer
 basic SPH body properties (only with falcON SPH)
h    real    returns the smoothing length, 
n    real    returns the number of gas neighbours
U    real    returns the internal energy
Ui    real    returns the (dU/dt)_internal
Ue    real    returns the (dU/dt)_external
U    real    returns the internal energy
S    real    returns the entropy function
rho    real    returns the gas density
f    real    returns the factor f_i
s    real    returns the sound speed
 components of basic body properties
x    real    returns x, the x-component of pos
y    real    returns y, the y-component of pos
z    real    returns z, the z-component of pos
vx    real    returns vx, the x-component of vel
vy    real    returns vy, the y-component of vel
vz    real    returns vz, the z-component of vel
ax    real    returns ax, the x-component of acc
ay    real    returns ay, the y-component of acc
az    real    returns az, the z-component of acc
 compounds from basic body properties
r    real    returns abs(pos), the radius
R    real    returns sqrt(x*x+y*y), the cylindrical radius
v    real    returns abs(vel), the total velocity
a    real    returns abs(acc), the total acceleration
vr    real    returns vr, the radial component of vel
vt    real    returns vt, the absolute value of tangential velocity
vphi    real    returns vphi, the azimuthal component of vel
l    vector    returns l=x^v, the specific angular momentum
lx    real    returns Lx, the x-component of l
ly    real    returns Ly, the y-component of l
lz    real    returns Lz, the z-component of l
ltot    real    returns abs(l), the total specific angular momentum
jtot    real    the same as ltot, for NEMO compatibility
L    vector    returns L=l*m, the angular momentum vector
Lx    real    returns Lx, the x-component of L
Ly    real    returns Ly, the y-component of L
Lz    real    returns Lz, the z-component of L
Ltot    real    returns abs(L), the total angular momentum
E    real    returns phi+vel*vel/2, the total energy
etot    real    the same as E, for NEMO compatibility

Operations and functions

In addition, the expression may use any standard mathematical expressions, including math functions. For vectors, all operations defined for tupel<3,real>, see tupel(5falcON) , are allowed. The following lists some of these and additional functions supported.

Name    Type    Description
vector*vector    real        returns the scalar product
vector^vector    vector        returns the vector cross product
vector(x)    vector        converts scalar to vector
real(x)    real        converts integer to real
norm(x)                returns x*x for any type
abs(vector)    real        returns sqrt(norm(vector))
abs(real)    real        returns |real|
max(x,y)    scalar        returns the greater of two scalars
max(vector)    real        returns the greatest vector element        
min(x,y)    scalar        returns the smaller of two scalars
min(vector)    real        returns the smallest vector element        

Compatibilitybodyfunc expressions are backward compatible with bodytrans(5NEMO)
expressions, i.e. any valid bodytrans expression may be used. Note, however
that bodyfunc allows more functionality, for example vector expressions.
 ExamplesThe following lists some example bodyfunc expressions 
expression    Type    Description
r<2    bool    true if the radius is less than 2
norm(pos)<#0    bool    same as before, but more efficient, since (1) no sqrt()
needed and (2) the limit is parametrized
E<0? L:vector(zero)    vector    bound bodies: angular momentum, unbound: 0

See Alsobodyfunc(1falcON), bodytrans(5NEMO) AuthorWalter Dehnen Update
21-jul-2004 Created    WD
07-nov-2004 parameters added, changed cond#expr to expr@cond    WD
12-jul-2006 Updated    WD

Table of Contents