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:

  1. declare two custom variables in your model class:
    Quantity global; ///< global verbosity
    Quantity instance; ///< instance verbosity
  2. initialize them in the model class constructor initializer list:
    DEFINE(global, "global verbosity", 0.0, ""),
    DEFINE(instance, "instance verbosity", 0.0, ""),
  3. register them in the model class constructor body:
    addVariable(global);
    addVariable(instance);
  4. make them user-modifiable in the setup method of the model class:
    global.setInput();
    instance.setInput();
  5. 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();
    }
avatar

About paolog

homo technologicus cynicus
This entry was posted in C++, Chemeng, Howtos and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *