All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parameter evaluation caching

Some parameter fields apply to every particle being processed. For example, POPs that apply forces have a mass parameter for setting the mass to use if the attribute doesn't exist. This parameter could be set to a constant value or can be different for every particle if an expression like $ID is used.

For efficiency, when the value is constant, the parameter shouldn't be continually re-evaluated for every particle. Only when the expression is variable dependent should the parameter be re-evaluated.

There are some built-in macros and typedefs that help in achieving this. This section describes how to use them.

First, in the class definition, make sure there is a way to evaluate the parameter using the regular OP methods. For example:

float SCALE (float t) { FLOAT_PARM("scale", 0, 0, t) };
int ID (float t) { INT_PARM("id", 1, 0, t) };
The above code fragment uses hard-coded parameter indices for simplicity. This does not lend itself well to incorporating changes and is not a recommended practice.

Add a cache variable and a method to retrieve that cache value to the class definition. For example: For example,

POP_FPARM(myScale, getScale);
There are different macros for float and integer parameter types.

Use a method pointer variable for parameter evaluation. These variables are generally defined in cookPop().

Before processing the particles, assign the method pointer to point to the appropriate evaluation method.

POP_FCACHE(scale, SCALE, getScale, myScale);
POP_ICACHE(id, ID, getID, myID);

The macro is used as follows: POP_FCACHE(function pointer, regular evaluation method, cache evaluation method, cache value, class name).

The macro will evaluate the parameter once to determine if it is dependent on local variables or not. If it is, it sets the function pointer to use the regular OP evaluation method. If it isn't, it stores the value in the cache variable and sets the function pointer to the method that just returns the cache value.

To evaluate the parameter while iterating through the particles, use the the POP_PEVAL macro.

Make sure that the current time (OP_Context::getTime()) and the current thread (OP_Context::getThread()) are available in the current scope as t and thread, respectively.