- Introduction

This is sample program which use 'Commont Tangent Method' to draw Hexane VLE(Vapor-Liquid Equilibrium) phase diagram by PHSC(Perturbed Hard Sphere Chain) Theory (Molecular Thermodynamics of Fluid-Phase Equilibria, 3rd Edition : John M. Prausnitz et al : http://www.cchem.berkeley.edu/~jmpgrp/).
Source is best view when indent and tab size is set to 2.



- Some Thermodynamics 

'Common tangent method' find equlibrium points by finding common tangent line of free energy, which should be 4th order curve.
Once, common tangent line of free energy curve is found, 2 contact points of common tangent line with free energy curve are equilibrium points.
In pure fluid system, molecular number 'n' versus free energy 'A or G' graph is used.
In binary system, mole fraction 'phi' versus free energy per mer 'g or a' graph is used.
2 contact points of free energy curve with common tangent line satisfy equilibrium condition.
Without a graph, it is hard to explain this.

Originally, PHSC theory is expressed in terms of relative number density 'rho'.
In this code, Helmholtz free energy and chemical potential functions are converted in terms of molecular number 'n' because this is pure fluid system.
If this is binary systems (e.g. like polymer solution), free energy per mer(g or a)' and '(partial differential of g or a / partial differential of phi)' should be used and 'chemical potential' and they should be expressed in terms of mole fraction 'phi'.
This is important point in common tangent method.



- File Information

PHSC_Draw.c : Main code file.
              It read in EOS parameter from 'parameter.txt', calculate phase equilibria of PHSC theory with common tangent method and write the result data in 'result.dat'.
parameter.txt : EOS parameters are read in from this file.
                If you change 'paramter.txt', you can obtain VLE phase diagram of other fluids.
result.dat : Result data. First column is mass density and second column is absolute temperature(K).
Makefile : used by 'make' command to compile job easier.
  Makefile-gcc : Makefile for GCC(and it's variants)
  Makefile-bcc : Makefile for Borland C++.
  Makefile-vc : Makefile for Microsoft Visual C++.
readme.txt : The file you are reading.
rm.bat : This is simple batch file whick help 'make -f ./Makefile-gcc clean' works properly on MS-Windows.
         To remove or delete file, UNIX use 'rm' command and MS-Windows use 'del' command.
         You can remove this file if
           1. You use UNIX, Linux, Cygwin or any environment which have 'rm' command instead of 'del'.
           2. You replace all 'rm' with 'del' in 'Makefile'.



- Compiler

This code is compiled and tested with following compilers.

GCC variants
  - DJGPP
  - MinGW + MSys
  - Cygwin
Borland C++ 5.5
Microsoft Visual C++ 6.0

GCC on UNIX, Linux and other variants should have no problem compiling.



- How to Compile 

GCC(and it's variants) : 'make -f ./Makefile-gcc'
Borland C++ 5.5 : 'make -fMakefile-bcc'
MS Visual C++ 6.0 : 'nmake /f Makefile-vc'

To run the program, 'PHSC_Draw.exe'(+ Enter key).

To view the calculated phase diagram, use your favorite plotting program.
(I use gnuplot(http://gnuplot.info) which is FREE. Note for first time users of gnuplot : Use 'plot' command instead of 'open'. Use 'help' often.)

To clean up all executive and object files, 
GCC(and it's variants) : 'make -f ./Makefile-gcc clean'
Borland C++ 5.5 : 'make -fMakefile-bcc clean'
Microsoft Visual C++ 6.0 : 'nmake /f Makefile-vc clean'



- Compile Trouble Shooting

General : If failure of finding 'comtan.h' occurs, check if the 'include' statement in 'PHSC_Draw.c' and the real path of 'comtan.h' matches.
Borland C++ 5.5 : Read the 'readme.txt' and do whatever it says. (e.g. Add path. Creat 'bcc32.cfg' and 'ilink32.cfg' in 'bin' directory.) And Reboot. Ignore compile warning.
Microsoft Visual C++ 6.0 : Run 'vcvars32.bat' first.
                 If 'Out of Environment' error occurs, increase the space for environment variables.
                   On MS-Windows 95, 98 and ME : Right-click the MS-DOS Prompt shortcut, and then click Properties. Click the Memory tab. In the Initial Environment box, set the initial environment size to 4,096 bytes. Click OK
                   On MS-Windows NT : Control Panel - System - Environment - Comspec - Increase the amount of environment space. 'ComSpec = <drive:\windir>\system32\cmd.exe /e:4096' 
                   On MS-Windows 2000 : Control Panel - Advanced - Environment Variables. - In the System variables, click ComSpec. - Increase the amount of environment space. 'ComSpec = <drive:\windir>\system32\cmd.exe /e:4096'
                   On MS-Windows XP : Sorry. Help yourself. Microsoft knowledge base can be helpful. Use keyword 'out of environment'.



- Brief description of free C compilers for MS-Windows 

GCC variants
  GCC is a free C compiler. There is no restriction about source code. You can see, modify and distribute the source. But, you can not hide the source. It was orginally developed for UNIX, but these days they are ported to MS-Windows and other OSes.
  DJGPP(http://www.delorie.com/djgpp/) is a GCC port of MS-DOS and also runs on MS-Windows.
  MinGW(http://www.mingw.org) is a GCC port of MS-Windows. To use develpment utilities, MSys(http://www.mingw.org) is needed. MSys is a free UNIX shell emulation on MS-Windows.
  Cygwin(http://www.cygwin.com/) is a free UNIX on MS-Windows. Cygwin have compilers, nice GUI debugger and free X-windows.

Borland C++
  Borland C++ 5.5 is the core compiler for Borland C++ Builder and distributed at no charge.
  In my private test, Borland C++ is the fastest free C compiler for MS-Windows.
  You can download at Borland website(http://www.borland.com) with no charge.

Choice for development process
  - Cygwin
      Cygwin includes a nice GUI debugger 'insight' which makes debugging process easier.

Choice for calculation process
  - Borland C++ 5.5
      When code is stable and heavy calculation is performed, Borland C++ 5.5 is the best choice and DJGPP is the next because they gives high speed to save calculation time (as much as 60%).
      Borland C++ 5.5 is faster than MS Visual C++ 6.0, when both compiler have no optimization option.