April 8th, 2011 by Garron Fish
Outputting data and messages to the simulation log is a useful way for the model to communicate results or operation with the user. There are a number of ways that this can be done.
The assert function can be used to generate an error if a certain condition is not met. This error message is written to the simulation log if the condition becomes false.
function assert "assert that a condition is true" input Boolean _condition; input String _error; The given condition should be true. If it is false an error message will be given end assert;
This function terminates the current model when called.
function terminate "terminate simulation" input String _error; Successfully terminate the simulation and print the given string. end terminate;
This is usually called from inside a when equation.
This function is useful for displaying warnings. For example if a model is outside its calibrated operational area, such as the fluid temperature is higher then you have calibrated the fuild model to, a warning could be generated. This function is also useful for displaying results in the simulation log. This function can also be used to writing to a text file.
This function is in Modelica.Utilities.Stream and the code is below:
The function called ModelicaError() can be used to write to the simulation log from inside an external C function. To use this function you will need to include theModelicaUtilities.h file that is inside the Dymola source directory. During compilation your code is linked to a Dymola lib file that contains this functionality.
To display matrices there is a matrix to string function called Modelica.Math.Matrices.toString. There is also a vector to string function called Modelica.Math.Vector.toString.