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),
- cp (constant-pressure heat capacity),
- cv (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.
- 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
- 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
- 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.
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, and jacob:models/johnpye/fprops/test/jacob_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.