<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://ascend4.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=RichardTowers</id>
	<title>ASCEND - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://ascend4.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=RichardTowers"/>
	<link rel="alternate" type="text/html" href="https://ascend4.org/Special:Contributions/RichardTowers"/>
	<updated>2026-04-28T22:08:33Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://ascend4.org/index.php?title=Data_structures_in_FPROPS&amp;diff=3027</id>
		<title>Data structures in FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Data_structures_in_FPROPS&amp;diff=3027"/>
		<updated>2011-08-22T14:06:23Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: My thoughts on data in FPROPS&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
==Current Method==&lt;br /&gt;
At the time of writing the data needed for each fluid and correlation are declared as global C structures at compile time. For example, for water:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
HelmholtzData helmholtz_data_water = {&lt;br /&gt;
	&amp;quot;water&amp;quot;&lt;br /&gt;
	, /* R */ WATER_R /* J/kg/K */&lt;br /&gt;
	, /* M */ 18.015242 /* kg/kmol -- G S Kell, J Phys Chem Ref Data (6) 1109 (1977) */&lt;br /&gt;
	, /* rho_star */ WATER_RHOC /* kg/m³ */&lt;br /&gt;
	, /* T_star */ WATER_TC /* K */&lt;br /&gt;
&lt;br /&gt;
	, /* T_c */ WATER_TC&lt;br /&gt;
	, /* rho_c */ WATER_RHOC&lt;br /&gt;
	, /* T_t */ 273.16&lt;br /&gt;
&lt;br /&gt;
	, 0.344 /* acentric factor, source: Reid, Prausnitz &amp;amp; Polling */&lt;br /&gt;
	, &amp;amp;ideal_data_water&lt;br /&gt;
    , 0 /* no helmholtz coeffs implemented yet...*/&lt;br /&gt;
	, (int)51 /* np */&lt;br /&gt;
	, (HelmholtzPowTerm[]){&lt;br /&gt;
		/* a_i, t_i, d_i, l_i */&lt;br /&gt;
		{0.12533547935523E-1, -0.5, 1, 0}&lt;br /&gt;
		,{0.78957634722828E1, 0.875, 1, 0}&lt;br /&gt;
		//...&lt;br /&gt;
		,{-0.11841182425981, 50, 6, 6}&lt;br /&gt;
	}&lt;br /&gt;
	, 3 /* gaussian terms */&lt;br /&gt;
	, (HelmholtzGausTerm[]){&lt;br /&gt;
		/* n, t, d, alpha, beta, gamma, epsilon */&lt;br /&gt;
		{-0.31306260323435e2, 0, 3, 20, 150, 1.21, 1}&lt;br /&gt;
		,{0.31546140237781e2, 1, 3, 20, 150, 1.21, 1}&lt;br /&gt;
		,{-0.25213154341695e4,4, 3, 20, 250, 1.25, 1}&lt;br /&gt;
	}&lt;br /&gt;
	, 2 /* critical terms */&lt;br /&gt;
	, (HelmholtzCritTerm[]){&lt;br /&gt;
		/* n, a, b, beta, A, B, C, D */&lt;br /&gt;
		{-0.14874640856724, 3.5, 0.85, 0.3, 0.32, 0.2, 28, 700}&lt;br /&gt;
		,{0.31806110878444, 3.5, 0.95, 0.3, 0.32, 0.2, 32, 800}&lt;br /&gt;
	}&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This can be accessed from any function in the program and used to build up higher level structures such as the PureFluid data type.&lt;br /&gt;
There are a few disadvantages to handling data in this way, I won&#039;t go into all of them now but the main problem is that this method does not scale up well as we add more features to FPROPS. For example if we decide to add or remove a piece of data from a struct all of the initialisers in each fluid file have to be rewritten to match the new struct. &lt;br /&gt;
==Future Method==&lt;br /&gt;
The key criterion that a future solution must meet is that the data must be stored in a way that is independent of the program itself.&lt;br /&gt;
===XML and Relax NG===&lt;br /&gt;
One possible solution to this problem has been investigated in some depth. This method involves storing the data in an XML file, with lots of markup to make the data easily accessible. This has the advantage of being easily parsed by FPROPS and any other programs that might decide to use the data down the line. Also, using XSL and CSS these XML files can be viewed in a browser in a very human readable way. It also allows for handling of some more complicated relations, for example there could be several different types of correlation for any fluid, and each correlation could have several slightly different sources, furthermore the correlations may have some order of preference or range of applicability. An XML schema should be able to handle these complexities in a sane manner.&lt;br /&gt;
An example of what an XML file might look like:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;?xml-stylesheet type=&amp;quot;text/xsl&amp;quot; href=&amp;quot;dataTransform.xsl&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;fluid&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;octane&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;core source=&amp;quot;Span and Wagner&amp;quot; rank=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;M&amp;gt;114.231&amp;lt;/M&amp;gt;&lt;br /&gt;
        &amp;lt;T_c&amp;gt;569.32&amp;lt;/T_c&amp;gt;&lt;br /&gt;
        &amp;lt;P_c&amp;gt;2.497&amp;lt;/P_c&amp;gt;&lt;br /&gt;
        &amp;lt;rho_c&amp;gt;234.90&amp;lt;/rho_c&amp;gt;&lt;br /&gt;
        &amp;lt;omega&amp;gt;0.395&amp;lt;/omega&amp;gt;&lt;br /&gt;
        &amp;lt;T_t&amp;gt;216.37&amp;lt;/T_t&amp;gt;&lt;br /&gt;
    &amp;lt;/core&amp;gt;&lt;br /&gt;
    &amp;lt;ideal source=&amp;quot;Jaeschke and Schley&amp;quot; rank=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;const&amp;gt;-8.32044648201&amp;lt;/const&amp;gt;&lt;br /&gt;
        &amp;lt;lin&amp;gt;6.6832105268&amp;lt;/lin&amp;gt;&lt;br /&gt;
        &amp;lt;Cp_star&amp;gt;OCTANE_R&amp;lt;/Cp_star&amp;gt;&lt;br /&gt;
        &amp;lt;powerTerms number=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;c&amp;gt;4.00662&amp;lt;/c&amp;gt; &amp;lt;t&amp;gt;0&amp;lt;/t&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;c&amp;gt;4.00662&amp;lt;/c&amp;gt; &amp;lt;t&amp;gt;0&amp;lt;/t&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;c&amp;gt;4.00662&amp;lt;/c&amp;gt; &amp;lt;t&amp;gt;0&amp;lt;/t&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;c&amp;gt;4.00662&amp;lt;/c&amp;gt; &amp;lt;t&amp;gt;0&amp;lt;/t&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;c&amp;gt;4.00662&amp;lt;/c&amp;gt; &amp;lt;t&amp;gt;0&amp;lt;/t&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
		&amp;lt;/powerTerms&amp;gt;&lt;br /&gt;
        &amp;lt;exponentialTerms number=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;b&amp;gt;0.01243&amp;lt;/b&amp;gt;&amp;lt;beta&amp;gt;2&amp;lt;/beta&amp;gt;&lt;br /&gt;
        &amp;lt;/exponentialTerms&amp;gt;&lt;br /&gt;
    &amp;lt;/ideal&amp;gt;&lt;br /&gt;
    &amp;lt;helmholtz source=&amp;quot;Span and Wagner&amp;quot; rank=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;powerTerms number=&amp;quot;12&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;a&amp;gt;0.10722545e1&amp;lt;/a&amp;gt; &amp;lt;t&amp;gt;0.250&amp;lt;/t&amp;gt; &amp;lt;d&amp;gt;1&amp;lt;/d&amp;gt; &amp;lt;l&amp;gt;0&amp;lt;/l&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;a&amp;gt;0.10722545e1&amp;lt;/a&amp;gt; &amp;lt;t&amp;gt;0.250&amp;lt;/t&amp;gt; &amp;lt;d&amp;gt;1&amp;lt;/d&amp;gt; &amp;lt;l&amp;gt;0&amp;lt;/l&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;a&amp;gt;0.10722545e1&amp;lt;/a&amp;gt; &amp;lt;t&amp;gt;0.250&amp;lt;/t&amp;gt; &amp;lt;d&amp;gt;1&amp;lt;/d&amp;gt; &amp;lt;l&amp;gt;0&amp;lt;/l&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;a&amp;gt;0.10722545e1&amp;lt;/a&amp;gt; &amp;lt;t&amp;gt;0.250&amp;lt;/t&amp;gt; &amp;lt;d&amp;gt;1&amp;lt;/d&amp;gt; &amp;lt;l&amp;gt;0&amp;lt;/l&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;a&amp;gt;0.10722545e1&amp;lt;/a&amp;gt; &amp;lt;t&amp;gt;0.250&amp;lt;/t&amp;gt; &amp;lt;d&amp;gt;1&amp;lt;/d&amp;gt; &amp;lt;l&amp;gt;0&amp;lt;/l&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;a&amp;gt;0.10722545e1&amp;lt;/a&amp;gt; &amp;lt;t&amp;gt;0.250&amp;lt;/t&amp;gt; &amp;lt;d&amp;gt;1&amp;lt;/d&amp;gt; &amp;lt;l&amp;gt;0&amp;lt;/l&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;a&amp;gt;0.10722545e1&amp;lt;/a&amp;gt; &amp;lt;t&amp;gt;0.250&amp;lt;/t&amp;gt; &amp;lt;d&amp;gt;1&amp;lt;/d&amp;gt; &amp;lt;l&amp;gt;0&amp;lt;/l&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;a&amp;gt;0.10722545e1&amp;lt;/a&amp;gt; &amp;lt;t&amp;gt;0.250&amp;lt;/t&amp;gt; &amp;lt;d&amp;gt;1&amp;lt;/d&amp;gt; &amp;lt;l&amp;gt;0&amp;lt;/l&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;a&amp;gt;0.10722545e1&amp;lt;/a&amp;gt; &amp;lt;t&amp;gt;0.250&amp;lt;/t&amp;gt; &amp;lt;d&amp;gt;1&amp;lt;/d&amp;gt; &amp;lt;l&amp;gt;0&amp;lt;/l&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;a&amp;gt;0.10722545e1&amp;lt;/a&amp;gt; &amp;lt;t&amp;gt;0.250&amp;lt;/t&amp;gt; &amp;lt;d&amp;gt;1&amp;lt;/d&amp;gt; &amp;lt;l&amp;gt;0&amp;lt;/l&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;a&amp;gt;0.10722545e1&amp;lt;/a&amp;gt; &amp;lt;t&amp;gt;0.250&amp;lt;/t&amp;gt; &amp;lt;d&amp;gt;1&amp;lt;/d&amp;gt; &amp;lt;l&amp;gt;0&amp;lt;/l&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
            &amp;lt;term&amp;gt;&amp;lt;a&amp;gt;0.10722545e1&amp;lt;/a&amp;gt; &amp;lt;t&amp;gt;0.250&amp;lt;/t&amp;gt; &amp;lt;d&amp;gt;1&amp;lt;/d&amp;gt; &amp;lt;l&amp;gt;0&amp;lt;/l&amp;gt;&amp;lt;/term&amp;gt;&lt;br /&gt;
        &amp;lt;/powerTerms&amp;gt;&lt;br /&gt;
    &amp;lt;/helmholtz&amp;gt;&lt;br /&gt;
&amp;lt;/fluid&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The markup makes this file difficult for a human to read, however with XSL and CSS it can be transformed to a more readable format ([http://richard-towers.com/ASCEND/example.xml example])&lt;br /&gt;
&lt;br /&gt;
The problem with this method is that, because of the complex markup, manual data entry is prohibitively slow. For this to be a workable solution there needs to be some solution to this problem.&lt;br /&gt;
One answer would be to have the files stored on a webserver and have an XHTML form for data entry calling a PHP (or python etc.) script to do the file handling. This would however be a departure from the SVN version control system which is a clear disadvantage.&lt;br /&gt;
&lt;br /&gt;
One other solution would be to write a bespoke PyGTK GUI to deal with data entry, although this seems like overkill it would ensure properly formed documents, and data could be checked for plausibility at entry time.&lt;br /&gt;
: This is probably my preferred method [[User:RichardTowers|RichardTowers]] 14:06, 22 August 2011 (UTC)&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2996</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2996"/>
		<updated>2011-08-17T13:33:18Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
Goals have been updated as of 4 August 2011 and are shown below. The initial project goals are not vastly different, but can be seen in [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application].&lt;br /&gt;
&lt;br /&gt;
# Complete integration of PR EOS in FPROPS. All the departure functions should be implemented, tested, working, and connected with the ideal gas functions, for calculation of all the &#039;raw&#039; properties complete and correct.&lt;br /&gt;
# PR EOS should be tested with the current sat.c Akasaka approach for calculating single-fluid saturate mixture states. Algorthim should be working and giving reasonable values, and reasonable error messages if failing.&lt;br /&gt;
# Existing Helmholtz code should be modified to use the new data structures and all existing tests should still be working correctly with no changes having arising from the code refactor.&lt;br /&gt;
# Existing Python and ASCEND bindings need to be updated to work with all the new code, and be operating correctly.&lt;br /&gt;
# Existing build tools should be updated to operate on the new code, and FPROPS built and tested using SCons on all three operating systems.&lt;br /&gt;
# Progress on XML and XSLT tools for FPROPS should be documented, with remaining tasks/intentions detailed.&lt;br /&gt;
# FPROPS wiki page updated with information about the modifications completed, new functionality, etc.&lt;br /&gt;
# Convert data from RPP book to C data structures to increase fluid support to 50+ fluids.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;17th August 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Peng robinson and helmholtz in agreement on pressures now. If I can just get the helmholtz energy departure function working then it&#039;ll be working in time for the deadline.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12th August 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Difficult week, main computer broken, difficulties compiling on second. Finally succeeded in running scons. Work on python bindings, they&#039;re working now but need tidying up.&lt;br /&gt;
&lt;br /&gt;
Thought for the day: SWIG is &#039;&#039;really&#039;&#039; clever.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4th August 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Helmholtz calculations now work with the new data structures. All fluids and tests have been updated and work (except for ethanol and isohexane who&#039;s tests report small and large errors respectively). Peng-Robinson appears to give almost completely different values to helmholtz even for pressure which should be trivial. This is &#039;&#039;&#039;not&#039;&#039;&#039; expected, and the cause needs investigating before we can move into more FPROPS-esque support for ideal and saturation calculations. John emailed with an updated list of goals which are updated above.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;25th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Peng-Robinson EOS now successfully calculates &amp;lt;math&amp;gt;p(V,T)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;V(p,T)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\Delta h(V,T)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\Delta s(V,T)&amp;lt;/math&amp;gt;. Redlich-Kwong EOS also works, but has additional &#039;&#039;&#039;untested&#039;&#039;&#039; support for a,u,g departure functions. Once the two new EOSs are integrated with current ideal and saturation calculations then we&#039;ll have two new EOSs.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;15th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most of the way to a working implementation of the Peng-Robinson equation of state, there are still some issues to be resolved with respect to ideal properties and internal representation of data.&lt;br /&gt;
&lt;br /&gt;
XML data file structure decided upon and a human readable transformation written, still require an input form to create these files. Will also need to modify cToXML to create files for the existing fluids (Note: Will have to be careful with rounding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Having discussed flexibility with regards to equation of state decided on the future structure of the program. Using various structs and unions fprops now has a skeleton capable of supporting several possible equations. &lt;br /&gt;
&lt;br /&gt;
Still to do in this area: Actually implement other EOSs (peng-robinson first), Refactor FPROPS to fit with new way of doing things. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;24th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switched to Mac OS X for development, switched to the Xcode IDE for editing, hopefully the overheads in learning the new system will be worth it. Spoke to John about support for multiple equations of state, created a couple of files ready to start experimenting.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] &amp;amp; [[PengRobinson EOS in FPROPS|Peng Robinson]] cubic EOSs. See {{srcbranch|richard|models/johnpye/fprops/pengrob.c}},&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/pengrob.h}},&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/redkw.c}} and&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/redkw.h}} for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
One of the main challenges here is to write functions which can take any correlation data struct as an input, decide which correlation to use, and return the desired value. After some consultation with John, we&#039;ve decided on a struct containing all of the data and pointers to the various functions. A union is used to enable different types of data to be passed to functions with the same arguments.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/** Enumerate EOS correlations&lt;br /&gt;
 */&lt;br /&gt;
enum eos{&lt;br /&gt;
    pengrob,&lt;br /&gt;
    redkw,&lt;br /&gt;
    helmholtz,&lt;br /&gt;
    mbwr //etc.&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
/** Union for equation of state data&lt;br /&gt;
 */&lt;br /&gt;
typedef union eos_tag{&lt;br /&gt;
    HelmholtzData* helmholtzData;&lt;br /&gt;
    CubicData* cubicData;&lt;br /&gt;
    //etc...&lt;br /&gt;
} EosData;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Definition of a fluid property function pointer&lt;br /&gt;
 */&lt;br /&gt;
typedef double (*propFnPtr)(double,double,const EosData*);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Structure pointing to the necessary data and functions to calculate&lt;br /&gt;
    fluid properties.&lt;br /&gt;
*/&lt;br /&gt;
typedef struct pureFluid{&lt;br /&gt;
	enum eos type;&lt;br /&gt;
    IdealData *idealData;&lt;br /&gt;
	EosData  *eosData;&lt;br /&gt;
	//Pointers to departure functions&lt;br /&gt;
    propFnPtr p_fn;&lt;br /&gt;
    propFnPtr u_fn;&lt;br /&gt;
    propFnPtr h_fn;&lt;br /&gt;
    propFnPtr s_fn;&lt;br /&gt;
    propFnPtr a_fn;&lt;br /&gt;
    propFnPtr cv_fn;&lt;br /&gt;
    propFnPtr cp_fn;&lt;br /&gt;
    propFnPtr w_fn;&lt;br /&gt;
    propFnPtr g_fn;&lt;br /&gt;
} pureFluid;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The structure can be created as follows, and then the function pointers can simply be followed to the correct function.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
    EosData eosData={.cubicData=&amp;amp;cData};&lt;br /&gt;
    pureFluid fluidData={&lt;br /&gt;
        pengrob,&lt;br /&gt;
        &amp;amp;iData,&lt;br /&gt;
        &amp;amp;eosData,&lt;br /&gt;
        //Pointers to departure functions&lt;br /&gt;
        pengrob_p,&lt;br /&gt;
        pengrob_u_depart,&lt;br /&gt;
        pengrob_h_depart,&lt;br /&gt;
        pengrob_s_depart,&lt;br /&gt;
        pengrob_a_depart,&lt;br /&gt;
        pengrob_cv,&lt;br /&gt;
        pengrob_cp,&lt;br /&gt;
        pengrob_w,&lt;br /&gt;
        pengrob_g_depart&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
double p=fluidData.p_fn(T,rho,fluidData.eosData);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Category:GSOC2011]]&lt;br /&gt;
[[Category:ASCEND Contributors]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2994</id>
		<title>PengRobinson EOS in FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2994"/>
		<updated>2011-08-16T17:49:09Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{task}}&lt;br /&gt;
Work on this is went on as a part of GSoC 2010 (Project [[User:Ankitml|Ankit]]) and continues as part of GSoC 2011 ([[User:richardTowers|Richard Towers]]).&lt;br /&gt;
See also [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Comments and suggestions are welcome&lt;br /&gt;
==Overview==&lt;br /&gt;
The Peng-Robinson EOS is a cubic equation of state in that it contains volume terms to the third power. It is usually expressed to give pressure in terms of temperature and molar volume &amp;lt;math&amp;gt;{\bar v}&amp;lt;/math&amp;gt;:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
p =\frac{{\bar R} T}{{\bar v}-b}-\frac{a(T)}{{\bar v}({\bar v}+b)+b({\bar v}-b)}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
&lt;br /&gt;
a(T) &amp;amp;= 0.45724  \frac{{\bar R}^2{T_c}^2}{p_c} \alpha \left(T \right) \\&lt;br /&gt;
&lt;br /&gt;
\alpha &amp;amp;= \left( 1+\kappa \left( 1-\sqrt{\frac{T}{T_c}} \right) \right)^2 \\&lt;br /&gt;
 &lt;br /&gt;
\kappa &amp;amp;= 0.37464+1.54226\omega - 0.26992\omega^2 \\&lt;br /&gt;
&lt;br /&gt;
b &amp;amp;= \frac{0.0778\bar R T_c}{p_c}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is sometimes more convenient to express the equation as a cubic polynomial in terms of compressibility factor &amp;lt;math&amp;gt;Z=\frac{p {\bar v}}{{\bar R} T}&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
Z^3+(-1+B)Z^2+(A-3B^2-2B)Z-AB+B^2+B^3=0&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
in which&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A &amp;amp;= \frac{a \left(T \right) p}{({\bar R} T)^2} \\&lt;br /&gt;
B &amp;amp;= \frac{b}{{\bar R} T}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Departure Functions==&lt;br /&gt;
Departure functions represent the departure of the &#039;&#039;real&#039;&#039; properties from the &#039;&#039;ideal&#039;&#039; properties - i.e the properties of a fluid at zero pressure or infinite molar volume.&lt;br /&gt;
The departure functions of the Peng-Robinson equation of state are as follows:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
H_{m}-H_{m}^{\text{ideal}}&amp;amp;={\bar R} T(Z-1)+\frac{T\left(\frac{da}{dT}\right)-a}{2\sqrt{2}b}\ln\left[\frac{Z+(1+\sqrt{2})B}{Z+(1-\sqrt{2})B}\right] \\&lt;br /&gt;
&lt;br /&gt;
S_{m}-S_{m}^{\text{ideal}}&amp;amp;={\bar R} \ln (Z-B)+\frac{\frac{da}{dT}}{2\sqrt{2}b}\ln\left[\frac{Z+(1+\sqrt{2})B}{Z+(1-\sqrt{2})B}\right]&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Clearly to evaluate these functions we need to be able to evaluate &amp;lt;math&amp;gt;\frac{da}{dT}&amp;lt;/math&amp;gt; (checked, agrees with Sandler):&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{da}{dT}= -0.45724 \frac{{\bar R}^{2} {T_c}^{\frac{3}{2}} }{p_c} \kappa \frac{\sqrt{\alpha} }{ \sqrt{T}}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Comparisons==&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2986</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2986"/>
		<updated>2011-08-12T13:28:08Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
Goals have been updated as of 4 August 2011 and are shown below. The initial project goals are not vastly different, but can be seen in [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application].&lt;br /&gt;
&lt;br /&gt;
# Complete integration of PR EOS in FPROPS. All the departure functions should be implemented, tested, working, and connected with the ideal gas functions, for calculation of all the &#039;raw&#039; properties complete and correct.&lt;br /&gt;
# PR EOS should be tested with the current sat.c Akasaka approach for calculating single-fluid saturate mixture states. Algorthim should be working and giving reasonable values, and reasonable error messages if failing.&lt;br /&gt;
# Existing Helmholtz code should be modified to use the new data structures and all existing tests should still be working correctly with no changes having arising from the code refactor.&lt;br /&gt;
# Existing Python and ASCEND bindings need to be updated to work with all the new code, and be operating correctly.&lt;br /&gt;
# Existing build tools should be updated to operate on the new code, and FPROPS built and tested using SCons on all three operating systems.&lt;br /&gt;
# Progress on XML and XSLT tools for FPROPS should be documented, with remaining tasks/intentions detailed.&lt;br /&gt;
# FPROPS wiki page updated with information about the modifications completed, new functionality, etc.&lt;br /&gt;
# Convert data from RPP book to C data structures to increase fluid support to 50+ fluids.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;12th August 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Difficult week, main computer broken, difficulties compiling on second. Finally succeeded in running scons. Work on python bindings, they&#039;re working now but need tidying up.&lt;br /&gt;
&lt;br /&gt;
Thought for the day: SWIG is &#039;&#039;really&#039;&#039; clever.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4th August 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Helmholtz calculations now work with the new data structures. All fluids and tests have been updated and work (except for ethanol and isohexane who&#039;s tests report small and large errors respectively). Peng-Robinson appears to give almost completely different values to helmholtz even for pressure which should be trivial. This is &#039;&#039;&#039;not&#039;&#039;&#039; expected, and the cause needs investigating before we can move into more FPROPS-esque support for ideal and saturation calculations. John emailed with an updated list of goals which are updated above.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;25th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Peng-Robinson EOS now successfully calculates &amp;lt;math&amp;gt;p(V,T)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;V(p,T)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\Delta h(V,T)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\Delta s(V,T)&amp;lt;/math&amp;gt;. Redlich-Kwong EOS also works, but has additional &#039;&#039;&#039;untested&#039;&#039;&#039; support for a,u,g departure functions. Once the two new EOSs are integrated with current ideal and saturation calculations then we&#039;ll have two new EOSs.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;15th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most of the way to a working implementation of the Peng-Robinson equation of state, there are still some issues to be resolved with respect to ideal properties and internal representation of data.&lt;br /&gt;
&lt;br /&gt;
XML data file structure decided upon and a human readable transformation written, still require an input form to create these files. Will also need to modify cToXML to create files for the existing fluids (Note: Will have to be careful with rounding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Having discussed flexibility with regards to equation of state decided on the future structure of the program. Using various structs and unions fprops now has a skeleton capable of supporting several possible equations. &lt;br /&gt;
&lt;br /&gt;
Still to do in this area: Actually implement other EOSs (peng-robinson first), Refactor FPROPS to fit with new way of doing things. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;24th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switched to Mac OS X for development, switched to the Xcode IDE for editing, hopefully the overheads in learning the new system will be worth it. Spoke to John about support for multiple equations of state, created a couple of files ready to start experimenting.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] &amp;amp; [[PengRobinson EOS in FPROPS|Peng Robinson]] cubic EOSs. See {{srcbranch|richard|models/johnpye/fprops/pengrob.c}},&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/pengrob.h}},&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/redkw.c}} and&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/redkw.h}} for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
One of the main challenges here is to write functions which can take any correlation data struct as an input, decide which correlation to use, and return the desired value. After some consultation with John, we&#039;ve decided on a struct containing all of the data and pointers to the various functions. A union is used to enable different types of data to be passed to functions with the same arguments.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/** Enumerate EOS correlations&lt;br /&gt;
 */&lt;br /&gt;
enum eos{&lt;br /&gt;
    pengrob,&lt;br /&gt;
    redkw,&lt;br /&gt;
    helmholtz,&lt;br /&gt;
    mbwr //etc.&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
/** Union for equation of state data&lt;br /&gt;
 */&lt;br /&gt;
typedef union eos_tag{&lt;br /&gt;
    HelmholtzData* helmholtzData;&lt;br /&gt;
    CubicData* cubicData;&lt;br /&gt;
    //etc...&lt;br /&gt;
} EosData;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Definition of a fluid property function pointer&lt;br /&gt;
 */&lt;br /&gt;
typedef double (*propFnPtr)(double,double,const EosData*);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Structure pointing to the necessary data and functions to calculate&lt;br /&gt;
    fluid properties.&lt;br /&gt;
*/&lt;br /&gt;
typedef struct pureFluid{&lt;br /&gt;
	enum eos type;&lt;br /&gt;
    IdealData *idealData;&lt;br /&gt;
	EosData  *eosData;&lt;br /&gt;
	//Pointers to departure functions&lt;br /&gt;
    propFnPtr p_fn;&lt;br /&gt;
    propFnPtr u_fn;&lt;br /&gt;
    propFnPtr h_fn;&lt;br /&gt;
    propFnPtr s_fn;&lt;br /&gt;
    propFnPtr a_fn;&lt;br /&gt;
    propFnPtr cv_fn;&lt;br /&gt;
    propFnPtr cp_fn;&lt;br /&gt;
    propFnPtr w_fn;&lt;br /&gt;
    propFnPtr g_fn;&lt;br /&gt;
} pureFluid;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The structure can be created as follows, and then the function pointers can simply be followed to the correct function.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
    EosData eosData={.cubicData=&amp;amp;cData};&lt;br /&gt;
    pureFluid fluidData={&lt;br /&gt;
        pengrob,&lt;br /&gt;
        &amp;amp;iData,&lt;br /&gt;
        &amp;amp;eosData,&lt;br /&gt;
        //Pointers to departure functions&lt;br /&gt;
        pengrob_p,&lt;br /&gt;
        pengrob_u_depart,&lt;br /&gt;
        pengrob_h_depart,&lt;br /&gt;
        pengrob_s_depart,&lt;br /&gt;
        pengrob_a_depart,&lt;br /&gt;
        pengrob_cv,&lt;br /&gt;
        pengrob_cp,&lt;br /&gt;
        pengrob_w,&lt;br /&gt;
        pengrob_g_depart&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
double p=fluidData.p_fn(T,rho,fluidData.eosData);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Category:GSOC2011]]&lt;br /&gt;
[[Category:ASCEND Contributors]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Talk:Porting_to_Mac&amp;diff=2981</id>
		<title>Talk:Porting to Mac</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Talk:Porting_to_Mac&amp;diff=2981"/>
		<updated>2011-08-10T13:43:01Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I&#039;m having some problems having moved to OS X 10.7 (Lion). For starters it appears that SWIG no longer comes bundled with Xcode (4.1), so macports is required, this has the knock on effect of causing problems buliding pyGTK. More on this as I work through the issues. [[User:RichardTowers|RichardTowers]] 13:39, 10 August 2011 (UTC)&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Talk:Porting_to_Mac&amp;diff=2980</id>
		<title>Talk:Porting to Mac</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Talk:Porting_to_Mac&amp;diff=2980"/>
		<updated>2011-08-10T13:39:42Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: OS X Lion&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I&#039;m having some problems having moved to OS X 10.7 (Lion). For starters it appears that SWIG no longer comes bundled with Xcode, so macports is required, this has the knock on effect of causing problems buliding pyGTK. More on this as I work through the issues. [[User:RichardTowers|RichardTowers]] 13:39, 10 August 2011 (UTC)&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2949</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2949"/>
		<updated>2011-08-04T18:51:04Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Goals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
An updated list of goals can be found below. For an idea of my initial goals have a look at  [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application].&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;4th August 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Helmholtz calculations now work with the new data structures. All fluids and tests have been updated and work (except for ethanol and isohexane who&#039;s tests report small and large errors respectively). Peng-Robinson appears to give almost completely different values to helmholtz even for pressure which should be trivial. This is &#039;&#039;&#039;not&#039;&#039;&#039; expected, and the cause needs investigating before we can move into more FPROPS-esque support for ideal and saturation calculations. John emailed with an updated list of goals which are as follows:&lt;br /&gt;
* Complete integration of PR EOS in FPROPS. All the departure functions should be implemented, tested, working, and connected with the ideal gas functions, for calculation of all the &#039;raw&#039; properties complete and correct.&lt;br /&gt;
* PR EOS should be tested with the current sat.c Akasaka approach for calculating single-fluid saturate mixture states. Algorthim should be working and giving reasonable values, and reasonable error messages if failing.&lt;br /&gt;
* Existing Helmholtz code should be modified to use the new data structures and all existing tests should still be working correctly with no changes having arising from the code refactor.&lt;br /&gt;
* Existing Python and ASCEND bindings need to be updated to work with all the new code, and be operating correctly.&lt;br /&gt;
* Existing build tools should be updated to operate on the new code, and FPROPS built and tested using SCons on all three operating systems.&lt;br /&gt;
* Progress on XML and XSLT tools for FPROPS should be documented, with remaining tasks/intentions detailed.&lt;br /&gt;
* FPROPS wiki page updated with information about the modifications completed, new functionality, etc.&lt;br /&gt;
* Convert data from RPP book to C data structures to increase fluid support to 50+ fluids.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;25th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Peng-Robinson EOS now successfully calculates &amp;lt;math&amp;gt;p(V,T)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;V(p,T)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\Delta h(V,T)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\Delta s(V,T)&amp;lt;/math&amp;gt;. Redlich-Kwong EOS also works, but has additional &#039;&#039;&#039;untested&#039;&#039;&#039; support for a,u,g departure functions. Once the two new EOSs are integrated with current ideal and saturation calculations then we&#039;ll have two new EOSs.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;15th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most of the way to a working implementation of the Peng-Robinson equation of state, there are still some issues to be resolved with respect to ideal properties and internal representation of data.&lt;br /&gt;
&lt;br /&gt;
XML data file structure decided upon and a human readable transformation written, still require an input form to create these files. Will also need to modify cToXML to create files for the existing fluids (Note: Will have to be careful with rounding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Having discussed flexibility with regards to equation of state decided on the future structure of the program. Using various structs and unions fprops now has a skeleton capable of supporting several possible equations. &lt;br /&gt;
&lt;br /&gt;
Still to do in this area: Actually implement other EOSs (peng-robinson first), Refactor FPROPS to fit with new way of doing things. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;24th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switched to Mac OS X for development, switched to the Xcode IDE for editing, hopefully the overheads in learning the new system will be worth it. Spoke to John about support for multiple equations of state, created a couple of files ready to start experimenting.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] &amp;amp; [[PengRobinson EOS in FPROPS|Peng Robinson]] cubic EOSs. See {{srcbranch|richard|models/johnpye/fprops/pengrob.c}},&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/pengrob.h}},&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/redkw.c}} and&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/redkw.h}} for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
One of the main challenges here is to write functions which can take any correlation data struct as an input, decide which correlation to use, and return the desired value. After some consultation with John, we&#039;ve decided on a struct containing all of the data and pointers to the various functions. A union is used to enable different types of data to be passed to functions with the same arguments.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/** Enumerate EOS correlations&lt;br /&gt;
 */&lt;br /&gt;
enum eos{&lt;br /&gt;
    pengrob,&lt;br /&gt;
    redkw,&lt;br /&gt;
    helmholtz,&lt;br /&gt;
    mbwr //etc.&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
/** Union for equation of state data&lt;br /&gt;
 */&lt;br /&gt;
typedef union eos_tag{&lt;br /&gt;
    HelmholtzData* helmholtzData;&lt;br /&gt;
    CubicData* cubicData;&lt;br /&gt;
    //etc...&lt;br /&gt;
} EosData;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Definition of a fluid property function pointer&lt;br /&gt;
 */&lt;br /&gt;
typedef double (*propFnPtr)(double,double,const EosData*);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Structure pointing to the necessary data and functions to calculate&lt;br /&gt;
    fluid properties.&lt;br /&gt;
*/&lt;br /&gt;
typedef struct pureFluid{&lt;br /&gt;
	enum eos type;&lt;br /&gt;
    IdealData *idealData;&lt;br /&gt;
	EosData  *eosData;&lt;br /&gt;
	//Pointers to departure functions&lt;br /&gt;
    propFnPtr p_fn;&lt;br /&gt;
    propFnPtr u_fn;&lt;br /&gt;
    propFnPtr h_fn;&lt;br /&gt;
    propFnPtr s_fn;&lt;br /&gt;
    propFnPtr a_fn;&lt;br /&gt;
    propFnPtr cv_fn;&lt;br /&gt;
    propFnPtr cp_fn;&lt;br /&gt;
    propFnPtr w_fn;&lt;br /&gt;
    propFnPtr g_fn;&lt;br /&gt;
} pureFluid;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The structure can be created as follows, and then the function pointers can simply be followed to the correct function.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
    EosData eosData={.cubicData=&amp;amp;cData};&lt;br /&gt;
    pureFluid fluidData={&lt;br /&gt;
        pengrob,&lt;br /&gt;
        &amp;amp;iData,&lt;br /&gt;
        &amp;amp;eosData,&lt;br /&gt;
        //Pointers to departure functions&lt;br /&gt;
        pengrob_p,&lt;br /&gt;
        pengrob_u_depart,&lt;br /&gt;
        pengrob_h_depart,&lt;br /&gt;
        pengrob_s_depart,&lt;br /&gt;
        pengrob_a_depart,&lt;br /&gt;
        pengrob_cv,&lt;br /&gt;
        pengrob_cp,&lt;br /&gt;
        pengrob_w,&lt;br /&gt;
        pengrob_g_depart&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
double p=fluidData.p_fn(T,rho,fluidData.eosData);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2948</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2948"/>
		<updated>2011-08-04T15:21:25Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: New goals&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;4th August 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Helmholtz calculations now work with the new data structures. All fluids and tests have been updated and work (except for ethanol and isohexane who&#039;s tests report small and large errors respectively). Peng-Robinson appears to give almost completely different values to helmholtz even for pressure which should be trivial. This is &#039;&#039;&#039;not&#039;&#039;&#039; expected, and the cause needs investigating before we can move into more FPROPS-esque support for ideal and saturation calculations. John emailed with an updated list of goals which are as follows:&lt;br /&gt;
* Complete integration of PR EOS in FPROPS. All the departure functions should be implemented, tested, working, and connected with the ideal gas functions, for calculation of all the &#039;raw&#039; properties complete and correct.&lt;br /&gt;
* PR EOS should be tested with the current sat.c Akasaka approach for calculating single-fluid saturate mixture states. Algorthim should be working and giving reasonable values, and reasonable error messages if failing.&lt;br /&gt;
* Existing Helmholtz code should be modified to use the new data structures and all existing tests should still be working correctly with no changes having arising from the code refactor.&lt;br /&gt;
* Existing Python and ASCEND bindings need to be updated to work with all the new code, and be operating correctly.&lt;br /&gt;
* Existing build tools should be updated to operate on the new code, and FPROPS built and tested using SCons on all three operating systems.&lt;br /&gt;
* Progress on XML and XSLT tools for FPROPS should be documented, with remaining tasks/intentions detailed.&lt;br /&gt;
* FPROPS wiki page updated with information about the modifications completed, new functionality, etc.&lt;br /&gt;
* Convert data from RPP book to C data structures to increase fluid support to 50+ fluids.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;25th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Peng-Robinson EOS now successfully calculates &amp;lt;math&amp;gt;p(V,T)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;V(p,T)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\Delta h(V,T)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\Delta s(V,T)&amp;lt;/math&amp;gt;. Redlich-Kwong EOS also works, but has additional &#039;&#039;&#039;untested&#039;&#039;&#039; support for a,u,g departure functions. Once the two new EOSs are integrated with current ideal and saturation calculations then we&#039;ll have two new EOSs.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;15th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most of the way to a working implementation of the Peng-Robinson equation of state, there are still some issues to be resolved with respect to ideal properties and internal representation of data.&lt;br /&gt;
&lt;br /&gt;
XML data file structure decided upon and a human readable transformation written, still require an input form to create these files. Will also need to modify cToXML to create files for the existing fluids (Note: Will have to be careful with rounding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Having discussed flexibility with regards to equation of state decided on the future structure of the program. Using various structs and unions fprops now has a skeleton capable of supporting several possible equations. &lt;br /&gt;
&lt;br /&gt;
Still to do in this area: Actually implement other EOSs (peng-robinson first), Refactor FPROPS to fit with new way of doing things. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;24th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switched to Mac OS X for development, switched to the Xcode IDE for editing, hopefully the overheads in learning the new system will be worth it. Spoke to John about support for multiple equations of state, created a couple of files ready to start experimenting.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] &amp;amp; [[PengRobinson EOS in FPROPS|Peng Robinson]] cubic EOSs. See {{srcbranch|richard|models/johnpye/fprops/pengrob.c}},&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/pengrob.h}},&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/redkw.c}} and&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/redkw.h}} for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
One of the main challenges here is to write functions which can take any correlation data struct as an input, decide which correlation to use, and return the desired value. After some consultation with John, we&#039;ve decided on a struct containing all of the data and pointers to the various functions. A union is used to enable different types of data to be passed to functions with the same arguments.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/** Enumerate EOS correlations&lt;br /&gt;
 */&lt;br /&gt;
enum eos{&lt;br /&gt;
    pengrob,&lt;br /&gt;
    redkw,&lt;br /&gt;
    helmholtz,&lt;br /&gt;
    mbwr //etc.&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
/** Union for equation of state data&lt;br /&gt;
 */&lt;br /&gt;
typedef union eos_tag{&lt;br /&gt;
    HelmholtzData* helmholtzData;&lt;br /&gt;
    CubicData* cubicData;&lt;br /&gt;
    //etc...&lt;br /&gt;
} EosData;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Definition of a fluid property function pointer&lt;br /&gt;
 */&lt;br /&gt;
typedef double (*propFnPtr)(double,double,const EosData*);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Structure pointing to the necessary data and functions to calculate&lt;br /&gt;
    fluid properties.&lt;br /&gt;
*/&lt;br /&gt;
typedef struct pureFluid{&lt;br /&gt;
	enum eos type;&lt;br /&gt;
    IdealData *idealData;&lt;br /&gt;
	EosData  *eosData;&lt;br /&gt;
	//Pointers to departure functions&lt;br /&gt;
    propFnPtr p_fn;&lt;br /&gt;
    propFnPtr u_fn;&lt;br /&gt;
    propFnPtr h_fn;&lt;br /&gt;
    propFnPtr s_fn;&lt;br /&gt;
    propFnPtr a_fn;&lt;br /&gt;
    propFnPtr cv_fn;&lt;br /&gt;
    propFnPtr cp_fn;&lt;br /&gt;
    propFnPtr w_fn;&lt;br /&gt;
    propFnPtr g_fn;&lt;br /&gt;
} pureFluid;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The structure can be created as follows, and then the function pointers can simply be followed to the correct function.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
    EosData eosData={.cubicData=&amp;amp;cData};&lt;br /&gt;
    pureFluid fluidData={&lt;br /&gt;
        pengrob,&lt;br /&gt;
        &amp;amp;iData,&lt;br /&gt;
        &amp;amp;eosData,&lt;br /&gt;
        //Pointers to departure functions&lt;br /&gt;
        pengrob_p,&lt;br /&gt;
        pengrob_u_depart,&lt;br /&gt;
        pengrob_h_depart,&lt;br /&gt;
        pengrob_s_depart,&lt;br /&gt;
        pengrob_a_depart,&lt;br /&gt;
        pengrob_cv,&lt;br /&gt;
        pengrob_cp,&lt;br /&gt;
        pengrob_w,&lt;br /&gt;
        pengrob_g_depart&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
double p=fluidData.p_fn(T,rho,fluidData.eosData);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2947</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2947"/>
		<updated>2011-08-04T15:16:01Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;4th August 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Helmholtz calculations now work with the new data structures. All fluids and tests have been updated and work (except for ethanol and isohexane who&#039;s tests report small and large errors respectively). Peng-Robinson appears to give almost completely different values to helmholtz even for pressure which should be trivial. This is &#039;&#039;&#039;not&#039;&#039;&#039; expected, and the cause needs investigating before we can move into more FPROPS-esque support for ideal and saturation calculations. John emailed with an updated list of goals which are as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;25th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Peng-Robinson EOS now successfully calculates &amp;lt;math&amp;gt;p(V,T)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;V(p,T)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\Delta h(V,T)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\Delta s(V,T)&amp;lt;/math&amp;gt;. Redlich-Kwong EOS also works, but has additional &#039;&#039;&#039;untested&#039;&#039;&#039; support for a,u,g departure functions. Once the two new EOSs are integrated with current ideal and saturation calculations then we&#039;ll have two new EOSs.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;15th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most of the way to a working implementation of the Peng-Robinson equation of state, there are still some issues to be resolved with respect to ideal properties and internal representation of data.&lt;br /&gt;
&lt;br /&gt;
XML data file structure decided upon and a human readable transformation written, still require an input form to create these files. Will also need to modify cToXML to create files for the existing fluids (Note: Will have to be careful with rounding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Having discussed flexibility with regards to equation of state decided on the future structure of the program. Using various structs and unions fprops now has a skeleton capable of supporting several possible equations. &lt;br /&gt;
&lt;br /&gt;
Still to do in this area: Actually implement other EOSs (peng-robinson first), Refactor FPROPS to fit with new way of doing things. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;24th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switched to Mac OS X for development, switched to the Xcode IDE for editing, hopefully the overheads in learning the new system will be worth it. Spoke to John about support for multiple equations of state, created a couple of files ready to start experimenting.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] &amp;amp; [[PengRobinson EOS in FPROPS|Peng Robinson]] cubic EOSs. See {{srcbranch|richard|models/johnpye/fprops/pengrob.c}},&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/pengrob.h}},&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/redkw.c}} and&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/redkw.h}} for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
One of the main challenges here is to write functions which can take any correlation data struct as an input, decide which correlation to use, and return the desired value. After some consultation with John, we&#039;ve decided on a struct containing all of the data and pointers to the various functions. A union is used to enable different types of data to be passed to functions with the same arguments.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/** Enumerate EOS correlations&lt;br /&gt;
 */&lt;br /&gt;
enum eos{&lt;br /&gt;
    pengrob,&lt;br /&gt;
    redkw,&lt;br /&gt;
    helmholtz,&lt;br /&gt;
    mbwr //etc.&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
/** Union for equation of state data&lt;br /&gt;
 */&lt;br /&gt;
typedef union eos_tag{&lt;br /&gt;
    HelmholtzData* helmholtzData;&lt;br /&gt;
    CubicData* cubicData;&lt;br /&gt;
    //etc...&lt;br /&gt;
} EosData;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Definition of a fluid property function pointer&lt;br /&gt;
 */&lt;br /&gt;
typedef double (*propFnPtr)(double,double,const EosData*);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Structure pointing to the necessary data and functions to calculate&lt;br /&gt;
    fluid properties.&lt;br /&gt;
*/&lt;br /&gt;
typedef struct pureFluid{&lt;br /&gt;
	enum eos type;&lt;br /&gt;
    IdealData *idealData;&lt;br /&gt;
	EosData  *eosData;&lt;br /&gt;
	//Pointers to departure functions&lt;br /&gt;
    propFnPtr p_fn;&lt;br /&gt;
    propFnPtr u_fn;&lt;br /&gt;
    propFnPtr h_fn;&lt;br /&gt;
    propFnPtr s_fn;&lt;br /&gt;
    propFnPtr a_fn;&lt;br /&gt;
    propFnPtr cv_fn;&lt;br /&gt;
    propFnPtr cp_fn;&lt;br /&gt;
    propFnPtr w_fn;&lt;br /&gt;
    propFnPtr g_fn;&lt;br /&gt;
} pureFluid;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The structure can be created as follows, and then the function pointers can simply be followed to the correct function.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
    EosData eosData={.cubicData=&amp;amp;cData};&lt;br /&gt;
    pureFluid fluidData={&lt;br /&gt;
        pengrob,&lt;br /&gt;
        &amp;amp;iData,&lt;br /&gt;
        &amp;amp;eosData,&lt;br /&gt;
        //Pointers to departure functions&lt;br /&gt;
        pengrob_p,&lt;br /&gt;
        pengrob_u_depart,&lt;br /&gt;
        pengrob_h_depart,&lt;br /&gt;
        pengrob_s_depart,&lt;br /&gt;
        pengrob_a_depart,&lt;br /&gt;
        pengrob_cv,&lt;br /&gt;
        pengrob_cp,&lt;br /&gt;
        pengrob_w,&lt;br /&gt;
        pengrob_g_depart&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
double p=fluidData.p_fn(T,rho,fluidData.eosData);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2925</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2925"/>
		<updated>2011-07-26T08:59:40Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;25th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Peng-Robinson EOS now successfully calculates &amp;lt;math&amp;gt;p(V,T)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;V(p,T)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\Delta h(V,T)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\Delta s(V,T)&amp;lt;/math&amp;gt;. Redlich-Kwong EOS also works, but has additional &#039;&#039;&#039;untested&#039;&#039;&#039; support for a,u,g departure functions. Once the two new EOSs are integrated with current ideal and saturation calculations then we&#039;ll have two new EOSs.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;15th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most of the way to a working implementation of the Peng-Robinson equation of state, there are still some issues to be resolved with respect to ideal properties and internal representation of data.&lt;br /&gt;
&lt;br /&gt;
XML data file structure decided upon and a human readable transformation written, still require an input form to create these files. Will also need to modify cToXML to create files for the existing fluids (Note: Will have to be careful with rounding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Having discussed flexibility with regards to equation of state decided on the future structure of the program. Using various structs and unions fprops now has a skeleton capable of supporting several possible equations. &lt;br /&gt;
&lt;br /&gt;
Still to do in this area: Actually implement other EOSs (peng-robinson first), Refactor FPROPS to fit with new way of doing things. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;24th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switched to Mac OS X for development, switched to the Xcode IDE for editing, hopefully the overheads in learning the new system will be worth it. Spoke to John about support for multiple equations of state, created a couple of files ready to start experimenting.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] &amp;amp; [[PengRobinson EOS in FPROPS|Peng Robinson]] cubic EOSs. See {{srcbranch|richard|models/johnpye/fprops/pengrob.c}},&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/pengrob.h}},&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/redkw.c}} and&lt;br /&gt;
{{srcbranch|richard|models/johnpye/fprops/redkw.h}} for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
One of the main challenges here is to write functions which can take any correlation data struct as an input, decide which correlation to use, and return the desired value. After some consultation with John, we&#039;ve decided on a struct containing all of the data and pointers to the various functions. A union is used to enable different types of data to be passed to functions with the same arguments.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/** Enumerate EOS correlations&lt;br /&gt;
 */&lt;br /&gt;
enum eos{&lt;br /&gt;
    pengrob,&lt;br /&gt;
    redkw,&lt;br /&gt;
    helmholtz,&lt;br /&gt;
    mbwr //etc.&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
/** Union for equation of state data&lt;br /&gt;
 */&lt;br /&gt;
typedef union eos_tag{&lt;br /&gt;
    HelmholtzData* helmholtzData;&lt;br /&gt;
    CubicData* cubicData;&lt;br /&gt;
    //etc...&lt;br /&gt;
} EosData;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Definition of a fluid property function pointer&lt;br /&gt;
 */&lt;br /&gt;
typedef double (*propFnPtr)(double,double,const EosData*);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Structure pointing to the necessary data and functions to calculate&lt;br /&gt;
    fluid properties.&lt;br /&gt;
*/&lt;br /&gt;
typedef struct pureFluid{&lt;br /&gt;
	enum eos type;&lt;br /&gt;
    IdealData *idealData;&lt;br /&gt;
	EosData  *eosData;&lt;br /&gt;
	//Pointers to departure functions&lt;br /&gt;
    propFnPtr p_fn;&lt;br /&gt;
    propFnPtr u_fn;&lt;br /&gt;
    propFnPtr h_fn;&lt;br /&gt;
    propFnPtr s_fn;&lt;br /&gt;
    propFnPtr a_fn;&lt;br /&gt;
    propFnPtr cv_fn;&lt;br /&gt;
    propFnPtr cp_fn;&lt;br /&gt;
    propFnPtr w_fn;&lt;br /&gt;
    propFnPtr g_fn;&lt;br /&gt;
} pureFluid;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The structure can be created as follows, and then the function pointers can simply be followed to the correct function.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
    EosData eosData={.cubicData=&amp;amp;cData};&lt;br /&gt;
    pureFluid fluidData={&lt;br /&gt;
        pengrob,&lt;br /&gt;
        &amp;amp;iData,&lt;br /&gt;
        &amp;amp;eosData,&lt;br /&gt;
        //Pointers to departure functions&lt;br /&gt;
        pengrob_p,&lt;br /&gt;
        pengrob_u_depart,&lt;br /&gt;
        pengrob_h_depart,&lt;br /&gt;
        pengrob_s_depart,&lt;br /&gt;
        pengrob_a_depart,&lt;br /&gt;
        pengrob_cv,&lt;br /&gt;
        pengrob_cp,&lt;br /&gt;
        pengrob_w,&lt;br /&gt;
        pengrob_g_depart&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
double p=fluidData.p_fn(T,rho,fluidData.eosData);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2890</id>
		<title>PengRobinson EOS in FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2890"/>
		<updated>2011-07-22T15:00:05Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Overview - fixed elusive mistake which has been bugging me for HOURS.*/&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{task}}&lt;br /&gt;
Work on this is went on as a part of GSoC 2010 (Project [[User:Ankitml|Ankit]]) and continues as part of GSoC 2011 ([[User:richardTowers|Richard Towers]]).&lt;br /&gt;
See also [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Comments and suggestions are welcome&lt;br /&gt;
==Overview==&lt;br /&gt;
The Peng-Robinson EOS is a cubic equation of state in that it contains volume terms to the third power. It is usually expressed to give pressure in terms of temperature and molar volume &amp;lt;math&amp;gt;{\bar v}&amp;lt;/math&amp;gt;:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
p =\frac{{\bar R} T}{{\bar v}-b}-\frac{a(T)}{{\bar v}({\bar v}+b)+b({\bar v}-b)}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
&lt;br /&gt;
a(T) &amp;amp;= 0.45724  \frac{{\bar R}^2{T_c}^2}{P_c} \alpha \left(T \right) \\&lt;br /&gt;
&lt;br /&gt;
\alpha &amp;amp;= \left( 1+\kappa \left( 1-\sqrt{\frac{T}{T_c}} \right) \right)^2 \\&lt;br /&gt;
 &lt;br /&gt;
\kappa &amp;amp;= 0.37464+1.54226\omega - 0.26992\omega^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is sometimes more convenient to express the equation as a cubic polynomial in terms of compressibility factor &amp;lt;math&amp;gt;Z=\frac{PV_m}{RT}&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
Z^3+(-1+B)Z^2+(A-3B^2-2B)Z-AB+B^2+B^3=0&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
in which&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A &amp;amp;= \frac{a \left(T \right) p}{({\bar R} T)^2} \\&lt;br /&gt;
B &amp;amp;= \frac{b}{{\bar R} T}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Departure Functions==&lt;br /&gt;
Departure functions represent the departure of the &#039;&#039;real&#039;&#039; properties from the &#039;&#039;ideal&#039;&#039; properties - i.e the properties of a fluid at zero pressure or infinite molar volume.&lt;br /&gt;
The departure functions of the Peng-Robinson equation of state are as follows:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
H_{m}-H_{m}^{\text{ideal}}&amp;amp;={\bar R} T(Z-1)+\frac{T\left(\frac{da}{dT}\right)-a}{2\sqrt{2}b}\ln\left[\frac{Z+(1+\sqrt{2})B}{Z+(1-\sqrt{2})B}\right] \\&lt;br /&gt;
&lt;br /&gt;
S_{m}-S_{m}^{\text{ideal}}&amp;amp;={\bar R} \ln (Z-B)+\frac{\frac{da}{dT}}{2\sqrt{2}b}\ln\left[\frac{Z+(1+\sqrt{2})B}{Z+(1-\sqrt{2})B}\right]&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Clearly to evaluate these functions we need to be able to evaluate &amp;lt;math&amp;gt;\frac{da}{dT}&amp;lt;/math&amp;gt;: (CHECK THIS)&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{da}{dT}=- 0.45724 \frac{T_c {\bar R}^{2}}{p_c} \kappa \left(\sqrt{\frac{T_c}{T}} - 1\right)&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Sandler seems to have:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{da}{dT}=- 0.45724 \frac{T_c {\bar R}^{2}}{p_c} \kappa \left(\sqrt{\frac{\alpha}{T T_c}} \right)&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Comparisons==&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2884</id>
		<title>PengRobinson EOS in FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2884"/>
		<updated>2011-07-17T20:32:21Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Departure Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{task}}&lt;br /&gt;
Work on this is went on as a part of GSoC 2010 (Project [[User:Ankitml|Ankit]]) and continues as part of GSoC 2011 ([[User:richardTowers|Richard Towers]]).&lt;br /&gt;
See also [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Comments and suggestions are welcome&lt;br /&gt;
==Overview==&lt;br /&gt;
The Peng-Robinson EOS is a cubic equation of state in that it contains volume terms to the third power. It is usually expressed to give Pressure in terms of Temperature and Molar Volume:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
P =\frac{RT}{V_m-b}-\frac{a(T)}{V_m(V_m+b)+b(V_m-b)}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
&lt;br /&gt;
a(T)&amp;amp;=0.45724  \frac{R^2{T_c}^2}{P_c} \left(1+\kappa \left(1-\sqrt{\frac{T}{T_c}} \right) \right)^2 \\&lt;br /&gt;
&lt;br /&gt;
\kappa&amp;amp;=0.37464+1.54226\omega - 0.26992\omega^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is sometimes more convenient to express the equation as a cubic polynomial in terms of compressibility factor &amp;lt;math&amp;gt;Z=\frac{PV_m}{RT}&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
Z^3+(-1-B)Z^2+(A-3B^2-2B)Z-AB+B^2+B^3=0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
in which&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A=\frac{aP}{(RT)^2} \\&lt;br /&gt;
B=\frac{bP}{RT}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Departure Functions==&lt;br /&gt;
Departure functions represent the departure of the &#039;&#039;real&#039;&#039; properties from the &#039;&#039;ideal&#039;&#039; properties - i.e the properties of a fluid at zero pressure or infinite molar volume.&lt;br /&gt;
The departure functions of the Peng-Robinson equation of state are as follows:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
H_{m}-H_{m}^{\text{ideal}}&amp;amp;=RT(Z-1)+\frac{T\left(\frac{da}{dT}\right)-a}{2\sqrt{2}b}\ln\left[\frac{Z+(1+\sqrt{2})B}{Z+(1-\sqrt{2})B}\right] \\&lt;br /&gt;
&lt;br /&gt;
S_{m}-S_{m}^{\text{ideal}}&amp;amp;=R\ln (Z-B)+\frac{\frac{da}{dT}}{2\sqrt{2}b}\ln\left[\frac{Z+(1+\sqrt{2})B}{Z+(1-\sqrt{2})B}\right]&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Clearly to evaluate these functions we need to be able to evaluate &amp;lt;math&amp;gt;\frac{da}{dT}&amp;lt;/math&amp;gt;: (CHECK THIS)&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{da}{dT}=- 0.45724 \frac{T_c R^{2}}{P_c} \kappa \left(\sqrt{\frac{T_c}{T}} - 1\right)&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Sandler seems to have:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{da}{dT}=- 0.45724 \frac{T_c R^{2}}{P_c} \kappa \left(\sqrt{\frac{\alpha}{T T_c}} \right)&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\alpha=\left( 1+\kappa \left( 1-\sqrt{\frac{T}{T_c}} \right) \right)^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Comparisons==&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2879</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2879"/>
		<updated>2011-07-15T16:36:44Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;15th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most of the way to a working implementation of the Peng-Robinson equation of state, there are still some issues to be resolved with respect to ideal properties and internal representation of data.&lt;br /&gt;
&lt;br /&gt;
XML data file structure decided upon and a human readable transformation written, still require an input form to create these files. Will also need to modify cToXML to create files for the existing fluids (Note: Will have to be careful with rounding).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Having discussed flexibility with regards to equation of state decided on the future structure of the program. Using various structs and unions fprops now has a skeleton capable of supporting several possible equations. &lt;br /&gt;
&lt;br /&gt;
Still to do in this area: Actually implement other EOSs (peng-robinson first), Refactor FPROPS to fit with new way of doing things. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;24th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switched to Mac OS X for development, switched to the Xcode IDE for editing, hopefully the overheads in learning the new system will be worth it. Spoke to John about support for multiple equations of state, created a couple of files ready to start experimenting.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] &amp;amp; [[PengRobinson EOS in FPROPS|Peng Robinson]] cubic EOSs. See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup redkw.c], [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup redkw.h], &lt;br /&gt;
[http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
One of the main challenges here is to write functions which can take any correlation data struct as an input, decide which correlation to use, and return the desired value. After some consultation with John, we&#039;ve decided on a struct containing all of the data and pointers to the various functions. A union is used to enable different types of data to be passed to functions with the same arguments.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/** Enumerate EOS correlations&lt;br /&gt;
 */&lt;br /&gt;
enum eos{&lt;br /&gt;
    pengrob,&lt;br /&gt;
    redkw,&lt;br /&gt;
    helmholtz,&lt;br /&gt;
    mbwr //etc.&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
/** Union for equation of state data&lt;br /&gt;
 */&lt;br /&gt;
typedef union eos_tag{&lt;br /&gt;
    HelmholtzData* helmholtzData;&lt;br /&gt;
    CubicData* cubicData;&lt;br /&gt;
    //etc...&lt;br /&gt;
} EosData;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Definition of a fluid property function pointer&lt;br /&gt;
 */&lt;br /&gt;
typedef double (*propFnPtr)(double,double,const EosData*);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Structure pointing to the necessary data and functions to calculate&lt;br /&gt;
    fluid properties.&lt;br /&gt;
*/&lt;br /&gt;
typedef struct pureFluid{&lt;br /&gt;
	enum eos type;&lt;br /&gt;
    IdealData *idealData;&lt;br /&gt;
	EosData  *eosData;&lt;br /&gt;
	//Pointers to departure functions&lt;br /&gt;
    propFnPtr p_fn;&lt;br /&gt;
    propFnPtr u_fn;&lt;br /&gt;
    propFnPtr h_fn;&lt;br /&gt;
    propFnPtr s_fn;&lt;br /&gt;
    propFnPtr a_fn;&lt;br /&gt;
    propFnPtr cv_fn;&lt;br /&gt;
    propFnPtr cp_fn;&lt;br /&gt;
    propFnPtr w_fn;&lt;br /&gt;
    propFnPtr g_fn;&lt;br /&gt;
} pureFluid;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The structure can be created as follows, and then the function pointers can simply be followed to the correct function.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
    EosData eosData={.cubicData=&amp;amp;cData};&lt;br /&gt;
    pureFluid fluidData={&lt;br /&gt;
        pengrob,&lt;br /&gt;
        &amp;amp;iData,&lt;br /&gt;
        &amp;amp;eosData,&lt;br /&gt;
        //Pointers to departure functions&lt;br /&gt;
        pengrob_p,&lt;br /&gt;
        pengrob_u_depart,&lt;br /&gt;
        pengrob_h_depart,&lt;br /&gt;
        pengrob_s_depart,&lt;br /&gt;
        pengrob_a_depart,&lt;br /&gt;
        pengrob_cv,&lt;br /&gt;
        pengrob_cp,&lt;br /&gt;
        pengrob_w,&lt;br /&gt;
        pengrob_g_depart&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
double p=fluidData.p_fn(T,rho,fluidData.eosData);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2869</id>
		<title>PengRobinson EOS in FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2869"/>
		<updated>2011-07-14T13:43:33Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Departure Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{task}}&lt;br /&gt;
Work on this is went on as a part of GSoC 2010 (Project [[User:Ankitml|Ankit]]) and continues as part of GSoC 2011 ([[User:richardTowers|Richard Towers]]).&lt;br /&gt;
See also [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Comments and suggestions are welcome&lt;br /&gt;
==Overview==&lt;br /&gt;
The Peng-Robinson EOS is a cubic equation of state in that it contains volume terms to the third power. It is usually expressed to give Pressure in terms of Temperature and Molar Volume:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
P=\frac{RT}{V_m-b}-\frac{a(T)}{V_m(V_m+b)+b(V_m-b)}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
It is sometimes more convenient to express the equation in terms of compressibility factor:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
Z^3+(-1-B)Z^2+(A-3B^2-2B)Z-AB+B^2+B^3=0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The various fluid-dependant constants and variables in the above are defined as:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
a(T)=0.45724\times \frac{R^2{T_c}^2}{P_c} \left(1+\kappa \left(1-\sqrt{\frac{T}{T_c}} \right) \right)^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\kappa=0.37464+1.54226\omega - 0.26992\omega^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A=\frac{aP}{(RT)^2}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
B=\frac{bP}{RT}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
By definition:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
Z=\frac{PV_m}{RT}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
==Departure Functions==&lt;br /&gt;
Departure functions represent the departure of the &#039;&#039;real&#039;&#039; properties from the &#039;&#039;ideal&#039;&#039; properties - i.e the properties of a fluid at zero pressure or infinite molar volume.&lt;br /&gt;
The departure functions of the Peng-Robinson equation of state are as follows:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
H_{m}-H_{m}^{\text{Ideal Gas}}=RT(Z-1)+\frac{T\left(\frac{da}{dT}\right)-a}{2\sqrt{2}b}\ln\left[\frac{Z+(1+\sqrt{2})B}{Z+(1-\sqrt{2})B}\right]&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
S_{m}-S_{m}^{\text{Ideal Gas}}=R\ln (Z-B)+\frac{\frac{da}{dT}}{2\sqrt{2}b}\ln\left[\frac{Z+(1+\sqrt{2})B}{Z+(1-\sqrt{2})B}\right]&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Clearly to evaluate these functions we need to be able to evaluate &amp;lt;math&amp;gt;\frac{da}{dT}&amp;lt;/math&amp;gt;:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{da}{dT}=-\frac{\left(0.45724T_{c}R^{2}\kappa\left(1-\sqrt{\frac{T}{T_{c}}}\right)\right)}{P_{c}\sqrt{\frac{T}{T_{c}}}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Comparisons==&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2868</id>
		<title>PengRobinson EOS in FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2868"/>
		<updated>2011-07-14T12:00:22Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Departure Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{task}}&lt;br /&gt;
Work on this is went on as a part of GSoC 2010 (Project [[User:Ankitml|Ankit]]) and continues as part of GSoC 2011 ([[User:richardTowers|Richard Towers]]).&lt;br /&gt;
See also [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Comments and suggestions are welcome&lt;br /&gt;
==Overview==&lt;br /&gt;
The Peng-Robinson EOS is a cubic equation of state in that it contains volume terms to the third power. It is usually expressed to give Pressure in terms of Temperature and Molar Volume:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
P=\frac{RT}{V_m-b}-\frac{a(T)}{V_m(V_m+b)+b(V_m-b)}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
It is sometimes more convenient to express the equation in terms of compressibility factor:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
Z^3+(-1-B)Z^2+(A-3B^2-2B)Z-AB+B^2+B^3=0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The various fluid-dependant constants and variables in the above are defined as:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
a(T)=0.45724\times \frac{R^2{T_c}^2}{P_c} \left(1+\kappa \left(1-\sqrt{\frac{T}{T_c}} \right) \right)^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\kappa=0.37464+1.54226\omega - 0.26992\omega^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A=\frac{aP}{(RT)^2}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
B=\frac{bP}{RT}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
By definition:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
Z=\frac{PV_m}{RT}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
==Departure Functions==&lt;br /&gt;
Departure functions represent the departure of the &#039;&#039;real&#039;&#039; properties from the &#039;&#039;ideal&#039;&#039; properties - i.e the properties of a fluid at zero pressure or infinite molar volume.&lt;br /&gt;
The departure functions of the Peng-Robinson equation of state are as follows:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
H_{m}-H_{m}^{\text{Ideal Gas}}=RT(Z-1)+\frac{T\left(\frac{da}{dT}\right)-a}{2\sqrt{2b}}\ln\left[\frac{Z+(1+\sqrt{2})B}{Z+(1-\sqrt{2})B}\right]&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
S_{m}-S_{m}^{\text{Ideal Gas}}=R\ln (Z-B)+\frac{\frac{da}{dT}}{2\sqrt{2b}}\ln\left[\frac{Z+(1+\sqrt{2})B}{Z+(1-\sqrt{2})B}\right]&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Clearly to evaluate these functions we need to be able to evaluate &amp;lt;math&amp;gt;\frac{da}{dT}&amp;lt;/math&amp;gt;:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{da}{dT}=-\frac{\left(0.45724T_{c}R^{2}\kappa\left(1-\sqrt{\frac{T}{T_{c}}}\right)\right)}{P_{c}\sqrt{\frac{T}{T_{c}}}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Comparisons==&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2867</id>
		<title>PengRobinson EOS in FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2867"/>
		<updated>2011-07-14T10:50:06Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Overview - Rewritten to get my head straight...*/&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{task}}&lt;br /&gt;
Work on this is went on as a part of GSoC 2010 (Project [[User:Ankitml|Ankit]]) and continues as part of GSoC 2011 ([[User:richardTowers|Richard Towers]]).&lt;br /&gt;
See also [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Comments and suggestions are welcome&lt;br /&gt;
==Overview==&lt;br /&gt;
The Peng-Robinson EOS is a cubic equation of state in that it contains volume terms to the third power. It is usually expressed to give Pressure in terms of Temperature and Molar Volume:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
P=\frac{RT}{V_m-b}-\frac{a(T)}{V_m(V_m+b)+b(V_m-b)}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
It is sometimes more convenient to express the equation in terms of compressibility factor:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
Z^3+(-1-B)Z^2+(A-3B^2-2B)Z-AB+B^2+B^3=0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The various fluid-dependant constants and variables in the above are defined as:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
a(T)=0.45724\times \frac{R^2{T_c}^2}{P_c} \left(1+\kappa \left(1-\sqrt{\frac{T}{T_c}} \right) \right)^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\kappa=0.37464+1.54226\omega - 0.26992\omega^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A=\frac{aP}{(RT)^2}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
B=\frac{bP}{RT}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
By definition:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
Z=\frac{PV_m}{RT}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
==Departure Functions==&lt;br /&gt;
Departure functions represent the departure of the &#039;&#039;real&#039;&#039; properties from the &#039;&#039;ideal&#039;&#039; properties - i.e the properties of a fluid at zero pressure or infinite molar volume.&lt;br /&gt;
The departure functions of the Peng-Robinson equation of state are as follows:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
H_{m}-H_{m}^{\text{Ideal Gas}}=RT(Z-1)+\frac{T\left(\frac{da}{dT}\right)-a}{2\sqrt{2b}}\ln\left[\frac{Z+(1+\sqrt{2})B}{Z+(1-\sqrt{2})B}\right]&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
S_{m}-S_{m}^{\text{Ideal Gas}}=R\ln (Z-B)+\frac{\frac{da}{dT}}{2\sqrt{2b}}\ln\left[\frac{Z+(1+\sqrt{2})B}{Z+(1-\sqrt{2})B}\right]&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Clearly to evaluate these functions we need to be able to evaluate &amp;lt;math&amp;gt;\frac{da}{dT}&amp;lt;/math&amp;gt;:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{da}{dT}=...&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Comparisons==&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2813</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2813"/>
		<updated>2011-07-09T21:50:03Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Goals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;4th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Having discussed flexibility with regards to equation of state decided on the future structure of the program. Using various structs and unions fprops now has a skeleton capable of supporting several possible equations. &lt;br /&gt;
&lt;br /&gt;
Still to do in this area: Actually implement other EOSs (peng-robinson first), Refactor FPROPS to fit with new way of doing things. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;24th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switched to Mac OS X for development, switched to the Xcode IDE for editing, hopefully the overheads in learning the new system will be worth it. Spoke to John about support for multiple equations of state, created a couple of files ready to start experimenting.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] &amp;amp; [[PengRobinson EOS in FPROPS|Peng Robinson]] cubic EOSs. See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup redkw.c], [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup redkw.h], &lt;br /&gt;
[http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
One of the main challenges here is to write functions which can take any correlation data struct as an input, decide which correlation to use, and return the desired value. After some consultation with John, we&#039;ve decided on a struct containing all of the data and pointers to the various functions. A union is used to enable different types of data to be passed to functions with the same arguments.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/** Enumerate EOS correlations&lt;br /&gt;
 */&lt;br /&gt;
enum eos{&lt;br /&gt;
    pengrob,&lt;br /&gt;
    redkw,&lt;br /&gt;
    helmholtz,&lt;br /&gt;
    mbwr //etc.&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
/** Union for equation of state data&lt;br /&gt;
 */&lt;br /&gt;
typedef union eos_tag{&lt;br /&gt;
    HelmholtzData* helmholtzData;&lt;br /&gt;
    CubicData* cubicData;&lt;br /&gt;
    //etc...&lt;br /&gt;
} EosData;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Definition of a fluid property function pointer&lt;br /&gt;
 */&lt;br /&gt;
typedef double (*propFnPtr)(double,double,const EosData*);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Structure pointing to the necessary data and functions to calculate&lt;br /&gt;
    fluid properties.&lt;br /&gt;
*/&lt;br /&gt;
typedef struct pureFluid{&lt;br /&gt;
	enum eos type;&lt;br /&gt;
    IdealData *idealData;&lt;br /&gt;
	EosData  *eosData;&lt;br /&gt;
	//Pointers to departure functions&lt;br /&gt;
    propFnPtr p_fn;&lt;br /&gt;
    propFnPtr u_fn;&lt;br /&gt;
    propFnPtr h_fn;&lt;br /&gt;
    propFnPtr s_fn;&lt;br /&gt;
    propFnPtr a_fn;&lt;br /&gt;
    propFnPtr cv_fn;&lt;br /&gt;
    propFnPtr cp_fn;&lt;br /&gt;
    propFnPtr w_fn;&lt;br /&gt;
    propFnPtr g_fn;&lt;br /&gt;
} pureFluid;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The structure can be created as follows, and then the function pointers can simply be followed to the correct function.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
    EosData eosData={.cubicData=&amp;amp;cData};&lt;br /&gt;
    pureFluid fluidData={&lt;br /&gt;
        pengrob,&lt;br /&gt;
        &amp;amp;iData,&lt;br /&gt;
        &amp;amp;eosData,&lt;br /&gt;
        //Pointers to departure functions&lt;br /&gt;
        pengrob_p,&lt;br /&gt;
        pengrob_u_depart,&lt;br /&gt;
        pengrob_h_depart,&lt;br /&gt;
        pengrob_s_depart,&lt;br /&gt;
        pengrob_a_depart,&lt;br /&gt;
        pengrob_cv,&lt;br /&gt;
        pengrob_cp,&lt;br /&gt;
        pengrob_w,&lt;br /&gt;
        pengrob_g_depart&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
double p=fluidData.p_fn(T,rho,fluidData.eosData);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Porting_to_Mac&amp;diff=2811</id>
		<title>Porting to Mac</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Porting_to_Mac&amp;diff=2811"/>
		<updated>2011-07-07T21:56:48Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Building Native GTK+ - There are binaries now!*/&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ASCEND now &#039;&#039;&#039;runs successfully on Mac&#039;&#039;&#039; without problems. The remaining work is to package ASCEND as an installer or as an &#039;app&#039;, and to fix it so that it connects with Apple Events for opening files from the Finder, etc -- see below for details.&lt;br /&gt;
{{task}}&lt;br /&gt;
&lt;br /&gt;
== Installing the necessary tools ==&lt;br /&gt;
&lt;br /&gt;
You should install the following tools in order to be able to build ASCEND on Mac:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;XCode&#039;&#039;&#039; from your OS X CD.&lt;br /&gt;
* &#039;&#039;&#039;gfortran&#039;&#039;&#039;. Use gfortran-macosx-x86.dmg from http://gcc.gnu.org/wiki/GFortranBinaries&lt;br /&gt;
* &#039;&#039;&#039;scons&#039;&#039;&#039; by typing &#039;sudo easy_install scons&#039;&lt;br /&gt;
* &#039;&#039;&#039;swig&#039;&#039;&#039;. We have version 1.3.31, which comes with Xcode (confirmed as of Xcode 4.02)&lt;br /&gt;
* &#039;&#039;&#039;subversion&#039;&#039;&#039; (see [[VersionManagement|here]] or try the [http://www.open.collab.net/downloads/community/OpenCollabNet OpenCollabNet version])&lt;br /&gt;
&lt;br /&gt;
== Building ==&lt;br /&gt;
&lt;br /&gt;
When the above tools are installed and you have obtained the source code either from a file release or from our [[VersionManagement|code repository]], now you should be able to build ASCEND. Try just running &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sh&amp;quot;&amp;gt;scons&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There should be some output to tell you if you&#039;re missing any important components. Otherwise, you should then be able to run &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sh&amp;quot;&amp;gt;./test.py TestSolver.testlog10&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you should see a message saying &#039;OK&#039;. At this stage you have a complete working copy of ASCEND, possibly minus some of the userful [[solvers]] like [[IPOPT]], [[IDA]], [[CONOPT]]. The other important thing that you&#039;re missing is the GTK+ GUI library that allows ASCEND to present its user interface.&lt;br /&gt;
&lt;br /&gt;
== Building Native GTK+ ==&lt;br /&gt;
=== The Easy Way ===&lt;br /&gt;
&lt;br /&gt;
The good people who develop PyGTK have produced a pre-compiled package: [http://afb.users.sourceforge.net/zero-install/PyGTK.pkg PyGTK.pkg].&lt;br /&gt;
&lt;br /&gt;
: As of July 2011 this is in testing, it worked perfectly for me though. [[User:RichardTowers|RichardTowers]] 21:56, 7 July 2011 (UTC)&lt;br /&gt;
&lt;br /&gt;
=== The Hard Way ===&lt;br /&gt;
&lt;br /&gt;
ASCEND uses GTK+ for its GUI. This is a cross-platform GUI library that works primarily on Linux but is also supported on Windows and Mac OS X. For Mac, it is currently necessary to build it from source, following the [http://sourceforge.net/apps/trac/gtk-osx/wiki/Build instructions from the GTK-OSX project].&lt;br /&gt;
&lt;br /&gt;
Steps are something like this:&lt;br /&gt;
&lt;br /&gt;
* Make sure you have Xcode, subversion and git installed, as outlined at http://sourceforge.net/apps/trac/gtk-osx/wiki/Build&lt;br /&gt;
* Download the script [https://raw.github.com/jralls/gtk-osx-build/master/gtk-osx-build-setup.sh] and run it using &#039;&amp;lt;tt&amp;gt;sh gtk-osx-build-setup.sh&amp;lt;/tt&amp;gt;&#039; (no quotes).&lt;br /&gt;
* Edit the resulting &amp;lt;tt&amp;gt;~/.jhbuildrc-custom&amp;lt;/tt&amp;gt; file, adding &#039;&amp;lt;tt&amp;gt;build_policy = &amp;quot;updated-deps&amp;quot;&amp;lt;/tt&amp;gt;&#039; as a line at the end of the file (no single quotes).&lt;br /&gt;
* Set up an alias that will run &amp;lt;tt&amp;gt;jhbuild&amp;lt;/tt&amp;gt; in a stripped down environment that does not contain any reference to the Fink (/sw/...) or MacPorts (?) directories (if you have them): A good option is to set&lt;br /&gt;
:&amp;lt;pre&amp;gt;alias jhbuild=&amp;quot;PATH=/opt/subversion/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:~/gtk/inst ~/.local/bin/jhbuild&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
* According to the [http://sourceforge.net/apps/trac/gtk-osx/wiki/Build description on Sourceforge], build PyGTK as follows:&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild bootstrap&amp;lt;/tt&amp;gt;&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild build meta-gtk-osx-bootstrap&amp;lt;/tt&amp;gt;&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild build meta-gtk-osx-core&amp;lt;/tt&amp;gt;&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild pygtk&amp;lt;/tt&amp;gt; (or [http://sourceforge.net/apps/trac/gtk-osx/wiki/PyGtk should it be]: &amp;lt;tt&amp;gt;meta-gtk-osx-python&amp;lt;/tt&amp;gt; ?)&lt;br /&gt;
&lt;br /&gt;
You can now test that PyGTK is working by running &amp;lt;tt&amp;gt;python&amp;lt;/tt&amp;gt; and checking that &amp;lt;tt&amp;gt;import gtk&amp;lt;/tt&amp;gt; doesn&#039;t cause errors.&lt;br /&gt;
&lt;br /&gt;
If that&#039;s working, you should be able to use your working copy of ASCEND (as above) to run &amp;lt;tt&amp;gt;pygtk/ascdev&amp;lt;/tt&amp;gt;. This should open ASCEND, but you may have to command-tab to the correct window, as it won&#039;t pop to the front automatically.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a screenshot of ASCEND on Native GTK-Quartz on OS X!&lt;br /&gt;
&lt;br /&gt;
[[Image:ASCENDnativeOSX.png|thumb|300px|none|Screenshot of the PyGTK GUI running on Mac OSX with GTK-OSX (Quartz/Native GTK)]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: currently, the ASCEND GUI on Mac still behaves much the same as it would on Windows or Linux; we haven&#039;t yet &#039;mackified&#039; the keyboard shortcuts and menu layout. This will be using the &#039;ige-mac-integration&#039; library that&#039;s also provided by the GTK-OSX project.&lt;br /&gt;
&lt;br /&gt;
Note that allegedly it is also possible to build native GTK using macports, but we haven&#039;t yet tried that.&lt;br /&gt;
&lt;br /&gt;
== Building the Tcl/Tk GUI ==&lt;br /&gt;
&lt;br /&gt;
No work yet to determine what will be required to the Tcl/Tk GUI running on Mac. &lt;br /&gt;
&lt;br /&gt;
It &#039;&#039;may&#039;&#039; be fairly straightforward to get this GUI running, possibly using these binaries for Tcl/Tk:&lt;br /&gt;
&lt;br /&gt;
* http://www.categorifiedcoder.info/tcltk/&lt;br /&gt;
&lt;br /&gt;
== Preparing for distribution ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The following part is still under development.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Once GTK is build using jhbuild above, we need to re-package ASCEND in the form of a &#039;normal&#039; Mac OS X application. To do this,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;a4c&amp;quot;&amp;gt;cd ~/ascend&lt;br /&gt;
python scons/installgtk.py&lt;br /&gt;
scons install INSTALL_PREFIX=~/ascinst&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Those steps will first copy GTK and associated files into &amp;lt;tt&amp;gt;dist/PyGTK.bundle&amp;lt;/tt&amp;gt;. Next, they will copy all the ASCEND files as well as PyGTK.bundle into ~/ascinst/ASCEND.app. Other files will be added to the ~/ascint folder, in preparation for making a .dmg disk image that will be suitable for distribution.&lt;br /&gt;
&lt;br /&gt;
Currently, we are still working out some final bugs with the creation of the PyGTK.bundle, so this final step doesn&#039;t entirely work.&lt;br /&gt;
&lt;br /&gt;
== Development notes ==&lt;br /&gt;
&lt;br /&gt;
=== Packaging and distribution ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s recommended for most Mac applications that everything be distributed as an Application Bundle that just be dragged by the user into their Applications folder. This is certainly possible with ASCEND, but a problem is that the ASCEND Model Library is something that we would like users to see and interact with. We would like users to be able to see these folders and their contents easily using the Finder. Nesting the files within an Application bundle makes this rather difficult.&lt;br /&gt;
&lt;br /&gt;
One option would be for the ASCEND application to unpack its model library to ~/Library/Application Support/ASCEND when the program is first run. This would require Python scripting, and would not be compatible with a shared installation of the Tcl/Tk GUI on the same system.&lt;br /&gt;
&lt;br /&gt;
Another option would be to install the model library in /Library/Application Support/ASCEND/Models. This seems to be the right way forward, but it means that ASCEND can no longer just be dragged to the Applications folder to be installed. Instead, it would need an Installer to place the necessary files on the user&#039;s system. That&#039;s quite desirable, though, because such an installer could also check that the user has the correct versions of Python, GTK and PyGTK already installed on the system, and could even possibly download and install them first if required.&lt;br /&gt;
&lt;br /&gt;
It&#039;s worth noting that Mac editors like TextEdit can&#039;t peer into Application Bundles, but non-Mac editors like gedit can do so... they don&#039;t impose the same restriction on entering inside such bundles.&lt;br /&gt;
&lt;br /&gt;
As a first attempt for getting everything running, it seems wise to take the simple application bundle approach.&lt;br /&gt;
&lt;br /&gt;
We&#039;re not currently proposing to provide the Tcl/Tk GUI for Mac. This is a whole separate packaging problem.&lt;br /&gt;
&lt;br /&gt;
We&#039;re not currently proposing to package libascend as a Framework for Mac, although that is an option, and would be appropriate if attempting to provide both Tcl/Tk and PyGTK GUIs on the same machine, and to make it easier for users to develop their own solvers, etc, on that platform.&lt;br /&gt;
&lt;br /&gt;
The general opinion on GTK is that we should include it within out Application Bundle. From the linux point of view, this is terribly inefficient, but such things are standard practise on Mac, and we should respect that in the first instance.&lt;br /&gt;
&lt;br /&gt;
The alternative of providing ASCEND to the Mac community as a Fink package was considered, however, according to Fink developers, the current &#039;stable&#039; repository for Fink is very stagnant, so we are unlikely to be able to use that as a means for distribution. &lt;br /&gt;
&lt;br /&gt;
If we want to distribute ASCEND as a multi-component thing (libascend framework, Tcl/Tk GUI, PyGTK, model library all separate) then we would need to use the Apple tool, &#039;&#039;PackageMaker&#039;&#039;, which allows developers to produce their own .pkg installers, apparently&amp;lt;ref&amp;gt;http://s.sudre.free.fr/Stuff/PackageMaker_Howto.html&amp;lt;/ref&amp;gt;. It is preferable to distribute a simple Application Bundle within a .dmg Disk Image.&lt;br /&gt;
&lt;br /&gt;
=== Creating ASCEND.app ===&lt;br /&gt;
&lt;br /&gt;
To create the ASCEND application bundle&lt;br /&gt;
&lt;br /&gt;
* scons -j2 install INSTALL_PREFIX=~/ascinst&lt;br /&gt;
* The bundle will appear as ~/ascinst/ASCEND.app&lt;br /&gt;
* TODO: add necessary GTK files to the .app!&lt;br /&gt;
* follow instructions below to turn it into a redistributable disk image&lt;br /&gt;
&lt;br /&gt;
The file {{src|mac/Info.plist}} contains all the key-value stuff describing the application. We had to make changes to {{src|pygtk/ascend.in}} to accommodate the particularities of the Mac platform, too.&lt;br /&gt;
&lt;br /&gt;
=== Creating a Disk Image (ASCEND-0.9.X.dmg) ===&lt;br /&gt;
&lt;br /&gt;
Some instructions are here: http://www.wikihow.com/Make-a-DMG-File-on-a-Mac&lt;br /&gt;
&lt;br /&gt;
In summary:&lt;br /&gt;
&lt;br /&gt;
* use the Applications/Utilities/Disk Utility application&lt;br /&gt;
* create a new image large enough for your needs&lt;br /&gt;
* mount and open the image&lt;br /&gt;
* from the Terminal, run scons -j2 install INSTALL_PREFIX=(location of your disk image folder)&lt;br /&gt;
* set the folder background image to ~/ascend/mac/folder-background.png&lt;br /&gt;
* arrange the files so that they look OK, the folder-background arrow should point from the ASCEND.app to the Applications folder alias.&lt;br /&gt;
* return to the disk image program&lt;br /&gt;
* click &#039;convert&#039; and convert to a compressed image (OK to overwrite)&lt;br /&gt;
* all done, you can double-click the image file now, and it should mount and appear as you wanted it.&lt;br /&gt;
&lt;br /&gt;
=== Finding all the GTK files ===&lt;br /&gt;
&lt;br /&gt;
To create a safely porting ASCEND.app, we need to embed all of GTK into the application bundle. The above application won&#039;t be complete until we achieve that.&lt;br /&gt;
&lt;br /&gt;
Looks like some Python packages called [http://docs.python.org/library/modulefinder.html modulefinder] (built-in to Python) or [http://pypi.python.org/pypi/modulegraph/ modulegraph] (external) may be able to help with locating all the necessary files for satisfying Python &#039;import&#039; dependencies.&lt;br /&gt;
&lt;br /&gt;
Then, [http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/otool.1.html otool] (&#039;otool -L&#039;) can be used to find shared library dependencies.&lt;br /&gt;
&lt;br /&gt;
There are also some other files such as bitmaps, &#039;locale&#039; files, and maybe others that will be required for correct running of GTK; these also need to be bundled.&lt;br /&gt;
&lt;br /&gt;
The tool [http://sourceforge.net/apps/trac/gtk-osx/wiki/Bundle ige-mac-bundler] seems to provide some degree of automation for this process, although it seems to be more oriented for C application than Python. We have some [[Porting_to_Mac/ige-mac-bundler|notes on how it works]].&lt;br /&gt;
&lt;br /&gt;
The shell-script gimpguts.sh, available from GIMPskel.zip on [http://gimp-app.sourceforge.net/ this page] also contains some code for pulling in the necessary bits of GTK for packaging.&lt;br /&gt;
&lt;br /&gt;
Our solution is a Python script that makes calls to &#039;otool&#039; and &#039;modulefinder&#039;. We hope to be able to incorporate this script into our SCons build scripts as a &#039;tool&#039;, but at the moment, {{src|scons/installgtk.py}} is standalone. This is still under development.&lt;br /&gt;
&lt;br /&gt;
Most Mac libraries by default are hard-wired with absolute dependency paths as [http://blogs.sun.com/dipol/entry/dynamic_libraries_rpath_and_mac described by Joe Di Pol]. The solution seems to be to post-process the shared libraries after they have been copied, using &#039;install_name_tool&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Problems with non-english Systems ===&lt;br /&gt;
&lt;br /&gt;
You need to set your System to english - it&#039;s not about your system user interface language and not about your keyboard, it about the Formats.&lt;br /&gt;
&lt;br /&gt;
Go to&lt;br /&gt;
System Preferences -&amp;gt; Interantional -&amp;gt; Formats&lt;br /&gt;
&lt;br /&gt;
select english US and reboot your system.&lt;br /&gt;
&lt;br /&gt;
If you do not take this step, ascend will ignore all decimal places.&lt;br /&gt;
PI will be 3.0000 instead of 3.1415, numbers like 0.12345 will be 0.00000 possibly causing &amp;quot;Division by Zero&amp;quot; Errors.&lt;br /&gt;
&lt;br /&gt;
=== Problems With Matplotlib ===&lt;br /&gt;
&lt;br /&gt;
[http://matplotlib.sourceforge.net/ Matplotlib] is used for all plotting by the PyGTK GUI, and Matplotlib in turn depends on [http://numpy.scipy.org/ NumPy]. NumPy doesn&#039;t work correctly with Apple&#039;s System Python, so you have to install MacPython to use the standard binary releases of Matplotlib and NumPy. Alternatively, it&#039;s possible to go back and download older versions of NumPy that &#039;&#039;do&#039;&#039; run on Apple&#039;s Python, but you&#039;ll presumably be losing some functionaly as a result.&lt;br /&gt;
&lt;br /&gt;
The conclusion from all this is that it might be advisable for ASCEND on the Mac to be linked against MacPython, and for a runtime check to be made to ensure that the correct version is in place.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to Apple Events ===&lt;br /&gt;
&lt;br /&gt;
Currently, GTK on Mac has no support for receiving or sending Apple Events. This is a problem, because Mac OS X attempts to communicate using Apple Events when a file is to be opened. If the app is not listening for events, then nothing will happen.&lt;br /&gt;
&lt;br /&gt;
However, there seems to be a workaround for the case of Python scripts: [http://appscript.sourceforge.net appscript], which contains a module called [http://appscript.sourceforge.net/py-appscript/doc/aem-manual/05_targettingapplications.html py-aem]. It may be possible to incorporate this into ASCEND as a way for processing such events. There may be other similar modules, possible. Also, PyObjC may provide another way of creating event listeners. These modules are included by default with [http://www.python.org/download/mac/ MacPython].&lt;br /&gt;
&lt;br /&gt;
According to GTK-OSX, there has not yet been any attempt to incorporate this stuff into ige-mac-integration, although it was agreed that it would be desirable to integrate it there (to benefit also C-based GTK applications ported to Mac).&lt;br /&gt;
&lt;br /&gt;
An alternative approach might be to write a very small Carbon/Cocoa application that could do the event listening, and pass the events on to the main application.&lt;br /&gt;
&lt;br /&gt;
=== Alternative approach: Homebrew? ===&lt;br /&gt;
&lt;br /&gt;
A new method&amp;lt;ref&amp;gt;http://blog.abhiomkar.in/2010/01/02/macports-to-homebrew-new-packaging-system-for-mac-os-x/&amp;lt;/ref&amp;gt; of obtaining GTK, SWIG, SCons and other tools is via [http://github.com/mxcl/homebrew Homebrew].&lt;br /&gt;
&lt;br /&gt;
An initial check of Homebrew shows that although it provides GTK+, at this stage it only provides the X11 version of GTK+, which does not help with the task of creating native GTK+ ASCEND as desired here. Also, the &#039;gtk-demo&#039; compiled by Homebrew seems to segfault, not sure what the reason for that was.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Mac_OS_X]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Porting_to_Mac&amp;diff=2810</id>
		<title>Porting to Mac</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Porting_to_Mac&amp;diff=2810"/>
		<updated>2011-07-07T10:33:40Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Building Native GTK+ - Fixed outdated file link*/&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ASCEND now &#039;&#039;&#039;runs successfully on Mac&#039;&#039;&#039; without problems. The remaining work is to package ASCEND as an installer or as an &#039;app&#039;, and to fix it so that it connects with Apple Events for opening files from the Finder, etc -- see below for details.&lt;br /&gt;
{{task}}&lt;br /&gt;
&lt;br /&gt;
== Installing the necessary tools ==&lt;br /&gt;
&lt;br /&gt;
You should install the following tools in order to be able to build ASCEND on Mac:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;XCode&#039;&#039;&#039; from your OS X CD.&lt;br /&gt;
* &#039;&#039;&#039;gfortran&#039;&#039;&#039;. Use gfortran-macosx-x86.dmg from http://gcc.gnu.org/wiki/GFortranBinaries&lt;br /&gt;
* &#039;&#039;&#039;scons&#039;&#039;&#039; by typing &#039;sudo easy_install scons&#039;&lt;br /&gt;
* &#039;&#039;&#039;swig&#039;&#039;&#039;. We have version 1.3.31, which comes with Xcode (confirmed as of Xcode 4.02)&lt;br /&gt;
* &#039;&#039;&#039;subversion&#039;&#039;&#039; (see [[VersionManagement|here]] or try the [http://www.open.collab.net/downloads/community/OpenCollabNet OpenCollabNet version])&lt;br /&gt;
&lt;br /&gt;
== Building ==&lt;br /&gt;
&lt;br /&gt;
When the above tools are installed and you have obtained the source code either from a file release or from our [[VersionManagement|code repository]], now you should be able to build ASCEND. Try just running &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sh&amp;quot;&amp;gt;scons&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There should be some output to tell you if you&#039;re missing any important components. Otherwise, you should then be able to run &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sh&amp;quot;&amp;gt;./test.py TestSolver.testlog10&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you should see a message saying &#039;OK&#039;. At this stage you have a complete working copy of ASCEND, possibly minus some of the userful [[solvers]] like [[IPOPT]], [[IDA]], [[CONOPT]]. The other important thing that you&#039;re missing is the GTK+ GUI library that allows ASCEND to present its user interface.&lt;br /&gt;
&lt;br /&gt;
== Building Native GTK+ ==&lt;br /&gt;
&lt;br /&gt;
ASCEND uses GTK+ for its GUI. This is a cross-platform GUI library that works primarily on Linux but is also supported on Windows and Mac OS X. For Mac, it is currently necessary to build it from source, following the [http://sourceforge.net/apps/trac/gtk-osx/wiki/Build instructions from the GTK-OSX project].&lt;br /&gt;
&lt;br /&gt;
Steps are something like this:&lt;br /&gt;
&lt;br /&gt;
* Make sure you have Xcode, subversion and git installed, as outlined at http://sourceforge.net/apps/trac/gtk-osx/wiki/Build&lt;br /&gt;
* Download the script [https://raw.github.com/jralls/gtk-osx-build/master/gtk-osx-build-setup.sh] and run it using &#039;&amp;lt;tt&amp;gt;sh gtk-osx-build-setup.sh&amp;lt;/tt&amp;gt;&#039; (no quotes).&lt;br /&gt;
* Edit the resulting &amp;lt;tt&amp;gt;~/.jhbuildrc-custom&amp;lt;/tt&amp;gt; file, adding &#039;&amp;lt;tt&amp;gt;build_policy = &amp;quot;updated-deps&amp;quot;&amp;lt;/tt&amp;gt;&#039; as a line at the end of the file (no single quotes).&lt;br /&gt;
* Set up an alias that will run &amp;lt;tt&amp;gt;jhbuild&amp;lt;/tt&amp;gt; in a stripped down environment that does not contain any reference to the Fink (/sw/...) or MacPorts (?) directories (if you have them): A good option is to set&lt;br /&gt;
:&amp;lt;pre&amp;gt;alias jhbuild=&amp;quot;PATH=/opt/subversion/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:~/gtk/inst ~/.local/bin/jhbuild&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
* According to the [http://sourceforge.net/apps/trac/gtk-osx/wiki/Build description on Sourceforge], build PyGTK as follows:&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild bootstrap&amp;lt;/tt&amp;gt;&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild build meta-gtk-osx-bootstrap&amp;lt;/tt&amp;gt;&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild build meta-gtk-osx-core&amp;lt;/tt&amp;gt;&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild pygtk&amp;lt;/tt&amp;gt; (or [http://sourceforge.net/apps/trac/gtk-osx/wiki/PyGtk should it be]: &amp;lt;tt&amp;gt;meta-gtk-osx-python&amp;lt;/tt&amp;gt; ?)&lt;br /&gt;
&lt;br /&gt;
You can now test that PyGTK is working by running &amp;lt;tt&amp;gt;python&amp;lt;/tt&amp;gt; and checking that &amp;lt;tt&amp;gt;import gtk&amp;lt;/tt&amp;gt; doesn&#039;t cause errors.&lt;br /&gt;
&lt;br /&gt;
If that&#039;s working, you should be able to use your working copy of ASCEND (as above) to run &amp;lt;tt&amp;gt;pygtk/ascdev&amp;lt;/tt&amp;gt;. This should open ASCEND, but you may have to command-tab to the correct window, as it won&#039;t pop to the front automatically.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a screenshot of ASCEND on Native GTK-Quartz on OS X!&lt;br /&gt;
&lt;br /&gt;
[[Image:ASCENDnativeOSX.png|thumb|300px|none|Screenshot of the PyGTK GUI running on Mac OSX with GTK-OSX (Quartz/Native GTK)]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: currently, the ASCEND GUI on Mac still behaves much the same as it would on Windows or Linux; we haven&#039;t yet &#039;mackified&#039; the keyboard shortcuts and menu layout. This will be using the &#039;ige-mac-integration&#039; library that&#039;s also provided by the GTK-OSX project.&lt;br /&gt;
&lt;br /&gt;
Note that allegedly it is also possible to build native GTK using macports, but we haven&#039;t yet tried that.&lt;br /&gt;
&lt;br /&gt;
== Building the Tcl/Tk GUI ==&lt;br /&gt;
&lt;br /&gt;
No work yet to determine what will be required to the Tcl/Tk GUI running on Mac. &lt;br /&gt;
&lt;br /&gt;
It &#039;&#039;may&#039;&#039; be fairly straightforward to get this GUI running, possibly using these binaries for Tcl/Tk:&lt;br /&gt;
&lt;br /&gt;
* http://www.categorifiedcoder.info/tcltk/&lt;br /&gt;
&lt;br /&gt;
== Preparing for distribution ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The following part is still under development.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Once GTK is build using jhbuild above, we need to re-package ASCEND in the form of a &#039;normal&#039; Mac OS X application. To do this,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;a4c&amp;quot;&amp;gt;cd ~/ascend&lt;br /&gt;
python scons/installgtk.py&lt;br /&gt;
scons install INSTALL_PREFIX=~/ascinst&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Those steps will first copy GTK and associated files into &amp;lt;tt&amp;gt;dist/PyGTK.bundle&amp;lt;/tt&amp;gt;. Next, they will copy all the ASCEND files as well as PyGTK.bundle into ~/ascinst/ASCEND.app. Other files will be added to the ~/ascint folder, in preparation for making a .dmg disk image that will be suitable for distribution.&lt;br /&gt;
&lt;br /&gt;
Currently, we are still working out some final bugs with the creation of the PyGTK.bundle, so this final step doesn&#039;t entirely work.&lt;br /&gt;
&lt;br /&gt;
== Development notes ==&lt;br /&gt;
&lt;br /&gt;
=== Packaging and distribution ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s recommended for most Mac applications that everything be distributed as an Application Bundle that just be dragged by the user into their Applications folder. This is certainly possible with ASCEND, but a problem is that the ASCEND Model Library is something that we would like users to see and interact with. We would like users to be able to see these folders and their contents easily using the Finder. Nesting the files within an Application bundle makes this rather difficult.&lt;br /&gt;
&lt;br /&gt;
One option would be for the ASCEND application to unpack its model library to ~/Library/Application Support/ASCEND when the program is first run. This would require Python scripting, and would not be compatible with a shared installation of the Tcl/Tk GUI on the same system.&lt;br /&gt;
&lt;br /&gt;
Another option would be to install the model library in /Library/Application Support/ASCEND/Models. This seems to be the right way forward, but it means that ASCEND can no longer just be dragged to the Applications folder to be installed. Instead, it would need an Installer to place the necessary files on the user&#039;s system. That&#039;s quite desirable, though, because such an installer could also check that the user has the correct versions of Python, GTK and PyGTK already installed on the system, and could even possibly download and install them first if required.&lt;br /&gt;
&lt;br /&gt;
It&#039;s worth noting that Mac editors like TextEdit can&#039;t peer into Application Bundles, but non-Mac editors like gedit can do so... they don&#039;t impose the same restriction on entering inside such bundles.&lt;br /&gt;
&lt;br /&gt;
As a first attempt for getting everything running, it seems wise to take the simple application bundle approach.&lt;br /&gt;
&lt;br /&gt;
We&#039;re not currently proposing to provide the Tcl/Tk GUI for Mac. This is a whole separate packaging problem.&lt;br /&gt;
&lt;br /&gt;
We&#039;re not currently proposing to package libascend as a Framework for Mac, although that is an option, and would be appropriate if attempting to provide both Tcl/Tk and PyGTK GUIs on the same machine, and to make it easier for users to develop their own solvers, etc, on that platform.&lt;br /&gt;
&lt;br /&gt;
The general opinion on GTK is that we should include it within out Application Bundle. From the linux point of view, this is terribly inefficient, but such things are standard practise on Mac, and we should respect that in the first instance.&lt;br /&gt;
&lt;br /&gt;
The alternative of providing ASCEND to the Mac community as a Fink package was considered, however, according to Fink developers, the current &#039;stable&#039; repository for Fink is very stagnant, so we are unlikely to be able to use that as a means for distribution. &lt;br /&gt;
&lt;br /&gt;
If we want to distribute ASCEND as a multi-component thing (libascend framework, Tcl/Tk GUI, PyGTK, model library all separate) then we would need to use the Apple tool, &#039;&#039;PackageMaker&#039;&#039;, which allows developers to produce their own .pkg installers, apparently&amp;lt;ref&amp;gt;http://s.sudre.free.fr/Stuff/PackageMaker_Howto.html&amp;lt;/ref&amp;gt;. It is preferable to distribute a simple Application Bundle within a .dmg Disk Image.&lt;br /&gt;
&lt;br /&gt;
=== Creating ASCEND.app ===&lt;br /&gt;
&lt;br /&gt;
To create the ASCEND application bundle&lt;br /&gt;
&lt;br /&gt;
* scons -j2 install INSTALL_PREFIX=~/ascinst&lt;br /&gt;
* The bundle will appear as ~/ascinst/ASCEND.app&lt;br /&gt;
* TODO: add necessary GTK files to the .app!&lt;br /&gt;
* follow instructions below to turn it into a redistributable disk image&lt;br /&gt;
&lt;br /&gt;
The file {{src|mac/Info.plist}} contains all the key-value stuff describing the application. We had to make changes to {{src|pygtk/ascend.in}} to accommodate the particularities of the Mac platform, too.&lt;br /&gt;
&lt;br /&gt;
=== Creating a Disk Image (ASCEND-0.9.X.dmg) ===&lt;br /&gt;
&lt;br /&gt;
Some instructions are here: http://www.wikihow.com/Make-a-DMG-File-on-a-Mac&lt;br /&gt;
&lt;br /&gt;
In summary:&lt;br /&gt;
&lt;br /&gt;
* use the Applications/Utilities/Disk Utility application&lt;br /&gt;
* create a new image large enough for your needs&lt;br /&gt;
* mount and open the image&lt;br /&gt;
* from the Terminal, run scons -j2 install INSTALL_PREFIX=(location of your disk image folder)&lt;br /&gt;
* set the folder background image to ~/ascend/mac/folder-background.png&lt;br /&gt;
* arrange the files so that they look OK, the folder-background arrow should point from the ASCEND.app to the Applications folder alias.&lt;br /&gt;
* return to the disk image program&lt;br /&gt;
* click &#039;convert&#039; and convert to a compressed image (OK to overwrite)&lt;br /&gt;
* all done, you can double-click the image file now, and it should mount and appear as you wanted it.&lt;br /&gt;
&lt;br /&gt;
=== Finding all the GTK files ===&lt;br /&gt;
&lt;br /&gt;
To create a safely porting ASCEND.app, we need to embed all of GTK into the application bundle. The above application won&#039;t be complete until we achieve that.&lt;br /&gt;
&lt;br /&gt;
Looks like some Python packages called [http://docs.python.org/library/modulefinder.html modulefinder] (built-in to Python) or [http://pypi.python.org/pypi/modulegraph/ modulegraph] (external) may be able to help with locating all the necessary files for satisfying Python &#039;import&#039; dependencies.&lt;br /&gt;
&lt;br /&gt;
Then, [http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/otool.1.html otool] (&#039;otool -L&#039;) can be used to find shared library dependencies.&lt;br /&gt;
&lt;br /&gt;
There are also some other files such as bitmaps, &#039;locale&#039; files, and maybe others that will be required for correct running of GTK; these also need to be bundled.&lt;br /&gt;
&lt;br /&gt;
The tool [http://sourceforge.net/apps/trac/gtk-osx/wiki/Bundle ige-mac-bundler] seems to provide some degree of automation for this process, although it seems to be more oriented for C application than Python. We have some [[Porting_to_Mac/ige-mac-bundler|notes on how it works]].&lt;br /&gt;
&lt;br /&gt;
The shell-script gimpguts.sh, available from GIMPskel.zip on [http://gimp-app.sourceforge.net/ this page] also contains some code for pulling in the necessary bits of GTK for packaging.&lt;br /&gt;
&lt;br /&gt;
Our solution is a Python script that makes calls to &#039;otool&#039; and &#039;modulefinder&#039;. We hope to be able to incorporate this script into our SCons build scripts as a &#039;tool&#039;, but at the moment, {{src|scons/installgtk.py}} is standalone. This is still under development.&lt;br /&gt;
&lt;br /&gt;
Most Mac libraries by default are hard-wired with absolute dependency paths as [http://blogs.sun.com/dipol/entry/dynamic_libraries_rpath_and_mac described by Joe Di Pol]. The solution seems to be to post-process the shared libraries after they have been copied, using &#039;install_name_tool&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Problems with non-english Systems ===&lt;br /&gt;
&lt;br /&gt;
You need to set your System to english - it&#039;s not about your system user interface language and not about your keyboard, it about the Formats.&lt;br /&gt;
&lt;br /&gt;
Go to&lt;br /&gt;
System Preferences -&amp;gt; Interantional -&amp;gt; Formats&lt;br /&gt;
&lt;br /&gt;
select english US and reboot your system.&lt;br /&gt;
&lt;br /&gt;
If you do not take this step, ascend will ignore all decimal places.&lt;br /&gt;
PI will be 3.0000 instead of 3.1415, numbers like 0.12345 will be 0.00000 possibly causing &amp;quot;Division by Zero&amp;quot; Errors.&lt;br /&gt;
&lt;br /&gt;
=== Problems With Matplotlib ===&lt;br /&gt;
&lt;br /&gt;
[http://matplotlib.sourceforge.net/ Matplotlib] is used for all plotting by the PyGTK GUI, and Matplotlib in turn depends on [http://numpy.scipy.org/ NumPy]. NumPy doesn&#039;t work correctly with Apple&#039;s System Python, so you have to install MacPython to use the standard binary releases of Matplotlib and NumPy. Alternatively, it&#039;s possible to go back and download older versions of NumPy that &#039;&#039;do&#039;&#039; run on Apple&#039;s Python, but you&#039;ll presumably be losing some functionaly as a result.&lt;br /&gt;
&lt;br /&gt;
The conclusion from all this is that it might be advisable for ASCEND on the Mac to be linked against MacPython, and for a runtime check to be made to ensure that the correct version is in place.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to Apple Events ===&lt;br /&gt;
&lt;br /&gt;
Currently, GTK on Mac has no support for receiving or sending Apple Events. This is a problem, because Mac OS X attempts to communicate using Apple Events when a file is to be opened. If the app is not listening for events, then nothing will happen.&lt;br /&gt;
&lt;br /&gt;
However, there seems to be a workaround for the case of Python scripts: [http://appscript.sourceforge.net appscript], which contains a module called [http://appscript.sourceforge.net/py-appscript/doc/aem-manual/05_targettingapplications.html py-aem]. It may be possible to incorporate this into ASCEND as a way for processing such events. There may be other similar modules, possible. Also, PyObjC may provide another way of creating event listeners. These modules are included by default with [http://www.python.org/download/mac/ MacPython].&lt;br /&gt;
&lt;br /&gt;
According to GTK-OSX, there has not yet been any attempt to incorporate this stuff into ige-mac-integration, although it was agreed that it would be desirable to integrate it there (to benefit also C-based GTK applications ported to Mac).&lt;br /&gt;
&lt;br /&gt;
An alternative approach might be to write a very small Carbon/Cocoa application that could do the event listening, and pass the events on to the main application.&lt;br /&gt;
&lt;br /&gt;
=== Alternative approach: Homebrew? ===&lt;br /&gt;
&lt;br /&gt;
A new method&amp;lt;ref&amp;gt;http://blog.abhiomkar.in/2010/01/02/macports-to-homebrew-new-packaging-system-for-mac-os-x/&amp;lt;/ref&amp;gt; of obtaining GTK, SWIG, SCons and other tools is via [http://github.com/mxcl/homebrew Homebrew].&lt;br /&gt;
&lt;br /&gt;
An initial check of Homebrew shows that although it provides GTK+, at this stage it only provides the X11 version of GTK+, which does not help with the task of creating native GTK+ ASCEND as desired here. Also, the &#039;gtk-demo&#039; compiled by Homebrew seems to segfault, not sure what the reason for that was.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Mac_OS_X]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Porting_to_Mac&amp;diff=2809</id>
		<title>Porting to Mac</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Porting_to_Mac&amp;diff=2809"/>
		<updated>2011-07-07T09:54:00Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Installing the necessary tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ASCEND now &#039;&#039;&#039;runs successfully on Mac&#039;&#039;&#039; without problems. The remaining work is to package ASCEND as an installer or as an &#039;app&#039;, and to fix it so that it connects with Apple Events for opening files from the Finder, etc -- see below for details.&lt;br /&gt;
{{task}}&lt;br /&gt;
&lt;br /&gt;
== Installing the necessary tools ==&lt;br /&gt;
&lt;br /&gt;
You should install the following tools in order to be able to build ASCEND on Mac:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;XCode&#039;&#039;&#039; from your OS X CD.&lt;br /&gt;
* &#039;&#039;&#039;gfortran&#039;&#039;&#039;. Use gfortran-macosx-x86.dmg from http://gcc.gnu.org/wiki/GFortranBinaries&lt;br /&gt;
* &#039;&#039;&#039;scons&#039;&#039;&#039; by typing &#039;sudo easy_install scons&#039;&lt;br /&gt;
* &#039;&#039;&#039;swig&#039;&#039;&#039;. We have version 1.3.31, which comes with Xcode (confirmed as of Xcode 4.02)&lt;br /&gt;
* &#039;&#039;&#039;subversion&#039;&#039;&#039; (see [[VersionManagement|here]] or try the [http://www.open.collab.net/downloads/community/OpenCollabNet OpenCollabNet version])&lt;br /&gt;
&lt;br /&gt;
== Building ==&lt;br /&gt;
&lt;br /&gt;
When the above tools are installed and you have obtained the source code either from a file release or from our [[VersionManagement|code repository]], now you should be able to build ASCEND. Try just running &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sh&amp;quot;&amp;gt;scons&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There should be some output to tell you if you&#039;re missing any important components. Otherwise, you should then be able to run &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sh&amp;quot;&amp;gt;./test.py TestSolver.testlog10&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you should see a message saying &#039;OK&#039;. At this stage you have a complete working copy of ASCEND, possibly minus some of the userful [[solvers]] like [[IPOPT]], [[IDA]], [[CONOPT]]. The other important thing that you&#039;re missing is the GTK+ GUI library that allows ASCEND to present its user interface.&lt;br /&gt;
&lt;br /&gt;
== Building Native GTK+ ==&lt;br /&gt;
&lt;br /&gt;
ASCEND uses GTK+ for its GUI. This is a cross-platform GUI library that works primarily on Linux but is also supported on Windows and Mac OS X. For Mac, it is currently necessary to build it from source, following the [http://sourceforge.net/apps/trac/gtk-osx/wiki/Build instructions from the GTK-OSX project].&lt;br /&gt;
&lt;br /&gt;
Steps are something like this:&lt;br /&gt;
&lt;br /&gt;
* Make sure you have Xcode, subversion and git installed, as outlined at http://sourceforge.net/apps/trac/gtk-osx/wiki/Build&lt;br /&gt;
* Download the script [http://downloads.sourceforge.net/sourceforge/gtk-osx/gtk-osx-build-setup.sh gtk-osx-build-setup.sh] and run it using &#039;&amp;lt;tt&amp;gt;sh gtk-osx-build-setup.sh&amp;lt;/tt&amp;gt;&#039; (no quotes).&lt;br /&gt;
* Edit the resulting &amp;lt;tt&amp;gt;~/.jhbuildrc-custom&amp;lt;/tt&amp;gt; file, adding &#039;&amp;lt;tt&amp;gt;build_policy = &amp;quot;updated-deps&amp;quot;&amp;lt;/tt&amp;gt;&#039; as a line at the end of the file (no single quotes).&lt;br /&gt;
* Set up an alias that will run &amp;lt;tt&amp;gt;jhbuild&amp;lt;/tt&amp;gt; in a stripped down environment that does not contain any reference to the Fink (/sw/...) or MacPorts (?) directories (if you have them): A good option is to set&lt;br /&gt;
:&amp;lt;pre&amp;gt;alias jhbuild=&amp;quot;PATH=/opt/subversion/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:~/gtk/inst ~/.local/bin/jhbuild&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
* According to the [http://sourceforge.net/apps/trac/gtk-osx/wiki/Build description on Sourceforge], build PyGTK as follows:&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild bootstrap&amp;lt;/tt&amp;gt;&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild build meta-gtk-osx-bootstrap&amp;lt;/tt&amp;gt;&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild build meta-gtk-osx-core&amp;lt;/tt&amp;gt;&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild pygtk&amp;lt;/tt&amp;gt; (or [http://sourceforge.net/apps/trac/gtk-osx/wiki/PyGtk should it be]: &amp;lt;tt&amp;gt;meta-gtk-osx-python&amp;lt;/tt&amp;gt; ?)&lt;br /&gt;
&lt;br /&gt;
You can now test that PyGTK is working by running &amp;lt;tt&amp;gt;python&amp;lt;/tt&amp;gt; and checking that &amp;lt;tt&amp;gt;import gtk&amp;lt;/tt&amp;gt; doesn&#039;t cause errors.&lt;br /&gt;
&lt;br /&gt;
If that&#039;s working, you should be able to use your working copy of ASCEND (as above) to run &amp;lt;tt&amp;gt;pygtk/ascdev&amp;lt;/tt&amp;gt;. This should open ASCEND, but you may have to command-tab to the correct window, as it won&#039;t pop to the front automatically.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a screenshot of ASCEND on Native GTK-Quartz on OS X!&lt;br /&gt;
&lt;br /&gt;
[[Image:ASCENDnativeOSX.png|thumb|300px|none|Screenshot of the PyGTK GUI running on Mac OSX with GTK-OSX (Quartz/Native GTK)]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: currently, the ASCEND GUI on Mac still behaves much the same as it would on Windows or Linux; we haven&#039;t yet &#039;mackified&#039; the keyboard shortcuts and menu layout. This will be using the &#039;ige-mac-integration&#039; library that&#039;s also provided by the GTK-OSX project.&lt;br /&gt;
&lt;br /&gt;
Note that allegedly it is also possible to build native GTK using macports, but we haven&#039;t yet tried that.&lt;br /&gt;
&lt;br /&gt;
== Building the Tcl/Tk GUI ==&lt;br /&gt;
&lt;br /&gt;
No work yet to determine what will be required to the Tcl/Tk GUI running on Mac. &lt;br /&gt;
&lt;br /&gt;
It &#039;&#039;may&#039;&#039; be fairly straightforward to get this GUI running, possibly using these binaries for Tcl/Tk:&lt;br /&gt;
&lt;br /&gt;
* http://www.categorifiedcoder.info/tcltk/&lt;br /&gt;
&lt;br /&gt;
== Preparing for distribution ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The following part is still under development.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Once GTK is build using jhbuild above, we need to re-package ASCEND in the form of a &#039;normal&#039; Mac OS X application. To do this,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;a4c&amp;quot;&amp;gt;cd ~/ascend&lt;br /&gt;
python scons/installgtk.py&lt;br /&gt;
scons install INSTALL_PREFIX=~/ascinst&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Those steps will first copy GTK and associated files into &amp;lt;tt&amp;gt;dist/PyGTK.bundle&amp;lt;/tt&amp;gt;. Next, they will copy all the ASCEND files as well as PyGTK.bundle into ~/ascinst/ASCEND.app. Other files will be added to the ~/ascint folder, in preparation for making a .dmg disk image that will be suitable for distribution.&lt;br /&gt;
&lt;br /&gt;
Currently, we are still working out some final bugs with the creation of the PyGTK.bundle, so this final step doesn&#039;t entirely work.&lt;br /&gt;
&lt;br /&gt;
== Development notes ==&lt;br /&gt;
&lt;br /&gt;
=== Packaging and distribution ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s recommended for most Mac applications that everything be distributed as an Application Bundle that just be dragged by the user into their Applications folder. This is certainly possible with ASCEND, but a problem is that the ASCEND Model Library is something that we would like users to see and interact with. We would like users to be able to see these folders and their contents easily using the Finder. Nesting the files within an Application bundle makes this rather difficult.&lt;br /&gt;
&lt;br /&gt;
One option would be for the ASCEND application to unpack its model library to ~/Library/Application Support/ASCEND when the program is first run. This would require Python scripting, and would not be compatible with a shared installation of the Tcl/Tk GUI on the same system.&lt;br /&gt;
&lt;br /&gt;
Another option would be to install the model library in /Library/Application Support/ASCEND/Models. This seems to be the right way forward, but it means that ASCEND can no longer just be dragged to the Applications folder to be installed. Instead, it would need an Installer to place the necessary files on the user&#039;s system. That&#039;s quite desirable, though, because such an installer could also check that the user has the correct versions of Python, GTK and PyGTK already installed on the system, and could even possibly download and install them first if required.&lt;br /&gt;
&lt;br /&gt;
It&#039;s worth noting that Mac editors like TextEdit can&#039;t peer into Application Bundles, but non-Mac editors like gedit can do so... they don&#039;t impose the same restriction on entering inside such bundles.&lt;br /&gt;
&lt;br /&gt;
As a first attempt for getting everything running, it seems wise to take the simple application bundle approach.&lt;br /&gt;
&lt;br /&gt;
We&#039;re not currently proposing to provide the Tcl/Tk GUI for Mac. This is a whole separate packaging problem.&lt;br /&gt;
&lt;br /&gt;
We&#039;re not currently proposing to package libascend as a Framework for Mac, although that is an option, and would be appropriate if attempting to provide both Tcl/Tk and PyGTK GUIs on the same machine, and to make it easier for users to develop their own solvers, etc, on that platform.&lt;br /&gt;
&lt;br /&gt;
The general opinion on GTK is that we should include it within out Application Bundle. From the linux point of view, this is terribly inefficient, but such things are standard practise on Mac, and we should respect that in the first instance.&lt;br /&gt;
&lt;br /&gt;
The alternative of providing ASCEND to the Mac community as a Fink package was considered, however, according to Fink developers, the current &#039;stable&#039; repository for Fink is very stagnant, so we are unlikely to be able to use that as a means for distribution. &lt;br /&gt;
&lt;br /&gt;
If we want to distribute ASCEND as a multi-component thing (libascend framework, Tcl/Tk GUI, PyGTK, model library all separate) then we would need to use the Apple tool, &#039;&#039;PackageMaker&#039;&#039;, which allows developers to produce their own .pkg installers, apparently&amp;lt;ref&amp;gt;http://s.sudre.free.fr/Stuff/PackageMaker_Howto.html&amp;lt;/ref&amp;gt;. It is preferable to distribute a simple Application Bundle within a .dmg Disk Image.&lt;br /&gt;
&lt;br /&gt;
=== Creating ASCEND.app ===&lt;br /&gt;
&lt;br /&gt;
To create the ASCEND application bundle&lt;br /&gt;
&lt;br /&gt;
* scons -j2 install INSTALL_PREFIX=~/ascinst&lt;br /&gt;
* The bundle will appear as ~/ascinst/ASCEND.app&lt;br /&gt;
* TODO: add necessary GTK files to the .app!&lt;br /&gt;
* follow instructions below to turn it into a redistributable disk image&lt;br /&gt;
&lt;br /&gt;
The file {{src|mac/Info.plist}} contains all the key-value stuff describing the application. We had to make changes to {{src|pygtk/ascend.in}} to accommodate the particularities of the Mac platform, too.&lt;br /&gt;
&lt;br /&gt;
=== Creating a Disk Image (ASCEND-0.9.X.dmg) ===&lt;br /&gt;
&lt;br /&gt;
Some instructions are here: http://www.wikihow.com/Make-a-DMG-File-on-a-Mac&lt;br /&gt;
&lt;br /&gt;
In summary:&lt;br /&gt;
&lt;br /&gt;
* use the Applications/Utilities/Disk Utility application&lt;br /&gt;
* create a new image large enough for your needs&lt;br /&gt;
* mount and open the image&lt;br /&gt;
* from the Terminal, run scons -j2 install INSTALL_PREFIX=(location of your disk image folder)&lt;br /&gt;
* set the folder background image to ~/ascend/mac/folder-background.png&lt;br /&gt;
* arrange the files so that they look OK, the folder-background arrow should point from the ASCEND.app to the Applications folder alias.&lt;br /&gt;
* return to the disk image program&lt;br /&gt;
* click &#039;convert&#039; and convert to a compressed image (OK to overwrite)&lt;br /&gt;
* all done, you can double-click the image file now, and it should mount and appear as you wanted it.&lt;br /&gt;
&lt;br /&gt;
=== Finding all the GTK files ===&lt;br /&gt;
&lt;br /&gt;
To create a safely porting ASCEND.app, we need to embed all of GTK into the application bundle. The above application won&#039;t be complete until we achieve that.&lt;br /&gt;
&lt;br /&gt;
Looks like some Python packages called [http://docs.python.org/library/modulefinder.html modulefinder] (built-in to Python) or [http://pypi.python.org/pypi/modulegraph/ modulegraph] (external) may be able to help with locating all the necessary files for satisfying Python &#039;import&#039; dependencies.&lt;br /&gt;
&lt;br /&gt;
Then, [http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/otool.1.html otool] (&#039;otool -L&#039;) can be used to find shared library dependencies.&lt;br /&gt;
&lt;br /&gt;
There are also some other files such as bitmaps, &#039;locale&#039; files, and maybe others that will be required for correct running of GTK; these also need to be bundled.&lt;br /&gt;
&lt;br /&gt;
The tool [http://sourceforge.net/apps/trac/gtk-osx/wiki/Bundle ige-mac-bundler] seems to provide some degree of automation for this process, although it seems to be more oriented for C application than Python. We have some [[Porting_to_Mac/ige-mac-bundler|notes on how it works]].&lt;br /&gt;
&lt;br /&gt;
The shell-script gimpguts.sh, available from GIMPskel.zip on [http://gimp-app.sourceforge.net/ this page] also contains some code for pulling in the necessary bits of GTK for packaging.&lt;br /&gt;
&lt;br /&gt;
Our solution is a Python script that makes calls to &#039;otool&#039; and &#039;modulefinder&#039;. We hope to be able to incorporate this script into our SCons build scripts as a &#039;tool&#039;, but at the moment, {{src|scons/installgtk.py}} is standalone. This is still under development.&lt;br /&gt;
&lt;br /&gt;
Most Mac libraries by default are hard-wired with absolute dependency paths as [http://blogs.sun.com/dipol/entry/dynamic_libraries_rpath_and_mac described by Joe Di Pol]. The solution seems to be to post-process the shared libraries after they have been copied, using &#039;install_name_tool&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Problems with non-english Systems ===&lt;br /&gt;
&lt;br /&gt;
You need to set your System to english - it&#039;s not about your system user interface language and not about your keyboard, it about the Formats.&lt;br /&gt;
&lt;br /&gt;
Go to&lt;br /&gt;
System Preferences -&amp;gt; Interantional -&amp;gt; Formats&lt;br /&gt;
&lt;br /&gt;
select english US and reboot your system.&lt;br /&gt;
&lt;br /&gt;
If you do not take this step, ascend will ignore all decimal places.&lt;br /&gt;
PI will be 3.0000 instead of 3.1415, numbers like 0.12345 will be 0.00000 possibly causing &amp;quot;Division by Zero&amp;quot; Errors.&lt;br /&gt;
&lt;br /&gt;
=== Problems With Matplotlib ===&lt;br /&gt;
&lt;br /&gt;
[http://matplotlib.sourceforge.net/ Matplotlib] is used for all plotting by the PyGTK GUI, and Matplotlib in turn depends on [http://numpy.scipy.org/ NumPy]. NumPy doesn&#039;t work correctly with Apple&#039;s System Python, so you have to install MacPython to use the standard binary releases of Matplotlib and NumPy. Alternatively, it&#039;s possible to go back and download older versions of NumPy that &#039;&#039;do&#039;&#039; run on Apple&#039;s Python, but you&#039;ll presumably be losing some functionaly as a result.&lt;br /&gt;
&lt;br /&gt;
The conclusion from all this is that it might be advisable for ASCEND on the Mac to be linked against MacPython, and for a runtime check to be made to ensure that the correct version is in place.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to Apple Events ===&lt;br /&gt;
&lt;br /&gt;
Currently, GTK on Mac has no support for receiving or sending Apple Events. This is a problem, because Mac OS X attempts to communicate using Apple Events when a file is to be opened. If the app is not listening for events, then nothing will happen.&lt;br /&gt;
&lt;br /&gt;
However, there seems to be a workaround for the case of Python scripts: [http://appscript.sourceforge.net appscript], which contains a module called [http://appscript.sourceforge.net/py-appscript/doc/aem-manual/05_targettingapplications.html py-aem]. It may be possible to incorporate this into ASCEND as a way for processing such events. There may be other similar modules, possible. Also, PyObjC may provide another way of creating event listeners. These modules are included by default with [http://www.python.org/download/mac/ MacPython].&lt;br /&gt;
&lt;br /&gt;
According to GTK-OSX, there has not yet been any attempt to incorporate this stuff into ige-mac-integration, although it was agreed that it would be desirable to integrate it there (to benefit also C-based GTK applications ported to Mac).&lt;br /&gt;
&lt;br /&gt;
An alternative approach might be to write a very small Carbon/Cocoa application that could do the event listening, and pass the events on to the main application.&lt;br /&gt;
&lt;br /&gt;
=== Alternative approach: Homebrew? ===&lt;br /&gt;
&lt;br /&gt;
A new method&amp;lt;ref&amp;gt;http://blog.abhiomkar.in/2010/01/02/macports-to-homebrew-new-packaging-system-for-mac-os-x/&amp;lt;/ref&amp;gt; of obtaining GTK, SWIG, SCons and other tools is via [http://github.com/mxcl/homebrew Homebrew].&lt;br /&gt;
&lt;br /&gt;
An initial check of Homebrew shows that although it provides GTK+, at this stage it only provides the X11 version of GTK+, which does not help with the task of creating native GTK+ ASCEND as desired here. Also, the &#039;gtk-demo&#039; compiled by Homebrew seems to segfault, not sure what the reason for that was.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Mac_OS_X]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Porting_to_Mac&amp;diff=2808</id>
		<title>Porting to Mac</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Porting_to_Mac&amp;diff=2808"/>
		<updated>2011-07-07T09:47:18Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Installing the necessary tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ASCEND now &#039;&#039;&#039;runs successfully on Mac&#039;&#039;&#039; without problems. The remaining work is to package ASCEND as an installer or as an &#039;app&#039;, and to fix it so that it connects with Apple Events for opening files from the Finder, etc -- see below for details.&lt;br /&gt;
{{task}}&lt;br /&gt;
&lt;br /&gt;
== Installing the necessary tools ==&lt;br /&gt;
&lt;br /&gt;
You should install the following tools in order to be able to build ASCEND on Mac:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;XCode&#039;&#039;&#039; from your OS X CD.&lt;br /&gt;
* &#039;&#039;&#039;gfortran&#039;&#039;&#039;. Use gfortran-macosx-x86.dmg from http://gcc.gnu.org/wiki/GFortranBinaries&lt;br /&gt;
* &#039;&#039;&#039;scons&#039;&#039;&#039; by typing &#039;easy_install scons&#039;&lt;br /&gt;
* &#039;&#039;&#039;swig&#039;&#039;&#039;. We have version 1.3.31, which comes with Xcode (confirmed as of Xcode 4.02)&lt;br /&gt;
* &#039;&#039;&#039;subversion&#039;&#039;&#039; (see [[VersionManagement|here]] or try the [http://www.open.collab.net/downloads/community/OpenCollabNet OpenCollabNet version])&lt;br /&gt;
&lt;br /&gt;
== Building ==&lt;br /&gt;
&lt;br /&gt;
When the above tools are installed and you have obtained the source code either from a file release or from our [[VersionManagement|code repository]], now you should be able to build ASCEND. Try just running &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sh&amp;quot;&amp;gt;scons&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There should be some output to tell you if you&#039;re missing any important components. Otherwise, you should then be able to run &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sh&amp;quot;&amp;gt;./test.py TestSolver.testlog10&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you should see a message saying &#039;OK&#039;. At this stage you have a complete working copy of ASCEND, possibly minus some of the userful [[solvers]] like [[IPOPT]], [[IDA]], [[CONOPT]]. The other important thing that you&#039;re missing is the GTK+ GUI library that allows ASCEND to present its user interface.&lt;br /&gt;
&lt;br /&gt;
== Building Native GTK+ ==&lt;br /&gt;
&lt;br /&gt;
ASCEND uses GTK+ for its GUI. This is a cross-platform GUI library that works primarily on Linux but is also supported on Windows and Mac OS X. For Mac, it is currently necessary to build it from source, following the [http://sourceforge.net/apps/trac/gtk-osx/wiki/Build instructions from the GTK-OSX project].&lt;br /&gt;
&lt;br /&gt;
Steps are something like this:&lt;br /&gt;
&lt;br /&gt;
* Make sure you have Xcode, subversion and git installed, as outlined at http://sourceforge.net/apps/trac/gtk-osx/wiki/Build&lt;br /&gt;
* Download the script [http://downloads.sourceforge.net/sourceforge/gtk-osx/gtk-osx-build-setup.sh gtk-osx-build-setup.sh] and run it using &#039;&amp;lt;tt&amp;gt;sh gtk-osx-build-setup.sh&amp;lt;/tt&amp;gt;&#039; (no quotes).&lt;br /&gt;
* Edit the resulting &amp;lt;tt&amp;gt;~/.jhbuildrc-custom&amp;lt;/tt&amp;gt; file, adding &#039;&amp;lt;tt&amp;gt;build_policy = &amp;quot;updated-deps&amp;quot;&amp;lt;/tt&amp;gt;&#039; as a line at the end of the file (no single quotes).&lt;br /&gt;
* Set up an alias that will run &amp;lt;tt&amp;gt;jhbuild&amp;lt;/tt&amp;gt; in a stripped down environment that does not contain any reference to the Fink (/sw/...) or MacPorts (?) directories (if you have them): A good option is to set&lt;br /&gt;
:&amp;lt;pre&amp;gt;alias jhbuild=&amp;quot;PATH=/opt/subversion/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:~/gtk/inst ~/.local/bin/jhbuild&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
* According to the [http://sourceforge.net/apps/trac/gtk-osx/wiki/Build description on Sourceforge], build PyGTK as follows:&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild bootstrap&amp;lt;/tt&amp;gt;&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild build meta-gtk-osx-bootstrap&amp;lt;/tt&amp;gt;&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild build meta-gtk-osx-core&amp;lt;/tt&amp;gt;&lt;br /&gt;
** &amp;lt;tt&amp;gt;jhbuild pygtk&amp;lt;/tt&amp;gt; (or [http://sourceforge.net/apps/trac/gtk-osx/wiki/PyGtk should it be]: &amp;lt;tt&amp;gt;meta-gtk-osx-python&amp;lt;/tt&amp;gt; ?)&lt;br /&gt;
&lt;br /&gt;
You can now test that PyGTK is working by running &amp;lt;tt&amp;gt;python&amp;lt;/tt&amp;gt; and checking that &amp;lt;tt&amp;gt;import gtk&amp;lt;/tt&amp;gt; doesn&#039;t cause errors.&lt;br /&gt;
&lt;br /&gt;
If that&#039;s working, you should be able to use your working copy of ASCEND (as above) to run &amp;lt;tt&amp;gt;pygtk/ascdev&amp;lt;/tt&amp;gt;. This should open ASCEND, but you may have to command-tab to the correct window, as it won&#039;t pop to the front automatically.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a screenshot of ASCEND on Native GTK-Quartz on OS X!&lt;br /&gt;
&lt;br /&gt;
[[Image:ASCENDnativeOSX.png|thumb|300px|none|Screenshot of the PyGTK GUI running on Mac OSX with GTK-OSX (Quartz/Native GTK)]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: currently, the ASCEND GUI on Mac still behaves much the same as it would on Windows or Linux; we haven&#039;t yet &#039;mackified&#039; the keyboard shortcuts and menu layout. This will be using the &#039;ige-mac-integration&#039; library that&#039;s also provided by the GTK-OSX project.&lt;br /&gt;
&lt;br /&gt;
Note that allegedly it is also possible to build native GTK using macports, but we haven&#039;t yet tried that.&lt;br /&gt;
&lt;br /&gt;
== Building the Tcl/Tk GUI ==&lt;br /&gt;
&lt;br /&gt;
No work yet to determine what will be required to the Tcl/Tk GUI running on Mac. &lt;br /&gt;
&lt;br /&gt;
It &#039;&#039;may&#039;&#039; be fairly straightforward to get this GUI running, possibly using these binaries for Tcl/Tk:&lt;br /&gt;
&lt;br /&gt;
* http://www.categorifiedcoder.info/tcltk/&lt;br /&gt;
&lt;br /&gt;
== Preparing for distribution ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The following part is still under development.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Once GTK is build using jhbuild above, we need to re-package ASCEND in the form of a &#039;normal&#039; Mac OS X application. To do this,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;a4c&amp;quot;&amp;gt;cd ~/ascend&lt;br /&gt;
python scons/installgtk.py&lt;br /&gt;
scons install INSTALL_PREFIX=~/ascinst&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Those steps will first copy GTK and associated files into &amp;lt;tt&amp;gt;dist/PyGTK.bundle&amp;lt;/tt&amp;gt;. Next, they will copy all the ASCEND files as well as PyGTK.bundle into ~/ascinst/ASCEND.app. Other files will be added to the ~/ascint folder, in preparation for making a .dmg disk image that will be suitable for distribution.&lt;br /&gt;
&lt;br /&gt;
Currently, we are still working out some final bugs with the creation of the PyGTK.bundle, so this final step doesn&#039;t entirely work.&lt;br /&gt;
&lt;br /&gt;
== Development notes ==&lt;br /&gt;
&lt;br /&gt;
=== Packaging and distribution ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s recommended for most Mac applications that everything be distributed as an Application Bundle that just be dragged by the user into their Applications folder. This is certainly possible with ASCEND, but a problem is that the ASCEND Model Library is something that we would like users to see and interact with. We would like users to be able to see these folders and their contents easily using the Finder. Nesting the files within an Application bundle makes this rather difficult.&lt;br /&gt;
&lt;br /&gt;
One option would be for the ASCEND application to unpack its model library to ~/Library/Application Support/ASCEND when the program is first run. This would require Python scripting, and would not be compatible with a shared installation of the Tcl/Tk GUI on the same system.&lt;br /&gt;
&lt;br /&gt;
Another option would be to install the model library in /Library/Application Support/ASCEND/Models. This seems to be the right way forward, but it means that ASCEND can no longer just be dragged to the Applications folder to be installed. Instead, it would need an Installer to place the necessary files on the user&#039;s system. That&#039;s quite desirable, though, because such an installer could also check that the user has the correct versions of Python, GTK and PyGTK already installed on the system, and could even possibly download and install them first if required.&lt;br /&gt;
&lt;br /&gt;
It&#039;s worth noting that Mac editors like TextEdit can&#039;t peer into Application Bundles, but non-Mac editors like gedit can do so... they don&#039;t impose the same restriction on entering inside such bundles.&lt;br /&gt;
&lt;br /&gt;
As a first attempt for getting everything running, it seems wise to take the simple application bundle approach.&lt;br /&gt;
&lt;br /&gt;
We&#039;re not currently proposing to provide the Tcl/Tk GUI for Mac. This is a whole separate packaging problem.&lt;br /&gt;
&lt;br /&gt;
We&#039;re not currently proposing to package libascend as a Framework for Mac, although that is an option, and would be appropriate if attempting to provide both Tcl/Tk and PyGTK GUIs on the same machine, and to make it easier for users to develop their own solvers, etc, on that platform.&lt;br /&gt;
&lt;br /&gt;
The general opinion on GTK is that we should include it within out Application Bundle. From the linux point of view, this is terribly inefficient, but such things are standard practise on Mac, and we should respect that in the first instance.&lt;br /&gt;
&lt;br /&gt;
The alternative of providing ASCEND to the Mac community as a Fink package was considered, however, according to Fink developers, the current &#039;stable&#039; repository for Fink is very stagnant, so we are unlikely to be able to use that as a means for distribution. &lt;br /&gt;
&lt;br /&gt;
If we want to distribute ASCEND as a multi-component thing (libascend framework, Tcl/Tk GUI, PyGTK, model library all separate) then we would need to use the Apple tool, &#039;&#039;PackageMaker&#039;&#039;, which allows developers to produce their own .pkg installers, apparently&amp;lt;ref&amp;gt;http://s.sudre.free.fr/Stuff/PackageMaker_Howto.html&amp;lt;/ref&amp;gt;. It is preferable to distribute a simple Application Bundle within a .dmg Disk Image.&lt;br /&gt;
&lt;br /&gt;
=== Creating ASCEND.app ===&lt;br /&gt;
&lt;br /&gt;
To create the ASCEND application bundle&lt;br /&gt;
&lt;br /&gt;
* scons -j2 install INSTALL_PREFIX=~/ascinst&lt;br /&gt;
* The bundle will appear as ~/ascinst/ASCEND.app&lt;br /&gt;
* TODO: add necessary GTK files to the .app!&lt;br /&gt;
* follow instructions below to turn it into a redistributable disk image&lt;br /&gt;
&lt;br /&gt;
The file {{src|mac/Info.plist}} contains all the key-value stuff describing the application. We had to make changes to {{src|pygtk/ascend.in}} to accommodate the particularities of the Mac platform, too.&lt;br /&gt;
&lt;br /&gt;
=== Creating a Disk Image (ASCEND-0.9.X.dmg) ===&lt;br /&gt;
&lt;br /&gt;
Some instructions are here: http://www.wikihow.com/Make-a-DMG-File-on-a-Mac&lt;br /&gt;
&lt;br /&gt;
In summary:&lt;br /&gt;
&lt;br /&gt;
* use the Applications/Utilities/Disk Utility application&lt;br /&gt;
* create a new image large enough for your needs&lt;br /&gt;
* mount and open the image&lt;br /&gt;
* from the Terminal, run scons -j2 install INSTALL_PREFIX=(location of your disk image folder)&lt;br /&gt;
* set the folder background image to ~/ascend/mac/folder-background.png&lt;br /&gt;
* arrange the files so that they look OK, the folder-background arrow should point from the ASCEND.app to the Applications folder alias.&lt;br /&gt;
* return to the disk image program&lt;br /&gt;
* click &#039;convert&#039; and convert to a compressed image (OK to overwrite)&lt;br /&gt;
* all done, you can double-click the image file now, and it should mount and appear as you wanted it.&lt;br /&gt;
&lt;br /&gt;
=== Finding all the GTK files ===&lt;br /&gt;
&lt;br /&gt;
To create a safely porting ASCEND.app, we need to embed all of GTK into the application bundle. The above application won&#039;t be complete until we achieve that.&lt;br /&gt;
&lt;br /&gt;
Looks like some Python packages called [http://docs.python.org/library/modulefinder.html modulefinder] (built-in to Python) or [http://pypi.python.org/pypi/modulegraph/ modulegraph] (external) may be able to help with locating all the necessary files for satisfying Python &#039;import&#039; dependencies.&lt;br /&gt;
&lt;br /&gt;
Then, [http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/otool.1.html otool] (&#039;otool -L&#039;) can be used to find shared library dependencies.&lt;br /&gt;
&lt;br /&gt;
There are also some other files such as bitmaps, &#039;locale&#039; files, and maybe others that will be required for correct running of GTK; these also need to be bundled.&lt;br /&gt;
&lt;br /&gt;
The tool [http://sourceforge.net/apps/trac/gtk-osx/wiki/Bundle ige-mac-bundler] seems to provide some degree of automation for this process, although it seems to be more oriented for C application than Python. We have some [[Porting_to_Mac/ige-mac-bundler|notes on how it works]].&lt;br /&gt;
&lt;br /&gt;
The shell-script gimpguts.sh, available from GIMPskel.zip on [http://gimp-app.sourceforge.net/ this page] also contains some code for pulling in the necessary bits of GTK for packaging.&lt;br /&gt;
&lt;br /&gt;
Our solution is a Python script that makes calls to &#039;otool&#039; and &#039;modulefinder&#039;. We hope to be able to incorporate this script into our SCons build scripts as a &#039;tool&#039;, but at the moment, {{src|scons/installgtk.py}} is standalone. This is still under development.&lt;br /&gt;
&lt;br /&gt;
Most Mac libraries by default are hard-wired with absolute dependency paths as [http://blogs.sun.com/dipol/entry/dynamic_libraries_rpath_and_mac described by Joe Di Pol]. The solution seems to be to post-process the shared libraries after they have been copied, using &#039;install_name_tool&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Problems with non-english Systems ===&lt;br /&gt;
&lt;br /&gt;
You need to set your System to english - it&#039;s not about your system user interface language and not about your keyboard, it about the Formats.&lt;br /&gt;
&lt;br /&gt;
Go to&lt;br /&gt;
System Preferences -&amp;gt; Interantional -&amp;gt; Formats&lt;br /&gt;
&lt;br /&gt;
select english US and reboot your system.&lt;br /&gt;
&lt;br /&gt;
If you do not take this step, ascend will ignore all decimal places.&lt;br /&gt;
PI will be 3.0000 instead of 3.1415, numbers like 0.12345 will be 0.00000 possibly causing &amp;quot;Division by Zero&amp;quot; Errors.&lt;br /&gt;
&lt;br /&gt;
=== Problems With Matplotlib ===&lt;br /&gt;
&lt;br /&gt;
[http://matplotlib.sourceforge.net/ Matplotlib] is used for all plotting by the PyGTK GUI, and Matplotlib in turn depends on [http://numpy.scipy.org/ NumPy]. NumPy doesn&#039;t work correctly with Apple&#039;s System Python, so you have to install MacPython to use the standard binary releases of Matplotlib and NumPy. Alternatively, it&#039;s possible to go back and download older versions of NumPy that &#039;&#039;do&#039;&#039; run on Apple&#039;s Python, but you&#039;ll presumably be losing some functionaly as a result.&lt;br /&gt;
&lt;br /&gt;
The conclusion from all this is that it might be advisable for ASCEND on the Mac to be linked against MacPython, and for a runtime check to be made to ensure that the correct version is in place.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to Apple Events ===&lt;br /&gt;
&lt;br /&gt;
Currently, GTK on Mac has no support for receiving or sending Apple Events. This is a problem, because Mac OS X attempts to communicate using Apple Events when a file is to be opened. If the app is not listening for events, then nothing will happen.&lt;br /&gt;
&lt;br /&gt;
However, there seems to be a workaround for the case of Python scripts: [http://appscript.sourceforge.net appscript], which contains a module called [http://appscript.sourceforge.net/py-appscript/doc/aem-manual/05_targettingapplications.html py-aem]. It may be possible to incorporate this into ASCEND as a way for processing such events. There may be other similar modules, possible. Also, PyObjC may provide another way of creating event listeners. These modules are included by default with [http://www.python.org/download/mac/ MacPython].&lt;br /&gt;
&lt;br /&gt;
According to GTK-OSX, there has not yet been any attempt to incorporate this stuff into ige-mac-integration, although it was agreed that it would be desirable to integrate it there (to benefit also C-based GTK applications ported to Mac).&lt;br /&gt;
&lt;br /&gt;
An alternative approach might be to write a very small Carbon/Cocoa application that could do the event listening, and pass the events on to the main application.&lt;br /&gt;
&lt;br /&gt;
=== Alternative approach: Homebrew? ===&lt;br /&gt;
&lt;br /&gt;
A new method&amp;lt;ref&amp;gt;http://blog.abhiomkar.in/2010/01/02/macports-to-homebrew-new-packaging-system-for-mac-os-x/&amp;lt;/ref&amp;gt; of obtaining GTK, SWIG, SCons and other tools is via [http://github.com/mxcl/homebrew Homebrew].&lt;br /&gt;
&lt;br /&gt;
An initial check of Homebrew shows that although it provides GTK+, at this stage it only provides the X11 version of GTK+, which does not help with the task of creating native GTK+ ASCEND as desired here. Also, the &#039;gtk-demo&#039; compiled by Homebrew seems to segfault, not sure what the reason for that was.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Mac_OS_X]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2798</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2798"/>
		<updated>2011-07-05T09:54:21Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Equations of State */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* &amp;lt;strike&amp;gt;[[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&amp;lt;/strike&amp;gt;&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;4th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Having discussed flexibility with regards to equation of state decided on the future structure of the program. Using various structs and unions fprops now has a skeleton capable of supporting several possible equations. &lt;br /&gt;
&lt;br /&gt;
Still to do in this area: Actually implement other EOSs (peng-robinson first), Refactor FPROPS to fit with new way of doing things. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;24th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switched to Mac OS X for development, switched to the Xcode IDE for editing, hopefully the overheads in learning the new system will be worth it. Spoke to John about support for multiple equations of state, created a couple of files ready to start experimenting.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] &amp;amp; [[PengRobinson EOS in FPROPS|Peng Robinson]] cubic EOSs. See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup redkw.c], [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup redkw.h], &lt;br /&gt;
[http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
One of the main challenges here is to write functions which can take any correlation data struct as an input, decide which correlation to use, and return the desired value. After some consultation with John, we&#039;ve decided on a struct containing all of the data and pointers to the various functions. A union is used to enable different types of data to be passed to functions with the same arguments.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/** Enumerate EOS correlations&lt;br /&gt;
 */&lt;br /&gt;
enum eos{&lt;br /&gt;
    pengrob,&lt;br /&gt;
    redkw,&lt;br /&gt;
    helmholtz,&lt;br /&gt;
    mbwr //etc.&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
/** Union for equation of state data&lt;br /&gt;
 */&lt;br /&gt;
typedef union eos_tag{&lt;br /&gt;
    HelmholtzData* helmholtzData;&lt;br /&gt;
    CubicData* cubicData;&lt;br /&gt;
    //etc...&lt;br /&gt;
} EosData;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Definition of a fluid property function pointer&lt;br /&gt;
 */&lt;br /&gt;
typedef double (*propFnPtr)(double,double,const EosData*);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Structure pointing to the necessary data and functions to calculate&lt;br /&gt;
    fluid properties.&lt;br /&gt;
*/&lt;br /&gt;
typedef struct pureFluid{&lt;br /&gt;
	enum eos type;&lt;br /&gt;
    IdealData *idealData;&lt;br /&gt;
	EosData  *eosData;&lt;br /&gt;
	//Pointers to departure functions&lt;br /&gt;
    propFnPtr p_fn;&lt;br /&gt;
    propFnPtr u_fn;&lt;br /&gt;
    propFnPtr h_fn;&lt;br /&gt;
    propFnPtr s_fn;&lt;br /&gt;
    propFnPtr a_fn;&lt;br /&gt;
    propFnPtr cv_fn;&lt;br /&gt;
    propFnPtr cp_fn;&lt;br /&gt;
    propFnPtr w_fn;&lt;br /&gt;
    propFnPtr g_fn;&lt;br /&gt;
} pureFluid;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The structure can be created as follows, and then the function pointers can simply be followed to the correct function.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
    EosData eosData={.cubicData=&amp;amp;cData};&lt;br /&gt;
    pureFluid fluidData={&lt;br /&gt;
        pengrob,&lt;br /&gt;
        &amp;amp;iData,&lt;br /&gt;
        &amp;amp;eosData,&lt;br /&gt;
        //Pointers to departure functions&lt;br /&gt;
        pengrob_p,&lt;br /&gt;
        pengrob_u_depart,&lt;br /&gt;
        pengrob_h_depart,&lt;br /&gt;
        pengrob_s_depart,&lt;br /&gt;
        pengrob_a_depart,&lt;br /&gt;
        pengrob_cv,&lt;br /&gt;
        pengrob_cp,&lt;br /&gt;
        pengrob_w,&lt;br /&gt;
        pengrob_g_depart&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
double p=fluidData.p_fn(T,rho,fluidData.eosData);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User_talk:Aakash&amp;diff=2786</id>
		<title>User talk:Aakash</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User_talk:Aakash&amp;diff=2786"/>
		<updated>2011-07-04T16:49:27Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: Blanked the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2785</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2785"/>
		<updated>2011-07-04T16:48:17Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Equations of State - New code, should be moved to its own page probably.*/&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* &amp;lt;strike&amp;gt;[[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&amp;lt;/strike&amp;gt;&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;4th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Having discussed flexibility with regards to equation of state decided on the future structure of the program. Using various structs and unions fprops now has a skeleton capable of supporting several possible equations. &lt;br /&gt;
&lt;br /&gt;
Still to do in this area: Actually implement other EOSs (peng-robinson first), Refactor FPROPS to fit with new way of doing things. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;24th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switched to Mac OS X for development, switched to the Xcode IDE for editing, hopefully the overheads in learning the new system will be worth it. Spoke to John about support for multiple equations of state, created a couple of files ready to start experimenting.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] &amp;amp; [[Peng Robinson EOS in FPROPS|Peng Robinson]] cubic EOSs. See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup redkw.c], [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup redkw.h], &lt;br /&gt;
[http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
One of the main challenges here is to write functions which can take any correlation data struct as an input, decide which correlation to use, and return the desired value. After some consultation with John, we&#039;ve decided on a struct containing all of the data and pointers to the various functions. A union is used to enable different types of data to be passed to functions with the same arguments.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/** Enumerate EOS correlations&lt;br /&gt;
 */&lt;br /&gt;
enum eos{&lt;br /&gt;
    pengrob,&lt;br /&gt;
    redkw,&lt;br /&gt;
    helmholtz,&lt;br /&gt;
    mbwr //etc.&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
/** Union for equation of state data&lt;br /&gt;
 */&lt;br /&gt;
typedef union eos_tag{&lt;br /&gt;
    HelmholtzData* helmholtzData;&lt;br /&gt;
    CubicData* cubicData;&lt;br /&gt;
    //etc...&lt;br /&gt;
} EosData;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Definition of a fluid property function pointer&lt;br /&gt;
 */&lt;br /&gt;
typedef double (*propFnPtr)(double,double,const EosData*);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Structure pointing to the necessary data and functions to calculate&lt;br /&gt;
    fluid properties.&lt;br /&gt;
*/&lt;br /&gt;
typedef struct pureFluid{&lt;br /&gt;
	enum eos type;&lt;br /&gt;
    IdealData *idealData;&lt;br /&gt;
	EosData  *eosData;&lt;br /&gt;
	//Pointers to departure functions&lt;br /&gt;
    propFnPtr p_fn;&lt;br /&gt;
    propFnPtr u_fn;&lt;br /&gt;
    propFnPtr h_fn;&lt;br /&gt;
    propFnPtr s_fn;&lt;br /&gt;
    propFnPtr a_fn;&lt;br /&gt;
    propFnPtr cv_fn;&lt;br /&gt;
    propFnPtr cp_fn;&lt;br /&gt;
    propFnPtr w_fn;&lt;br /&gt;
    propFnPtr g_fn;&lt;br /&gt;
} pureFluid;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The structure can be created as follows, and then the function pointers can simply be followed to the correct function.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
    EosData eosData={.cubicData=&amp;amp;cData};&lt;br /&gt;
    pureFluid fluidData={&lt;br /&gt;
        pengrob,&lt;br /&gt;
        &amp;amp;iData,&lt;br /&gt;
        &amp;amp;eosData,&lt;br /&gt;
        //Pointers to departure functions&lt;br /&gt;
        pengrob_p,&lt;br /&gt;
        pengrob_u_depart,&lt;br /&gt;
        pengrob_h_depart,&lt;br /&gt;
        pengrob_s_depart,&lt;br /&gt;
        pengrob_a_depart,&lt;br /&gt;
        pengrob_cv,&lt;br /&gt;
        pengrob_cp,&lt;br /&gt;
        pengrob_w,&lt;br /&gt;
        pengrob_g_depart&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
double p=fluidData.p_fn(T,rho,fluidData.eosData);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2784</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2784"/>
		<updated>2011-07-04T16:38:16Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* &amp;lt;strike&amp;gt;[[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&amp;lt;/strike&amp;gt;&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;4th July 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Having discussed flexibility with regards to equation of state decided on the future structure of the program. Using various structs and unions fprops now has a skeleton capable of supporting several possible equations. &lt;br /&gt;
&lt;br /&gt;
Still to do in this area: Actually implement other EOSs (peng-robinson first), Refactor FPROPS to fit with new way of doing things. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;24th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switched to Mac OS X for development, switched to the Xcode IDE for editing, hopefully the overheads in learning the new system will be worth it. Spoke to John about support for multiple equations of state, created a couple of files ready to start experimenting.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] cubic EOS, possibly adding some other equations in the same family (van der Waals and Peng-Robinson for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup redkw.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup redkw.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
One of the main challenges here is to write functions which can take any correlation data struct as an input, decide which correlation to use, and return the desired value. The suggested method is to use a higher level struct which contains details of the correlation being used, and a pointer to the necessary data (along with NULL pointers to the other possible data):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
typedef struct eosData{&lt;br /&gt;
	short ID;&lt;br /&gt;
	HelmholtzData* helmholtz;&lt;br /&gt;
	CubicData* cubic;&lt;br /&gt;
	//Add more as new equations of state are added,&lt;br /&gt;
	//each eos should have its own header file defining the structs&lt;br /&gt;
} EosData;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
A high level function then takes this data, uses the ID flag to decide on the correlation, and calls the appropriate function. Potentially function pointers could simplify the code here:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
double fprops_p(double T, double rho, const EosData *data) {&lt;br /&gt;
	switch(data-&amp;gt;ID) {&lt;br /&gt;
		case PENGROBINSON:&lt;br /&gt;
			//Not yet implemented...&lt;br /&gt;
			break;&lt;br /&gt;
		case REDKW:&lt;br /&gt;
			return redkw_p(T,rho,data-&amp;gt;cubic);&lt;br /&gt;
			break;&lt;br /&gt;
		case HELMHOLTZ:&lt;br /&gt;
			return helmholtz_p(T,rho,data-&amp;gt;helmholtz);&lt;br /&gt;
			break;&lt;br /&gt;
		case MBWR:&lt;br /&gt;
			//Not yet implemented...&lt;br /&gt;
			break;&lt;br /&gt;
		default:&lt;br /&gt;
			fprintf(stderr, &amp;quot;fprops_p error: Unrecognised correlation ID: %d\n&amp;quot;, data-&amp;gt;ID);&lt;br /&gt;
			break;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2736</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2736"/>
		<updated>2011-06-26T11:57:46Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Equations of State */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* &amp;lt;strike&amp;gt;[[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&amp;lt;/strike&amp;gt;&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;24th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switched to Mac OS X for development, switched to the Xcode IDE for editing, hopefully the overheads in learning the new system will be worth it. Spoke to John about support for multiple equations of state, created a couple of files ready to start experimenting.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] cubic EOS, possibly adding some other equations in the same family (van der Waals and Peng-Robinson for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup redkw.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup redkw.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
One of the main challenges here is to write functions which can take any correlation data struct as an input, decide which correlation to use, and return the desired value. The suggested method is to use a higher level struct which contains details of the correlation being used, and a pointer to the necessary data (along with NULL pointers to the other possible data):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
typedef struct eosData{&lt;br /&gt;
	short ID;&lt;br /&gt;
	HelmholtzData* helmholtz;&lt;br /&gt;
	CubicData* cubic;&lt;br /&gt;
	//Add more as new equations of state are added,&lt;br /&gt;
	//each eos should have its own header file defining the structs&lt;br /&gt;
} EosData;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
A high level function then takes this data, uses the ID flag to decide on the correlation, and calls the appropriate function. Potentially function pointers could simplify the code here:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
double fprops_p(double T, double rho, const EosData *data) {&lt;br /&gt;
	switch(data-&amp;gt;ID) {&lt;br /&gt;
		case PENGROBINSON:&lt;br /&gt;
			//Not yet implemented...&lt;br /&gt;
			break;&lt;br /&gt;
		case REDKW:&lt;br /&gt;
			return redkw_p(T,rho,data-&amp;gt;cubic);&lt;br /&gt;
			break;&lt;br /&gt;
		case HELMHOLTZ:&lt;br /&gt;
			return helmholtz_p(T,rho,data-&amp;gt;helmholtz);&lt;br /&gt;
			break;&lt;br /&gt;
		case MBWR:&lt;br /&gt;
			//Not yet implemented...&lt;br /&gt;
			break;&lt;br /&gt;
		default:&lt;br /&gt;
			fprintf(stderr, &amp;quot;fprops_p error: Unrecognised correlation ID: %d\n&amp;quot;, data-&amp;gt;ID);&lt;br /&gt;
			break;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2726</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2726"/>
		<updated>2011-06-24T19:48:12Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Progress reports ~ 24th*/&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* &amp;lt;strike&amp;gt;[[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&amp;lt;/strike&amp;gt;&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;24th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switched to Mac OS X for development, switched to the Xcode IDE for editing, hopefully the overheads in learning the new system will be worth it. Spoke to John about support for multiple equations of state, created a couple of files ready to start experimenting.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] cubic EOS, possibly adding some other equations in the same family (van der Waals and Peng-Robinson for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup redkw.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup redkw.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User_talk:Aakash&amp;diff=2723</id>
		<title>User talk:Aakash</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User_talk:Aakash&amp;diff=2723"/>
		<updated>2011-06-24T18:32:36Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: Hello Aakash!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi Aakash, I&#039;m Richard, a fellow GSOC 2011 student. Our areas of interest are very different, but I mentioned to John that I&#039;d switched to developing on a Mac and he said I ought to get in touch with you.&lt;br /&gt;
&lt;br /&gt;
If you need any OS X code testing, or if there&#039;s anything I can help with, just give me a shout. [[User:RichardTowers|RichardTowers]] 18:32, 24 June 2011 (UTC)&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2650</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2650"/>
		<updated>2011-06-21T13:33:18Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Separating Correlation Coefficients */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* &amp;lt;strike&amp;gt;[[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&amp;lt;/strike&amp;gt;&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/xml/hydrogen.fluid?view=markup hydrogen.fluid]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/parserMkII.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] cubic EOS, possibly adding some other equations in the same family (van der Waals and Peng-Robinson for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup redkw.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup redkw.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2649</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2649"/>
		<updated>2011-06-21T13:28:59Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* &amp;lt;strike&amp;gt;[[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&amp;lt;/strike&amp;gt;&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;20th June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All fluid files converted from source to XML, parser demonstrated to work for every file tried so far. Further features (multiple correlations from multiple sources etc.) should be relatively easy to implement now. Acquired a copy of Sandler &amp;quot;Chemical and Engineering Thermodynamics&amp;quot; which will be helpful in sorting out implementations of the cubic equations of state.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/hydrogen.xml?view=markup hydrogen.xml]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/parser.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] cubic EOS, possibly adding some other equations in the same family (van der Waals and Peng-Robinson for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup redkw.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup redkw.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2620</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2620"/>
		<updated>2011-06-17T17:15:22Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* &amp;lt;strike&amp;gt;[[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&amp;lt;/strike&amp;gt;&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;17 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finished writing an xml parser and translating c data files to xml .fluid files. readFluidFile() from parser.c will now load data at run time. There&#039;s still a few features to be implemented here but it&#039;s up and running now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/hydrogen.xml?view=markup hydrogen.xml]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/parser.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] cubic EOS, possibly adding some other equations in the same family (van der Waals and Peng-Robinson for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup redkw.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup redkw.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2619</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2619"/>
		<updated>2011-06-17T17:12:42Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Goals - finished parser/xml*/&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* &amp;lt;strike&amp;gt;[[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&amp;lt;/strike&amp;gt;&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/hydrogen.xml?view=markup hydrogen.xml]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/parser.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] cubic EOS, possibly adding some other equations in the same family (van der Waals and Peng-Robinson for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup redkw.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup redkw.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Redlich_Kwong_EOS_in_FPROPS&amp;diff=2591</id>
		<title>Redlich Kwong EOS in FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Redlich_Kwong_EOS_in_FPROPS&amp;diff=2591"/>
		<updated>2011-06-15T10:15:17Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Departure Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{task}}&lt;br /&gt;
Work on this continues as part of GSoC 2011 ([[User:richardTowers|Richard Towers]]). See also [[FPROPS]], [[PengRobinson EOS in FPROPS]].&lt;br /&gt;
==Overview==&lt;br /&gt;
The Redlich-Kwong equation of state is one of several cubic equations of state that FPROPS aims to implement in the future. In its basic form it relates pressure to temperature and relative volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
P=\frac{RT}{V-b}-\frac{a}{V(V+b)}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Departure Functions==&lt;br /&gt;
Other thermodynamic properties can be calculated from the departure functions:&lt;br /&gt;
&lt;br /&gt;
Helmholtz Energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A-A^{0}=-RT\ln\frac{V-b}{V}-\frac{a}{b}\ln\frac{V+b}{V}-RT\ln\frac{V}{V^{0}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entropy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
S-S^{0}=R\ln\frac{V-b}{V}-\frac{a}{2bT}\ln\frac{V+b}{V}+R\ln\frac{V}{V^{0}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enthalpy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
H-H^{0}=\frac{bRT}{V-b}-\frac{a}{V+b}-\frac{3a}{2b}\ln\frac{V+b}{V}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Internal Energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
U-U^{0}=-\frac{3a}{2b}\ln\frac{V+b}{V}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Gibbs free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G-G^{0}=\frac{bRT}{V-b}-\frac{a}{V+b}-RT\ln\frac{V-b}{V}-\frac{a}{b}\ln\frac{V+b}{V}-RT\ln\frac{V}{V^{0}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specific Heat Capacity at Constant Pressure:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Specific Heat Capacity at Constant Temperature:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Other Properties==&lt;br /&gt;
Fugacity:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\ln\frac{f}{P}=\frac{b}{V-b}-\frac{a}{RT(V+b)}-\ln\frac{V-b}{V}-\frac{a}{bRT}\ln\frac{V+b}{V}-\ln\left(\frac{V}{V-b}-\frac{a}{RT(V+b)}\right)&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2590</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2590"/>
		<updated>2011-06-15T09:56:31Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Equations of State */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Browse code: {{srcbranchdir|richard|models/johnpye/fprops}}&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/hydrogen.xml?view=markup hydrogen.xml]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/parser.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[Redlich Kwong EOS in FPROPS|Redlich Kwong]] cubic EOS, possibly adding some other equations in the same family (van der Waals and Peng-Robinson for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup redkw.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup redkw.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2574</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2574"/>
		<updated>2011-06-12T14:54:29Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;12 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Found a function to calculate critical pressure in sat.c, made this public and used it in redkw.c. In the process of testing the results now.&lt;br /&gt;
Should still probably rewrite in terms of reduced vars, and still need to think about V_0. Also remaining dep. functions need deriving. Once that&#039;s nailed there&#039;s some computing on the horizon...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/hydrogen.xml?view=markup hydrogen.xml]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/parser.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[PengRobinson EOS in FPROPS|Peng-Robinson]] cubic EOS, possibly adding some other equations in the same family (van der Waals, Redlich-Kwon and Soave for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup pengrobinson.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2572</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2572"/>
		<updated>2011-06-11T19:37:41Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;11 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The simpler departure functions for Redlich Kwon are nearly implemented now (see [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/redkw.c?revision=3481&amp;amp;view=markup&amp;amp;pathrev=3481 redkw.c]). The functions should probably be rewritten in terms of reduced variables, which may eliminate the (currently terminal) problem of unspecified critical pressure. Also careful consideration needs to be given to the value of &amp;lt;math&amp;gt;V^0&amp;lt;/math&amp;gt;, this seems to be related to a reference state, which needs to be defined. Finally the calculation of Redlich-Kwong coefficients should be moved so that they&#039;re calculated a minimum number of times, we&#039;ll need some variables for this.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/hydrogen.xml?view=markup hydrogen.xml]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/parser.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[PengRobinson EOS in FPROPS|Peng-Robinson]] cubic EOS, possibly adding some other equations in the same family (van der Waals, Redlich-Kwon and Soave for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup pengrobinson.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2570</id>
		<title>PengRobinson EOS in FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2570"/>
		<updated>2011-06-09T11:32:41Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: Removed Ankit&amp;#039;s code etc. since the focus of this has shifted.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{task}}&lt;br /&gt;
Work on this is went on as a part of GSoC 2010 (Project [[User:Ankitml|Ankit]]) and continues as part of GSoC 2011 ([[User:richardTowers|Richard Towers]]).&lt;br /&gt;
See also [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Comments and suggestions are welcome&lt;br /&gt;
==Overview==&lt;br /&gt;
The Peng-Robinson EOS is a cubic equation of state in that it contains volume terms to the third power, it is one of several equations of state that can be expressed in the form&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
P=\frac{RT}{V-b}-\frac{a}{V^2+ubV+wb^2}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
Z^3-(1+B^*-uB^*)Z^2+(A^*+wB^{*2}-uB^*-uB^{*2})Z-A^*B^*-wB^{*2}-wB^{*3}=0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Where&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A^*=\frac{aP}{R^2T^2}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
B^*=\frac{bP}{RT}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
In the Peng-Robinson values for &amp;lt;math&amp;gt;u,&amp;lt;/math&amp;gt; &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;b&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt; are set as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
u=2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
w=-1&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
b=\frac{0.7780RT_c}{P_c}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
a=\frac{0.45724R^2T_c^2}{P_c}[1+f\omega(1-T_r^{\frac{1}{2}})]^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
f\omega=0.37464+1.54226\omega-0.26992\omega^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For any given pair of P,V and T we can solve for the other. Other thermodynamic properties can be obtained from the departure functions.&lt;br /&gt;
&lt;br /&gt;
==Comparisons==&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Redlich_Kwong_EOS_in_FPROPS&amp;diff=2569</id>
		<title>Redlich Kwong EOS in FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Redlich_Kwong_EOS_in_FPROPS&amp;diff=2569"/>
		<updated>2011-06-09T11:20:50Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{task}}&lt;br /&gt;
Work on this continues as part of GSoC 2011 ([[User:richardTowers|Richard Towers]]). See also [[FPROPS]], [[PengRobinson EOS in FPROPS]].&lt;br /&gt;
==Overview==&lt;br /&gt;
The Redlich-Kwong equation of state is one of several cubic equations of state that FPROPS aims to implement in the future. In its basic form it relates pressure to temperature and relative volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
P=\frac{RT}{V-b}-\frac{a}{V(V+b)}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Departure Functions==&lt;br /&gt;
Other thermodynamic properties can be calculated from the departure functions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A-A^{0}=-RT\ln\frac{V-b}{V}-\frac{a}{b}\ln\frac{V+b}{V}-RT\ln\frac{V}{V^{0}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
S-S^{0}=R\ln\frac{V-b}{V}-\frac{a}{2bT}\ln\frac{V+b}{V}+R\ln\frac{V}{V^{0}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
H-H^{0}=\frac{bRT}{V-b}-\frac{a}{V+b}-\frac{3a}{2b}\ln\frac{V+b}{V}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
U-U^{0}=-\frac{3a}{2b}\ln\frac{V+b}{V}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G-G^{0}=\frac{bRT}{V-b}-\frac{a}{V+b}-RT\ln\frac{V-b}{V}-\frac{a}{b}\ln\frac{V+b}{V}-RT\ln\frac{V}{V^{0}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\ln\frac{f}{P}=\frac{b}{V-b}-\frac{a}{RT(V+b)}-\ln\frac{V-b}{V}-\frac{a}{bRT}\ln\frac{V+b}{V}-\ln\left(\frac{V}{V-b}-\frac{a}{RT(V+b)}\right)&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2568</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2568"/>
		<updated>2011-06-09T11:20:05Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See [[Redlich Kwong EOS in FPROPS]] for details of current thoughts on its implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/hydrogen.xml?view=markup hydrogen.xml]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/parser.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[PengRobinson EOS in FPROPS|Peng-Robinson]] cubic EOS, possibly adding some other equations in the same family (van der Waals, Redlich-Kwon and Soave for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup pengrobinson.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Redlich_Kwong_EOS_in_FPROPS&amp;diff=2567</id>
		<title>Redlich Kwong EOS in FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Redlich_Kwong_EOS_in_FPROPS&amp;diff=2567"/>
		<updated>2011-06-09T11:19:31Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: Basics of Redlich Kwong&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{task}}&lt;br /&gt;
Work on this continues as part of GSoC 2011 ([[User:richardTowers|Richard Towers]]). See also [[FPROPS]], [[PengRobinson EOS in FPROPS]].&lt;br /&gt;
==Overview==&lt;br /&gt;
The Redlich-Kwong equation of state is one of several cubic equations of state that FPROPS aims to implement in the future. In its basic form it relates pressure to temperature and relative volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
P=\frac{RT}{V-b}-\frac{a}{V(V+b)}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other thermodynamic properties can be calculated from the departure functions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A-A^{0}=-RT\ln\frac{V-b}{V}-\frac{a}{b}\ln\frac{V+b}{V}-RT\ln\frac{V}{V^{0}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
S-S^{0}=R\ln\frac{V-b}{V}-\frac{a}{2bT}\ln\frac{V+b}{V}+R\ln\frac{V}{V^{0}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
H-H^{0}=\frac{bRT}{V-b}-\frac{a}{V+b}-\frac{3a}{2b}\ln\frac{V+b}{V}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
U-U^{0}=-\frac{3a}{2b}\ln\frac{V+b}{V}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G-G^{0}=\frac{bRT}{V-b}-\frac{a}{V+b}-RT\ln\frac{V-b}{V}-\frac{a}{b}\ln\frac{V+b}{V}-RT\ln\frac{V}{V^{0}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\ln\frac{f}{P}=\frac{b}{V-b}-\frac{a}{RT(V+b)}-\ln\frac{V-b}{V}-\frac{a}{bRT}\ln\frac{V+b}{V}-\ln\left(\frac{V}{V-b}-\frac{a}{RT(V+b)}\right)&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2566</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2566"/>
		<updated>2011-06-09T10:49:39Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Progress reports - Departure fns from RP&amp;amp;P*/&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;9 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
From Reid, Prausnitz and Poling, for the Redlich-Kwong EOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A-A^{0}=-RT\ln\frac{V-b}{V}-\frac{a}{b}\ln\frac{V+b}{V}-RT\ln\frac{V}{V^{0}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
S-S^{0}=R\ln\frac{V-b}{V}-\frac{a}{2bT}\ln\frac{V+b}{V}+R\ln\frac{V}{V^{0}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
H-H^{0}=\frac{bRT}{V-b}-\frac{a}{V+b}-\frac{3a}{2b}\ln\frac{V+b}{V}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
U-U^{0}=-\frac{3a}{2b}\ln\frac{V+b}{V}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G-G^{0}=\frac{bRT}{V-b}-\frac{a}{V+b}-RT\ln\frac{V-b}{V}-\frac{a}{b}\ln\frac{V+b}{V}-RT\ln\frac{V}{V^{0}}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\ln\frac{f}{P}=\frac{b}{V-b}-\frac{a}{RT(V+b)}-\ln\frac{V-b}{V}-\frac{a}{bRT}\ln\frac{V+b}{V}-\ln\left(\frac{V}{V-b}-\frac{a}{RT(V+b)}\right)&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4 June 2011&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Record of an email sent by [[John Pye]] to Richard:&lt;br /&gt;
&lt;br /&gt;
Looking at Reid, Prausnitz &amp;amp; Poling (I have the 4th edition) it might be that you will have an easier time getting started with Redlich-Kwong equations of state, rather than the Peng-Robinson ones. The EOS is detailed in Section 3-4 &amp;quot;Cubic Equations of State&amp;quot; and the derivation of so-called &#039;departure functions&#039; is detailed in Example 5-1 &amp;quot;Derive the departure functions for a pure material...&amp;quot;. This derivation includes functions for calculation of extensive properties A, S, H, U, G. Some additional partial derivatives should give you Cp, Cv, and then you need also to convert to the intensive properties. How to use these departure functions to calculate is detailed in Section 5-2 &amp;quot;Fundamental Thermodynamic Principles&amp;quot;, eg eq 5-2.4.&lt;br /&gt;
&lt;br /&gt;
Let me put the above into the context of the current code. The eq 5-2.5 contains an ideal part (an integral of Cp°), a &#039;departure function&#039;. The departure functions are functions exclusively of the p-v-T surface, ie the EOS. So given the EOS we can do the maths to work out what these departure functions need to be. This is done for the Helmholtz approach in the file helmholtz.c: see the functions eg helmholtz_h_raw, which shows the ideal and the &#039;residual&#039;  (departure) parts clearly. The residual parts are then implemented further down in that file.&lt;br /&gt;
&lt;br /&gt;
I would propose then that to do a RK or PR EOS, we can keep most of helmholtz.[ch] and simply calculate new functions like helm_resid_tau and so on, specific to the EOS in question. All the current stuff from ideal.c continues to be used as-is, and the saturation calculation also remains as-is. We just need new functions like redkw_resid, redkw_resid_del, redkw_resid_tau, etc.&lt;br /&gt;
&lt;br /&gt;
Doing the maths for those functions will need to be extremely carefully done, as from my experience is very very easy to introduce little calculation errors along the way. A good idea is to make use of tools like wxMaxima or similar, to do some of the maths symbolically, even if only as a double-check for hand-calculation. You then need to take the resulting expressions and work out how to code them efficiently.&lt;br /&gt;
&lt;br /&gt;
We will of course then need to work out suitable data-structrues that allow functions like helmholtz_h_raw (renamed to fprops_h_raw, perhaps) to be common. That will require the HelmholtzData structure to be generalised to contain some pointer to the a struct containing the necessary residual functions, I suspect.&lt;br /&gt;
&lt;br /&gt;
Further to the above, we will have to ponder how to implement support for thermo derivatives (derivs.[ch]). I think that this requires additional functions helmholtz_betap and helmholtz_alphap to be generalised as well. That might be trivial, actually.&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/hydrogen.xml?view=markup hydrogen.xml]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/parser.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[PengRobinson EOS in FPROPS|Peng-Robinson]] cubic EOS, possibly adding some other equations in the same family (van der Waals, Redlich-Kwon and Soave for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup pengrobinson.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2557</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2557"/>
		<updated>2011-06-08T16:19:36Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Equations of State */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/hydrogen.xml?view=markup hydrogen.xml]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/parser.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the [[PengRobinson EOS in FPROPS|Peng-Robinson]] cubic EOS, possibly adding some other equations in the same family (van der Waals, Redlich-Kwon and Soave for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup pengrobinson.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2556</id>
		<title>PengRobinson EOS in FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2556"/>
		<updated>2011-06-08T11:11:48Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: Punctuation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{task}}&lt;br /&gt;
Work on this is went on as a part of GSoC 2010 (Project [[User:Ankitml|Ankit]]) and continues as part of GSoC 2011 ([[User:richardTowers|Richard Towers]]).&lt;br /&gt;
See also [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Comments and suggestions are welcome&lt;br /&gt;
==Overview==&lt;br /&gt;
The Peng-Robinson EOS is a cubic equation of state in that it contains volume terms to the third power, it is one of several equations of state that can be expressed in the form&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
P=\frac{RT}{V-b}-\frac{a}{V^2+ubV+wb^2}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
Z^3-(1+B^*-uB^*)Z^2+(A^*+wB^{*2}-uB^*-uB^{*2})Z-A^*B^*-wB^{*2}-wB^{*3}=0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Where&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A^*=\frac{aP}{R^2T^2}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
B^*=\frac{bP}{RT}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
In the Peng-Robinson values for &amp;lt;math&amp;gt;u,&amp;lt;/math&amp;gt; &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;b&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt; are set as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
u=2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
w=-1&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
b=\frac{0.7780RT_c}{P_c}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
a=\frac{0.45724R^2T_c^2}{P_c}[1+f\omega(1-T_r^{\frac{1}{2}})]^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
f\omega=0.37464+1.54226\omega-0.26992\omega^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So, for given values of &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;T_c&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;T_r&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;P_c&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\omega&amp;lt;/math&amp;gt; we can solve for &amp;lt;math&amp;gt;Z&amp;lt;/math&amp;gt;. What next??&lt;br /&gt;
==Algorithm==&lt;br /&gt;
===Algorithm From Literature===&lt;br /&gt;
*Guess a Pressure.  &lt;br /&gt;
*Find roots of volume using PR-EOS, if roots&amp;lt;3 guess P again.&lt;br /&gt;
*Min V is the molar liquid volume, and the max V is vapour molar volume.&lt;br /&gt;
*get Zl and Zv.&lt;br /&gt;
*Get fugacities of both phases.&lt;br /&gt;
*Pnew = Pold*fl/fv&lt;br /&gt;
&lt;br /&gt;
===The current Algorithm===&lt;br /&gt;
*Calculate PV data using PR_EOS from 0.001 to 6666 cm3/mol.&lt;br /&gt;
*Get the range of Pressure in which volume has 3 roots.&lt;br /&gt;
*Give this range as lower and upper bounds to a golden search algorithm, minimizing the difference in fugacities.&lt;br /&gt;
*To calculate fugacities a non iterative analytical expression was derived for PR-EOS.&lt;br /&gt;
&lt;br /&gt;
===Issues That Forced to Deviate From Literature===&lt;br /&gt;
*Find a non iterative way to solve a cubic Equation for volume. The normal iterative one makes the algorithm very slow, as it is required to solve the volume cubic many number of times to arrive at the solution. So right now generating PV data for a range with a constant increment in V. &lt;br /&gt;
*This also helps in guessing the first P in the range of 3 roots, which is required as the first step.&lt;br /&gt;
*The golden search algorithm is just experimental over the standard Pnew = Pold*Fl/Fv iteration, which requires a good guess whereas Golden search requires a bracket in which solution lies. It is yet to be tested which one is better.&lt;br /&gt;
&lt;br /&gt;
==Limitations==&lt;br /&gt;
===Errors===&lt;br /&gt;
*Not working at some temperatures. [It should work on entire range from triple point to Critical Temperature]&lt;br /&gt;
&lt;br /&gt;
[Solution] - Currently trying got find out the reason for this behaviour. - [http://ascendwiki.cheme.cmu.edu/User:Ankitml Ankit ]&lt;br /&gt;
&lt;br /&gt;
*Not predicting Saturation Volumes for Liquids correctly.&lt;br /&gt;
[Solution] - Its a problem with Peng Robinson EOS, a modification to PR_EOS was proposed by G. Heyen in the paper, &amp;quot;Liquid and Vapor Properties from a cubic Equation of state&amp;quot;, in 2nd International Conference on Phase Equilibria and Fluid Properties, 1980.&lt;br /&gt;
&lt;br /&gt;
===Changes to be done to integrate with ASCEND===&lt;br /&gt;
*Data (Pc,Tc,Omega) to be taken from data files and only component name should be required in the code.&lt;br /&gt;
*No main function&lt;br /&gt;
*ASCEND wrapper&lt;br /&gt;
*Code should be in C, remove C++ functions.&lt;br /&gt;
&lt;br /&gt;
=Code=&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
//Global Variables&lt;br /&gt;
double Tc,Pc,Omega,R,Tre,b,a,RT,T,P[20000],V[20000],Phil,Phiv,Vl,Vv;&lt;br /&gt;
int j;&lt;br /&gt;
&lt;br /&gt;
int noRoots(double Psat); //gives out number of roots (of V) at a particular Pressure&lt;br /&gt;
double Pcalc(double T, double V);  // Calculates Pressure at Given T and V using PR-EOS&lt;br /&gt;
int PhiCalc(double PsatGuess); //Calculates fugacities at a given Pressure and Stores it in global variables&lt;br /&gt;
double phiDiff(double Pguess); //Finds fugacity difference at a particular P, uses function PhiCalc and is required for golden search algorithm&lt;br /&gt;
double goldSer(double a,double c,double b); //Golden search algorithm, function to be minimized is phiDiff and a is the lower bound, b is upper bound, c is the center.&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	Tc = 304.1282;  // Kelvin&lt;br /&gt;
        Pc = 73.773;  // bar&lt;br /&gt;
        Omega = 0.22394; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 260;&lt;br /&gt;
	RT = R*T;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	&lt;br /&gt;
	double p[20000],v[20000];&lt;br /&gt;
	//following for loop calculates P V data till v=6500cm3/mol and stores it in P,V arrays only if P is within bounds of 60 and -160&lt;br /&gt;
	j = 0;&lt;br /&gt;
        for (int i=0;i&amp;lt;20000;i++)&lt;br /&gt;
        {&lt;br /&gt;
                v[i] = (i + 0.001)/3;&lt;br /&gt;
                p[i] = Pcalc(T,v[i]);&lt;br /&gt;
                if(p[i]&amp;lt;60.0 &amp;amp;&amp;amp; p[i]&amp;gt;-160.0)&lt;br /&gt;
                {&lt;br /&gt;
                        P[j] = p[i];&lt;br /&gt;
                        V[j] = v[i];&lt;br /&gt;
                        j++;&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
//finding the bounds for P&lt;br /&gt;
        double pStart,deltaP;&lt;br /&gt;
        pStart = 0.01;&lt;br /&gt;
        deltaP = 1.0;&lt;br /&gt;
        for(int n = 0;n&amp;lt;3;n++)&lt;br /&gt;
        {&lt;br /&gt;
                for(double pp = pStart;pp&amp;lt;60.0;pp=pp+deltaP)&lt;br /&gt;
                {&lt;br /&gt;
                        int nor;&lt;br /&gt;
                        nor = noRoots(pp);&lt;br /&gt;
                        if (nor==3)&lt;br /&gt;
                        {&lt;br /&gt;
                                pStart = pp - deltaP;&lt;br /&gt;
                                pp = 59.0;&lt;br /&gt;
                        }&lt;br /&gt;
                }&lt;br /&gt;
                deltaP = deltaP/10;&lt;br /&gt;
        }&lt;br /&gt;
        pStart = pStart + 0.01;&lt;br /&gt;
&lt;br /&gt;
        double pEnd;&lt;br /&gt;
        pEnd = pStart;&lt;br /&gt;
        deltaP = 1.0;&lt;br /&gt;
       for(int n = 0;n&amp;lt;2;n++)&lt;br /&gt;
       {&lt;br /&gt;
                for(double pp = pEnd;pp&amp;lt;60.0;pp=pp+deltaP)&lt;br /&gt;
                {&lt;br /&gt;
                        int nor;&lt;br /&gt;
                        nor = noRoots(pp);&lt;br /&gt;
                        if (nor&amp;lt;3)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = pp - deltaP;&lt;br /&gt;
                                pp = 5000;&lt;br /&gt;
                        }&lt;br /&gt;
                }&lt;br /&gt;
                deltaP = deltaP/10;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	int sandbox;&lt;br /&gt;
	double Pa,Pb,Pc,sol,phi,resphi;&lt;br /&gt;
	phi = (1 + sqrt(5))/2;&lt;br /&gt;
        resphi = 2 - phi;&lt;br /&gt;
	Pa = pStart;&lt;br /&gt;
	Pb = pEnd;&lt;br /&gt;
	Pc = (Pb - Pa)*resphi + Pa;&lt;br /&gt;
	sol = goldSer(Pa,Pc,Pb);&lt;br /&gt;
	sandbox=PhiCalc(sol);&lt;br /&gt;
	cout&amp;lt;&amp;lt;&amp;quot;Molar Volume (L) = &amp;quot;&amp;lt;&amp;lt;Vl&amp;lt;&amp;lt;&amp;quot; cm3/mol&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&lt;br /&gt;
	cout&amp;lt;&amp;lt;&amp;quot;Molar Volume (V) = &amp;quot;&amp;lt;&amp;lt;Vv&amp;lt;&amp;lt;&amp;quot; cm3/mol&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&lt;br /&gt;
	cout&amp;lt;&amp;lt;&amp;quot;Difference in fugacities of vapour and liquid = &amp;quot;&amp;lt;&amp;lt;fabs(Phil-Phiv)&amp;lt;&amp;lt;&#039;\n&#039;;&lt;br /&gt;
	cout&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&#039;\t&#039;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&#039;\t&#039;&amp;lt;&amp;lt;Vl&amp;lt;&amp;lt;&#039;\t&#039;&amp;lt;&amp;lt;Vv&amp;lt;&amp;lt;&#039;\t&#039;&amp;lt;&amp;lt;fabs(Phil-Phiv)&amp;lt;&amp;lt;&#039;\n&#039;;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int noRoots(double Psat)&lt;br /&gt;
{&lt;br /&gt;
        double Vroot[3];&lt;br /&gt;
        Vroot[0] = -99; Vroot[1] = -99; Vroot[2] = -99;&lt;br /&gt;
        int rootCount = 0;&lt;br /&gt;
        for (int i = 0; i &amp;lt; j-1;i++)&lt;br /&gt;
        {&lt;br /&gt;
                if((Psat&amp;lt;=P[i+1] &amp;amp;&amp;amp; Psat&amp;gt;=P[i]) || (Psat&amp;gt;=P[i+1] &amp;amp;&amp;amp; Psat&amp;lt;=P[i]))&lt;br /&gt;
                {&lt;br /&gt;
                        Vroot[rootCount] = V[i]+(Psat-P[i])*(V[i+1]-V[i])/(P[i+1]-P[i]);&lt;br /&gt;
                        rootCount++;&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
        return rootCount;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
double Pcalc(double T, double V)&lt;br /&gt;
{&lt;br /&gt;
        double P,m,tmp;&lt;br /&gt;
        b = 0.0778*R*Tc/Pc;&lt;br /&gt;
        m = 0.37464+1.54226*Omega-0.26992*pow(Omega,2);&lt;br /&gt;
        tmp = 1+m*(1-sqrt(Tre));&lt;br /&gt;
        a = 0.45724*R*R*Tc*(Tc/Pc)*pow(tmp,2);&lt;br /&gt;
        P = R*T/(V-b) - a/(V*(V+b)+b*(V-b));&lt;br /&gt;
        return P;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int PhiCalc(double PsatGuess)&lt;br /&gt;
{       double Vroot[3],A,B;&lt;br /&gt;
        B = PsatGuess*b/RT;&lt;br /&gt;
        A = a*PsatGuess/pow(RT,2);&lt;br /&gt;
        Vroot[0] = -99; Vroot[1] = -99; Vroot[2] = -99;&lt;br /&gt;
        int rootCount = 0;&lt;br /&gt;
        for (int i = 0; i &amp;lt; j-1;i++)&lt;br /&gt;
        {&lt;br /&gt;
                if((PsatGuess&amp;lt;=P[i+1] &amp;amp;&amp;amp; PsatGuess&amp;gt;=P[i]) || (PsatGuess&amp;gt;=P[i+1] &amp;amp;&amp;amp; PsatGuess&amp;lt;=P[i]))&lt;br /&gt;
                {&lt;br /&gt;
                        Vroot[rootCount] =V[i]+(PsatGuess-P[i])*(V[i+1]-V[i])/(P[i+1]-P[i]);&lt;br /&gt;
                        rootCount++;&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        double Zv,Zl;&lt;br /&gt;
        double term_a,term_b,term_c;&lt;br /&gt;
&lt;br /&gt;
        Vl = Vroot[0];   //liquid volume is the smaller root&lt;br /&gt;
        Vv = Vroot[2];   // vapour volume is the largest one&lt;br /&gt;
&lt;br /&gt;
        Zl = PsatGuess*Vl/(R*T);  //the corresponding Z&lt;br /&gt;
        Zv = PsatGuess*Vv/(R*T);&lt;br /&gt;
&lt;br /&gt;
        term_a = (1 + sqrt(2))*B;&lt;br /&gt;
        term_b = (1 - sqrt(2))*B;&lt;br /&gt;
        term_c = 2*sqrt(2)*B;&lt;br /&gt;
&lt;br /&gt;
        Phil = (Zl-1) - log(Zl-B) - A/term_c*log((Zl+term_a)/(Zl+term_b));&lt;br /&gt;
        Phiv = (Zv-1) - log(Zv-B) - A/term_c*log((Zv+term_a)/(Zv+term_b));&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
double phiDiff(double Pguess)&lt;br /&gt;
{&lt;br /&gt;
	double phiD;&lt;br /&gt;
	int sandbox;&lt;br /&gt;
	sandbox = PhiCalc(Pguess);&lt;br /&gt;
	phiD = fabs(Phil - Phiv);&lt;br /&gt;
	return phiD;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
double goldSer(double a,double c,double b)&lt;br /&gt;
{&lt;br /&gt;
        double d,phi,resphi;&lt;br /&gt;
	phi = (1 + sqrt(5))/2;&lt;br /&gt;
        resphi = 2 - phi;&lt;br /&gt;
        if (fabs(a-b)&amp;lt;0.000001)&lt;br /&gt;
                return ((a+b)/2);&lt;br /&gt;
&lt;br /&gt;
        d = c + resphi*(b - c);&lt;br /&gt;
&lt;br /&gt;
        if (phiDiff(d)&amp;lt;phiDiff(c))&lt;br /&gt;
                return goldSer(c,d,b);&lt;br /&gt;
        else&lt;br /&gt;
                return goldSer(d,c,a);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
&lt;br /&gt;
* Maybe this is of interest: http://pubs.acs.org/doi/abs/10.1021/ed066p54.2 ? [[User:Jpye|Jpye]] 06:39, 5 August 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==Comparisons==&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2533</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2533"/>
		<updated>2011-06-03T08:26:12Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Initial Thoughts -&amp;gt; Goals*/&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/hydrogen.xml?view=markup hydrogen.xml]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/parser.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the Peng-Robinson cubic EOS, possibly adding some other equations in the same family (van der Waals, Redlich-Kwon and Soave for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup pengrobinson.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2532</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2532"/>
		<updated>2011-06-03T08:25:23Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Parser */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
== Initial Thoughts ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/hydrogen.xml?view=markup hydrogen.xml]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/parser.c?view=markup parser.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the Peng-Robinson cubic EOS, possibly adding some other equations in the same family (van der Waals, Redlich-Kwon and Soave for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup pengrobinson.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=FPROPS&amp;diff=2527</id>
		<title>FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=FPROPS&amp;diff=2527"/>
		<updated>2011-06-02T16:50:07Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Implementation - Moved peng robinson to PengRobinson EOS in FPROPS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div style=&amp;quot;float:right;border:solid 1pt green;background-color=#EEFFEE;width:18em;padding:12px&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Fluids supported by FPROPS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{{fpropsfluid|ammonia}}, {{fpropsfluid|nitrogen}}, {{fpropsfluid|hydrogen}}, {{fpropsfluid|water}}, {{fpropsfluid|carbondioxide}}, {{fpropsfluid|methane}}, {{fpropsfluid|carbonmonoxide}}, {{fpropsfluid|ethanol}}, {{fpropsfluid|acetone}}, {{fpropsfluid|carbonylsulfide}}, {{fpropsfluid|decane}}, {{fpropsfluid|hydrogensulfide}}, {{fpropsfluid|isohexane}}, {{fpropsfluid|isopentane}}, {{fpropsfluid|krypton}}, {{fpropsfluid|neopentane}}, {{fpropsfluid|nitrousoxide}}, {{fpropsfluid|nonane}}, {{fpropsfluid|sulfurdioxide}}, {{fpropsfluid|toluene}}, {{fpropsfluid|xenon}}, {{fpropsfluid|butane}}, {{fpropsfluid|butene}}, {{fpropsfluid|cisbutene}}, {{fpropsfluid|isobutene}}, {{fpropsfluid|transbutene}}, {{fpropsfluid|dimethylether}}, {{fpropsfluid|ethane}}, {{fpropsfluid|parahydrogen}}, {{fpropsfluid|isobutane}}, {{fpropsfluid|r41}}, {{fpropsfluid|r116}}, {{fpropsfluid|r141b}}, {{fpropsfluid|r142b}}, {{fpropsfluid|r218}}, {{fpropsfluid|r245fa}}&lt;br /&gt;
&lt;br /&gt;
(in svn, at r3042)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;FPROPS&#039;&#039;&#039; is a free open-source C-based library for high-accuracy evaluation of thermodynamic properties for a number of pure substances. It makes use of published data for the Helmholtz fundamental equation for those substances. It has been developed by [[User:Jpye|John Pye]] and [[#Contributors|others]], and will happily function as standalone code, but is also provided with [[external library]] code for ASCEND so that it can be used to access these accurate property correlations from within a [[MODEL]].&lt;br /&gt;
&lt;br /&gt;
Currently FPROPS supports calculation of the properties of the pure substances shown on the right. The properties that can be calculated are internal energy &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt;, entropy &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;, pressure &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt;, enthalpy &amp;lt;math&amp;gt;h&amp;lt;/math&amp;gt; and Helmholtz energy &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt;, as well as various partial derivatives of these with respect to temperature and density.&lt;br /&gt;
&lt;br /&gt;
FPROPS reproduces a limited subset of the functionality of commercial programs such as [http://www.nist.gov/srd/nist23.htm REFPROP], [http://gibbs.mech.kyushu-u.ac.jp/~akasaka/propath_man/ PROPATH], EES, [http://www.ruhr-uni-bochum.de/thermo/Software/Seiten/Fluidcal-eng.htm FLUIDCAL], [[freesteam]], SteamTab, and others, but is free open-source software, licensed under the [http://www.gnu.org/licenses/gpl.html GPL]. Contributions are most welcome!&lt;br /&gt;
&lt;br /&gt;
Enhancement to FPROPS feature set and list of supported fluids has been going on as part of ASCEND&#039;s involvement in [[GSOC2010]].&lt;br /&gt;
&lt;br /&gt;
FPROPS is included with ASCEND as of version 0.9.5.116, or you can browse the code at {{srcdir|models/johnpye/fprops/}} or access it [[VersionManagement|via subversion]] (code is evolving rapidly, as of Aug 2010).&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
The calculation routines implement calculation of reduced Helmholtz energy &amp;lt;math&amp;gt;\phi = a / R T&amp;lt;/math&amp;gt; as a function of reduced density &amp;lt;math&amp;gt;\delta = \rho / \rho_c&amp;lt;/math&amp;gt; and &#039;&#039;inverse&#039;&#039; reduced temperature &amp;lt;math&amp;gt;\tau = T_c / T&amp;lt;/math&amp;gt;, by dividing it into ideal &amp;lt;math&amp;gt;\phi^0 \left(\tau,\delta\right)&amp;lt;/math&amp;gt; and &#039;real&#039; or &#039;residual&#039; &amp;lt;math&amp;gt;\phi^r \left(\tau,\delta \right)&amp;lt;/math&amp;gt; parts, as described in IAPWS-95&amp;lt;ref name=iapws95&amp;gt;http://www.iapws.org/relguide/IAPWS95-Rev.pdf&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Ideal part ===&lt;br /&gt;
&lt;br /&gt;
Calculation of the &#039;&#039;&#039;ideal part&#039;&#039;&#039; of the reduced Helmholtz energy is derived from the expression for the zero-pressure limit of reduced specific heat capacity at constant pressure, &amp;lt;math&amp;gt;c_p^0 / R&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the specific gas constant. This quantity &amp;lt;math&amp;gt;{c_p^0}(T)/R&amp;lt;/math&amp;gt; can be expressed as a series composed of two different types of terms:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;3&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
! type !! expression !! correlation constants&lt;br /&gt;
|-&lt;br /&gt;
| power terms || &amp;lt;math&amp;gt;c_i T^{t_i}&amp;lt;/math&amp;gt; || &amp;lt;math&amp;gt;c, t&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| exponential terms&amp;lt;br/&amp;gt;(also called &#039;Einstein&#039; terms&amp;lt;ref&amp;gt;Lemmon, E.W. and Span, R.,&lt;br /&gt;
2006, &#039;&#039;Short Fundamental Equations of State for 20 Industrial Fluids&#039;&#039;, J. Chem. Eng. Data, &#039;&#039;&#039;51&#039;&#039;&#039;, 785-850, {{doi|10.1021/je050186n}}&amp;lt;/ref&amp;gt;) || &amp;lt;math&amp;gt;\frac{b_i x_i^2 exp(-x_i)}{[1-exp(-x_i)]^2}&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;x_i = \frac{\beta_i}{T}&amp;lt;/math&amp;gt; || &amp;lt;math&amp;gt;b, \beta&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An expression for calculating the ideal component of Helmholtz energy &amp;lt;math&amp;gt;a^0 \left(T , \rho \right)&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;c_p^0&amp;lt;/math&amp;gt; is given by Span et al&amp;lt;ref&amp;gt;Span &amp;amp; Wagner (1996), &amp;quot;A new equation of state for carbon dioxide covering from the triple point temperature to 1100 K at pressures up to 800 MPa&amp;quot; &#039;&#039;J. Phys. Chem. Ref. Data&#039;&#039;, &#039;&#039;&#039;25&#039;&#039;&#039; p 1509 ff, http://link.aip.org/link/?jpr/25/1509%26agg=NIST, {{doi|10.1063/1.555991}}&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{a^0}{RT} = \phi^0 = \frac{h_0^0 \tau}{R T_c} - \frac{s_0^0}{R} - 1 + \ln {\frac{\delta / \delta_0}{\tau / \tau_0}} - \frac{\tau}{R} \int_{\tau_0}^{\tau}{\frac{c_p^0}{\tau^2}d\tau} + \frac{1}{R} \int_{\tau_0}^{\tau}{\frac{c_p^0}{\tau} d \tau}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the &#039;&#039;&#039;reduced temperature&#039;&#039;&#039; is &amp;lt;math&amp;gt;\tau = \frac{T^{*}}{T}&amp;lt;/math&amp;gt; and the &#039;&#039;&#039;reduced density&#039;&#039;&#039; is &amp;lt;math&amp;gt;\delta = \frac{\rho}{\rho^{*}}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
On the other hand, using the relations for the Helmholtz fundamental equation, one can see that&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{c_p^0}{R} = 1 -\tau^2 \phi^0_{\tau \tau}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so coefficients of &amp;lt;math&amp;gt;c_p^0&amp;lt;/math&amp;gt; can be calculated from coefficients of &amp;lt;math&amp;gt;\phi^0&amp;lt;/math&amp;gt; (providing, we assume, that the fundamental equation has smooth first and second (and possibly third) derivatives, and that when terms of &amp;lt;math&amp;gt;{c_p^0}(T)&amp;lt;/math&amp;gt; are integrated they don&#039;t &#039;interact&#039;). One can go the other way, and determine &amp;lt;math&amp;gt;\phi^0&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;c_p^0&amp;lt;/math&amp;gt;, with the exception of the integration constants, which are, in that case, determined using specified values of enthalpy &amp;lt;math&amp;gt;h^0_{ref}&amp;lt;/math&amp;gt; and entropy &amp;lt;math&amp;gt;s^0_{ref}&amp;lt;/math&amp;gt; at a reference state &amp;lt;math&amp;gt;\left(T_{ref},\rho_{ref} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Residual part ===&lt;br /&gt;
&lt;br /&gt;
For the &#039;&#039;&#039;residual part&#039;&#039;&#039; of the reduced Helmholtz energy, FPROPS currently supports three different kinds of terms:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;3&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
! type !! expression !! correlation constants&lt;br /&gt;
|-&lt;br /&gt;
| power terms || &amp;lt;math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
\begin{cases} &lt;br /&gt;
  a_i \tau^{t_i} \delta^{d_i} exp(-\delta^{l_i}), &amp;amp; \mbox{if }l \ne 0 \\&lt;br /&gt;
  a_i \tau^{t_i} \delta^{d_i},  &amp;amp; \mbox{otherwise} &lt;br /&gt;
\end{cases}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/math&amp;gt; || &amp;lt;math&amp;gt;a, t, d, l&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| gaussian terms || &amp;lt;math&amp;gt;n_i \tau^{t_i} \delta^{d_i} exp[-\alpha_i(\delta - \epsilon_i)^2 - \beta_i(\tau - \gamma_i)^2]&amp;lt;/math&amp;gt; || &amp;lt;math&amp;gt; n, t, d, \alpha, \beta, \gamma, \epsilon&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| critical terms || &amp;lt;math&amp;gt;n_i \Delta^{b_i} \delta \psi \mbox{  where } \begin{cases}&lt;br /&gt;
  \Delta = \theta^2 + B_i \left[ \left( \delta - 1 \right)^2 \right]^{a_i} \\&lt;br /&gt;
  \theta = \left( 1- \tau \right) + A_i \left[ \left( \delta - 1 \right)^2 \right]^{\frac{1}{2 \beta_i}} \\&lt;br /&gt;
  \psi = exp \left[-C_i \left(\delta-1 \right)^2 - D_i \left( \tau - 1 \right)^2 \right]&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|| &amp;lt;math&amp;gt;n, a, b, \beta, A, B, C, D&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
These different terms are used in various combinations across a number of high-accuracy publications of thermodynamic property data. Overall, the residual series permits calculation of &#039;real&#039; reduced Helmholtz energy &amp;lt;math&amp;gt;\phi \left(\tau,\delta \right) = \phi^0 \left(\tau,\delta \right) + \phi^r \left( \tau,\delta \right)&amp;lt;/math&amp;gt; and hence the specific Helmholtz energy &amp;lt;math&amp;gt;a = R T \phi \left(\tau,\delta\right)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
From the expression for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;, we can then derive expressions for &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;h&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and their partial derivatives with respect to density and temperature. These expressions are summarised in IAPWS-95&amp;lt;ref name=iapws95&amp;gt;&amp;lt;/ref&amp;gt; as well as by Tillner Roth et al&amp;lt;ref&amp;gt;Tillner-Roth, Harms-Watzenberg and Baehr (1993), &amp;quot;Eine neue Fundamentalgleichung für Ammoniak&amp;quot;,&lt;br /&gt;
&#039;&#039;DKV-Tagungsbericht&#039;&#039;, &#039;&#039;&#039;20&#039;&#039;&#039;, 167-181&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Saturated mixture properties ===&lt;br /&gt;
&lt;br /&gt;
The Helmholtz function &amp;lt;math&amp;gt;a \left(\rho,T \right)&amp;lt;/math&amp;gt;, given above, applies for all regions outside the saturation region. The saturation region, on the other hand, is not calculated directly from the raw Helmholtz correlation. Instead within the saturation region, the stable equilibrium of phases must be calculated such that the liquid phase vapour phases have equal Gibbs free energy &amp;lt;math&amp;gt;g = a + p / \rho&amp;lt;/math&amp;gt;. This requirement is equivalent to the Maxwell equal area rule&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Van_der_Waals_equation&amp;lt;/ref&amp;gt;&amp;lt;ref name=iapws95&amp;gt;&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;Eubank &amp;amp; Hall (2004), &amp;quot;Equal area rule and algorithm for determining phase compositions&amp;quot;, &#039;&#039;AIChE Journal&#039;&#039;, &#039;&#039;&#039;41&#039;&#039;&#039;, {{doi|10.1002/aic.690410419}}&amp;lt;/ref&amp;gt;. The condition can be expressed as a set of three simultaneous equations in the variables &amp;lt;math&amp;gt;p_{sat}, \rho_f, \rho_g&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
p_{sat} &amp;amp; = p \left(\rho_f, T \right) \\&lt;br /&gt;
p_{sat} &amp;amp; = p \left(\rho_g, T \right) \\&lt;br /&gt;
g\left(\rho_f,T \right) &amp;amp;= g\left(\rho_g,T \right)&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This can be further reduced to :&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
p_{sat} &amp;amp; = R T \rho_f \left(1 + \delta_f \phi^r_\delta \left(\tau,\delta_f \right) \right) \\&lt;br /&gt;
p_{sat} &amp;amp; = R T \rho_g \left(1 + \delta_g \phi^r_\delta \left(\tau,\delta_g, \right) \right) \\&lt;br /&gt;
\frac{p_{sat}}{R T} \left( \frac{1}{\rho_g} - \frac{1}{\rho_f} \right) &amp;amp; = \phi \left(\tau, \delta_f \right) - \phi \left(\tau, \delta_g \right)&lt;br /&gt;
 = \ln \left( \frac{\rho_f}{\rho_g} \right) + \phi^r \left(\tau, \delta_f \right) - \phi^r \left(\tau, \delta_g  \right)&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calculation of the phase equilibrium conditions requires iterative solution of these three equations; one suitable approach is that of Akasaka&amp;lt;ref name=akasaka2008&amp;gt;Akasaka (2008) &amp;quot;A Reliable and Useful Method to Determine the Saturation State from Helmholtz Energy Equations of State&amp;quot;, &#039;&#039;Journal of Thermal Science and Technology&#039;&#039;, &#039;&#039;&#039;3&#039;&#039;&#039;, 442-451, {{doi|10.1299/jtst.3.442}}&amp;lt;/ref&amp;gt;, which first eliminates &amp;lt;math&amp;gt;p_{sat}&amp;lt;/math&amp;gt; from the above equations, then iterates only on &amp;lt;math&amp;gt;\rho_f&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\rho_g&amp;lt;/math&amp;gt;. The approach seems to be robust, with tests currently performed with a sample of five fluids including water, carbon-dioxide and nitrogen. Our code is in {{src|models/johnpye/fprops/sat.c}}.&lt;br /&gt;
&lt;br /&gt;
The Akasaka approach is markedly simpler to implement that the complicated algorithm used in REFPROP (which is explained by Akasaka, and also by Soave&amp;lt;ref&amp;gt;Soave (1986), &amp;quot;Direct calculation of pure-compound vapour pressures through cubic equations of state &amp;quot;, &#039;&#039;Fluid Phase Equilibria&#039;&#039;, &#039;&#039;&#039;31&#039;&#039;&#039;, 203-207, {{doi|10.1016/0378-3812(86)90013-0}}&amp;lt;/ref&amp;gt;). A limitation of the Soave approach is that it does not converge for temperatures &amp;lt;math&amp;gt;T \gtrapprox 0.99 T_c&amp;lt;/math&amp;gt;, and hence requires yet another, even more complicated, algorithm to be implemented for that region (including need for the very tedious-to-calculate third partial derivatives &amp;lt;math&amp;gt;\phi^r_{\delta \delta \delta}&amp;lt;/math&amp;gt;!).&lt;br /&gt;
&lt;br /&gt;
=== Saturation Tsat(p) ===&lt;br /&gt;
&lt;br /&gt;
To calculation the saturation temperature as a function of pressure, a different iteration scheme from the above for &amp;lt;math&amp;gt;p_{sat}(T)&amp;lt;/math&amp;gt; is needed. &amp;lt;ref&amp;gt;Long X. Nghiem and Yau-Kun Li, 1985, &#039;&#039;Application of the tangent plane criterion to saturation pressure and temperature computations&#039;&#039;, Fluid Phase Equilibria, {{doi|10.1016/0378-3812(85)90059-7}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;M Michelson, 1984, &#039;&#039;Saturation point calculations&#039;&#039;, Fluid Phase Equilibria, {{doi|10.1016/0378-3812(85)90005-6}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At present, we have implemented &amp;lt;tt&amp;gt;fprops_sat_p&amp;lt;/tt&amp;gt; in {{src|models/johnpye/fprops/sat.c}} which provides a solution via simple Newton iteration that makes repeated calls to &amp;lt;tt&amp;gt;fprops_sat_T&amp;lt;/tt&amp;gt;. The iteration makes use of the Clapeyron equation to calculate the gradients,&lt;br /&gt;
:&amp;lt;math&amp;gt;\left(\frac{\partial p}{\partial T} \right)_{sat} = \frac{h_{fg}}{T v_{fg}}&amp;lt;/math&amp;gt;&lt;br /&gt;
There is probably a more efficient approach, but this is adequate for the moment.&lt;br /&gt;
&lt;br /&gt;
=== Thermodynamic property derivatives ===&lt;br /&gt;
{{experimental}}&lt;br /&gt;
&lt;br /&gt;
The IAPWS has made a release&amp;lt;ref&amp;gt;IAPWS, 2008, &#039;&#039;Revised Advisory Note No. 3 Thermodynamic Derivatives from IAPWS Formulation&#039;&#039;, http://www.iapws.org&amp;lt;/ref&amp;gt; with information about how partial derivatives of thermodynamic properties with respect to other properties can be calculated in general. &lt;br /&gt;
&lt;br /&gt;
FPROPS includes an initial implementation of these derivative calculations in {{src|models/johnpye/fprops/derivs.c}}, but they have not yet been thoroughly tested.&lt;br /&gt;
&lt;br /&gt;
=== Properties in terms of (p,h) ===&lt;br /&gt;
&lt;br /&gt;
{{experimental}}&lt;br /&gt;
It seems to be very helpful to have property correlations calculable in terms of the independent variables (p,h). This seems to aid stability of calculation in larger systems, compared to the (v,T) property pair. This would appear to be in part due to the very small, steep subcooled region when using (v,T) coordinates.&lt;br /&gt;
&lt;br /&gt;
An initial implementation of an iterative solver for properties in terms of (p,h) has been implemented for FPROPS in {{src|models/johnpye/fprops/solve_ph.c}}. Currently, it solves for all regions except for pressures below the triple-point pressure. We hope to overcome this problem soon.&lt;br /&gt;
&lt;br /&gt;
=== Properties in terms of (T,x) ===&lt;br /&gt;
&lt;br /&gt;
For convenience some simple functions for calculating properties in terms of (T,x) have been written. The implementation is in {{src|models/johnpye/fprops/solve_Tx.c}}. Any input with x outside [0,1] or T outside [T_t,T_c] will return an error code. Otherwise, the corresponding rho value will be returned such that (T,rho) is equivalent to the desired state.&lt;br /&gt;
&lt;br /&gt;
A python demonstration of this code is in {{src|models/johnpye/fprops/python/solve_Tx.py}}, which gives the following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
john@thunder:~/ascend/models/johnpye/fprops/python$ python solve_Tx.py &lt;br /&gt;
solved state&lt;br /&gt;
T = 300.000000, x = 0.500000&lt;br /&gt;
--&amp;gt; rho = 0.309802, h = 395476.135716, s = 381991.898474, u = 1491.770280&lt;br /&gt;
&lt;br /&gt;
checking reverse solve:&lt;br /&gt;
--&amp;gt; x = 0.500000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing the code ==&lt;br /&gt;
&lt;br /&gt;
FPROPS includes a suite of self tests for each fluid that has been implemented. Some of the test data comes from the publications from which the correlations have been taken; other test data comes from using the commercial package [http://www.nist.gov/srd/nist23.htm REFPROP] to calculate some sample data points, and comparing the FPROPS output with that data.&lt;br /&gt;
&lt;br /&gt;
To run the FPROPS tests for a given fluid, &amp;lt;tt&amp;gt;cd&amp;lt;/tt&amp;gt; to the FPROPS directory (eg &amp;lt;tt&amp;gt;cd ~/ascend/models/johnpye/fprops&amp;amp;lt;/tdd&amp;amp;gt;) then run the test script &amp;amp;lt;tt&amp;amp;gt;./test.py &#039;&#039;fluidname&#039;&#039;&amp;lt;/tt&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;a4c&amp;quot;&amp;gt;./test.py hydrogen&lt;br /&gt;
./test.py nitrogen&amp;lt;/source&amp;gt;&lt;br /&gt;
&#039;&#039;Requires GNU scientific library(libgsl0-dev) to be installed in the system&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The output will tell you if all calculated values have conformed to expected error margins.&lt;br /&gt;
&lt;br /&gt;
Test code for each fluid is (should be) embedded at the end of the corresponding fluid file, for example {{src|models/johnpye/fprops/fluids/hydrogen.c}}.&lt;br /&gt;
&lt;br /&gt;
During development, some additional testing routines are in the python subdirectory. These include&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;satcvgc.py&amp;lt;/tt&amp;gt; to test converge of saturation region routines &amp;lt;tt&amp;gt;fprops_sat_T&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;fprops_sat_p&amp;lt;/tt&amp;gt; are working.&lt;br /&gt;
* &amp;lt;tt&amp;gt;solve_ph_array&amp;lt;/tt&amp;gt; to test convergence of the &amp;lt;tt&amp;gt;fprops_solve_ph&amp;lt;/tt&amp;gt; routine, including plotting of regions where the routine is failing.&lt;br /&gt;
&lt;br /&gt;
== Adding new fluids ==&lt;br /&gt;
&lt;br /&gt;
Currently, new fluids must be added by declaring constant data structures in C code.&lt;br /&gt;
&lt;br /&gt;
An example of a fluid declaration is shown in {{src|models/johnpye/fprops/fluids/hydrogen.c}}.&lt;br /&gt;
&lt;br /&gt;
After adding the data structures in &amp;quot;component&amp;quot;.c file, a corresponding &amp;quot;component&amp;quot;.h is required. &lt;br /&gt;
&lt;br /&gt;
An example of which is shown in {{src|models/johnpye/fprops/fluids/hydrogen.h}}&lt;br /&gt;
&lt;br /&gt;
The new component has to be declared in SConstruct and asc_helmholtz.c.&lt;br /&gt;
&lt;br /&gt;
The data structures which are to be filled are declared in {{src|models/johnpye/fprops/ideal.h}} and {{src|models/johnpye/fprops/helmholtz.h}}.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: when adding new fluids it is important to observe that different papers give different &#039;zero points&#039; for enthalpy and entropy for the substances in question, and the zero points vary from paper to paper. These Helmholtz equations of state can be adjusted for different &#039;zero points&#039; by adjusting the constant and linear parameters (&#039;&amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt;&#039; and &#039;&amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;&#039;) in the IdealData object that is provided in your data structures. The equation to fix these values is&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{\Delta h}{RT} = \tau \Delta \phi_{\tau}^0 = T^{*} \Delta a_2^0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{\Delta s}{R} = \tau \Delta \phi_{\tau}^0 -  \Delta \phi^0 = - \Delta a_1^0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where we assume&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\phi^0(\tau,\delta) = a_1^0 + a_2^0 \tau + \mathrm{other\ terms\ in\ \tau, \delta}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In other words, to correct an offset in &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&#039;&#039;h&#039;&#039;&amp;lt;/span&amp;gt; and &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&#039;&#039;s&#039;&#039;&amp;lt;/span&amp;gt;, these formulae tell you the offset to apply to the constant and linear terms in &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&amp;amp;phi;&amp;lt;sup&amp;gt;0&amp;lt;/sup&amp;gt;(&amp;amp;tau;,&amp;amp;delta;)&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Using within ASCEND ==&lt;br /&gt;
&lt;br /&gt;
To use FPROPS from ASCEND, see the example code in {{src|models/johnpye/fprops/fprops_test.a4c}}. Essentially you must declare a [[DATA]] instance into which you must place the name of the substance for which you wish to calculate properties. Then you can use the functions &lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_p&amp;lt;/tt&amp;gt;, to calculate p(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_u&amp;lt;/tt&amp;gt;, to calculate u(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_h&amp;lt;/tt&amp;gt;, to calculate h(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_s&amp;lt;/tt&amp;gt;, to calculate s(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_a&amp;lt;/tt&amp;gt;, to calculate a(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_cp&amp;lt;/tt&amp;gt;, to calculate cp(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_cv&amp;lt;/tt&amp;gt;, to calculate cv(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_w&amp;lt;/tt&amp;gt;, to calculate speed of sound for given (T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_phsx_vT&amp;lt;/tt&amp;gt; is also available which returns p, h, s and x in for specified (v,T).&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_Tvsx_ph&amp;lt;/tt&amp;gt; returns T, v, s and x for specified (p,h). Recommended for energy system models.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. When solving properties in &#039;reverse&#039; mode (eg solving for &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&amp;amp;rho;,&#039;&#039;T&#039;&#039;&amp;lt;/span&amp;gt; when &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&#039;&#039;p&#039;&#039;,&#039;&#039;h&#039;&#039;&amp;lt;/span&amp;gt; are know), you will get significantly better results by switching the QRSlv solver parameter for &#039;convergence test&#039; (convopt) to &#039;RELNOM_SCALE&#039;. This significantly improves ASCEND&#039;s ability to solve these problems. Also, use &amp;lt;tt&amp;gt;OPTION iterationlimit 200&amp;lt;/tt&amp;gt; for larger models.&lt;br /&gt;
&lt;br /&gt;
A first system model using FPROPS is available in {{src|models/johnpye/rankine_fprops.a4c}}. The key part is&lt;br /&gt;
&amp;lt;source lang=&amp;quot;a4c&amp;quot;&amp;gt;&lt;br /&gt;
cd IS_A fluid;&lt;br /&gt;
cd.component :== &#039;water&#039;;&lt;br /&gt;
(* ...definitions of p, h, T, v, s, x omitted here... *)&lt;br /&gt;
&lt;br /&gt;
calc_ph: helmholtz_Tvsx_ph(&lt;br /&gt;
    p, h : INPUT;&lt;br /&gt;
    T, v, s, x : OUTPUT;&lt;br /&gt;
    cd : DATA&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some details on the implementation of the &#039;wrapper&#039; code for connecting FPROPS with ASCEND is given in [[writing ASCEND external relations in C]].&lt;br /&gt;
&lt;br /&gt;
== Using from C ==&lt;br /&gt;
&lt;br /&gt;
Using the FPROPS code from C should also be very straightforward; example code is shown in {{src|models/johnpye/fprops/test.c}}.&lt;br /&gt;
&lt;br /&gt;
== Using from Python ==&lt;br /&gt;
&lt;br /&gt;
FPROPS can also be used from the Python language. There are a number of sample programs in {{srcdir|models/johnpye/fprops/python}}. The API is still evolving as we seek the cleanest ways to report errors back to the user, and catch floating-point errors, etc.&lt;br /&gt;
&lt;br /&gt;
== Further work ==&lt;br /&gt;
{{task}}&lt;br /&gt;
&lt;br /&gt;
FPROPS is still under development! We aim to implement a few more features including&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;s&amp;gt;add support for &#039;&#039;&#039;calculation of the saturation curve&#039;&#039;&#039; using Maxwell phase-equilibrium condition&amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt;add iterative solver for properties in terms of (p,h)&amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt;support for Water using IAPWS-95 correlation (partially complete, but needs support for another type of residual function term).&amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt;refactor the &#039;HelmholtzExpTerm&#039; which is actually a double of &#039;HelmholtzGausTerm&#039; with epsilon = 1.&amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt;add support for calculation of partial derivatives dp/dT, dp/drho, dh/dT, dh/drho, du/dT, du/drho,&amp;lt;/s&amp;gt; ds/dT, ds/drho, da/dT, da/drho &amp;lt;s&amp;gt;to improve convergence of ASCEND models that calculate p, h, u,&amp;lt;/s&amp;gt; s, a etc.&lt;br /&gt;
* investigate apparent disagreement between cp0 for &#039;&#039;&#039;ammonia&#039;&#039;&#039; in FPROPS and values from REFPROP (is it consistent with Tillner-Roth?)&lt;br /&gt;
* investigate apparent very small discrepancy between REFPROP and IAPWS95 in value of speed of sound near critical point.&lt;br /&gt;
* move specification of the &#039;&#039;&#039;zero point&#039;&#039;&#039; out of IdealData and into HelmholtzData. Third law of thermodynamics? How to avoid correlations with negative &#039;&#039;h&#039;&#039; or &#039;&#039;s&#039;&#039; values?&lt;br /&gt;
* implement a &#039;&#039;&#039;pre-calculation routine&#039;&#039;&#039; where for example coefficients of &amp;lt;math&amp;gt;\phi^0&amp;lt;/math&amp;gt; can be prepared?&lt;br /&gt;
* implement support for thermophysical properties &#039;&#039;&#039;conductivity, viscosity, surface tension,&#039;&#039;&#039; and possibly others.&lt;br /&gt;
* &amp;lt;s&amp;gt;implement support for calculation of the speed of sound.&amp;lt;/s&amp;gt;&lt;br /&gt;
* resolve the confusion between T* and T_crit in the data structures. Probably all correlations will be using T_crit -- but is that sure?&lt;br /&gt;
* &amp;lt;s&amp;gt;remove p_c from HelmholtzData structure, because that value can be calculated using p(T_c,rho_c).&amp;lt;/s&amp;gt;&lt;br /&gt;
* add support for solving in terms of (p,h) where p &amp;lt; p_t, the triple point pressure.&lt;br /&gt;
* possibly some additional coefficients needs in order to support correlations such as for Methanol&amp;lt;ref&amp;gt;K de Reuck, 1993, &#039;&#039;Methanol, International Thermodynamic Tables of the Fluid State Vol. 12 (1993)&#039;&#039;, Blackwell/IUPAC, http://www.iupac.org/objID/Source/sou65427568843800267934799&amp;lt;/ref&amp;gt;&lt;br /&gt;
* add properties of R-134a (see {{doi|10.1063/1.555958}})&lt;br /&gt;
&lt;br /&gt;
Further down the track we would like to support:&lt;br /&gt;
&lt;br /&gt;
* reading property correlations from a &#039;&#039;&#039;database&#039;&#039;&#039; (SQLite?) or text file.&lt;br /&gt;
* &amp;lt;font color=green&amp;gt;some simpler equations of state such as MBWR or Peng-Robinson.&amp;lt;/font&amp;gt;(Assigned to Ankit, see [[PengRobinson EOS in FPROPS]])&lt;br /&gt;
* lots more fluids&lt;br /&gt;
* &#039;&#039;&#039;mixing models&#039;&#039;&#039; for multi-phase, multi-component systems (or else incorporate FPROPS into exist code that supports this).&lt;br /&gt;
* [http://www.gerg.info/publications/tm/tm15_04.pdf natural gas properties?]&lt;br /&gt;
* [http://www.if.uidaho.edu/~vutgikar/Fall2007/Hydrogen/AIR.pdf air properties] {{doi|10.1063/1.1285884}}&lt;br /&gt;
&lt;br /&gt;
We&#039;d be very pleased to be able to collaborate on this work with others; the code has been made deliberately able to stand alone; it has no dependency on any other code from ASCEND, and is suitable for incorporation into other open source programs, subject to the restrictions of the GPL license.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Contributors ==&lt;br /&gt;
&lt;br /&gt;
The people who have contributed code and/or implementable advice for FPROPS:&lt;br /&gt;
* [[User:Jpye|John Pye]]&lt;br /&gt;
* [[User:Kchittur|Krishnan Chittur]]&lt;br /&gt;
* HongKe&lt;br /&gt;
* [[User:Rshrikanth|Shrikanth Ranganadham ]]&lt;br /&gt;
* [[User:Ankitml|Ankit Mittal]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[Combined-cycle gas turbine]]&lt;br /&gt;
* [[Thermodynamics with ASCEND]]&lt;br /&gt;
* [[freesteam]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Proposed]]&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2526</id>
		<title>PengRobinson EOS in FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=2526"/>
		<updated>2011-06-02T16:44:52Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: Added overview&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{task}}&lt;br /&gt;
Work on this is went on as a part of GSoC 2010, Project [[User:Ankitml|Ankit]] and continues as part of GSoC 2011, [[User:richardTowers|Richard Towers]]&lt;br /&gt;
&lt;br /&gt;
Comments and suggestions are welcome&lt;br /&gt;
==Overview==&lt;br /&gt;
The Peng-Robinson EOS is a cubic equation of state in that it contains volume terms to the third power, it is one of several equations of state that can be expressed in the form&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
P=\frac{RT}{V-b}-\frac{a}{V^2+ubV+wb^2}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
Z^3-(1+B^*-uB^*)Z^2+(A^*+wB^{*2}-uB^*-uB^{*2})Z-A^*B^*-wB^{*2}-wB^{*3}=0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Where&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A^*=\frac{aP}{R^2T^2}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
B^*=\frac{bP}{RT}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
In the Peng-Robinson values for &amp;lt;math&amp;gt;u,&amp;lt;/math&amp;gt; &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;b&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt; are set as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
u=2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
w=-1&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
b=\frac{0.7780RT_c}{P_c}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
a=\frac{0.45724R^2T_c^2}{P_c}[1+f\omega(1-T_r^{\frac{1}{2}})]^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
f\omega=0.37464+1.54226\omega-0.26992\omega^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So, for given values of &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;T_c&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;T_r&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;P_c&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\omega&amp;lt;/math&amp;gt; we can solve for &amp;lt;math&amp;gt;Z&amp;lt;/math&amp;gt;. What next??&lt;br /&gt;
==Algorithm==&lt;br /&gt;
===Algorithm From Literature===&lt;br /&gt;
*Guess a Pressure.  &lt;br /&gt;
*Find roots of volume using PR-EOS, if roots&amp;lt;3 guess P again.&lt;br /&gt;
*Min V is the molar liquid volume, and the max V is vapour molar volume.&lt;br /&gt;
*get Zl and Zv.&lt;br /&gt;
*Get fugacities of both phases.&lt;br /&gt;
*Pnew = Pold*fl/fv&lt;br /&gt;
&lt;br /&gt;
===The current Algorithm===&lt;br /&gt;
*Calculate PV data using PR_EOS from 0.001 to 6666 cm3/mol.&lt;br /&gt;
*Get the range of Pressure in which volume has 3 roots.&lt;br /&gt;
*Give this range as lower and upper bounds to a golden search algorithm, minimizing the difference in fugacities.&lt;br /&gt;
*To calculate fugacities a non iterative analytical expression was derived for PR-EOS.&lt;br /&gt;
&lt;br /&gt;
===Issues That Forced to Deviate From Literature===&lt;br /&gt;
*Find a non iterative way to solve a cubic Equation for volume. The normal iterative one makes the algorithm very slow, as it is required to solve the volume cubic many number of times to arrive at the solution. So right now generating PV data for a range with a constant increment in V. &lt;br /&gt;
*This also helps in guessing the first P in the range of 3 roots, which is required as the first step.&lt;br /&gt;
*The golden search algorithm is just experimental over the standard Pnew = Pold*Fl/Fv iteration, which requires a good guess whereas Golden search requires a bracket in which solution lies. It is yet to be tested which one is better.&lt;br /&gt;
&lt;br /&gt;
==Limitations==&lt;br /&gt;
===Errors===&lt;br /&gt;
*Not working at some temperatures. [It should work on entire range from triple point to Critical Temperature]&lt;br /&gt;
&lt;br /&gt;
[Solution] - Currently trying got find out the reason for this behaviour. - [http://ascendwiki.cheme.cmu.edu/User:Ankitml Ankit ]&lt;br /&gt;
&lt;br /&gt;
*Not predicting Saturation Volumes for Liquids correctly.&lt;br /&gt;
[Solution] - Its a problem with Peng Robinson EOS, a modification to PR_EOS was proposed by G. Heyen in the paper, &amp;quot;Liquid and Vapor Properties from a cubic Equation of state&amp;quot;, in 2nd International Conference on Phase Equilibria and Fluid Properties, 1980.&lt;br /&gt;
&lt;br /&gt;
===Changes to be done to integrate with ASCEND===&lt;br /&gt;
*Data (Pc,Tc,Omega) to be taken from data files and only component name should be required in the code.&lt;br /&gt;
*No main function&lt;br /&gt;
*ASCEND wrapper&lt;br /&gt;
*Code should be in C, remove C++ functions.&lt;br /&gt;
&lt;br /&gt;
=Code=&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
//Global Variables&lt;br /&gt;
double Tc,Pc,Omega,R,Tre,b,a,RT,T,P[20000],V[20000],Phil,Phiv,Vl,Vv;&lt;br /&gt;
int j;&lt;br /&gt;
&lt;br /&gt;
int noRoots(double Psat); //gives out number of roots (of V) at a particular Pressure&lt;br /&gt;
double Pcalc(double T, double V);  // Calculates Pressure at Given T and V using PR-EOS&lt;br /&gt;
int PhiCalc(double PsatGuess); //Calculates fugacities at a given Pressure and Stores it in global variables&lt;br /&gt;
double phiDiff(double Pguess); //Finds fugacity difference at a particular P, uses function PhiCalc and is required for golden search algorithm&lt;br /&gt;
double goldSer(double a,double c,double b); //Golden search algorithm, function to be minimized is phiDiff and a is the lower bound, b is upper bound, c is the center.&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	Tc = 304.1282;  // Kelvin&lt;br /&gt;
        Pc = 73.773;  // bar&lt;br /&gt;
        Omega = 0.22394; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 260;&lt;br /&gt;
	RT = R*T;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	&lt;br /&gt;
	double p[20000],v[20000];&lt;br /&gt;
	//following for loop calculates P V data till v=6500cm3/mol and stores it in P,V arrays only if P is within bounds of 60 and -160&lt;br /&gt;
	j = 0;&lt;br /&gt;
        for (int i=0;i&amp;lt;20000;i++)&lt;br /&gt;
        {&lt;br /&gt;
                v[i] = (i + 0.001)/3;&lt;br /&gt;
                p[i] = Pcalc(T,v[i]);&lt;br /&gt;
                if(p[i]&amp;lt;60.0 &amp;amp;&amp;amp; p[i]&amp;gt;-160.0)&lt;br /&gt;
                {&lt;br /&gt;
                        P[j] = p[i];&lt;br /&gt;
                        V[j] = v[i];&lt;br /&gt;
                        j++;&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
//finding the bounds for P&lt;br /&gt;
        double pStart,deltaP;&lt;br /&gt;
        pStart = 0.01;&lt;br /&gt;
        deltaP = 1.0;&lt;br /&gt;
        for(int n = 0;n&amp;lt;3;n++)&lt;br /&gt;
        {&lt;br /&gt;
                for(double pp = pStart;pp&amp;lt;60.0;pp=pp+deltaP)&lt;br /&gt;
                {&lt;br /&gt;
                        int nor;&lt;br /&gt;
                        nor = noRoots(pp);&lt;br /&gt;
                        if (nor==3)&lt;br /&gt;
                        {&lt;br /&gt;
                                pStart = pp - deltaP;&lt;br /&gt;
                                pp = 59.0;&lt;br /&gt;
                        }&lt;br /&gt;
                }&lt;br /&gt;
                deltaP = deltaP/10;&lt;br /&gt;
        }&lt;br /&gt;
        pStart = pStart + 0.01;&lt;br /&gt;
&lt;br /&gt;
        double pEnd;&lt;br /&gt;
        pEnd = pStart;&lt;br /&gt;
        deltaP = 1.0;&lt;br /&gt;
       for(int n = 0;n&amp;lt;2;n++)&lt;br /&gt;
       {&lt;br /&gt;
                for(double pp = pEnd;pp&amp;lt;60.0;pp=pp+deltaP)&lt;br /&gt;
                {&lt;br /&gt;
                        int nor;&lt;br /&gt;
                        nor = noRoots(pp);&lt;br /&gt;
                        if (nor&amp;lt;3)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = pp - deltaP;&lt;br /&gt;
                                pp = 5000;&lt;br /&gt;
                        }&lt;br /&gt;
                }&lt;br /&gt;
                deltaP = deltaP/10;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	int sandbox;&lt;br /&gt;
	double Pa,Pb,Pc,sol,phi,resphi;&lt;br /&gt;
	phi = (1 + sqrt(5))/2;&lt;br /&gt;
        resphi = 2 - phi;&lt;br /&gt;
	Pa = pStart;&lt;br /&gt;
	Pb = pEnd;&lt;br /&gt;
	Pc = (Pb - Pa)*resphi + Pa;&lt;br /&gt;
	sol = goldSer(Pa,Pc,Pb);&lt;br /&gt;
	sandbox=PhiCalc(sol);&lt;br /&gt;
	cout&amp;lt;&amp;lt;&amp;quot;Molar Volume (L) = &amp;quot;&amp;lt;&amp;lt;Vl&amp;lt;&amp;lt;&amp;quot; cm3/mol&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&lt;br /&gt;
	cout&amp;lt;&amp;lt;&amp;quot;Molar Volume (V) = &amp;quot;&amp;lt;&amp;lt;Vv&amp;lt;&amp;lt;&amp;quot; cm3/mol&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&lt;br /&gt;
	cout&amp;lt;&amp;lt;&amp;quot;Difference in fugacities of vapour and liquid = &amp;quot;&amp;lt;&amp;lt;fabs(Phil-Phiv)&amp;lt;&amp;lt;&#039;\n&#039;;&lt;br /&gt;
	cout&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&#039;\t&#039;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&#039;\t&#039;&amp;lt;&amp;lt;Vl&amp;lt;&amp;lt;&#039;\t&#039;&amp;lt;&amp;lt;Vv&amp;lt;&amp;lt;&#039;\t&#039;&amp;lt;&amp;lt;fabs(Phil-Phiv)&amp;lt;&amp;lt;&#039;\n&#039;;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int noRoots(double Psat)&lt;br /&gt;
{&lt;br /&gt;
        double Vroot[3];&lt;br /&gt;
        Vroot[0] = -99; Vroot[1] = -99; Vroot[2] = -99;&lt;br /&gt;
        int rootCount = 0;&lt;br /&gt;
        for (int i = 0; i &amp;lt; j-1;i++)&lt;br /&gt;
        {&lt;br /&gt;
                if((Psat&amp;lt;=P[i+1] &amp;amp;&amp;amp; Psat&amp;gt;=P[i]) || (Psat&amp;gt;=P[i+1] &amp;amp;&amp;amp; Psat&amp;lt;=P[i]))&lt;br /&gt;
                {&lt;br /&gt;
                        Vroot[rootCount] = V[i]+(Psat-P[i])*(V[i+1]-V[i])/(P[i+1]-P[i]);&lt;br /&gt;
                        rootCount++;&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
        return rootCount;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
double Pcalc(double T, double V)&lt;br /&gt;
{&lt;br /&gt;
        double P,m,tmp;&lt;br /&gt;
        b = 0.0778*R*Tc/Pc;&lt;br /&gt;
        m = 0.37464+1.54226*Omega-0.26992*pow(Omega,2);&lt;br /&gt;
        tmp = 1+m*(1-sqrt(Tre));&lt;br /&gt;
        a = 0.45724*R*R*Tc*(Tc/Pc)*pow(tmp,2);&lt;br /&gt;
        P = R*T/(V-b) - a/(V*(V+b)+b*(V-b));&lt;br /&gt;
        return P;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int PhiCalc(double PsatGuess)&lt;br /&gt;
{       double Vroot[3],A,B;&lt;br /&gt;
        B = PsatGuess*b/RT;&lt;br /&gt;
        A = a*PsatGuess/pow(RT,2);&lt;br /&gt;
        Vroot[0] = -99; Vroot[1] = -99; Vroot[2] = -99;&lt;br /&gt;
        int rootCount = 0;&lt;br /&gt;
        for (int i = 0; i &amp;lt; j-1;i++)&lt;br /&gt;
        {&lt;br /&gt;
                if((PsatGuess&amp;lt;=P[i+1] &amp;amp;&amp;amp; PsatGuess&amp;gt;=P[i]) || (PsatGuess&amp;gt;=P[i+1] &amp;amp;&amp;amp; PsatGuess&amp;lt;=P[i]))&lt;br /&gt;
                {&lt;br /&gt;
                        Vroot[rootCount] =V[i]+(PsatGuess-P[i])*(V[i+1]-V[i])/(P[i+1]-P[i]);&lt;br /&gt;
                        rootCount++;&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        double Zv,Zl;&lt;br /&gt;
        double term_a,term_b,term_c;&lt;br /&gt;
&lt;br /&gt;
        Vl = Vroot[0];   //liquid volume is the smaller root&lt;br /&gt;
        Vv = Vroot[2];   // vapour volume is the largest one&lt;br /&gt;
&lt;br /&gt;
        Zl = PsatGuess*Vl/(R*T);  //the corresponding Z&lt;br /&gt;
        Zv = PsatGuess*Vv/(R*T);&lt;br /&gt;
&lt;br /&gt;
        term_a = (1 + sqrt(2))*B;&lt;br /&gt;
        term_b = (1 - sqrt(2))*B;&lt;br /&gt;
        term_c = 2*sqrt(2)*B;&lt;br /&gt;
&lt;br /&gt;
        Phil = (Zl-1) - log(Zl-B) - A/term_c*log((Zl+term_a)/(Zl+term_b));&lt;br /&gt;
        Phiv = (Zv-1) - log(Zv-B) - A/term_c*log((Zv+term_a)/(Zv+term_b));&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
double phiDiff(double Pguess)&lt;br /&gt;
{&lt;br /&gt;
	double phiD;&lt;br /&gt;
	int sandbox;&lt;br /&gt;
	sandbox = PhiCalc(Pguess);&lt;br /&gt;
	phiD = fabs(Phil - Phiv);&lt;br /&gt;
	return phiD;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
double goldSer(double a,double c,double b)&lt;br /&gt;
{&lt;br /&gt;
        double d,phi,resphi;&lt;br /&gt;
	phi = (1 + sqrt(5))/2;&lt;br /&gt;
        resphi = 2 - phi;&lt;br /&gt;
        if (fabs(a-b)&amp;lt;0.000001)&lt;br /&gt;
                return ((a+b)/2);&lt;br /&gt;
&lt;br /&gt;
        d = c + resphi*(b - c);&lt;br /&gt;
&lt;br /&gt;
        if (phiDiff(d)&amp;lt;phiDiff(c))&lt;br /&gt;
                return goldSer(c,d,b);&lt;br /&gt;
        else&lt;br /&gt;
                return goldSer(d,c,a);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
&lt;br /&gt;
* Maybe this is of interest: http://pubs.acs.org/doi/abs/10.1021/ed066p54.2 ? [[User:Jpye|Jpye]] 06:39, 5 August 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==Comparisons==&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=FPROPS&amp;diff=2525</id>
		<title>FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=FPROPS&amp;diff=2525"/>
		<updated>2011-06-02T16:27:20Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Implementation  - As much as I understand on peng-robinson */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div style=&amp;quot;float:right;border:solid 1pt green;background-color=#EEFFEE;width:18em;padding:12px&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Fluids supported by FPROPS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{{fpropsfluid|ammonia}}, {{fpropsfluid|nitrogen}}, {{fpropsfluid|hydrogen}}, {{fpropsfluid|water}}, {{fpropsfluid|carbondioxide}}, {{fpropsfluid|methane}}, {{fpropsfluid|carbonmonoxide}}, {{fpropsfluid|ethanol}}, {{fpropsfluid|acetone}}, {{fpropsfluid|carbonylsulfide}}, {{fpropsfluid|decane}}, {{fpropsfluid|hydrogensulfide}}, {{fpropsfluid|isohexane}}, {{fpropsfluid|isopentane}}, {{fpropsfluid|krypton}}, {{fpropsfluid|neopentane}}, {{fpropsfluid|nitrousoxide}}, {{fpropsfluid|nonane}}, {{fpropsfluid|sulfurdioxide}}, {{fpropsfluid|toluene}}, {{fpropsfluid|xenon}}, {{fpropsfluid|butane}}, {{fpropsfluid|butene}}, {{fpropsfluid|cisbutene}}, {{fpropsfluid|isobutene}}, {{fpropsfluid|transbutene}}, {{fpropsfluid|dimethylether}}, {{fpropsfluid|ethane}}, {{fpropsfluid|parahydrogen}}, {{fpropsfluid|isobutane}}, {{fpropsfluid|r41}}, {{fpropsfluid|r116}}, {{fpropsfluid|r141b}}, {{fpropsfluid|r142b}}, {{fpropsfluid|r218}}, {{fpropsfluid|r245fa}}&lt;br /&gt;
&lt;br /&gt;
(in svn, at r3042)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;FPROPS&#039;&#039;&#039; is a free open-source C-based library for high-accuracy evaluation of thermodynamic properties for a number of pure substances. It makes use of published data for the Helmholtz fundamental equation for those substances. It has been developed by [[User:Jpye|John Pye]] and [[#Contributors|others]], and will happily function as standalone code, but is also provided with [[external library]] code for ASCEND so that it can be used to access these accurate property correlations from within a [[MODEL]].&lt;br /&gt;
&lt;br /&gt;
Currently FPROPS supports calculation of the properties of the pure substances shown on the right. The properties that can be calculated are internal energy &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt;, entropy &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;, pressure &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt;, enthalpy &amp;lt;math&amp;gt;h&amp;lt;/math&amp;gt; and Helmholtz energy &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt;, as well as various partial derivatives of these with respect to temperature and density.&lt;br /&gt;
&lt;br /&gt;
FPROPS reproduces a limited subset of the functionality of commercial programs such as [http://www.nist.gov/srd/nist23.htm REFPROP], [http://gibbs.mech.kyushu-u.ac.jp/~akasaka/propath_man/ PROPATH], EES, [http://www.ruhr-uni-bochum.de/thermo/Software/Seiten/Fluidcal-eng.htm FLUIDCAL], [[freesteam]], SteamTab, and others, but is free open-source software, licensed under the [http://www.gnu.org/licenses/gpl.html GPL]. Contributions are most welcome!&lt;br /&gt;
&lt;br /&gt;
Enhancement to FPROPS feature set and list of supported fluids has been going on as part of ASCEND&#039;s involvement in [[GSOC2010]].&lt;br /&gt;
&lt;br /&gt;
FPROPS is included with ASCEND as of version 0.9.5.116, or you can browse the code at {{srcdir|models/johnpye/fprops/}} or access it [[VersionManagement|via subversion]] (code is evolving rapidly, as of Aug 2010).&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
The calculation routines implement calculation of reduced Helmholtz energy &amp;lt;math&amp;gt;\phi = a / R T&amp;lt;/math&amp;gt; as a function of reduced density &amp;lt;math&amp;gt;\delta = \rho / \rho_c&amp;lt;/math&amp;gt; and &#039;&#039;inverse&#039;&#039; reduced temperature &amp;lt;math&amp;gt;\tau = T_c / T&amp;lt;/math&amp;gt;, by dividing it into ideal &amp;lt;math&amp;gt;\phi^0 \left(\tau,\delta\right)&amp;lt;/math&amp;gt; and &#039;real&#039; or &#039;residual&#039; &amp;lt;math&amp;gt;\phi^r \left(\tau,\delta \right)&amp;lt;/math&amp;gt; parts, as described in IAPWS-95&amp;lt;ref name=iapws95&amp;gt;http://www.iapws.org/relguide/IAPWS95-Rev.pdf&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Ideal part ===&lt;br /&gt;
&lt;br /&gt;
Calculation of the &#039;&#039;&#039;ideal part&#039;&#039;&#039; of the reduced Helmholtz energy is derived from the expression for the zero-pressure limit of reduced specific heat capacity at constant pressure, &amp;lt;math&amp;gt;c_p^0 / R&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; is the specific gas constant. This quantity &amp;lt;math&amp;gt;{c_p^0}(T)/R&amp;lt;/math&amp;gt; can be expressed as a series composed of two different types of terms:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;3&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
! type !! expression !! correlation constants&lt;br /&gt;
|-&lt;br /&gt;
| power terms || &amp;lt;math&amp;gt;c_i T^{t_i}&amp;lt;/math&amp;gt; || &amp;lt;math&amp;gt;c, t&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| exponential terms&amp;lt;br/&amp;gt;(also called &#039;Einstein&#039; terms&amp;lt;ref&amp;gt;Lemmon, E.W. and Span, R.,&lt;br /&gt;
2006, &#039;&#039;Short Fundamental Equations of State for 20 Industrial Fluids&#039;&#039;, J. Chem. Eng. Data, &#039;&#039;&#039;51&#039;&#039;&#039;, 785-850, {{doi|10.1021/je050186n}}&amp;lt;/ref&amp;gt;) || &amp;lt;math&amp;gt;\frac{b_i x_i^2 exp(-x_i)}{[1-exp(-x_i)]^2}&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;x_i = \frac{\beta_i}{T}&amp;lt;/math&amp;gt; || &amp;lt;math&amp;gt;b, \beta&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An expression for calculating the ideal component of Helmholtz energy &amp;lt;math&amp;gt;a^0 \left(T , \rho \right)&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;c_p^0&amp;lt;/math&amp;gt; is given by Span et al&amp;lt;ref&amp;gt;Span &amp;amp; Wagner (1996), &amp;quot;A new equation of state for carbon dioxide covering from the triple point temperature to 1100 K at pressures up to 800 MPa&amp;quot; &#039;&#039;J. Phys. Chem. Ref. Data&#039;&#039;, &#039;&#039;&#039;25&#039;&#039;&#039; p 1509 ff, http://link.aip.org/link/?jpr/25/1509%26agg=NIST, {{doi|10.1063/1.555991}}&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{a^0}{RT} = \phi^0 = \frac{h_0^0 \tau}{R T_c} - \frac{s_0^0}{R} - 1 + \ln {\frac{\delta / \delta_0}{\tau / \tau_0}} - \frac{\tau}{R} \int_{\tau_0}^{\tau}{\frac{c_p^0}{\tau^2}d\tau} + \frac{1}{R} \int_{\tau_0}^{\tau}{\frac{c_p^0}{\tau} d \tau}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the &#039;&#039;&#039;reduced temperature&#039;&#039;&#039; is &amp;lt;math&amp;gt;\tau = \frac{T^{*}}{T}&amp;lt;/math&amp;gt; and the &#039;&#039;&#039;reduced density&#039;&#039;&#039; is &amp;lt;math&amp;gt;\delta = \frac{\rho}{\rho^{*}}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
On the other hand, using the relations for the Helmholtz fundamental equation, one can see that&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{c_p^0}{R} = 1 -\tau^2 \phi^0_{\tau \tau}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so coefficients of &amp;lt;math&amp;gt;c_p^0&amp;lt;/math&amp;gt; can be calculated from coefficients of &amp;lt;math&amp;gt;\phi^0&amp;lt;/math&amp;gt; (providing, we assume, that the fundamental equation has smooth first and second (and possibly third) derivatives, and that when terms of &amp;lt;math&amp;gt;{c_p^0}(T)&amp;lt;/math&amp;gt; are integrated they don&#039;t &#039;interact&#039;). One can go the other way, and determine &amp;lt;math&amp;gt;\phi^0&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;c_p^0&amp;lt;/math&amp;gt;, with the exception of the integration constants, which are, in that case, determined using specified values of enthalpy &amp;lt;math&amp;gt;h^0_{ref}&amp;lt;/math&amp;gt; and entropy &amp;lt;math&amp;gt;s^0_{ref}&amp;lt;/math&amp;gt; at a reference state &amp;lt;math&amp;gt;\left(T_{ref},\rho_{ref} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Residual part ===&lt;br /&gt;
&lt;br /&gt;
For the &#039;&#039;&#039;residual part&#039;&#039;&#039; of the reduced Helmholtz energy, FPROPS currently supports three different kinds of terms:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;3&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
! type !! expression !! correlation constants&lt;br /&gt;
|-&lt;br /&gt;
| power terms || &amp;lt;math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
\begin{cases} &lt;br /&gt;
  a_i \tau^{t_i} \delta^{d_i} exp(-\delta^{l_i}), &amp;amp; \mbox{if }l \ne 0 \\&lt;br /&gt;
  a_i \tau^{t_i} \delta^{d_i},  &amp;amp; \mbox{otherwise} &lt;br /&gt;
\end{cases}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/math&amp;gt; || &amp;lt;math&amp;gt;a, t, d, l&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| gaussian terms || &amp;lt;math&amp;gt;n_i \tau^{t_i} \delta^{d_i} exp[-\alpha_i(\delta - \epsilon_i)^2 - \beta_i(\tau - \gamma_i)^2]&amp;lt;/math&amp;gt; || &amp;lt;math&amp;gt; n, t, d, \alpha, \beta, \gamma, \epsilon&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| critical terms || &amp;lt;math&amp;gt;n_i \Delta^{b_i} \delta \psi \mbox{  where } \begin{cases}&lt;br /&gt;
  \Delta = \theta^2 + B_i \left[ \left( \delta - 1 \right)^2 \right]^{a_i} \\&lt;br /&gt;
  \theta = \left( 1- \tau \right) + A_i \left[ \left( \delta - 1 \right)^2 \right]^{\frac{1}{2 \beta_i}} \\&lt;br /&gt;
  \psi = exp \left[-C_i \left(\delta-1 \right)^2 - D_i \left( \tau - 1 \right)^2 \right]&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|| &amp;lt;math&amp;gt;n, a, b, \beta, A, B, C, D&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
These different terms are used in various combinations across a number of high-accuracy publications of thermodynamic property data. Overall, the residual series permits calculation of &#039;real&#039; reduced Helmholtz energy &amp;lt;math&amp;gt;\phi \left(\tau,\delta \right) = \phi^0 \left(\tau,\delta \right) + \phi^r \left( \tau,\delta \right)&amp;lt;/math&amp;gt; and hence the specific Helmholtz energy &amp;lt;math&amp;gt;a = R T \phi \left(\tau,\delta\right)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
From the expression for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;, we can then derive expressions for &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;h&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and their partial derivatives with respect to density and temperature. These expressions are summarised in IAPWS-95&amp;lt;ref name=iapws95&amp;gt;&amp;lt;/ref&amp;gt; as well as by Tillner Roth et al&amp;lt;ref&amp;gt;Tillner-Roth, Harms-Watzenberg and Baehr (1993), &amp;quot;Eine neue Fundamentalgleichung für Ammoniak&amp;quot;,&lt;br /&gt;
&#039;&#039;DKV-Tagungsbericht&#039;&#039;, &#039;&#039;&#039;20&#039;&#039;&#039;, 167-181&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Saturated mixture properties ===&lt;br /&gt;
&lt;br /&gt;
The Helmholtz function &amp;lt;math&amp;gt;a \left(\rho,T \right)&amp;lt;/math&amp;gt;, given above, applies for all regions outside the saturation region. The saturation region, on the other hand, is not calculated directly from the raw Helmholtz correlation. Instead within the saturation region, the stable equilibrium of phases must be calculated such that the liquid phase vapour phases have equal Gibbs free energy &amp;lt;math&amp;gt;g = a + p / \rho&amp;lt;/math&amp;gt;. This requirement is equivalent to the Maxwell equal area rule&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Van_der_Waals_equation&amp;lt;/ref&amp;gt;&amp;lt;ref name=iapws95&amp;gt;&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;Eubank &amp;amp; Hall (2004), &amp;quot;Equal area rule and algorithm for determining phase compositions&amp;quot;, &#039;&#039;AIChE Journal&#039;&#039;, &#039;&#039;&#039;41&#039;&#039;&#039;, {{doi|10.1002/aic.690410419}}&amp;lt;/ref&amp;gt;. The condition can be expressed as a set of three simultaneous equations in the variables &amp;lt;math&amp;gt;p_{sat}, \rho_f, \rho_g&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
p_{sat} &amp;amp; = p \left(\rho_f, T \right) \\&lt;br /&gt;
p_{sat} &amp;amp; = p \left(\rho_g, T \right) \\&lt;br /&gt;
g\left(\rho_f,T \right) &amp;amp;= g\left(\rho_g,T \right)&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This can be further reduced to :&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
p_{sat} &amp;amp; = R T \rho_f \left(1 + \delta_f \phi^r_\delta \left(\tau,\delta_f \right) \right) \\&lt;br /&gt;
p_{sat} &amp;amp; = R T \rho_g \left(1 + \delta_g \phi^r_\delta \left(\tau,\delta_g, \right) \right) \\&lt;br /&gt;
\frac{p_{sat}}{R T} \left( \frac{1}{\rho_g} - \frac{1}{\rho_f} \right) &amp;amp; = \phi \left(\tau, \delta_f \right) - \phi \left(\tau, \delta_g \right)&lt;br /&gt;
 = \ln \left( \frac{\rho_f}{\rho_g} \right) + \phi^r \left(\tau, \delta_f \right) - \phi^r \left(\tau, \delta_g  \right)&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calculation of the phase equilibrium conditions requires iterative solution of these three equations; one suitable approach is that of Akasaka&amp;lt;ref name=akasaka2008&amp;gt;Akasaka (2008) &amp;quot;A Reliable and Useful Method to Determine the Saturation State from Helmholtz Energy Equations of State&amp;quot;, &#039;&#039;Journal of Thermal Science and Technology&#039;&#039;, &#039;&#039;&#039;3&#039;&#039;&#039;, 442-451, {{doi|10.1299/jtst.3.442}}&amp;lt;/ref&amp;gt;, which first eliminates &amp;lt;math&amp;gt;p_{sat}&amp;lt;/math&amp;gt; from the above equations, then iterates only on &amp;lt;math&amp;gt;\rho_f&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\rho_g&amp;lt;/math&amp;gt;. The approach seems to be robust, with tests currently performed with a sample of five fluids including water, carbon-dioxide and nitrogen. Our code is in {{src|models/johnpye/fprops/sat.c}}.&lt;br /&gt;
&lt;br /&gt;
The Akasaka approach is markedly simpler to implement that the complicated algorithm used in REFPROP (which is explained by Akasaka, and also by Soave&amp;lt;ref&amp;gt;Soave (1986), &amp;quot;Direct calculation of pure-compound vapour pressures through cubic equations of state &amp;quot;, &#039;&#039;Fluid Phase Equilibria&#039;&#039;, &#039;&#039;&#039;31&#039;&#039;&#039;, 203-207, {{doi|10.1016/0378-3812(86)90013-0}}&amp;lt;/ref&amp;gt;). A limitation of the Soave approach is that it does not converge for temperatures &amp;lt;math&amp;gt;T \gtrapprox 0.99 T_c&amp;lt;/math&amp;gt;, and hence requires yet another, even more complicated, algorithm to be implemented for that region (including need for the very tedious-to-calculate third partial derivatives &amp;lt;math&amp;gt;\phi^r_{\delta \delta \delta}&amp;lt;/math&amp;gt;!).&lt;br /&gt;
&lt;br /&gt;
=== Saturation Tsat(p) ===&lt;br /&gt;
&lt;br /&gt;
To calculation the saturation temperature as a function of pressure, a different iteration scheme from the above for &amp;lt;math&amp;gt;p_{sat}(T)&amp;lt;/math&amp;gt; is needed. &amp;lt;ref&amp;gt;Long X. Nghiem and Yau-Kun Li, 1985, &#039;&#039;Application of the tangent plane criterion to saturation pressure and temperature computations&#039;&#039;, Fluid Phase Equilibria, {{doi|10.1016/0378-3812(85)90059-7}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;M Michelson, 1984, &#039;&#039;Saturation point calculations&#039;&#039;, Fluid Phase Equilibria, {{doi|10.1016/0378-3812(85)90005-6}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At present, we have implemented &amp;lt;tt&amp;gt;fprops_sat_p&amp;lt;/tt&amp;gt; in {{src|models/johnpye/fprops/sat.c}} which provides a solution via simple Newton iteration that makes repeated calls to &amp;lt;tt&amp;gt;fprops_sat_T&amp;lt;/tt&amp;gt;. The iteration makes use of the Clapeyron equation to calculate the gradients,&lt;br /&gt;
:&amp;lt;math&amp;gt;\left(\frac{\partial p}{\partial T} \right)_{sat} = \frac{h_{fg}}{T v_{fg}}&amp;lt;/math&amp;gt;&lt;br /&gt;
There is probably a more efficient approach, but this is adequate for the moment.&lt;br /&gt;
&lt;br /&gt;
=== Thermodynamic property derivatives ===&lt;br /&gt;
{{experimental}}&lt;br /&gt;
&lt;br /&gt;
The IAPWS has made a release&amp;lt;ref&amp;gt;IAPWS, 2008, &#039;&#039;Revised Advisory Note No. 3 Thermodynamic Derivatives from IAPWS Formulation&#039;&#039;, http://www.iapws.org&amp;lt;/ref&amp;gt; with information about how partial derivatives of thermodynamic properties with respect to other properties can be calculated in general. &lt;br /&gt;
&lt;br /&gt;
FPROPS includes an initial implementation of these derivative calculations in {{src|models/johnpye/fprops/derivs.c}}, but they have not yet been thoroughly tested.&lt;br /&gt;
&lt;br /&gt;
=== Properties in terms of (p,h) ===&lt;br /&gt;
&lt;br /&gt;
{{experimental}}&lt;br /&gt;
It seems to be very helpful to have property correlations calculable in terms of the independent variables (p,h). This seems to aid stability of calculation in larger systems, compared to the (v,T) property pair. This would appear to be in part due to the very small, steep subcooled region when using (v,T) coordinates.&lt;br /&gt;
&lt;br /&gt;
An initial implementation of an iterative solver for properties in terms of (p,h) has been implemented for FPROPS in {{src|models/johnpye/fprops/solve_ph.c}}. Currently, it solves for all regions except for pressures below the triple-point pressure. We hope to overcome this problem soon.&lt;br /&gt;
&lt;br /&gt;
=== Properties in terms of (T,x) ===&lt;br /&gt;
&lt;br /&gt;
For convenience some simple functions for calculating properties in terms of (T,x) have been written. The implementation is in {{src|models/johnpye/fprops/solve_Tx.c}}. Any input with x outside [0,1] or T outside [T_t,T_c] will return an error code. Otherwise, the corresponding rho value will be returned such that (T,rho) is equivalent to the desired state.&lt;br /&gt;
&lt;br /&gt;
A python demonstration of this code is in {{src|models/johnpye/fprops/python/solve_Tx.py}}, which gives the following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
john@thunder:~/ascend/models/johnpye/fprops/python$ python solve_Tx.py &lt;br /&gt;
solved state&lt;br /&gt;
T = 300.000000, x = 0.500000&lt;br /&gt;
--&amp;gt; rho = 0.309802, h = 395476.135716, s = 381991.898474, u = 1491.770280&lt;br /&gt;
&lt;br /&gt;
checking reverse solve:&lt;br /&gt;
--&amp;gt; x = 0.500000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Peng-Robinson Equation of State ===&lt;br /&gt;
&amp;lt;b&amp;gt;NOT YET IMPLEMENTED&amp;lt;/b&amp;gt;&lt;br /&gt;
{{experimental}}&lt;br /&gt;
The Peng-Robinson EOS is a cubic equation of state in that it contains volume terms to the third power, it is one of several equations of state that can be expressed in the form&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
P=\frac{RT}{V-b}-\frac{a}{V^2+ubV+wb^2}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
Z^3-(1+B^*-uB^*)Z^2+(A^*+wB^{*2}-uB^*-uB^{*2})Z-A^*B^*-wB^{*2}-wB^{*3}=0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Where&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
A^*=\frac{aP}{R^2T^2}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
B^*=\frac{bP}{RT}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
In the Peng-Robinson values for &amp;lt;math&amp;gt;u,&amp;lt;/math&amp;gt; &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;b&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt; are set as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
u=2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
w=-1&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
b=\frac{0.7780RT_c}{P_c}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
a=\frac{0.45724R^2T_c^2}{P_c}[1+f\omega(1-T_r^{\frac{1}{2}})]^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
f\omega=0.37464+1.54226\omega-0.26992\omega^2&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So, for given values of &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;T_c&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;T_r&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;P_c&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\omega&amp;lt;/math&amp;gt; we can solve for &amp;lt;math&amp;gt;Z&amp;lt;/math&amp;gt;. What next??&lt;br /&gt;
&lt;br /&gt;
== Testing the code ==&lt;br /&gt;
&lt;br /&gt;
FPROPS includes a suite of self tests for each fluid that has been implemented. Some of the test data comes from the publications from which the correlations have been taken; other test data comes from using the commercial package [http://www.nist.gov/srd/nist23.htm REFPROP] to calculate some sample data points, and comparing the FPROPS output with that data.&lt;br /&gt;
&lt;br /&gt;
To run the FPROPS tests for a given fluid, &amp;lt;tt&amp;gt;cd&amp;lt;/tt&amp;gt; to the FPROPS directory (eg &amp;lt;tt&amp;gt;cd ~/ascend/models/johnpye/fprops&amp;amp;lt;/tdd&amp;amp;gt;) then run the test script &amp;amp;lt;tt&amp;amp;gt;./test.py &#039;&#039;fluidname&#039;&#039;&amp;lt;/tt&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;a4c&amp;quot;&amp;gt;./test.py hydrogen&lt;br /&gt;
./test.py nitrogen&amp;lt;/source&amp;gt;&lt;br /&gt;
&#039;&#039;Requires GNU scientific library(libgsl0-dev) to be installed in the system&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The output will tell you if all calculated values have conformed to expected error margins.&lt;br /&gt;
&lt;br /&gt;
Test code for each fluid is (should be) embedded at the end of the corresponding fluid file, for example {{src|models/johnpye/fprops/fluids/hydrogen.c}}.&lt;br /&gt;
&lt;br /&gt;
During development, some additional testing routines are in the python subdirectory. These include&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;satcvgc.py&amp;lt;/tt&amp;gt; to test converge of saturation region routines &amp;lt;tt&amp;gt;fprops_sat_T&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;fprops_sat_p&amp;lt;/tt&amp;gt; are working.&lt;br /&gt;
* &amp;lt;tt&amp;gt;solve_ph_array&amp;lt;/tt&amp;gt; to test convergence of the &amp;lt;tt&amp;gt;fprops_solve_ph&amp;lt;/tt&amp;gt; routine, including plotting of regions where the routine is failing.&lt;br /&gt;
&lt;br /&gt;
== Adding new fluids ==&lt;br /&gt;
&lt;br /&gt;
Currently, new fluids must be added by declaring constant data structures in C code.&lt;br /&gt;
&lt;br /&gt;
An example of a fluid declaration is shown in {{src|models/johnpye/fprops/fluids/hydrogen.c}}.&lt;br /&gt;
&lt;br /&gt;
After adding the data structures in &amp;quot;component&amp;quot;.c file, a corresponding &amp;quot;component&amp;quot;.h is required. &lt;br /&gt;
&lt;br /&gt;
An example of which is shown in {{src|models/johnpye/fprops/fluids/hydrogen.h}}&lt;br /&gt;
&lt;br /&gt;
The new component has to be declared in SConstruct and asc_helmholtz.c.&lt;br /&gt;
&lt;br /&gt;
The data structures which are to be filled are declared in {{src|models/johnpye/fprops/ideal.h}} and {{src|models/johnpye/fprops/helmholtz.h}}.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: when adding new fluids it is important to observe that different papers give different &#039;zero points&#039; for enthalpy and entropy for the substances in question, and the zero points vary from paper to paper. These Helmholtz equations of state can be adjusted for different &#039;zero points&#039; by adjusting the constant and linear parameters (&#039;&amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt;&#039; and &#039;&amp;lt;tt&amp;gt;m&amp;lt;/tt&amp;gt;&#039;) in the IdealData object that is provided in your data structures. The equation to fix these values is&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{\Delta h}{RT} = \tau \Delta \phi_{\tau}^0 = T^{*} \Delta a_2^0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{\Delta s}{R} = \tau \Delta \phi_{\tau}^0 -  \Delta \phi^0 = - \Delta a_1^0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where we assume&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\phi^0(\tau,\delta) = a_1^0 + a_2^0 \tau + \mathrm{other\ terms\ in\ \tau, \delta}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In other words, to correct an offset in &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&#039;&#039;h&#039;&#039;&amp;lt;/span&amp;gt; and &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&#039;&#039;s&#039;&#039;&amp;lt;/span&amp;gt;, these formulae tell you the offset to apply to the constant and linear terms in &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&amp;amp;phi;&amp;lt;sup&amp;gt;0&amp;lt;/sup&amp;gt;(&amp;amp;tau;,&amp;amp;delta;)&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Using within ASCEND ==&lt;br /&gt;
&lt;br /&gt;
To use FPROPS from ASCEND, see the example code in {{src|models/johnpye/fprops/fprops_test.a4c}}. Essentially you must declare a [[DATA]] instance into which you must place the name of the substance for which you wish to calculate properties. Then you can use the functions &lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_p&amp;lt;/tt&amp;gt;, to calculate p(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_u&amp;lt;/tt&amp;gt;, to calculate u(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_h&amp;lt;/tt&amp;gt;, to calculate h(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_s&amp;lt;/tt&amp;gt;, to calculate s(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_a&amp;lt;/tt&amp;gt;, to calculate a(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_cp&amp;lt;/tt&amp;gt;, to calculate cp(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_cv&amp;lt;/tt&amp;gt;, to calculate cv(T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_w&amp;lt;/tt&amp;gt;, to calculate speed of sound for given (T,rho)&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_phsx_vT&amp;lt;/tt&amp;gt; is also available which returns p, h, s and x in for specified (v,T).&lt;br /&gt;
* &amp;lt;tt&amp;gt;helmholtz_Tvsx_ph&amp;lt;/tt&amp;gt; returns T, v, s and x for specified (p,h). Recommended for energy system models.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;. When solving properties in &#039;reverse&#039; mode (eg solving for &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&amp;amp;rho;,&#039;&#039;T&#039;&#039;&amp;lt;/span&amp;gt; when &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&#039;&#039;p&#039;&#039;,&#039;&#039;h&#039;&#039;&amp;lt;/span&amp;gt; are know), you will get significantly better results by switching the QRSlv solver parameter for &#039;convergence test&#039; (convopt) to &#039;RELNOM_SCALE&#039;. This significantly improves ASCEND&#039;s ability to solve these problems. Also, use &amp;lt;tt&amp;gt;OPTION iterationlimit 200&amp;lt;/tt&amp;gt; for larger models.&lt;br /&gt;
&lt;br /&gt;
A first system model using FPROPS is available in {{src|models/johnpye/rankine_fprops.a4c}}. The key part is&lt;br /&gt;
&amp;lt;source lang=&amp;quot;a4c&amp;quot;&amp;gt;&lt;br /&gt;
cd IS_A fluid;&lt;br /&gt;
cd.component :== &#039;water&#039;;&lt;br /&gt;
(* ...definitions of p, h, T, v, s, x omitted here... *)&lt;br /&gt;
&lt;br /&gt;
calc_ph: helmholtz_Tvsx_ph(&lt;br /&gt;
    p, h : INPUT;&lt;br /&gt;
    T, v, s, x : OUTPUT;&lt;br /&gt;
    cd : DATA&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some details on the implementation of the &#039;wrapper&#039; code for connecting FPROPS with ASCEND is given in [[writing ASCEND external relations in C]].&lt;br /&gt;
&lt;br /&gt;
== Using from C ==&lt;br /&gt;
&lt;br /&gt;
Using the FPROPS code from C should also be very straightforward; example code is shown in {{src|models/johnpye/fprops/test.c}}.&lt;br /&gt;
&lt;br /&gt;
== Using from Python ==&lt;br /&gt;
&lt;br /&gt;
FPROPS can also be used from the Python language. There are a number of sample programs in {{srcdir|models/johnpye/fprops/python}}. The API is still evolving as we seek the cleanest ways to report errors back to the user, and catch floating-point errors, etc.&lt;br /&gt;
&lt;br /&gt;
== Further work ==&lt;br /&gt;
{{task}}&lt;br /&gt;
&lt;br /&gt;
FPROPS is still under development! We aim to implement a few more features including&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;s&amp;gt;add support for &#039;&#039;&#039;calculation of the saturation curve&#039;&#039;&#039; using Maxwell phase-equilibrium condition&amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt;add iterative solver for properties in terms of (p,h)&amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt;support for Water using IAPWS-95 correlation (partially complete, but needs support for another type of residual function term).&amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt;refactor the &#039;HelmholtzExpTerm&#039; which is actually a double of &#039;HelmholtzGausTerm&#039; with epsilon = 1.&amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt;add support for calculation of partial derivatives dp/dT, dp/drho, dh/dT, dh/drho, du/dT, du/drho,&amp;lt;/s&amp;gt; ds/dT, ds/drho, da/dT, da/drho &amp;lt;s&amp;gt;to improve convergence of ASCEND models that calculate p, h, u,&amp;lt;/s&amp;gt; s, a etc.&lt;br /&gt;
* investigate apparent disagreement between cp0 for &#039;&#039;&#039;ammonia&#039;&#039;&#039; in FPROPS and values from REFPROP (is it consistent with Tillner-Roth?)&lt;br /&gt;
* investigate apparent very small discrepancy between REFPROP and IAPWS95 in value of speed of sound near critical point.&lt;br /&gt;
* move specification of the &#039;&#039;&#039;zero point&#039;&#039;&#039; out of IdealData and into HelmholtzData. Third law of thermodynamics? How to avoid correlations with negative &#039;&#039;h&#039;&#039; or &#039;&#039;s&#039;&#039; values?&lt;br /&gt;
* implement a &#039;&#039;&#039;pre-calculation routine&#039;&#039;&#039; where for example coefficients of &amp;lt;math&amp;gt;\phi^0&amp;lt;/math&amp;gt; can be prepared?&lt;br /&gt;
* implement support for thermophysical properties &#039;&#039;&#039;conductivity, viscosity, surface tension,&#039;&#039;&#039; and possibly others.&lt;br /&gt;
* &amp;lt;s&amp;gt;implement support for calculation of the speed of sound.&amp;lt;/s&amp;gt;&lt;br /&gt;
* resolve the confusion between T* and T_crit in the data structures. Probably all correlations will be using T_crit -- but is that sure?&lt;br /&gt;
* &amp;lt;s&amp;gt;remove p_c from HelmholtzData structure, because that value can be calculated using p(T_c,rho_c).&amp;lt;/s&amp;gt;&lt;br /&gt;
* add support for solving in terms of (p,h) where p &amp;lt; p_t, the triple point pressure.&lt;br /&gt;
* possibly some additional coefficients needs in order to support correlations such as for Methanol&amp;lt;ref&amp;gt;K de Reuck, 1993, &#039;&#039;Methanol, International Thermodynamic Tables of the Fluid State Vol. 12 (1993)&#039;&#039;, Blackwell/IUPAC, http://www.iupac.org/objID/Source/sou65427568843800267934799&amp;lt;/ref&amp;gt;&lt;br /&gt;
* add properties of R-134a (see {{doi|10.1063/1.555958}})&lt;br /&gt;
&lt;br /&gt;
Further down the track we would like to support:&lt;br /&gt;
&lt;br /&gt;
* reading property correlations from a &#039;&#039;&#039;database&#039;&#039;&#039; (SQLite?) or text file.&lt;br /&gt;
* &amp;lt;font color=green&amp;gt;some simpler equations of state such as MBWR or Peng-Robinson.&amp;lt;/font&amp;gt;(Assigned to Ankit, see [[PengRobinson EOS in FPROPS]])&lt;br /&gt;
* lots more fluids&lt;br /&gt;
* &#039;&#039;&#039;mixing models&#039;&#039;&#039; for multi-phase, multi-component systems (or else incorporate FPROPS into exist code that supports this).&lt;br /&gt;
* [http://www.gerg.info/publications/tm/tm15_04.pdf natural gas properties?]&lt;br /&gt;
* [http://www.if.uidaho.edu/~vutgikar/Fall2007/Hydrogen/AIR.pdf air properties] {{doi|10.1063/1.1285884}}&lt;br /&gt;
&lt;br /&gt;
We&#039;d be very pleased to be able to collaborate on this work with others; the code has been made deliberately able to stand alone; it has no dependency on any other code from ASCEND, and is suitable for incorporation into other open source programs, subject to the restrictions of the GPL license.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Contributors ==&lt;br /&gt;
&lt;br /&gt;
The people who have contributed code and/or implementable advice for FPROPS:&lt;br /&gt;
* [[User:Jpye|John Pye]]&lt;br /&gt;
* [[User:Kchittur|Krishnan Chittur]]&lt;br /&gt;
* HongKe&lt;br /&gt;
* [[User:Rshrikanth|Shrikanth Ranganadham ]]&lt;br /&gt;
* [[User:Ankitml|Ankit Mittal]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[Combined-cycle gas turbine]]&lt;br /&gt;
* [[Thermodynamics with ASCEND]]&lt;br /&gt;
* [[freesteam]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Proposed]]&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2522</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2522"/>
		<updated>2011-06-02T15:19:00Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Separating Correlation Coefficients */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
== Initial Thoughts ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/hydrogen.xml?view=markup hydrogen.xml]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
====Parser====&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in the (accidentally misspelt) [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/parcer.c?view=markup parcer.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the Peng-Robinson cubic EOS, possibly adding some other equations in the same family (van der Waals, Redlich-Kwon and Soave for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup pengrobinson.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2521</id>
		<title>User:RichardTowers</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:RichardTowers&amp;diff=2521"/>
		<updated>2011-06-02T15:17:53Z</updated>

		<summary type="html">&lt;p&gt;RichardTowers: /* Equations of State  - link to source*/&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Richard Towers&#039;&#039;&#039; is a GSOC2011 student (Masters of Engineering, Mechanical) from The University of Durham (UK), working on improvements to [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
== Initial Thoughts ==&lt;br /&gt;
A brief summary of what I hope to achieve over the summer. These points largely follow [http://kh3dev.googlecode.com/files/FPROPSRichardTowers.pdf my GSOC application], feel free to ridicule my youthful ambition.&lt;br /&gt;
* [[#Testing|All current fluids tested and all discrepancies discovered]]&lt;br /&gt;
* Squashed some bugs!&lt;br /&gt;
* [[#Improvements to documentation|Improvements to documentation]]&lt;br /&gt;
* [[#Separating Correlation Coefficients|Separated correlation coefficients from program code, load at run-time]]&lt;br /&gt;
* [[#Equations of State|Added support for one other eqn. of state and tested successfully]]&lt;br /&gt;
* Increased confirmed fluid support to 50 fluids&lt;br /&gt;
* Added support for a0 (p, h) where p &amp;lt; pt&lt;br /&gt;
* Added support for two more eqns. of state, tested successfully&lt;br /&gt;
* Added support for pseudo-pure fluids&lt;br /&gt;
* Increased confirmed fluid support to 70 fluids&lt;br /&gt;
* Added support for at least one mixture&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Need to find &#039;&#039;correct&#039;&#039; data for comparison. Working version of REFPROP? Literature?&lt;br /&gt;
Inconsistencies need to be investigated and hopefully fixed.&lt;br /&gt;
== Improvements to documentation ==&lt;br /&gt;
As part of the build up to starting work I&#039;ve been reading through the LyX generated help file that comes with ASCEND, Having just finished a dissertation written in LyX and LaTeX/pgf/tikz I could probably help significantly with the general appearance of this document, for example:&lt;br /&gt;
{|&lt;br /&gt;
| [[File:OldAsendTypesDiagram.png|thumb|alt=An old spider diagram detailing ASCEND types|Old Types Diagram]]&lt;br /&gt;
| [[File:AscendTypes.png|thumb|alt=A new spider diagram detailing ASCEND types|New Types Diagram]]&lt;br /&gt;
| [[File:OldCylinder.png|thumb|alt=An old diagram showing a thin walled cylinder|Old Cylinder Diagram]]&lt;br /&gt;
| [[File:Cylinder.png|thumb|alt=A new diagram showing a thin walled cylinder|New Cylinder Diagram]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Separating Correlation Coefficients ==&lt;br /&gt;
Coefficients should be stored in human readable files, not as C source. The plan is to create an XML structure for these files and a function to parse the files, loading fluid information at runtime. John suggests using RelaxNG as the schema, I&#039;m not sure whether or not ASCEND already has a preferred cross platform XML parser, to begin with I&#039;ll use GNOME&#039;s libxml.&lt;br /&gt;
====Relax NG Grammar====&lt;br /&gt;
Element names identify the property in question and attributes identify values. The advantage of using attributes instead of node text is that we can specify different attributes (for the same property) that are treated differently, for example: it is sometimes useful to specify the constant ideal term as a multiple of the specific gas constant instead of as an absolute value. [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/fluidSchema.rng?view=markup fluidSchema.rng]&lt;br /&gt;
&lt;br /&gt;
====Example XML Fluid File====&lt;br /&gt;
As an example a fluid file for Hydrogen can be found in [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/hydrogen.xml?view=markup hydrogen.xml]. Note that the constant term is specified as a multiple of R as described above.&lt;br /&gt;
&lt;br /&gt;
===Parser===&lt;br /&gt;
The minimum requirements of the parser are quite simple, however it would be nice not to have to worry about arranging xml elements in a specific order and some variables are easier to specify as multiples of some other variable. The beginnings of a competent parser are found in the (accidentally misspelt) [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/fluids/parcer.c?view=markup parcer.c].&lt;br /&gt;
&lt;br /&gt;
== Equations of State ==&lt;br /&gt;
Firstly I&#039;ll be looking at the Peng-Robinson cubic EOS, possibly adding some other equations in the same family (van der Waals, Redlich-Kwon and Soave for example). See [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.c?view=markup pengrobinson.c] and [http://code.ascend4.org/viewvc/code/branches/richard/models/johnpye/fprops/pengrobinson.h?view=markup pengrobinson.h] for more.&lt;br /&gt;
Later an attempt might be made at implementing Lee and Kesler&#039;s modified Benedict-Webb-Rubin EOS, but this is another job for another day...&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>RichardTowers</name></author>
	</entry>
</feed>