HOWTO make verbosity level accessible for users
LIBPF’s 4 diagnostic levels allow the model developer to fine-tune the verbosity at a global, compilation, unit, function and class instance level. Of these, two (verbosityGlobal and verbosityInstance) are also available at run-time, but normally not for the model user.
If you want to make them accessible to the user, there are several options. Here I’ll show you how to do it using a couple of real-valued Quantities that can be directly manipulated in the user interface or via the LIBPF™ Model User API.
NOTE: we use Quantities rather than Integers because currently there is no way for the user to change integers at runtime; the user will have to enter an integer value such as 1, 2 or 100 for really high verbosity.
Se here we go:
-
declare two custom variables in your model class:
Quantity global; ///< global verbosity Quantity instance; ///< instance verbosity
-
initialize them in the model class constructor initializer list:
DEFINE(global, "global verbosity", 0.0, ""), DEFINE(instance, "instance verbosity", 0.0, ""),
-
register them in the model class constructor body:
addVariable(global); addVariable(instance);
-
make them user-modifiable in the setup method of the model class:
<pre id="cc_holder" class="cpp hljs">global.setInput(); instance.setInput();
-
use them at model calculation to increase /decrease the verbosityGlobal and verbosityInstance variables, by implementing the FlowSheet::pre and FlowSheet::post overrides of your model class:
void MyModel::pre(SolutionMode solutionMode, int level) { verbosityGlobal += global.toDouble(); verbosityInstance += instance.toDouble(); } void MyModel::post(SolutionMode solutionMode, int level) { verbosityGlobal -= global.toDouble(); verbosityInstance -= instance.toDouble(); }