User:Jacob: Difference between revisions

From ASCEND
Jump to navigation Jump to search
Jacob (talk | contribs)
Jacob (talk | contribs)
Line 202: Line 202:
Begin specifying names and purposes of functions which will be exported in the final API
Begin specifying names and purposes of functions which will be exported in the final API


''June 25:''
''June 25,26:''


Start writing file (asc_idealsolution) to export mixture functions.  Transfer (preliminary) mixture-modeling code from init_mixfuncs to several files for easier maintenance, and for putting into their final form.  Start re-writing functions used to define the mixture, as they will be used by this file.
Start writing file (asc_idealsolution) to export mixture functions.  Transfer (preliminary) mixture-modeling code from init_mixfuncs.c to several files for easier maintenance, and for putting into their final form.  Start re-writing functions used to define the mixture, as they will be used by this file.


== Explainations and Analysis ==
== Explainations and Analysis ==

Revision as of 03:53, 30 June 2015


Jacob Shealy is a student in the Computer Programming Certificate track at J. Sargeant Reynolds Community College in Richmond, Virginia. He also has a B.S. in Chemical Engineering from the University of Virginia.

Project Overview

This project is intended to add the ability to model ideal-solution mixing in FPROPS. Specifically, I will add functions that may be used to define mixtures of several pure components, and obtain their ideal-solution properties.

Ideal solutions make heavy use of pure-component properties, thus this project will build directly on existing FPROPS features. Non-ideal ('real') solution properties are commonly found from ideal solution properties plus 'excess' properties, so any future implementation of non-ideal solutions will presumably use these ideal-solution functions as a foundation.

I expect to implement functions to find:

  • The following properties, given T and rho (temperature and solution mass density) plus the mixture components:
    • P (pressure),
    • <math>c_p</math> (constant-pressure heat capacity),
    • <math>c_v</math> (constant-volume heat capacity),
    • u (internal energy),
    • h (enthalpy),
    • s (entropy),
    • g (Gibbs energy),
    • a (Helmholtz energy)
  • Mixing conditions (T, and P or rho) for a mixture with components that start at different conditions.

If time permits, I plan to lay the groundwork for non-ideal solutions. This would involve writing general functions to find partial molar properties (PMPs) for the properties above. It would also mean implementing functions which had the same inputs as would be used for non-ideal solutions, but with only ideal-solution models available for now. That is, excess properties would always be set to zero for now.

Schedule for GSOC 2015

This schedule represents current expectations as of June 1. Throughout the summer, I may be revising this schedule, adding edits in italics, with the date of each edit.

Week of May 25

  • Review theory and resolve any remaining questions about thermodynamic equations to be implemented; specify exact form of equations.
  • Explore in detail how pure-component properties are implemented in FPROPS, with attention to any issues that arise from theory.
  • Study existing ASCEND and C API of FPROPS further, to gain a better idea of how API to ideal-solution functions will have to work.

Week of June 1

  • Implement simple ad-hoc mixing model as a test of theory and to determine what data and procedures are necessary.
  • Based on theory and the findings from ad-hoc model, begin to specify data structures to be used for defining mixtures, storing mixture state, and performing ideal solution calculations.
  • Determine what pre-existing pure-component data structures will have to be passed in to the functions.

Week of June 8

  • Continue to determine necessary data structures and procedures for general ideal-solutions case. This may include specialized root-finding procedures for finding mixing conditions.
  • Provisionally specify form and purpose of functions in final API of solutions model.</>

Week of June 15

  • Write required new data structures for mixture definition and description.
  • Added June 16: Explore and specify procedures for solving multicomponent phase-equilibrium problems
  • Added June 17: Specify any changes to mixture structures necessitated by phase equilibrium</>
  • Finalize special procedures (e.g. root-finding functions) for solutions model
  • Continue to plan function input and output for API. Write function(s) for defining mixtures from pure components.

Week of June 22

  • Added June 25: Write library file to import mixture functions from files
  • Write preliminary forms of functions for first-law properties (P, rho, u, h, cp, cv &mdash) for mixtures. These properties are described by the first law of thermodynamics, hence the name.
  • Preliminary unit testing of these functions, especially in integration with functions for defining mixtures.

Week of June 29

  • Added June 29 Test how library file is imported, confirm that data is passed back and forth correctly and with the proper data types.
  • Added June 29 Add fugacity coefficient calculations to functions that find vapor-liquid equilibrium conditions, and handling of components in supercritical region(s).
  • Continue testing of first-law mixture property functions
  • Finalize integration of property and mixture-definition functions into final API.
  • Mid-term occurs at the end of this week, so one reasonable criterion for the mid-term evaluation would seem to be completion of first-law mixture property functions.

Week of July 6

  • Review progress to-date, and perform any catch-up. This week has no specifically assigned work.
  • I am planning to be on vacation from Tuesday of this week through Friday of the next week; hence the week of the 13th also has a light work load.

Week of July 13

  • Write preliminary forms of property functions for second-law properties (s, g, a). This should be closely analogous to the first-law property functions.
  • Perform preliminary unit testing of second-law property functions.

Week of July 20

  • Continue testing and integrating second-law property functions Review thermodynamics of partial molar properties (PMPs) and chemical potential. Chemical potential and related properties such as fugacity are used intensively in non-ideal solution modeling, and I want to provide functions for handling these quantities explicitly.
  • Review thermodynamics of non-ideal solutions, to try to determine what structures may be needed to handle such solutions.
    • The goal here is to successfully implement ideal-solution property functions in a form that can be cleanly extended to non-ideal-solution models.
    • To implement non-ideal models, we would simply add the logic to calculate excess properties.
  • Most work after this point is not strictly necessary to implement ideal-solution modeling, but rather is in preparation for extending the solution model to non-ideal systems.

Week of July 27

  • Specify exact form of equations for solution properties in terms of chemical potential.
  • Determine any special mixing conditions that may exist for non-ideal solutions. (There should not be any, but I want to check. The functions for finding mixing conditions for ideal solutions should be sufficient.)
  • Specify form of general-purpose solution property functions that for now only calculate ideal-solution properties.
  • Specify data structures to use in general-purpose solution property functions, and begin writing forms that these data structures will take for the simple case of ideal solutions.

Week of August 3

  • Review progress, and perform any further catch-up work, if such is needed.
  • This will probably be another relatively light week, and I plan to be at the beach for most of it.
  • Write preliminary form of functions for chemical potential and PMPs, as may be used by general-purpose mixture-property functions (but only returning the trivial ideal-solution values for now).
  • Preliminary unit testing of chemical potential and partial molar property functions.

Week of August 10

  • Continue to write and test chemical potential/PMP functions
  • Write preliminary form of general-purpose solution-property functions (in P,rho,u,h,cp,cv,s,g,a)
    • For now, these may simply call the ideal-solution property functions created earlier, but they must implement logic for choosing the ideal solution case.

August 17

  • Final testing of whole ideal-solution system.
  • Perform any final revision of chemical potential, PMP, and general-purpose property functions.
  • If time remains, plan out and write recommendations on how fluid-property files (e.g. acetone.c) may need to be extended for

Weekly/Daily Progress Report

Week of May 25

May 25, 26, 27:

Reviewed thermodynamic theory, determining the form of equations describing ideal solutions in terms of mass rather than moles, and specification of how mixing conditions may be calculated

May 27, 28, 29:

Examined existing FPROPS code further in light of thermodynamics. The 'sat', 'solve_ph', 'solve_px', and 'solve_Tx' files implement functions that solve iteratively for T,rho, or both in terms of other properties; this is similar to what the 'mixture_prepare' function will have to do to find reasonable solution conditions. Determined how FPROPS implements this functionality, using e.g. zeroin.c

Reviewed files in /fprops/test directory to familiarize myself with the C API of FPROPS. Started writing some peripheral functions for easier construction of similar test files.

Week of June 1

June 1:

Branch ASCEND repository and check out /models/johnpye/fprops directory to my working directory (removing the check out of /models/johnpye/fprops from the trunk that I was using before)

Write up this wiki page, and start to write up results of my studies from last week for the Explainations section below.

Start to write an initial ad-hoc model of three-phase mixing, to test procedures and theory.

June 2,3:

Expand and test ad-hoc mixing model.

Extend Explainations and Analysis section, with issues and theory explored in Week 1.

June 4,5:

Add second-law properties to ad-hoc mixing model.

Add my own functions for finding pure-component densities from temperature and pressure, instead of using ideal-gas densities or zeroin_solve.

Begin de-cluttering test files that implement mixing model, shifting tested functions to a dedicated library file; modify SConscript file to provide for proper compiling.

Week of June 8

June 8,9:

Finish preliminary cleanup of test files, also providing for better reporting of results.

Test ad-hoc model at non-ideal-gas conditions.

Further work on root-finding functions; attempt root-finding function that changes two variables simultaneously (not working at this point).

Begin writing structures to represent mixtures.

June 10,11:

Change all ad-hoc functions for mixture properties written to-date, to use the new structures that represent mixtures

Revise root-finding method that changes two variables simultaneously

June 11:

Skype with Mahesh.

  • Discussed setting mixture state, finding mixture properties, and the potential need to account for multiple phases when finding/setting state.
  • Decided to focus on mixtures at a single temperature and pressure, rather than dealing with the case of different components provided at different temperatures.
  • Will use ChemKit to compare and confirm results from mixture-property and other functions

June 12: Review solution and phase-equilibrium thermo for finding/setting state

Download ChemKit and begin installing dependencies to prepare for for installing ChemKit

Week of June 15

June 15,16:

Finish review of phase-equilibrium thermo, and sketch out what procedures I will need to implement for the ideal-solutions model.

Provisionally specify changes to mixture structures to accomodate multi-phase mixtures.

Begin writing and testing functions for solving phase-equilibrium problems.

June 17:

Update wiki page with phase-equilibrium theory

June 17-19:

Revise root-finding algorithms and consolidate in a single secant-method root-finding function; change functions that set mixture state to use this root-finding function, and test it.

Modify structs that represent mixture specifications and state to handle phases. Finish and test function to perform flash calculations when setting mixture state.

Skype with Mahesh on the 19th.

Week of June 22

June 22:

Implement functions to calculate fugacity coefficients for fluids in ideal-solution. This will allow vapor-liquid equilibrium to be modeled for ideal-solution mixtures in both the liquid and the vapor.

Skype with Mahesh again at 9 AM CBR time, 7 PM U.S. Eastern time; this will be the regular time that we Skype in the future.

June 23-25:

Study ASCEND facilities for writing external relations, and libraries that have been written (e.g. asc_fprops.c) in the past. Plan out file to allow importing functions used in modeling mixture.

Begin specifying names and purposes of functions which will be exported in the final API

June 25,26:

Start writing file (asc_idealsolution) to export mixture functions. Transfer (preliminary) mixture-modeling code from init_mixfuncs.c to several files for easier maintenance, and for putting into their final form. Start re-writing functions used to define the mixture, as they will be used by this file.

Explainations and Analysis

This section is intended to contain explainations and conclusions on specific issues that arise while studying the relevant thermodynamics, etc.

Mass-Specific Version of Ideal-Solution Equations

Throughout FPROPS, most pure-component properties are specific in mass - for instance, enthalpy is calculated not in absolute terms but per-unit-mass, in units of J/kg. On the other hand, most textbook discussions of solution thermodynamics seem to assume a mole basis, e.g. enthalpy is calculated in units of J/mol. To use the existing FPROPS functions most effectively, I have to determine how expressions for solution properties in terms of moles convert into expressions in terms of mass.

I have an extensive discussion of solution thermodynamics at http://www.jacobsworkbench.com/ascend/thermo.php

The most important equations, expressed in terms of moles, are at http://www.jacobsworkbench.com/ascend/thermo.php#ideal_solutions .

In general, the molar form of ideal-solution equations look generally like

([[#equation_{{{3}}}|{{{3}}}]])
1

for first-law ideal-solution properties (v, u, h, cp, cv). Here <math>u^{is}</math> is the ideal-solution internal energy.

For some component i, we can use the molar mass <math>M_i</math> to find the mole fraction <math>x_i</math> from the mass fraction <math>X_i</math>, and derive the other expressions for first-law and second-law properties in solution. The use of primes in the equations below indicates mass-specific as opposed to mole-specific properties

([[#equation_{{{3}}}|{{{3}}}]])
2
([[#equation_{{{3}}}|{{{3}}}]])
{{{2}}} </math>|3}}
([[#equation_{{{3}}}|{{{3}}}]])
4
([[#equation_{{{3}}}|{{{3}}}]])
5
([[#equation_{{{3}}}|{{{3}}}]])
6
([[#equation_{{{3}}}|{{{3}}}]])
7
([[#equation_{{{3}}}|{{{3}}}]])
8
([[#equation_{{{3}}}|{{{3}}}]])
9
([[#equation_{{{3}}}|{{{3}}}]])
10

The mole fractions in the natural logarithms in Eq 8,Eq 9,Eq 10 were left un-expanded for neatness, but of course in actual practice they have to be expanded according to Eq 2.

Notice that molar masses never come into consideration when calculating first-law properties.

Mixing Conditions

Ideal-solution mixing occurs at a constant enthalpy, internal energy, and heat capacity, as can be seen from the equations above. For some component i, any mass-specific property when weighted by the mass fraction represents the amount of that property that i has per unit mass of the solution prior to mixing; the solution property is simply the sum of these amounts, so total enthalpy, internal energy, etc. remain constant.

Another way of saying this is that the property change on mixing for all first-law properties, is zero.

From the constant-internal-energy and constant-enthalpy character of mixing, it can be shown that temperature, pressure, and total volume remain constant during ideal mixing. This allows post-mixing conditions to be more easily calculated from pre-mixing conditions for the individual components, e.g. when it is desired to mix components that start at disparate conditions.

Temperature, Pressure, and Set of Mass Fractions (T,P,{x})

Perhaps the simplest case to solve is of a mixture formed from some components at a given temperature and pressure (T, P). Each component's density rho can be found from T and P by a root-finding method. This case is complicated by the possibility that one or more components may be in the saturation region (vapor-liquid equilibrium). If so, more data than T and P are needed, since a substance can take a range of overall densities in that region.

Once individual densities are found, the overall density can be found by Eq 3 above, and other mixture properties can be found as well. The property functions provided in FPROPS give property values in terms of T and rho, so individual property values can be found, and mixture properties by equations 3 through 10, above. This is illustrated in a simple way in the test file jacob:models/johnpye/fprops/test/init_mix.c.

Temperature, Set of Densities, and Set of Mass Fractions (T,{rho},{x})

More challenging is the case when initial conditions are given in terms of temperature and the set of individual densities (T,{rho}). Here it may be necessary to guess the pressure and solve for individual densities from that, as before; that is, <math>\rho_i</math> such that:

([[#equation_{{{3}}}|{{{3}}}]])
11

And then solve iteratively for the mixing pressure P such that Eq 11 and Eq 12 both hold:

([[#equation_{{{3}}}|{{{3}}}]])
<math>\sum\limits_i X_i \rho_i^{\text{before mixing = \sum\limits_i X_i \rho_i^{\text{mixture}}</math>|12}}

I will have to check that these relations really do hold (more discussion of why I suspect they may not may follow), but since mixing occurs at constant internal energy and constant enthalpy, it should occur at constant volume as well, regardless of initial conditions.

Upon implementing this feature, it appears from preliminary results that the constant-volume assumption is roughly valid (enthalpy changes by about 0.2% when solving for mixing conditions assuming volume is strictly constant). However, using constant internal energy as a criterion works even better for consistency (enthalpy changes by about 0.002% in this case).

Multi-Phase Equilibrium in Mixtures

Important Variables

For any component i in solution, the chemical potential is defined as

([[#equation_{{{3}}}|{{{3}}}]])
{{{2}}}</math>|13}}

The fugacity <math>f_i</math> is defined as

([[#equation_{{{3}}}|{{{3}}}]])
14

For ideal-gas mixtures, the fugacity is <math>f_i^{ig} = y_i P</math>

For ideal-solution mixtures, the fugacity is <math>f_i^{is} = x_i f_i^{pure}</math>

The fugacity coefficient is defined as

([[#equation_{{{3}}}|{{{3}}}]])
<math>\phi_i \equiv \frac{f_i}{f_i^{ig = \frac{f_i}{y_i P}</math>|15}}

The ideal-solution fugacity coefficient for any component turns out to be the pure-component fugacity coefficient: <math>\phi_i^{is} = \phi_i^{pure}</math>.

Pure-component fugacity coefficients may be calculated from equations of state as

([[#equation_{{{3}}}|{{{3}}}]])
16

This is equivalent to equation 9.2-3b in Sandler, but the alternate form in that equation may be more convenient to calculate for ideal-solution conditions:

([[#equation_{{{3}}}|{{{3}}}]])
{{{2}}}{RT} \right)</math>|16b}}

Criteria for Phase Equilibrium

The fundamental condition for a mixture to be in phase equilibrium, is that for each component i, the chemical potential <math>\mu_i \equiv \overline{G}_i</math> is equal in all phases:

([[#equation_{{{3}}}|{{{3}}}]])
18

By Eq 14, if <math>\mu_i^\alpha = \mu_i^\beta </math>:

([[#equation_{{{3}}}|{{{3}}}]])
19

And the same principle applies for all the phases, so:

([[#equation_{{{3}}}|{{{3}}}]])
20

This form of the equilibrium condition is generally the most convenient to calculate.

Calculating Vapor-Liquid Phase Equilibria

The general condition for vapor-liquid equilibrium, per Eq 20, is <math>f_i^{vapor} = f_i^{liquid}</math>. In practice, the fugacities may be found in various ways.

The simplest method for finding vapor and liquid fugacities is to assume ideal-gas vapor and ideal-solution liquid. This results in 'Raoult's Law':

([[#equation_{{{3}}}|{{{3}}}]])
{{{2}}}</math>|21}}

Note that this indicates that in an ideal-solution liquid, <math>f_i^{pure} = P_i^{sat}</math>.

Raoult's Law can be modified to give ideal-solution behavior in the vapor phase by adding a fugacity coefficient to the vapor-phase term:

([[#equation_{{{3}}}|{{{3}}}]])
{{{2}}}</math>|22}}

Mole fractions are commonly used in performing phase calculations, e.g. partial pressure <math>P_i = y_i \phi_i P</math> uses mole fractions to properly weight pressure by the number of molecules (since pressure arises from interactions of individual molecules).

Finding Fugacity Coefficients <math>\phi_i</math>

The fugacity coefficient <math>\phi_i</math> can be calculated from equations of state using Eq 16 or similar equations, although for highly complex equations of state this method can be quite involved. For example, the form that pure-component fugacity coefficients take when using the Peng-Robinson equation is shown at http://www.trentfguidry.net/post/2009/07/10/Peng-Robinson-equation-fugacities.aspx

The pure-component <math>\phi_i</math> may be used to find ideal-solution fugacity from ideal-gas fugacity (which is simply <math>y_i P</math>). Upon implementing the equations for pure-component and mixture fugacity coefficients given at the site above, the pure-component form appears to be more practical to implement and to give well-behaved results.

One possibility to find <math>\phi_i</math> from the Helmholtz equation of state may be to find virial coefficients by the equations on page 10 of IAPWS-95[1], and use the following solution of Eq 16 for the virial equation with second and third coefficients B and C:

<math>\ln(\phi_i^{pure}) = \frac{B\,P}{R\,T} + \frac{(C-B^2)P^2}{2(RT)^2}</math>
<math>B = \frac{\lim_{\delta \to 0} \phi_\delta^r(\delta, \tau)}{\rho_c}</math>
<math>C = \frac{\lim_{\delta \to 0} \phi_{\delta\delta}^r(\delta, \tau)}{\rho_c^2}</math>

Where <math>\phi_\delta^r</math> is the partial differential of the residual part of the Helmholtz EOS with respect to the normalized density <math>\delta</math>, and <math>\phi_{\delta\delta}^r</math> is the second partial differential of the residual part with respect to <math>\delta</math>.

Categories of Phase-Equilibrium Calculations

The calculations that we perform to find phase-equilibrium conditions may be classified according to what we know, and what we have to find, among the available properties temperature, pressure, liquid-phase mass (or mole) fractions and vapor-phase mass (or mole) fractions (T, P, {x}, {y}):

  • Bubble-pressure calculations find P and {y} from T and {x}
  • Dew-pressure calculations find P and {x} from T and {y}
  • Bubble-temperature calculations find T and {y} from P and {x}
  • Dew-temperature calculations find T and {x} from P and {y}
  • Flash calculations find {x} and {y} from T, P, and overall mass fractions {z}

The calculation of most interest in finding or setting mixture state is the flash calculation, since the method can be used to determine whether a mixture at a given state (T,P, overall composition) is in the 'saturation' region. Users may also want to perform the other sorts of calculations specifically.

Bubble-pressure and bubble-temperature calculations generally sum the equilibrium-condition equations (e.g. Eq 22) for all components, and use the fact that the vapor-phase mole fractions sum to one, to eliminate these fractions from the sum:

([[#equation_{{{3}}}|{{{3}}}]])
{{{2}}}{\phi_i}</math>|23}}

Dew-pressure and dew-temperature calculations also sum equilibrium-condition equations, but eliminate liquid-phase mole fractions (which also sum to one):

([[#equation_{{{3}}}|{{{3}}}]])
{{{2}}}</math>|24}}

In these calculations, if temperature is known (bubble-pressure and dew-pressure calculations), the pressure can be directly calculated from Eq 23,Eq 24. If pressure is known, temperature must generally be found with iterative root-finding methods.

General Algorithm for Flash Calculations[2]

First we must convert all overall mass fractions, <math>Z_i</math>, into mole fractions, <math>z_i</math> according to the pattern of Eq 2.

We find bounding pressures:

  • bubble pressure, <math>P_B = \sum\limits_i z_i P_i^s</math>
  • dew pressure, <math>\frac{1}{P_D} = \sum\limits_i \frac{z_i}{P_i^s}</math>

The criterion to flash is <math>P_D <= P <= P_B</math>.

Using <math>\mathcal{V}</math> for fraction of moles in vapor, <math>\mathcal{L}</math> for fraction of moles in liquid, and use K-factor:

([[#equation_{{{3}}}|{{{3}}}]])
25
(26)
<math>K_i \equiv \frac{y_i}{x_i}</math>
([[#equation_{{{3}}}|{{{3}}}]])
27

So

([[#equation_{{{3}}}|{{{3}}}]])
28
([[#equation_{{{3}}}|{{{3}}}]])
29
([[#equation_{{{3}}}|{{{3}}}]])
30

Under the modified Raoult's Law that we are using (Eq 22),

([[#equation_{{{3}}}|{{{3}}}]])
{{{2}}}{\phi_i P}</math>|31}}

so we can solve Eq 30 for <math>\mathcal{V}</math> iteratively, and then find <math>y_i</math> from Eq 28 and <math>x_i</math> from Eq 29.

What Remains Constant Under Ideal Mixing?

Root-Finding Algorithms

Mixture Structures

The first structure used to represent a function simply specifies the number and amount of the components in the mixture:

typedef struct MixtureSpec_Struct {
	unsigned pures; /* number of components */
	double *xs;     /* mass fractions of components */
	PureFluid **Ps; /* pure fluid characteristics of components */
} MixtureSpec;

The second structure adds information on the state of the mixture: temperature and individual component densities:

typedef struct MixtureState_Struct {
	double T;       /* mixture temperature */
	double *rhos;   /* (current) mass densities of components */
	MixtureSpec *X; /* specification of pure-component members of mixture */
} MixtureState;

'MixtureState' may be extended with a calculated pressure in the future. Individual densities are given because mixture properties are calculated from the densities of individual components, which may not be equal to each other or the overall mixture density; see Eq 3 above.

The above structure captures some data about the state of the mixture, but does not allow for multi-phase mixtures to be described. I therefore propose using a third structure to capture data about the phases of a mixture:

typedef struct PhaseSpec_Struct {
	unsigned phases;    /* number of phases */
	PhaseName *ph_name; /* type of each phase */
	double *ph_frac;    /* fraction of total mass in each phase */
	double **Xs;        /* mass fractions of components in each phase */
	double **rhos       /* densities of components in each phase */
} PhaseSpec;

This allows phase data to be handled conveniently, and is used in the final structure to describe the mixture:

typedef struct PhaseMixtureState_Struct {
	double T;       /* temperature */
	double p;       /* pressure */
	PhaseSpec *PH;  /* specification of phases */
	MixtureSpec *MX /* specification of mixture */
} PhaseMixState;

Mixture API

Following the lead of the FPROPS library (with functions exported by asc_fprops.c), I plan to have one function used to prepare all exported functions, creating a MixtureSpec structure from initial data. This MixtureSpec will be passed in as

bbox->user_data

to each exported function when it is invoked.

Provisional List of Functions

  • mixture_specify is used to prepare a MixtureSpec structure from mass fractions and component names
  • mixture_state_Tp is used to set the state of the mixture from temperature and pressure. A few other functions may also be provided to set mixture state from other properties.
  • mixture_rho returns the overall density of the mixture
  • mixture_u returns the mixture internal energy
  • mixture_h returns the mixture enthalpy
  • mixture_cp returns the constant-pressure heat capacity of the mixture
  • mixture_cv returns the constant-volume heat capacity of the mixture
  • mixture_s returns the entropy of the mixture
  • mixture_g returns the Gibbs energy of the mixture
  • mixture_a returns the Helmholtz energy of the mixture

I am still considering the proper approach to integrate bubble-point and dew-point calculations, and querying the mixture state (what phases are present, what are the mass fractions of each component in each phase). These questions are related, since the output from performing VLE calculations should involve displaying the mixture state. However, bubble-point and dew-point calculations also involve explicitly setting mass fractions in one phase or the other.

Flash calculations can be performed by setting the state with mixture_state_Tp above (since that function will need to check for VLE conditions), then querying the mixture state.

Another issue is how to retrieve the properties of individual components in the mixture, in the most convenient possible manner.

Gas Constant 'R'

In the files that define each fluid (e.g. acetone), the familiar gas constant R is given a different value for each, since it is expressed in J/kg/K; the ordinary constant R is constant because it is measured with some molar unit in the denominator. Calculation of second-law mixture properties uses R (see Eq 8,Eq 9,Eq 10), so we might wonder what value of R is used. Fortunately, it is the constant, molar value; this is converted into units of mass naturally by the

( )
<math>\cdots \frac{X_i}{M_i} \cdots</math>

portion of the second term.

Every fluid listed in jacob:models/johnpye/fprops/fluids/fluids_list.h.in uses the same value for the molar form of the gas constant. This may be confirmed by compiling and running jacob:models/johnpye/fprops/test/gas_const_test.c, which will list all the mass-based and molar values of R.

References

  1. http://www.iapws.org/relguide/IAPWS95-Rev.pdf
  2. H.H. Rachford, Jr. and J.D. Rice, J. Petrol. Technol., 4(10), Sec.1, p.19, October 1952