One of the most widely used general languages historically is Fortran, 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, and there is a free version of a fortran compiler from Lahey which you can download to run on you own PC.
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 disadvantags:
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!
The risks of using spreadsheets are now well well documented, see work by Raymond Panko in the USA and Paine in the UK.
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.
The model can, and should, contain plentiful comments which explain what different parts of it mean. These are preceded by the symbols `!' and are ignored by the system.
real :: vmolar, romolar, romass, P
There are various things that can be done to improve readability by putting comments in the program, e.g.:
real :: vmolar ! specific molar volume real :: romolar, romass ! densities real :: P ! N/m2 required for gas lawComments cannot be `embedded' in Fortran instructions, but lines can be broken up using th `&' symbol which means `continued on next line, ignore anything else on this one'. (This is also used to when it is necessary to write instruction which do not fit on a single line.) 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.
This example is a very simple model 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 declaration instructions can also be written:
real :: & vmolar, & ! specific molar volume romolar, romass, & ! densities P ! N/m2 required for gas law
Note the use of both standard symbols for standard quantities, e.g. P for pressure, and mnemonic names for other quantities.
real, parameter :: MW = 16.0 ! methane, kg/kmol real, parameter :: T = 273.0 ! K temperature real, parameter :: Patm = 1.0 ! atmospheres, sensible units real, parameter :: R = 8.314 ! gas constant in SI units: gmol, Pa etc
Note the appearance of R, the gas constant in this section. strictly, R is a true constant, having a fixed value, but most modelling langauges 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!
! Start equations P = Patm * 101300.0 ! pressure required in SI vmolar = R*T/P ! m3/gmol romolar = 1/ vmolar ! gmol/m3 romass = romolar*MW/1000 ! kg.m3 ! end of equations
For this example the printout instructions could be:
print *, 'Parameters:' print *, 'MW ', MW print *, 'T, K ', T print *, 'Pressure, atm ', Patm print *, 'Variables:' print *, 'Molar density, mol/m3 ', romolar print *, 'Mass density, kg/m3 ', romass
The order of the sections is thus logical, and required to be:
program SomeNameand
end program`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.
program idealgas ! ideal gas density calculation real :: & vmolar, & ! specific molar volume romolar, romass, & ! densities P ! N/m2 required for gas law real, parameter :: MW = 16.0 ! methane, kg/kmol real, parameter :: T = 273.0 ! K temperature real, parameter :: Patm = 1.0 ! atmospheres, sensible units real, parameter :: R = 8.314 ! gas constant in SI units: gmol, Pa etc print *, 'Program to calculate gas densities' ! Start equations P = Patm * 101300.0 ! pressure required in SI vmolar = R*T/P ! m3/gmol romolar = 1/ vmolar ! gmol/m3 romass = romolar*MW/1000 ! kg.m3 ! end of equations ! output.. print *, 'Parameters:' print *, 'MW ', MW print *, 'T, K ', T print *, 'Pressure, atm ', Patm print *, 'Variables:' print *, 'Molar density, mol/m3 ', romolar print *, 'Mass density, kg/m3 ', romass end program
You can copy it from here.