Logs, Warnings, Errors

Log messages from simulation functions

Simulation functions can log messages to both console display and files using the OpenFLUID_Logger feature:

The messages logged to files are put in a file named with the ID of the simulation function suffixed by .log, placed in the simulation output directory.

The OpenFLUID_Logger facility is the recommended way to log messages. Please avoid using std::cout or similar C++ facilities.

Example:

 bool runStep(const openfluid::base::SimulationStatus* /*SimStatus*/)
{
  openfluid::core::Unit* TU;
  DECLARE_UNITS_ORDERED_LOOP(1);


  OPENFLUID_Logger.get() << "This is a message to both file and console" << std::endl;
  OPENFLUID_Logger.getFile() << "This is a message to file only" << std::endl;
  OPENFLUID_Logger.getStdout() << "This is a message to console only" << std::endl;


  BEGIN_UNITS_ORDERED_LOOP(1,"TestUnits",TU)
    OPENFLUID_Logger.get() << "TestUnits " << TU->getID() << std::endl;
  END_LOOP

  return true;
}

Raise warnings and errors

In order to trace error and warnings during the run of a simulation, simulation functions can raise error and warning messages to inform the framework that something wrong or critical had happened. An error stops the simulation the next time the OpenFLUID framework take the control, a warning does not stop the simulation. Error and warnings are reported in the simulation report (siminfo.out file). They both can be dated with the number of the time step when the warning or error occurs.

To raise a warning you can use OPENFLUID_RaiseWarning, to raise an error you can use OPENFLUID_RaiseError.

As already mentioned, an error stops the simulation the next time the framework takes control of the simulation.

Example:

bool Myfunction::checkConsistency()
{
  double TmpValue;
  openfluid::core::Unit* SU;
  DECLARE_SU_ORDERED_LOOP(1);
  
  BEGIN_SU_ORDERED_LOOP(1,"SU",SU)

    OPENFLUID_GetInputData(SU,"MyVar",TmpValue);
    
    if (TmpValue <= 0)
    {
      OPENFLUID_RaiseError("my.function","Wrong value for the MyProp distributed property on SU");
      return false;
    }    

  END_LOOP

  return true;
}

Generated using Doxygen 1.7.3
Creative Commons License Creative Commons By-NC-ND license