User:Jacob
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 problemsAdded 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 filesWrite 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.
Old Schedule for Weeks Beginning July 27-August 10
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.
Revised Schedule for Weeks Beginning July 27-August 10
Week of July 27
Fix library of imported functions (which provides the ASCEND API) to import and export variables correctly- Review objectives of API, and update list of API functions/API specification accordingly
- Mixture property values:
- Mixture phase splits (phases present, mass and mole fractions)
- Property values for individual components in the mixture
- How user can best specify calculation type (e.g. finding phase splits through dew-point or bubble-point calculations, which may require additional information like the mole/mass fraction of the system in each phase)
- Review mixture preparation (including specifying fluids in the mixture, and performing flash calculations) and mixture property functions. Determine what consistent form (inputs, outputs) and naming convention(s) these functions should have, and rewrite any that deviate from this form.
- Update the file structure in jacob:models/johnpye/fprops/mixtures/, porting functions from jacob:models/johnpye/fprops/mixtures/init_mixfuncs.c to the files where they will ultimately reside.
- Revise mixture-property functions to smoothly handle mixture phases:
- Finding mixture properties for each phase
- Finding mixture properties for all phases together
- Implement as many mixture-property functions and phase-equilibrium functions as possible in the library of imported functions/API.
- Begin writing functions to perform dew-point and bubble-point calculations and set the mixture state at the dew or bubble point.
Week of August 3
- Continue writing functions to perform, and set state through, dew-point and bubble-point calculations.
- Investigate how best to set mixture state through pressure and enthalpy (p,h), and begin writing the functions to do so.
- Continue to implement mixture-property functions and phase-equilibrium functions in the imported library file/API.
- Review thermodynamics of chemical potential, and sketch out how it may be used:
- by users
- in ideal solutions
- in modeling non-ideal solutions
- in crossing over from ideal to non-ideal solutions
- Perform a similar analysis for partial molar properties (which in ideal solutions are simply individual component properties).
Week of August 10
- Finish writing dew-point and bubble-point functions, and incorporate into API.
- Finish incorporating other mixture-property and phase-equilibrium functions into the API.
- Write any necessary functions for calculating chemical-potential and handling partial molar properties.
(Back to Original Schedule)
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.
Weeks of July 6 & 13
Revise & correct fugacity-coefficient function(s) for phase equilibrium.
Week of June 29
June 29,30:
Get basic library function working to allow importing mixture functions into ASCEND. Currently this imports the included functions, but will require further work to ensure that ASCEND and the C code agree on the function types, etc.
Further research on phase-equilibrium calculations and how to model supercritical components in the mixture.
July 1,2:
Write preliminary form of functions to calculate phase-equilibrium conditions with ideal solution in the vapor phase, and separating supercritical components from the mix to form their own (virtual?) single supercritical phase. In the future, any supercritical components for which we have Henry's constants (that is, correlations to calculate Henry's Constant from temperature and pressure or volume) may participate in vapor-liquid equilibrium, but for now, we don't have Henry's constants for any of the components.
Start writing up flowsheet to demonstrate VLE for an example mixture, using the above-mentioned functions. This ran repeatedly into problems with finding the correct vapor-phase density when checking whether the mixture flashes; density assumes non-physical values.
All functions are found in jacob:models/johnpye/fprops/test/init_mix.c
Also did planning work on how to improve the structs that represent mixtures and phases. More on this will be forthcoming.
July 3:
Continue to work on constructing flowsheet. Use dedicated functions to find dew-point and bubble-point, on the theory that the iterative methods used in finding these points (which bracket any flash process) may be more stable. Densities still recede to non-physical values. A more detailed look at the Peng-Robinson EOS may be necessary to identify the source of these problems.
Week of July 20
July 20,21:
Complete a working phase-equilibrium (flash) algorithm in the test file jacob:models/johnpye/fprops/test/init_mix.c, accounting for supercritical, vapor, and liquid phases.
July 22,23: Review and update structures that represent a mixture in some number of phases (see below).
Convert phase-equilibrium algorithm to stand-alone function 'mixture_flash' in jacob:models/johnpye/fprops/test/init_mix.c. This function accounts for supercritical, vapor, and liquid phases, finds mole fraction of each component in each phase, finds mole fraction of entire system in each phase, and stores this data in a PhaseSpec structure.
July 24,27:
In writing library file to import phase-equilibrium and mixture-property functions into ASCEND, review and summarize datatypes used in passing data from ASCEND to the library, focusing on Instance datatypes. Answer remaining questions about how data will be passed between ASCEND and the library.
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 \frac{z_i P_i^\text{sat}}{\phi_i^\text{vapor}}</math>
- dew pressure, <math>\frac{1}{P_D} = \sum\limits_i \frac{z_i \phi_i^\text{vapor}}{P_i^s}</math>
The dew and bubble pressures are calculated exactly as if for a dew-point or bubble-point problem, and criterion to flash is <math>P_D <= P <= P_B</math>.. Dew and bubble pressures must be calculated iteratively, since the <math>\phi_i^\text{vapor}</math> term is calculated at bubble or dew conditions.
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.
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 next important structure describes a single phase within the mixture:
typedef struct Phase_Struct { unsigned ncomps; /* number of components in the phase */ unsigned *c; /* index within a MixtureSpec of each component present in the phase */ double *Xs; /* mass fractions of components in the phase */ double *xs; /* mole (NOT mass) fractions of components in the phase */ PureFluid **PF; /* pure fluid characteristics of components */ double *rhos; /* densities of components in the phase */ } Phase;
For convenience, this structure contains a fair amount of redundant data. In particular, the pointers in the array variable PF will point to PureFluid structures in some MixtureSpec structure, e.g. for Phase PH_1 there will be some MixtureSpec MS_1 such that for each ith element in PF,
PH_1->PF[i] = MS_1->Ps[ PH_1->c[i] ];
Thus, any of the PureFluids in PF could be obtained using the indices of c instead. Likewise, the mass fractions in Xs could be obtained from the mole fractions in xs and the other way around.
The third structure specifies the complete set of phases in a mixture:
typedef struct PhaseSpec_Struct { unsigned phases; /* number of phases */ PhaseType *ph_type; /* type of each phase */ double *ph_frac; /* fraction of total mass in each phase */ Phase **PH; /* specification of each phase */ } PhaseSpec;
The fourth and final structure contains structures to represent the complete overall mixture composition (in a MixtureSpec), and any phases that the mixture assumes (in a PhaseSpec), and adds temperature and pressure information:
typedef struct PhaseMixtureState_Struct { double T; /* temperature */ double p; /* pressure */ PhaseSpec *PS; /* 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. This function might only be implemented in C, and be called behind the scenes when setting mixture conditions in other functions
- mixture_state_ph is used to set the state of the mixture with enthalpy and pressure, and returns the temperature at which the overall mixture enthalpy is equal to that given.
- 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.
The following functions return individual component properties, and must be provided with a symbol constant designating the component fluid for which to find the property. For now, I plan that they will return an array of (three) values, one for each possible phase of the mixture (liquid, vapor, supercritical).
- component_rho returns density.
- component_mass_frac returns mass fraction.
- component_u returns internal energy.
- component_h returns enthalpy.
- component_cp returns constant-pressure heat capacity.
- component_cv returns constant-volume heat capacity.
- component_s returns entropy.
- component_g returns gibbs energy.
The following functions perform equilibrium calculations. If any components are above their critical point, they will be modeled in a separate supercritical phase
- mixture_dew_p returns the pressure and liquid mass fractions at the dew-point (system is all vapor, with one negligible drop of liquid).
- mixture_dew_T returns the temperature and liquid mass fractions at the dew-point.
- mixture_bubble_p returns the pressure and vapor mass fractions at the bubble-point (system is all liquid, with one negligible bubble of vapor).
- mixture_bubble_T returns the temperature and vapor mass fractions at the bubble-point.
- mixture_flash_Tp returns the supercritical, liquid and vapor mass fractions when the mixture is flashed at a given temperature and pressure.
- mixture_flash_ph returns the supercritical, liquid and vapor mass fractions when the mixture is flashed at a given enthalpy and pressure.
- mixture_phases returns a description of the current phases, with fraction of the mass in each phase.
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
- ↑ http://www.iapws.org/relguide/IAPWS95-Rev.pdf
- ↑ H.H. Rachford, Jr. and J.D. Rice, J. Petrol. Technol., 4(10), Sec.1, p.19, October 1952