Documentation for OpenFLUID
2.2.0
|
OpenFLUID provides tools to use stochasticity inside your wares. To do so, a parameter with the key seed must be specified inside a ware tags in the model.fluidx file:
A seed is a value used to initialise a random number generator. It is used to produce a pseudo-random sequence of numbers, which will always be identical if the same seed is used again. It allows the reproduction of random results in simulations, for example. If a negative value is specified for this parameter, it will use a random seed value. If it is a positive value, it will use this value as the seed. In both cases, you can track the seed value in the simulation output logs.
Once the parameter seed has been added, go to your ware source code and add the include line: #include <openfluid/ware/WareRNG.hpp>
Create a class variable of type openfluid::ware::WareRNG RNG
. This variable will handle the randomness and provide few utility functions. To construct this variable, call its constructor by passing as argument the ware object
In order to use the seed value provided in the model.fluidx, we need to initialize the variable in the initParams(const openfluid::ware::WareParams_t& Params)
function by adding the line : Rng.init(Params);
Utility functions can now be used in order to generate random numbers.
The example below shows the use of stochasticity in ware.
To see all available utility functions, check openfluid::tools::RandomNumberGenerator class.