How to write messages to the simulation log

How to write messages to the simulation log

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

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;

The terminate function

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.

The ModelicaInternal_print() function

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:

Writing to the simulation log from an external c file

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.

Other useful string functions

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.

0 Comments

Leave a reply

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

*

CONTACT US

Got a question? Just fill in this form and send it to us and we'll get back to you shortly.

Sending

© Copyright 2010-2017 Claytex Services Ltd All Rights Reserved. | Designed by CMA Marketing

Log in with your credentials

Forgot your details?