Creating your first mathematical model in EMSO

Hi everyone, in this occasion I am going to talk about some basic concepts involved in the process of building models in EMSO. If you don’t know what I’m talking about, I recommend you to read my previous post (Introducing EMSO – An open-source software for modelling, simulation and optimization).The idea behind the current post is to illustrate the process of building mathematical models in EMSO.

To start building models in EMSO, you need to create a file. So, just click on File>>New File (you can also click on the New File icon available on the standard toolbar). Once you do that, the following window appears:

select-the-file-typein which you have to select the file type you want to create. As you can see in the previous figure, there are 4 possibilities, so let’s describe each one of them:

  • Model. Allows you to create a model, i.e., a mathematical abstraction comprising a set of variables, parameters and equations which altogether permits the user to describe a system (e.g. a phenomenon, equipment, etc.). This kind of file cannot be simulated in EMSO.
  • FlowSheet: In contrast to Model, this allows you to create simulable entities, i.e., to create either simple models or complete process flow diagrams which can be simulated. Both Model and FlowSheet files have the same extension in EMSO, *.mso.
  • Empty. Both Model and FlowSheet are code-based files. Each of them, as we will see, has  a specific structure (the well-known EMSO entity concept), so, if you select whichever of them it will show you a basic template illustrating its use. In case that you don’t want to use any of them, you can select a blank template by choosing Empty.
  • Diagram. Allows you to create block-oriented simulable model by simple drag-and-drop and linking operations. This kind of file is the raison d’être of the Palette tab mentioned in my EMSO previous introductory post. The extension of this file type once saved is *.pfd.

So let’s suppose we want to create a simple model in EMSO for describing the filling in (and filling out) of a cylindrical tank. For the sake of simplicity, suppose that the equations of the model have been deduced previously in the paper but we want to write our model in EMSO. So you have deduced that the model can be represented by the following set of equations:

Mass balance:   A \frac{dh(t)}{dt} = F_{in} - F_{out}

Cross-sectional area:   A = \pi \frac {D^2}{4}

Outlet flow:  F_{out} = k \sqrt{h}


F_{in}, F_{out}: inlet and outlet flowrates, in m^3/s

h: tank level, in m

D: tank diameter, in m

k: constant of the outlet valve, in m^{2.5}/h

When creating a model in EMSO, the first we have to do is to distinguish which of the previous symbols denote variables and which ones, parameters. In this part, EMSO can be a little tricky, so we can use the following rule:

Variables. Use variables for any magnitude that needs to be computed in the model but that only depends on other variables. In this sense, if you have a parameter of the original model which depends on a variable, you should create it in EMSO as it were a variable.

Parameters. In the same sense, use parameters for any magnitude that stays constant along the computations or that depends only on other parameters.

According to this we can differentiate the following variables and parameters:

Variables: F_{in}, F_{out}, h

Parameters: D, k, A

Once done the previous work, let’s start to work in EMSO:

  1. Open EMSO and create a Model, assign it a name (in this case we will use simpleTank.mso). Once done, you will see the following template (click on the image to zoom):modelTemplate
  2. From where, we can establish different facts:
    • Comments are shown in green color, are enclosed between #* and *#, and can include multiple lines.
    • Strings of text are shown in purple between quotes (“).
    • The modelling language keywords are shown in blue.
    • Regular text is shown in black.
    • Almost all lines must be finished with a semicolon (;).
  3. Models in EMSO are constituted by several sections denoted by the blue capitalized words PARAMETERS, VARIABLES, EQUATIONS, and INITIAL. Each end of section is limited by the beginning of the next one, i.e., end-words between sections are not required. The word end is reserved for establishing the end point of the Model entity.
  4. To declare parameters and variables, we must use the syntax \text{NAME as TYPE} (Brief="Text"), where \text{TYPE} refers to a base type in EMSO, which basically denotes a kind of magnitude that has as attributes a maximum value, a minimum value, units, and a default value, just for naming a few. You can find more info in the EMSO_QuickRef.pdf guide available in the EMSO program folder. As you can see in the previous image, in the template appear some base types (length, area, and volume). In case you don’t know what base type to use, you can always use the Real and Integer base types and assign units to them, after the Brief attribute, using the syntax \text{Unit}='UNIT', remeber to separate the attributes by using commas. As we don’t know yet the base types, we can use the Real base type for all the variables and parameters of our model assigning them their respective units.
  5. After erasing all the comments, our model would look like this:simpleTankModel
  6. Notice that EMSO counts with some special funcions to calculate temporal derivatives (\frac{d}{dt}) and the square roots (\sqrt{}). You can find other EMSO Built-In functions in the EMSO_QuickRef. pdf guide.

I hope this post had been helpful for those who wants either to learn or to revisit EMSO. I my next post I would like to talk in-deep about the Model entity we just exemplified in here.

Best regards,



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: