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 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.
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.
variableand
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 variableNote the use of both standard symbols for standard quantities, e.g. P for pressure, and mnemonic names for other quantities.
parameterand
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 endNote 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!
equationand
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
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:
model SomeNameand
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.
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.