Section L2.1: Philosophy of Modelling Languages

Models can in principle be written in any computer language. A large number of special purpose languages have been developed to represent the steady state behaviour of process flowsheets. Rather fewer specialised languages are available for modelling at the level with which most of this course in concerned, and the majority of process models are in practice described using general purpose computer languages.

One of the most widely used general languages historically is Fortran (section L3.1), and many large models, particularly of special purpose process units such as reactors will be found in this language. We have given a number of examples of algorithms in Fortran.

A very large number of models in the last few years have been written to run in spreadsheet systems. The spreadsheet is extremely convenient, as it can be found on every PC and most palmtops. However, spreadsheets have several very serious disadvantages:

As a result of the above, manually generated spreadsheets cannot be regarded as a safe modelling tool! The most important property which a model must have is that it should be UNDERSTANDABLE. This is much more important than that it should be correct!

However, the spreadsheet is so universal and so convenient for running models (as opposed to building them) that we have developed a simple modelling language. which avoids most of the above problems by providing a high level description of the model, but generates a spreadsheet which can be used on any PC.

The main purpose of this language is thus to facilitate the production of documented models. In its simplest version (release 2.1, September 1998 for algebraic equations) it provides no solution facilities not available to the standard spreadsheet system.

The Elements of a Modelling Language

The most important function of a modelling is that it should encourage the production of readable models. All models contain the following elements which must be represented in a modelling language: Additionally it is highly convenient to be able to represent: The definition of the model does not itself have to say anything about how the model is to be solved, although it may be convenient to include instructions about the nature of the solution, i.e. is it a steady state, unsteady state or optimisation problem which is to be solved. In addition it will usually be necessary to provide various `housekeeping' information about what length of time or degree of precision is required, and so forth. This is not strictly speaking part of the model itself.

The model itself should be easy to read and self explanatory. In addition, a modelling system may usefully provide additional and/or summarised information information about the model.

A Simple Modelling Language

Our language contains the three main elements above. The model is written in standard (ascii) characters, using a text editor or notepad tool. (Do not try and write it in Word!) In general each model element should be written on a separate line, but apart from the special words and phrases which introduce different parts of the model, they can usually be written on one line separated by semicolons or commas if this makes the model more readable.

The model can, and should, contain plentiful comments which explain what different parts of it mean. These are preceded by any of the symbols `!', `%' or `#' and are ignored by the modelling system.

The language can be used to model both steady state systems, represented by algebraic equations, and dynamic systems represented by differential-algebraic equations. The discussion below pertains specifically to algebraic equations.

Variables

The user specifies the variables in the model by listing them between two lines which say:
 variable 
and
 end variable 

The ability to give user specified names to variables is a key feature of any modelling language, and the choice of `meaningful' names is an important factor in making a model comprehensible.

For example, a very simple model is to be used to calculate the mass density in kg/m of an ideal gas at a given Kelvin temperature and pressure in atmospheres. We are also given the molecular weight of the gas. We decide that we need variables to represent the specific molar volume and mass and molar densities. Although the pressure is given, and is not an unknown or variable (it is a parameter, see below) the Gas Law requires pressure in pascals which the model will require to calculate, so we require a variable for this pressure, giving 4 variables in all. The model instructions are then:

variable
 vmolar   ! specific molar volume
 romolar, romass ! densities
 P        ! N/m2 required for gas law
end variable
Note the use of both standard symbols for standard quantities, e.g. P for pressure, and mnemonic names for other quantities.

Parameters

Parameter is a term used by modellers to mean a `variable constant', that is a quantity which is known, but which the modeller may wish to change. Here the specified temperature, pressure and gas molecular weight are parameters. They are introduced into the model in a similar way to the variables, i.e. between two lines:
 parameter 
and
 end parameter 

However parameters must be given values, which is done as in the example below.

parameter
 MW = 16 ! methane, kg/kmol
 T = 273 ! K temperature
 Patm = 1.0 ! atmospheres, sensible units
 R = 8.314  ! gas constant in SI units: gmol, Pa etc
end
Note the appearance of R, the gas constant in this section. strictly, R is a true constant, having a fixed value, but most modelling languages do not distinguish these from parameters.

The modelling languages requires initial values for parameters, but these can be changed once the model has been generated. Do not however change the values of constants like R!

Equations

Equations are written in normal `computer algebra' notation between the lines:
 equation 
and
 end equation 

The simplest version of the model generator requires that all equations be written as formulas, and that every unknown (variable) appears once and only once on the LHS of a formula. This approach is discussed in the general introduction to algebraic equations (section 3.1). The equations do not have to be ordered as described in section 3.2, as this is done by the spreadsheet system. The equations section for this model is as follows:

equation
 vmolar = R*T/P           ! m3/gmol
 romolar = 1/ vmolar      ! gmol/m3
 romass = romolar*MW/1000 ! kg.m3
 P = Patm * 101300
end equation

Housekeeping

The only additional information required for this model is to tell the solver that it is a purely algebraic or steady state model. This is done by putting the word steadystate in the model.

The order of the sections is currently fixed and is slightly different from that in we have introduced them. The more logical, and required, order is:

  1. Parameters
  2. Variables
  3. Equations
  4. Housekeeping and solver information
The whole model is enclosed by the keywords
 model SomeName 
and
 end model 
`SomeName' is a name which you can give the model.

Note that all names used in the model must be a combination of letters and number only , and must start with a letter. Upper and lower case letters are treated as being the same.

Complete Model

Here is the complete model:

model idealgas

! ideal gas density calculation

parameter
 MW = 16 ! methane, kg/kmol
 T = 273 ! K temperature
 Patm = 1.0 ! atmospheres, sensible units
 R = 8.314  ! gas constant in SI units: gmol, Pa etc
end

variable
 vmolar   ! specific molar volume
 romolar, romass ! densities
 P        ! N/m2 required for gas law
end

equation
 vmolar = R*T/P           ! m3/gmol
 romolar = 1/ vmolar      ! gmol/m3
 romass = romolar*MW/1000 ! kg.m3
 P = Patm * 101300
end equation

steadystate

end model
 

You can copy it from here, and generate a spreadsheet to run it here.

An Excel-compatible spreadsheet translation may be copied from here and when loaded should look like this.

Modelling Dynamic Systems with Differential Algebraic Equations

The use of the language to model DAE systems is described in section L2.3

Return to Modelling Lab

Course Organiser
Last Modified 2/9/00