[PREV]
[UP]
[TOP]
[HOME]
C++ functionality in DRAG & FZONE plugins
Getting an absolute value
The example plugins contain the expressions such as:-
or
fabs(t.aveThrow * t.dragRatio);
The C++ library function "fabs" returns the absolute value of a number and is often useful in the DRAG and FZONE plugins, since the trace variable "t.aveThrow" can have either positive or negative values (see
Trace Avarage throw).
Static variables
The
DRAG and
FZONE plugins contain a new term that is not used in the default versions of other plugins. The term is "static", and means that any variable which is declared static retains its value between calls to the plugin. Both the DRAG and FZONE plugin codes will be processed (i.e. called) as many times as there are traces in the parent model.
In both the examples the Boolean flag variable "seedFlag" is initially set to be true. The first time one of the examples is called - by the first trace in the model - "seedFlag" is tested and because it is true the block of code following the "if" line is executed.
static bool seedFlag = true;
if (seedFlag) {
srand(time(NULL));
seedFlag = false;
}
The block of code does two things: it seeds the random number generator (see Inclusion of stochasticity) and sets the value of "seedFlag" to false. The next time the plugin is called - by the next trace in the model - the "if" test does not execute the block of code making sure the generator is not reseeded.
NOTE:- The "seedFlag" variable in the DRAG plugin is completely independent of the variable of the same name in the FZONE plugin, so the random number generator is seeded on the first call of DRAG and then again on the first call of FZONE.
Inclusion of stochasticity
Both example plugins generate stochastic output. The random number is generated using the expression:-
double ranNum = double(rand())/double(RAND_MAX);
ranNum takes a value from a uniform distribution between 0.0 and 1.0, and can then be used, as in the two examples, to generate stochastic trace or fault zone properties.
The random number generator used in the default plugins is seeded using the current time, and will therefore give a different sequence of random numbers each time it is run. The line of code that seeds the random number generator is:-
Note that the "static seedFlag" variable ensures the seeding only takes place once for a particular plugin, no matter how many traces are processed during a ViewGen run.
If, however, a plugin is seeded to a particular value, it will always return the same sequence of random numbers, and therefore (unless the number of traces in the model is changed) will result in the same realisation each time ViewGen is run. This is achieved through the following line:-
where 124576 is an example seed and could be any positive integer.
NOTE:- Stochasticity may also be included in the all other plugins using similar methods.
Arrays
The FZONE plugin uses a hierarchical method with 8 variables required for each level of the hierarchy. In the example, the hierarchy is represented by a two-dimensional array of "double" (i.e. floating-point) constants.
static double params[2][8] = {
{ 4.0, 3.0, 1.0, 1.0, 0.0125, 1.0, 1.0, 0.1 },
{ 1.0, 3.0, 0.33, 1.0, 0.05, 0.25, 0.25, 0.1 }
};
The declaration of the array contains two integers in square brackets. The leftmost number - in this case 2 - denotes the number of levels in the hierarchy. The second number is the number of variables in each level. These two numbers - or dimensions - determine the number of rows and columns respectively of "double" constants that follow the declaration. Each row is enclosed by braces. The two-dimensional array is declared "static" (see
Static variables) and its content is preserved between calls of the plugin.
The main body of the plugin is enclosed within a "for" loop which processes each level of the hierarchy. Array indices in C++ begin at 0, so first time through the loop the integer variable "level" is set to 0 and constants accessed from the "params" array come from the first row of the data. The second time around the loop - or second iteration - "level" is incremented by 1 and the second row of constants from "params" is used and so on until "level" becomes too big and the loop finishes.
Elements within each row (or level) are also indexed from 0. For instance indexing the "params" array shown above gives the following values:-
params[0][0] has value of 4.0
params[1][0] has value of 1.0
params[0][4] has value of 0.0125
params[1][2] has value of 0.33
Implications of the new functionality to the PERM, THICK and AREA plugins
The following properties should be avoided in the connection-based PERM, THICK and AREA plugins if the new functionality is used, since they will not be correctly recognised in the trace minimodels (see
Visualising Traces,
Fault Properties and
Sub-resolution displays in
ViewGen):-
- Absolute X and Y locations (i.e. c.I, c.J for connections, v.I, v.J for connection verticies or up.I, up.J, down.I, down.J for cells).
- User-defined connection properties loaded as input. It is impossible to load user-defined connection properties for minimodels, therefore, in the fault trace minimodels all user-defined connection properties, unless actually calculated in the same plugin as they are referred to in, will revert to the default value (-1.0).
[PREV]
[UP]
[TOP]
[HOME]