presented at Second Electronic Computational Chemistry Conference, November 1995.
Laboratory of Chemical Thermodynamics
Moscow State University
In the first paper , the principles of employing object-oriented programming in sophisticated thermodynamic applications have been discussed. In the present paper, the fist thermodynamic class which allows the user to handle thermodynamic calculations with individual substances is presented.
Object-oriented programming  enjoys widespread use nowadays. Many people agree that well-done subject classes ease programming of the end applications significantly. The most classes designed so far are due to the programming needs themselves, e.g. for a fancy graphic user interface, although some useful mathematical classes, e.g. for matrix manipulation, have also been developed .
I have tried to apply object-oriented programming to the thermodynamics needs, and the paper presents the results obtained. C++  has been used, just because I enjoy it, but the ideas can be implemented in any object-oriented language.
The main idea besides mere employing object-oriented programming was to separate thermodynamic empirical data and the code as far as possible. To this end, some standard for representing thermodynamic functions has been created. The standard does not limit the user what functional dependencies should be used to describe the thermodynamic functions. Opposite, it allows the end user to work with any compound analytical function in temperature and pressure. The standard prescribes formal syntax rules for writing the functions in a datafile in such a manner that even being formal in nature to allow the computer code to work, this makes data files look intelligent and to be rather independent from the code.
Some more general words can be found in the previous paper .
A necessary condition for equilibrium calculations to be done is to put
into an equilibrium algorithm the values of molar Gibbs energies of
G_m(T, p) at given temperature and
pressure or the molar Gibbs energy of a reaction (
eq 1). It
should be mentioned that the molar Gibbs energy of an individual substance is
equal to its chemical potential (
eq 2) and that the other
thermodynamic properties of the substance can be found as appropriate
derivatives of the Gibbs energy. Examples are given by
eqs 3 to
Many algorithms require Gibbs energies at standard pressure only (
6) but this means nothing but that they use the simplest models to
estimate Gibbs energy at another pressure like the ideal gas (
7) or zero molar volume for liquid and crystals (
The problem that complicates the programming issues of what looks like quite a simple question is that there is a lot of ways in the thermodynamics literature to represent the Gibbs energy.
First, one can not estimate the absolute value of the Gibbs energy - he/she can only have a difference between two some states. In practical work, some reference state is chosen and all the Gibbs energies are counted from that state. There are several such reference states employed in chemical thermodynamics.
eq 9. Some people use another rule in the form of
eqs 11 and 12where F' and F are free energy functions (
eqs 13 and 14)
Second, there are different ways for representing temperature behavior of
the Gibbs energy. All of them are based on series in temperature, the most
encountered formula being
eq 15. Still, in different groups, the
number of members and the powers of the temperature used are quite different.
For example, in recent compilation of the Gibbs energies of the elements 
besides terms in eq (13) you can also find terms like in
Third, there are almost no standards in representing pressure dependence of the Gibbs energy. As mentioned above, most programs use just the simplest models like eqs (7) and (8). And, it is impossible to say a priori what functions will be necessary in real applications.
And the last, it is necessary to remember that just one function is not enough to represent the Gibbs energy of the substance in the whole range of temperature and pressure. The usual practice is to employ a compound function with different functions utilized for different temperature and pressure regions.
As mentioned in Introduction, the solution suggested is to give the end user an opportunity to employ in his/her data files the functions written in analytical form according to some standard. A discussion of this question is elsewhere .
Let us consider an example based upon the IVTAN-TERMO  database. The file ivt.txt contains the thermodynamic properties of three substances in the gas phase, O2, Al, and AlO, and these of the reaction
2AlO = 2Al + O2
calculated by the software CHET .
The database itself keeps some coefficients only and the software computes all the thermodynamic values "on the fly". These coefficients are the enthalpy of formation Del_f_H_o(0 K) and the coefficients for the free energy function F (eq. 14) at standard pressure given by eq 17.
In the case of our substances the whole temperature range from 298.15 K to 10000 K in the database was divided into three subintervals (298.15 - 1500 K, 1500 - 6000 K, 6000 - 10000 K) and the distinct set of the coefficients is employed for each subinterval.
To use the thermodynamic data with my library, one have to create the text
datafile like species.dat. The file is written in a
free format when the five symbols
":; are utilized as the
delimiters. The information sequence is as follows
chemical_formula_of_the_substance "name of the isomer" [phase state] first function : range of T and P for the first function : ... last function : range of T and P for the last function ;
Formal syntax rules of the format are given in the Annex.
The format gives the end user the freedom in the way of representing the Gibbs energy and allows him/her to make calculations with almost any reference thermodynamic data that there are in the literature without changing the code. He/she has just to write the appropriate expression in the datafile in accordance to the thermodynamics laws.
The library allows the end user to work with such datafiles and to make thermodynamic calculations while writing a few lines of code. The files testb.cpp and testc.cpp are the examples how such calculations can be done. Again, if the representation of the Gibbs energy is to change, this does not touch the files with the code at all and one don't have to recompile his/her binaries - all such changes should be made inside a datafile like species.dat only.
The library consists from seven classes, the class
being the final. The eighth class
global contains static data
only and it can be seen as auxiliary. The figure presents the relationships
among the classes.
species allows the user to work with any compound
analytical function of temperature and pressure and with chemical
semi-structural formulas. It inherits these properties from classes
formula accordingly. Besides, it
contains two objects of the class
label to handle additional
information about the substance. I had in mind the information about the
isomer name and the phase state, but they can be used for arbitrary text
formula contains objects of the class
elem, and the class
function is a container for the
objects of the class
smpl_func. The latter is an aggregate class
that combines the properties of the classes
func_Tp handles any simple analytical
function of temperature and pressure and class
lim_Tp keeps the
information on allowable range of temperature and pressure.
Each object can be represented by a text string according to a set of syntax rules described in Annex. The transformations from a text string to the internal representation and from the internal representation to the text string are defined for all the objects.
The complete description of the public part of the classes and examples are given in Annex.
The code presented has been tested under both Borland 4.0 and 4.5 C++ compilers. I did not try other compilers because I don't have them.
All the classes and functions are declared in three header files, func_tp.h, function.h and species.h. It is necessary to start the application with a line
The implementation of the functions is also in three files, func_tp.cpp, function.cpp and species.cpp. It is necessary to compile them and to link the objects files with the application. A good idea is to create a library file. With Borland compiler everything can be done by a command
bcc test.cpp func_tp.cpp function.cpp species.cpp
test.cpp stands for a name of the application.
I myself prefer to use
MAKE - makefile
is included. The command should look like
test is a name of the user program without an
The simplest way to get acquinted with the library is to read the test files and then to run them.
The presented library works with individuals substances only and this is certainly not enough for many important thermodynamics applications. The possible future development, as I see it, is given elsewhere.
Also, it should be stressed that the library is to improve in accordance to modern programming standards (everything is changing so fast in the programming). The error handling should be rewritten by using the exceptions, the code implementing containers should use modern standard container libraries (to this end, I like Standard Template Library  which I have learnt just recently).
The data format developed for the library is probably also to change. When I had started it I did not know about Standard Generalized Markup Language . And now, when I have learnt the SGML, I see that it is quite appropriate and powerful tool to switch to.
The financial support of Open Society Institute, International Soros Science Education Program, Grant d815, is acknowledged.
E.B. Rudnyi., G.F. Voronin. Classes and objects of chemical thermodynamics in object-oriented programming. 1. A class of analytical functions of temperature and pressure. CALPHAD. 1995, v. 19, N 2, p. 189-206.
R.J. Hathaway, Object FAQ.
Free C/C++ Sources for Numerical Computation
C & C++ Resources
A.T. Dinsdale, SGTE data for the pure elements. CALPHAD, 1991, v. 15, N 4, p. 317-425.
L.V. Gurvich. High Temp. Sci. 1989, v. 26, p. 197.
V.S. Lutsarev. K.V. Ermakov. CHEmical Thermodynamics. MS-DOS software.
Mumit's STL Newbie guide
Update May 2010. SGML PRIMER: the link does not work any more: http://www.sq.com/sgmlinfo/primintr.html.
A new link: A Guide to SGML - Standard Generalized Markup Language.