Classes and Objects of Chemical Thermodynamics in Object-Oriented Programming. 2. A Class of Chemical Species

presented at Second Electronic Computational Chemistry Conference, November 1995.

E.B. Rudnyi

Laboratory of Chemical Thermodynamics
Chemistry Department
Moscow State University
119899, Moscow
Russia

Abstract

In the first paper [1], 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.

Contents

Introduction

Object-oriented programming [2] 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 [3].

I have tried to apply object-oriented programming to the thermodynamics needs, and the paper presents the results obtained. C++ [4] 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 [1].

Thermodynamics background

A necessary condition for equilibrium calculations to be done is to put into an equilibrium algorithm the values of molar Gibbs energies of individual substances 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 5.



Many algorithms require Gibbs energies at standard pressure only (eq 6) but this means nothing but that they use the simplest models to estimate Gibbs energy at another pressure like the ideal gas (eq 7) or zero molar volume for liquid and crystals (eq 8).



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.



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 [5] besides terms in eq (13) you can also find terms like in eq 16.



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.

Quick tour around the library

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 [1].

Let us consider an example based upon the IVTAN-TERMO [6] 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 [7].

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 species 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.

The class 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 function and 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 strings.

Class 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 and lim_Tp. Class 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.

Using the library

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

#include "species.h"

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

where test.cpp stands for a name of the application.

I myself prefer to use MAKE - makefile is included. The command should look like

make NAME=test

where test is a name of the user program without an extension.

The simplest way to get acquinted with the library is to read the test files and then to run them.

Looking forward

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 [8] 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 [9]. And now, when I have learnt the SGML, I see that it is quite appropriate and powerful tool to switch to.

Acknowledgments

The financial support of Open Society Institute, International Soros Science Education Program, Grant d815, is acknowledged.

Literature

  1. 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.

  2. R.J. Hathaway, Object FAQ.
    http://www.objectfaq.com/oofaq2/

  3. Free C/C++ Sources for Numerical Computation
    http://cliodhna.cop.uop.edu/~hetrick/c-sources.html

  4. C & C++ Resources

  5. A.T. Dinsdale, SGTE data for the pure elements. CALPHAD, 1991, v. 15, N 4, p. 317-425.

  6. L.V. Gurvich. High Temp. Sci. 1989, v. 26, p. 197.

  7. V.S. Lutsarev. K.V. Ermakov. CHEmical Thermodynamics. MS-DOS software.

  8. Standard Template Library
    Mumit's STL Newbie guide

  9. 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.
    SGML Bibliography.


http://Evgenii.Rudnyi.Ru