HTML automatically generated with rman
Table of Contents

Name

bodiesfunc expression - used in generating bodiesfunc(1falcON) functions: functions taking a set of bodies, time and a set of parameters and returning bool, int, real, or vector.

Description

bodiesfunc expression are valid C (in fact C++) expressions that evaluate to either a bool, an integer, a real, or a vector. On construction of a bodiesfunc, 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 bodiesfunc(1falcON) .

List of valid subexpressions

The bodiesfunc expression may contain the following subexpressions


Name     Type      Description

 constants and global properties
Pi    r    3.14159265358979323846264338328
N    i    N, the total number of bodies
M    r    M, the total mass
t    r    t, the time of the snapshot
 operators
Sum{expr@cond}    i,r,v    sum of expr over bodies satisfying cond
Mean{expr@cond}    i,r,v    mean of expr over bodies satisfying cond
Mmean{expr@cond}    i,r,v    mass-weighted mean of expr over bodies satisfying cond
Max{expr@cond}    i,r,v    max of expr over bodies satisfying cond
Min{expr@cond}    i,r,v    min of expr over bodies satisfying cond
And{expr@cond}    b    AND of expr over bodies satisfying cond
Or {expr@cond}    b    OR  of expr over bodies satisfying cond
Num{cond}    i        Number of bodies satisfying cond

Note that Mean{X} is equivalent to (but more efficient than) Sum{X}/N. Similarly, Mmean{X} is equivalent to Sum{m*X}/M.

Operations and functions

The subexpression arguments cond and expr to the operators can be bodiesfunc expressions mixed with bodyfunc(5falcON) expressions. cond is defined as the part after the separator ’@’ and constitutes a condition for a body to be considered. If the argument of the operator contains no ’@’, the condition is omitted (all bodies are considered). The condition is converted to bool: non boolean conditions are considered true if non-zero.

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        

ExamplesThe following lists some example bodiesfunc expressions:     M and
Sum{m}
 
both evaluate the total mass of all bodies;     Min{eps} and Min{eps@r>#0}
 
evaluate the mininum softening length of, respectively, all bodies and
of all bodies with radius larger than parameter 0;     Sum{m@E<0} and 0.5*Sum{m*norm(vel)@E<0}
 
evaluate, respectively, the mass and the kinetic energy of all bound bodies;
    Num{r<Min{eps}} and Sum{1@r<Min{eps}}
 
both evaluate the number of bodies with radius less than the minimum softening
length (this demonstrates the usage of another bodiesfunc expression inside
a bodiesfunc operator);     Sum{l*m}/M, Mean{l*m}/Mean{m} and Mmean{l}
 
are three ways to evaluate the mass-weighted mean of specific angular momentum.
 See Alsobodiesfunc(1falcON), bodyfunc(1falcON), snapprop(1falcON) AuthorWalter
Dehnen Update History
21-jul-2004 Created    WD
20-aug-2004 nested expressions added    WD
07-nov-2004 parameters added, changed cond#expr to expr@cond    WD
12-jul-2006 Updated    WD


Table of Contents