<?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=Ankitml</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=Ankitml"/>
	<link rel="alternate" type="text/html" href="https://ascend4.org/Special:Contributions/Ankitml"/>
	<updated>2026-04-28T23:02:47Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=949</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=949"/>
		<updated>2010-07-14T21:43:26Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Work on this is still going on as a part of GSoC 2010, Project [http://ascendwiki.cheme.cmu.edu/User:Ankitml Ankit]&lt;br /&gt;
&lt;br /&gt;
Comments and suggestions are welcome&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;
==Possible Improvements in the code==&lt;br /&gt;
==Comparisons==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=941</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=941"/>
		<updated>2010-07-13T22:17:53Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Documentation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Work on this is still going on as a part of GSoC 2010, Project [http://ascendwiki.cheme.cmu.edu/User:Ankitml Ankit]&lt;br /&gt;
&lt;br /&gt;
Comments and suggestions are welcome&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;
&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;
//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 main()&lt;br /&gt;
{&lt;br /&gt;
        Tc = 408.2;  // Kelvin&lt;br /&gt;
        Pc = 36.5;  // bar&lt;br /&gt;
        Omega = 0.183; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 300.1;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	RT = R*T;&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;
//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==1)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = 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;
	cout&amp;lt;&amp;lt;&amp;quot;At Temp = &amp;quot;&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&amp;quot; K&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
	cout&amp;lt;&amp;lt;&amp;quot;Psat = &amp;quot;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&amp;quot; bar&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
&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;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
==Comparisons==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=940</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=940"/>
		<updated>2010-07-13T22:16:14Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Limitations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Documentation=&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;
&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;
//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 main()&lt;br /&gt;
{&lt;br /&gt;
        Tc = 408.2;  // Kelvin&lt;br /&gt;
        Pc = 36.5;  // bar&lt;br /&gt;
        Omega = 0.183; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 300.1;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	RT = R*T;&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;
//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==1)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = 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;
	cout&amp;lt;&amp;lt;&amp;quot;At Temp = &amp;quot;&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&amp;quot; K&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
	cout&amp;lt;&amp;lt;&amp;quot;Psat = &amp;quot;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&amp;quot; bar&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
&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;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
==Comparisons==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=939</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=939"/>
		<updated>2010-07-13T22:15:57Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Errors */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Documentation=&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;
===Possible Changes that can be done to remove limitations/errors===&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;
&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;
//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 main()&lt;br /&gt;
{&lt;br /&gt;
        Tc = 408.2;  // Kelvin&lt;br /&gt;
        Pc = 36.5;  // bar&lt;br /&gt;
        Omega = 0.183; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 300.1;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	RT = R*T;&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;
//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==1)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = 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;
	cout&amp;lt;&amp;lt;&amp;quot;At Temp = &amp;quot;&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&amp;quot; K&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
	cout&amp;lt;&amp;lt;&amp;quot;Psat = &amp;quot;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&amp;quot; bar&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
&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;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
==Comparisons==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=938</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=938"/>
		<updated>2010-07-13T22:05:17Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Algorithm */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Documentation=&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;
===Possible Changes that can be done to remove limitations/errors===&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;
&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;
//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 main()&lt;br /&gt;
{&lt;br /&gt;
        Tc = 408.2;  // Kelvin&lt;br /&gt;
        Pc = 36.5;  // bar&lt;br /&gt;
        Omega = 0.183; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 300.1;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	RT = R*T;&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;
//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==1)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = 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;
	cout&amp;lt;&amp;lt;&amp;quot;At Temp = &amp;quot;&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&amp;quot; K&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
	cout&amp;lt;&amp;lt;&amp;quot;Psat = &amp;quot;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&amp;quot; bar&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
&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;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
==Comparisons==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=937</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=937"/>
		<updated>2010-07-13T21:24:00Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Algorithm From Literature */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Documentation=&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;
&lt;br /&gt;
==Limitations==&lt;br /&gt;
===Errors===&lt;br /&gt;
===Possible Changes that can be done to remove limitations/errors===&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;
&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;
//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 main()&lt;br /&gt;
{&lt;br /&gt;
        Tc = 408.2;  // Kelvin&lt;br /&gt;
        Pc = 36.5;  // bar&lt;br /&gt;
        Omega = 0.183; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 300.1;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	RT = R*T;&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;
//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==1)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = 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;
	cout&amp;lt;&amp;lt;&amp;quot;At Temp = &amp;quot;&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&amp;quot; K&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
	cout&amp;lt;&amp;lt;&amp;quot;Psat = &amp;quot;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&amp;quot; bar&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
&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;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
==Comparisons==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=936</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=936"/>
		<updated>2010-07-13T21:10:39Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Documentation=&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 liquid density at that P, and the max V is vapour.&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;
&lt;br /&gt;
==Limitations==&lt;br /&gt;
===Errors===&lt;br /&gt;
===Possible Changes that can be done to remove limitations/errors===&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;
&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;
//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 main()&lt;br /&gt;
{&lt;br /&gt;
        Tc = 408.2;  // Kelvin&lt;br /&gt;
        Pc = 36.5;  // bar&lt;br /&gt;
        Omega = 0.183; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 300.1;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	RT = R*T;&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;
//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==1)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = 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;
	cout&amp;lt;&amp;lt;&amp;quot;At Temp = &amp;quot;&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&amp;quot; K&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
	cout&amp;lt;&amp;lt;&amp;quot;Psat = &amp;quot;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&amp;quot; bar&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
&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;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
==Comparisons==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=935</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=935"/>
		<updated>2010-07-13T21:01:53Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Algorithm */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Documentation=&lt;br /&gt;
==Algorithm==&lt;br /&gt;
===The general Algorithm===&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 liquid density at that P, and the max V is vapour.&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;
==Limitations==&lt;br /&gt;
===Errors===&lt;br /&gt;
===Possible Changes that can be done to remove limitations/errors===&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;
&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;
//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 main()&lt;br /&gt;
{&lt;br /&gt;
        Tc = 408.2;  // Kelvin&lt;br /&gt;
        Pc = 36.5;  // bar&lt;br /&gt;
        Omega = 0.183; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 300.1;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	RT = R*T;&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;
//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==1)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = 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;
	cout&amp;lt;&amp;lt;&amp;quot;At Temp = &amp;quot;&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&amp;quot; K&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
	cout&amp;lt;&amp;lt;&amp;quot;Psat = &amp;quot;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&amp;quot; bar&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
&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;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
==Comparisons==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=909</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=909"/>
		<updated>2010-07-12T02:15:02Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Changes to be done to integrate with ASCEND */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Documentation=&lt;br /&gt;
==Algorithm==&lt;br /&gt;
==Limitations==&lt;br /&gt;
===Errors===&lt;br /&gt;
===Possible Changes that can be done to remove limitations/errors===&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;
&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;
//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 main()&lt;br /&gt;
{&lt;br /&gt;
        Tc = 408.2;  // Kelvin&lt;br /&gt;
        Pc = 36.5;  // bar&lt;br /&gt;
        Omega = 0.183; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 300.1;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	RT = R*T;&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;
//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==1)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = 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;
	cout&amp;lt;&amp;lt;&amp;quot;At Temp = &amp;quot;&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&amp;quot; K&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
	cout&amp;lt;&amp;lt;&amp;quot;Psat = &amp;quot;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&amp;quot; bar&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
&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;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
==Comparisons==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=908</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=908"/>
		<updated>2010-07-12T02:13:52Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Limitations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Documentation=&lt;br /&gt;
==Algorithm==&lt;br /&gt;
==Limitations==&lt;br /&gt;
===Errors===&lt;br /&gt;
===Possible Changes that can be done to remove limitations/errors===&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;
&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;
&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;
//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 main()&lt;br /&gt;
{&lt;br /&gt;
        Tc = 408.2;  // Kelvin&lt;br /&gt;
        Pc = 36.5;  // bar&lt;br /&gt;
        Omega = 0.183; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 300.1;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	RT = R*T;&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;
//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==1)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = 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;
	cout&amp;lt;&amp;lt;&amp;quot;At Temp = &amp;quot;&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&amp;quot; K&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
	cout&amp;lt;&amp;lt;&amp;quot;Psat = &amp;quot;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&amp;quot; bar&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
&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;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
==Comparisons==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=FPROPS&amp;diff=907</id>
		<title>FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=FPROPS&amp;diff=907"/>
		<updated>2010-07-12T02:08:33Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Further work */&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;
* {{src|models/johnpye/fprops/ammonia.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/hydrogen.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/nitrogen.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/water.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/carbondioxide.c}}&lt;br /&gt;
&lt;br /&gt;
* Some more, yet to be merged: [http://ascendcode.cheme.cmu.edu/viewvc.cgi/code/branches/hongke/models/johnpye/fprops/ &amp;lt;font color=&amp;quot;orange&amp;quot;&amp;gt;hongke&amp;lt;/font&amp;gt;:models/johnpye/fprops/]&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 evaluating thermodynamic properties of a number of pure substances via published data for the Helmholtz fundamental equation for those substances. It has been developed by [[User:Jpye|John Pye]] 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 at right. The properties that can be calculated are internal energy, entropy, pressure, enthalpy and Helmholtz energy, 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], EES, FLUIDCAL, [[freesteam]], SteamTab, and others, but is open source software and licensed under the [http://www.gnu.org/licenses/gpl.html GPL]. Contributions are most welcome!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT NOTE:&#039;&#039;&#039; FPROPS does not yet implement calculation of the saturation curve, so it gives incorrect property evaluations anywhere within the saturation region. This is because the code for evaluating the &#039;Maxwell criterion&#039; is not yet completely implemented.&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]] (there have been changes since the 0.9.5.116 release).&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
The calculation routines implement calculation of reduced Helmholtz energy &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&amp;amp;phi;&amp;lt;/span&amp;gt; by dividing it into ideal (&amp;lt;math&amp;gt;\phi^0&amp;lt;/math&amp;gt;) and residual (&amp;lt;math&amp;gt;\phi^r&amp;lt;/math&amp;gt;) parts, as described in IAPWS-95&amp;lt;sup id=&amp;quot;_ref-iapws95_0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-iapws95&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&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;
* power terms, &amp;lt;math&amp;gt;c_i T^{t_i}&amp;lt;/math&amp;gt;&lt;br /&gt;
* exponential terms, &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;&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;sup id=&amp;quot;_ref-0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-0&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&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 would in that case be determined using specified values of enthalpy &amp;lt;math&amp;gt;h_ref&amp;lt;/math&amp;gt; and entropy &amp;lt;math&amp;gt;s_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;
* power terms, &amp;lt;math&amp;gt;a_i \tau^{t_i}\delta^{d_i}&amp;lt;/math&amp;gt; (these are HelmoltzPowTerm with &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&#039;&#039;l&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt; = 0&amp;lt;/span&amp;gt;)&lt;br /&gt;
* exponential terms, &amp;lt;math&amp;gt;a_i \tau^{t_i} \delta^{d_i} exp(-\delta^{l_i})&amp;lt;/math&amp;gt; (these are HelmholtzPowTerm with &amp;lt;math&amp;gt;l_i \ne 0&amp;lt;/math&amp;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;&lt;br /&gt;
* critical terms, &amp;lt;math&amp;gt;n_i \Delta^{b_i} \delta \psi&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;\Delta = \theta^2 + B_i \left[ \left( \delta - 1 \right)^2 \right]^{a_i}&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;\theta = \left( 1- \tau \right) + A_i \left[ \left( \delta - 1 \right)^2 \right]^{\frac{1}{2 \beta_i}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\psi = exp \left[-C_i \left(\delta-1 \right)^2 - D_i \left( \tau - 1 \right)^2 \right]&amp;lt;/math&amp;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;.&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 as well as by Tillner Roth et al&amp;lt;sup id=&amp;quot;_ref-0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-0&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The source code for FPROPS is available via the ASCEND [[VersionManagement|subversion repository]], in the {{srcdir|models/johnpye/fprops}} directory. There is some further information on the implementation on the page about [[writing ASCEND external relations in C]].&lt;br /&gt;
&lt;br /&gt;
=== Maxwell criterion ===&lt;br /&gt;
&lt;br /&gt;
The Helmholtz function above applies for all regions outside the saturation region. The saturation region is determined by a set of equations call the Maxwell phase equilibrium criteria or Maxwell equal-area rule &amp;lt;sup id=&amp;quot;_ref-iapws95_0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-iapws95&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&amp;gt;&amp;lt;sup id=&amp;quot;_ref-0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-0&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calculation of the phase equilibrium conditions requires iterative solution of three equations; a suitable algorithm for efficiently performing this has not yet been incorporated into FPROPS; contributions are welcome.&lt;br /&gt;
&lt;br /&gt;
The Maxwell criterion is stated in IAPWS-95 as being the preferred approach for determining the location of the saturation line, but it could be possible that we can use equality of Gibbs Free Energy to work this out. Need to investigate this and work out a suitable approach.&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;
&lt;br /&gt;
Test code for each fluid is embedded at the end of the corresponding fluid file, for example {{src|models/johnpye/fprops/hydrogen.c}}.&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/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/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 &amp;lt;tt&amp;gt;helmholtz_p&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_u&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_h&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_p&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_s&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_a&amp;lt;/tt&amp;gt; to calculate the property you need.&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.&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;
== 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;font color=green&amp;gt;add support for &#039;&#039;&#039;calculation of the saturation curve&#039;&#039;&#039; using Maxwell phase-equilibrium condition&amp;lt;/font&amp;gt;  (Assigned to Shrikanth)&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.&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;
&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;(Assign to Ankit)&lt;br /&gt;
** Check [http://ascendwiki.cheme.cmu.edu/PengRobinson_EOS_in_FPROPS PR-EOS] for Peng-Robinson&lt;br /&gt;
* more fluids of general interest.&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;
&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.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[Thermodynamics with ASCEND]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Proposed]]&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=906</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=906"/>
		<updated>2010-07-12T02:02:41Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Documentation=&lt;br /&gt;
==Algorithm==&lt;br /&gt;
==Limitations==&lt;br /&gt;
*limitations&lt;br /&gt;
*Errors&lt;br /&gt;
*Possible Changes that can be done to remove limitations/errors&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;
&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;
//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 main()&lt;br /&gt;
{&lt;br /&gt;
        Tc = 408.2;  // Kelvin&lt;br /&gt;
        Pc = 36.5;  // bar&lt;br /&gt;
        Omega = 0.183; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 300.1;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	RT = R*T;&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;
//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==1)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = 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;
	cout&amp;lt;&amp;lt;&amp;quot;At Temp = &amp;quot;&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&amp;quot; K&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
	cout&amp;lt;&amp;lt;&amp;quot;Psat = &amp;quot;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&amp;quot; bar&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
&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;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
==Comparisons==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=905</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=905"/>
		<updated>2010-07-12T01:59:33Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Limitations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Documentation=&lt;br /&gt;
==Algorithm==&lt;br /&gt;
==Limitations==&lt;br /&gt;
*limitations&lt;br /&gt;
*Errors&lt;br /&gt;
*Possible Changes that can be done to remove limitations/errors&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[25000],V[25000],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;
        Tc = 408.2;  // Kelvin&lt;br /&gt;
        Pc = 36.5;  // bar&lt;br /&gt;
        Omega = 0.183; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 300.1;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	RT = R*T;&lt;br /&gt;
	&lt;br /&gt;
	double p[25000],v[25000];&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;25000;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;
//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==1)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = 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;
	cout&amp;lt;&amp;lt;&amp;quot;At Temp = &amp;quot;&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&amp;quot; K&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
	cout&amp;lt;&amp;lt;&amp;quot;Psat = &amp;quot;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&amp;quot; bar&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
&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;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
==Comparisons==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=904</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=904"/>
		<updated>2010-07-12T01:59:03Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Documentation=&lt;br /&gt;
==Algorithm==&lt;br /&gt;
==Limitations==&lt;br /&gt;
*limitations&lt;br /&gt;
*Possible Changes that can be done to remove &lt;br /&gt;
*Errors&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[25000],V[25000],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;
        Tc = 408.2;  // Kelvin&lt;br /&gt;
        Pc = 36.5;  // bar&lt;br /&gt;
        Omega = 0.183; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 300.1;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	RT = R*T;&lt;br /&gt;
	&lt;br /&gt;
	double p[25000],v[25000];&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;25000;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;
//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==1)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = 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;
	cout&amp;lt;&amp;lt;&amp;quot;At Temp = &amp;quot;&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&amp;quot; K&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
	cout&amp;lt;&amp;lt;&amp;quot;Psat = &amp;quot;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&amp;quot; bar&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
&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;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Improvements in the code==&lt;br /&gt;
==Comparisons==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=PengRobinson_EOS_in_FPROPS&amp;diff=903</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=903"/>
		<updated>2010-07-12T01:53:44Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: Created page with &amp;#039;=Documentation= ==Algorithm== ==Limitations== *limitations *Possible Changes that can be done to remove   =Code= &amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt; #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;math.h&amp;gt; #include &amp;lt;…&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Documentation=&lt;br /&gt;
==Algorithm==&lt;br /&gt;
==Limitations==&lt;br /&gt;
*limitations&lt;br /&gt;
*Possible Changes that can be done to remove &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[25000],V[25000],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;
        Tc = 408.2;  // Kelvin&lt;br /&gt;
        Pc = 36.5;  // bar&lt;br /&gt;
        Omega = 0.183; // acentric factor&lt;br /&gt;
        R = 83.14; //bar[cm3]/k/mol&lt;br /&gt;
	T = 300.1;&lt;br /&gt;
        Tre = T/Tc;&lt;br /&gt;
	RT = R*T;&lt;br /&gt;
	&lt;br /&gt;
	double p[25000],v[25000];&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;25000;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;
//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==1)&lt;br /&gt;
                        {&lt;br /&gt;
                                pEnd = 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;
	cout&amp;lt;&amp;lt;&amp;quot;At Temp = &amp;quot;&amp;lt;&amp;lt;T&amp;lt;&amp;lt;&amp;quot; K&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
	cout&amp;lt;&amp;lt;&amp;quot;Psat = &amp;quot;&amp;lt;&amp;lt;sol&amp;lt;&amp;lt;&amp;quot; bar&amp;quot;&amp;lt;&amp;lt;&#039;\n&#039;;&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;
&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;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Improvements in the code==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=897</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=897"/>
		<updated>2010-07-08T16:05:01Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Undergraduate Senior at IIT Bombay&lt;br /&gt;
(5 year programme, Btech-MTech in Chemical Engineering)&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Subversion Branch [http://ascendcode.cheme.cmu.edu/viewvc/code/branches/ankit/ ankit]&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. Determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
&lt;br /&gt;
2.Create test cases for all new components added.&lt;br /&gt;
&lt;br /&gt;
3.Saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
5.Get IPOPT Installed and write some optimization models from (Edgar and Himmelblau)&lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [working code(maybe half) is there in shrikanth&#039;s branch]&lt;br /&gt;
*Ascend now working on Ubuntu 10.04. &lt;br /&gt;
&lt;br /&gt;
(9th June, 2010)&lt;br /&gt;
*Automated addition file is uploaded in ankit branch, readme will follow by evening.&lt;br /&gt;
*Three IPOPT examples from Edgar and Himelblau uploaded, one not solving. One giving better solution than the book and the third giving worse solution than the book.&lt;br /&gt;
&lt;br /&gt;
==To do==&lt;br /&gt;
*Implement Peng Robinson Equation of State for FPROPS&lt;br /&gt;
**Generate PV(using PREOS) data with variable delta-V so that increment in P is not very high. &lt;br /&gt;
**Store PV data in dynamic memory&lt;br /&gt;
**Three approaches to find Psat and equilibrium volumes&lt;br /&gt;
**1.Find an analytical expression for area between constant P and the peng robinson PV data and use maxwell equal area rule.&lt;br /&gt;
**2. Do the above numerically.&lt;br /&gt;
**3. Approach used on Pg46 of Reid and Polling (4th edition)&lt;br /&gt;
***Guess P&lt;br /&gt;
*** Solve for cubic Z&lt;br /&gt;
***find fugacity for Zl and Zv at guessed P&lt;br /&gt;
*** if fl==fv the P = Psat &lt;br /&gt;
*** else Pnew = P*fl/fv&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Perfecting the python script for easy adding of data structures to ASCEND&lt;br /&gt;
**Merge the two python scripts for creating the data and adding the test data.&lt;br /&gt;
**Create documentation for the python file&lt;br /&gt;
**Get the script tested by other ASCEND users.&lt;br /&gt;
**CHange it if required according to the feedback.&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=859</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=859"/>
		<updated>2010-06-18T08:12:12Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Undergraduate Senior at IIT Bombay&lt;br /&gt;
(5 year programme, Btech-MTech in Chemical Engineering)&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Subversion Branch [http://ascendcode.cheme.cmu.edu/viewvc/code/branches/ankit/ ankit]&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. Determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
&lt;br /&gt;
2.Create test cases for all new components added.&lt;br /&gt;
&lt;br /&gt;
3.Saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
5.Get IPOPT Installed and write some optimization models from (Edgar and Himmelblau)&lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [working code(maybe half) is there in shrikanth&#039;s branch]&lt;br /&gt;
*Ascend now working on Ubuntu 10.04. &lt;br /&gt;
&lt;br /&gt;
(9th June, 2010)&lt;br /&gt;
*Automated addition file is uploaded in ankit branch, readme will follow by evening.&lt;br /&gt;
*Three IPOPT examples from Edgar and Himelblau uploaded, one not solving. One giving better solution than the book and the third giving worse solution than the book.&lt;br /&gt;
&lt;br /&gt;
==To do==&lt;br /&gt;
*Implement Peng Robinson Equation of State for FPROPS&lt;br /&gt;
** create preos.c and preos.h similarly like mbwr&lt;br /&gt;
** create asc_preos.c (Wrapper for preos.c to allow access to the routine from ASCEND)&lt;br /&gt;
**Add a data structures preoe_data to components.c files (or separate files??)&lt;br /&gt;
**create python script for easy adding component&#039;s Peng Robinson Data&lt;br /&gt;
&lt;br /&gt;
*Perfecting the python script for easy adding of data structures to ASCEND&lt;br /&gt;
**Merge the two python scripts for creating the data and adding the test data.&lt;br /&gt;
**Create documentation for the python file&lt;br /&gt;
**Get the script tested by other ASCEND users.&lt;br /&gt;
**CHange it if required according to the feedback.&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=849</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=849"/>
		<updated>2010-06-09T09:21:09Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Undergraduate Senior at IIT Bombay&lt;br /&gt;
(5 year programme, Btech-MTech in Chemical Engineering)&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Subversion Branch [http://ascendcode.cheme.cmu.edu/viewvc/code/branches/ankit/ ankit]&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. Determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
&lt;br /&gt;
2.Create test cases for all new components added.&lt;br /&gt;
&lt;br /&gt;
3.Saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
5.Get IPOPT Installed and write some optimization models from (Edgar and Himmelblau)&lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [working code(maybe half) is there in shrikanth&#039;s branch]&lt;br /&gt;
*Ascend now working on Ubuntu 10.04. &lt;br /&gt;
&lt;br /&gt;
(9th June, 2010)&lt;br /&gt;
*Automated addition file is uploaded in ankit branch, readme will follow by evening.&lt;br /&gt;
*Three IPOPT examples from Edgar and Himelblau uploaded, one not solving. One giving better solution than the book and the third giving worse solution than the book.&lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=808</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=808"/>
		<updated>2010-06-07T06:22:25Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Undergraduate Senior at IIT Bombay&lt;br /&gt;
(5 year programme, Btech-MTech in Chemical Engineering)&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Subversion Branch [http://ascendcode.cheme.cmu.edu/viewvc/code/branches/ankit/ ankit]&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. Determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
&lt;br /&gt;
2.Create test cases for all new components added.&lt;br /&gt;
&lt;br /&gt;
3.Saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
5.Get IPOPT Installed and write some optimization models from (Edgar and Himmelblau)&lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [working code(maybe half) is there in shrikanth&#039;s branch]&lt;br /&gt;
*Ascend now working on Ubuntu 10.04. &lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=806</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=806"/>
		<updated>2010-06-06T22:09:17Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Detailed Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Undergraduate Senior at IIT Bombay&lt;br /&gt;
(5 year programme, Btech-MTech in Chemical Engineering)&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Subversion Branch [http://ascendcode.cheme.cmu.edu/viewvc/code/branches/ankit/ ankit]&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. Determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
&lt;br /&gt;
2.Create test cases for all new components added.&lt;br /&gt;
&lt;br /&gt;
3.Saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
5.Get IPOPT Installed and write some optimization models from (Edgar and Himmelblau)&lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [needs more discussion with prof.Krishnan]&lt;br /&gt;
*Ascend now working on Ubuntu 10.04. &lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=805</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=805"/>
		<updated>2010-06-06T22:08:51Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Detailed Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Undergraduate Senior at IIT Bombay&lt;br /&gt;
(5 year programme, Btech-MTech in Chemical Engineering)&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Subversion Branch [http://ascendcode.cheme.cmu.edu/viewvc/code/branches/ankit/ ankit]&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. Determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
&lt;br /&gt;
2.Create test cases for all new components added.&lt;br /&gt;
&lt;br /&gt;
3.Saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
5.Get IPOPT Installed and write some optimization models from (Edgar and Himmelblau)&lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [needs more discussion with prof.Krishnan]&lt;br /&gt;
*Ascend now working on Ubuntu 10.04. &lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=804</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=804"/>
		<updated>2010-06-06T21:58:31Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Detailed Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Undergraduate Senior at IIT Bombay&lt;br /&gt;
(5 year programme, Btech-MTech in Chemical Engineering)&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Subversion Branch [http://ascendcode.cheme.cmu.edu/viewvc/code/branches/ankit/ ankit]&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. Determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
&lt;br /&gt;
2.Create test cases for all new components added.&lt;br /&gt;
&lt;br /&gt;
3.Saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
---&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
5.Get IPOPT Installed and write some optimization models from (Edgar and Himmelblau)&lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [needs more discussion with prof.Krishnan]&lt;br /&gt;
*Ascend now working on Ubuntu 10.04. &lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=803</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=803"/>
		<updated>2010-06-06T21:40:56Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Undergraduate Senior at IIT Bombay&lt;br /&gt;
(5 year programme, Btech-MTech in Chemical Engineering)&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Subversion Branch [http://ascendcode.cheme.cmu.edu/viewvc/code/branches/ankit/ ankit]&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. Determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
&lt;br /&gt;
2.Create test cases for all new components added.&lt;br /&gt;
&lt;br /&gt;
3.Saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
---&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
5.Get IPOPT Installed and write some optimization models from (Edgar and Himmelblau)&lt;br /&gt;
&lt;br /&gt;
6.Get subversion working under IITB Proxy. &lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [needs more discussion with prof.Krishnan]&lt;br /&gt;
*Ascend now working on Ubuntu 10.04. &lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=802</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=802"/>
		<updated>2010-06-06T21:39:50Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Undergraduate Senior at IIT Bombay&lt;br /&gt;
(5 year programme, Btech-MTech in Chemical Engineering)&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Subversion Branch [http://ascendcode.cheme.cmu.edu/viewvc/code/branches/ankit/ ankit]&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. Determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
&lt;br /&gt;
2.Create test cases for all new components added.&lt;br /&gt;
&lt;br /&gt;
3.Saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
---&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
5.Get IPOPT Installed and write some optimization models from (Edgar and Himmelblau)&lt;br /&gt;
&lt;br /&gt;
6.Get subversion working under IITB Proxy. &lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [needs more discussion with prof.Krishnan]&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=801</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=801"/>
		<updated>2010-06-06T14:57:35Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Undergraduate Senior at IIT Bombay&lt;br /&gt;
(5 year programme, Btech-MTech in Chemical Engineering)&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Subversion Branch [http://ascendcode.cheme.cmu.edu/viewvc/code/branches/ankit/ ankit]&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. Determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
&lt;br /&gt;
2.Create test cases for all new components added.&lt;br /&gt;
&lt;br /&gt;
3.Saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [needs more discussion with prof.Krishnan]&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=800</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=800"/>
		<updated>2010-06-06T14:47:42Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Undergraduate Senior&lt;br /&gt;
(5 year programme, Btech-MTech in Chemical Engineering)&lt;br /&gt;
&lt;br /&gt;
IIT Bombay&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
Subversion Branch [http://ascendcode.cheme.cmu.edu/viewvc/code/branches/ankit/ ankit]&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. Determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
&lt;br /&gt;
2.Create test cases for all new components added.&lt;br /&gt;
&lt;br /&gt;
3.Saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [needs more discussion with prof.Krishnan]&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=799</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=799"/>
		<updated>2010-06-06T12:44:10Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Detailed Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. Determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
&lt;br /&gt;
2.Create test cases for all new components added.&lt;br /&gt;
&lt;br /&gt;
3.Saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [needs more discussion with prof.Krishnan]&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=798</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=798"/>
		<updated>2010-06-06T12:42:13Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Detailed Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
&lt;br /&gt;
2.create test cases for all new components added.&lt;br /&gt;
&lt;br /&gt;
3.saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [needs more discussion with prof.Krishnan]&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=780</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=780"/>
		<updated>2010-06-06T10:39:02Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Ankit Mittal&#039;&#039;&#039; [mailto:ankitml@gmail.com ankitml@gmail.com]&lt;br /&gt;
&lt;br /&gt;
Mentor: [[Krishnan Chittur]]&lt;br /&gt;
&lt;br /&gt;
My GSOC 2010 [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626 proposal] is relating to the ASCEND component, [[FPROPS]].&lt;br /&gt;
&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;br /&gt;
&lt;br /&gt;
Ankit: some thoughts on a more detailed breakdown... [[User:Jpye|Jpye]] 00:35, 27 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
1. determine a use case for testing purposes, eg an ammonia synthesis reactor flowsheet, or Krishnan&#039;s flowsheet example?&lt;br /&gt;
2.create test cases for all new components added.&lt;br /&gt;
3.saturation curve work... look at my numerical experiments (sat.c, I think?) and read up on possible methods to solve this&lt;br /&gt;
4.Automated addition of components to FPROPS. (Added by Ankit on 6th June,2010.)&lt;br /&gt;
&lt;br /&gt;
==Work Done==&lt;br /&gt;
(6th June,2010)&lt;br /&gt;
*Added 15 components to FrPROPS library. (With Shrikanth)&lt;br /&gt;
*Test data for isopentane was taken from NIST Webbook, was showing error more than permissible levels (&amp;gt;1%). Test was complete by changing the acceptable tolerances.[Discuss this with Prof.Krishnan Tomorrow]&lt;br /&gt;
*Started working on a python script for automated addition of components. [needs more discussion with prof.Krishnan]&lt;br /&gt;
&lt;br /&gt;
[[Category:GSOC2010]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=FPROPS&amp;diff=718</id>
		<title>FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=FPROPS&amp;diff=718"/>
		<updated>2010-05-26T21:43:59Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Adding new fluids */&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;
* {{src|models/johnpye/fprops/ammonia.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/hydrogen.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/nitrogen.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/water.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/carbondioxide.c}}&lt;br /&gt;
&lt;br /&gt;
* Some more, yet to be merged: [http://ascendcode.cheme.cmu.edu/viewvc.cgi/code/branches/hongke/models/johnpye/fprops/ &amp;lt;font color=&amp;quot;orange&amp;quot;&amp;gt;hongke&amp;lt;/font&amp;gt;:models/johnpye/fprops/]&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 evaluating thermodynamic properties of a number of pure substances via published data for the Helmholtz fundamental equation for those substances. It has been developed by [[User:Jpye|John Pye]] 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 at right. The properties that can be calculated are internal energy, entropy, pressure, enthalpy and Helmholtz energy, 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], EES, FLUIDCAL, [[freesteam]], SteamTab, and others, but is open source software and licensed under the [http://www.gnu.org/licenses/gpl.html GPL]. Contributions are most welcome!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT NOTE:&#039;&#039;&#039; FPROPS does not yet implement calculation of the saturation curve, so it gives incorrect property evaluations anywhere within the saturation region. This is because the code for evaluating the &#039;Maxwell criterion&#039; is not yet completely implemented.&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]] (there have been changes since the 0.9.5.116 release).&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
The calculation routines implement calculation of reduced Helmholtz energy &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&amp;amp;phi;&amp;lt;/span&amp;gt; by dividing it into ideal (&amp;lt;math&amp;gt;\phi^0&amp;lt;/math&amp;gt;) and residual (&amp;lt;math&amp;gt;\phi^r&amp;lt;/math&amp;gt;) parts, as described in IAPWS-95&amp;lt;sup id=&amp;quot;_ref-iapws95_0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-iapws95&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&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;
* power terms, &amp;lt;math&amp;gt;c_i T^{t_i}&amp;lt;/math&amp;gt;&lt;br /&gt;
* exponential terms, &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;&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;sup id=&amp;quot;_ref-0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-0&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&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 would in that case be determined using specified values of enthalpy &amp;lt;math&amp;gt;h_ref&amp;lt;/math&amp;gt; and entropy &amp;lt;math&amp;gt;s_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;
* power terms, &amp;lt;math&amp;gt;a_i \tau^{t_i}\delta^{d_i}&amp;lt;/math&amp;gt; (these are HelmoltzPowTerm with &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&#039;&#039;l&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt; = 0&amp;lt;/span&amp;gt;)&lt;br /&gt;
* exponential terms, &amp;lt;math&amp;gt;a_i \tau^{t_i} \delta^{d_i} exp(-\delta^{l_i})&amp;lt;/math&amp;gt; (these are HelmholtzPowTerm with &amp;lt;math&amp;gt;l_i \ne 0&amp;lt;/math&amp;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;&lt;br /&gt;
* critical terms, &amp;lt;math&amp;gt;n_i \Delta^{b_i} \delta \psi&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;\Delta = \theta^2 + B_i \left[ \left( \delta - 1 \right)^2 \right]^{a_i}&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;\theta = \left( 1- \tau \right) + A_i \left[ \left( \delta - 1 \right)^2 \right]^{\frac{1}{2 \beta_i}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\psi = exp \left[-C_i \left(\delta-1 \right)^2 - D_i \left( \tau - 1 \right)^2 \right]&amp;lt;/math&amp;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;.&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 as well as by Tillner Roth et al&amp;lt;sup id=&amp;quot;_ref-0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-0&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The source code for FPROPS is available via the ASCEND [[VersionManagement|subversion repository]], in the {{srcdir|models/johnpye/fprops}} directory. There is some further information on the implementation on the page about [[writing ASCEND external relations in C]].&lt;br /&gt;
&lt;br /&gt;
=== Maxwell criterion ===&lt;br /&gt;
&lt;br /&gt;
The Helmholtz function above applies for all regions outside the saturation region. The saturation region is determined by a set of equations call the Maxwell phase equilibrium criteria or Maxwell equal-area rule &amp;lt;sup id=&amp;quot;_ref-iapws95_0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-iapws95&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&amp;gt;&amp;lt;sup id=&amp;quot;_ref-0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-0&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calculation of the phase equilibrium conditions requires iterative solution of three equations; a suitable algorithm for efficiently performing this has not yet been incorporated into FPROPS; contributions are welcome.&lt;br /&gt;
&lt;br /&gt;
The Maxwell criterion is stated in IAPWS-95 as being the preferred approach for determining the location of the saturation line, but it could be possible that we can use equality of Gibbs Free Energy to work this out. Need to investigate this and work out a suitable approach.&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;
&lt;br /&gt;
Test code for each fluid is embedded at the end of the corresponding fluid file, for example {{src|models/johnpye/fprops/hydrogen.c}}.&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/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/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 &amp;lt;tt&amp;gt;helmholtz_p&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_u&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_h&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_p&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_s&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_a&amp;lt;/tt&amp;gt; to calculate the property you need.&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.&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;
== 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;font color=green&amp;gt;add support for &#039;&#039;&#039;calculation of the saturation curve&#039;&#039;&#039; using Maxwell phase-equilibrium condition&amp;lt;/font&amp;gt; (Assign to Ankit)&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.&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;
&lt;br /&gt;
Further down the track we would like to support:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;font color=green&amp;gt;reading property correlations from a &#039;&#039;&#039;database&#039;&#039;&#039; (SQLite?) or text file.&amp;lt;/font&amp;gt; (Assigned to Shrikanth)&lt;br /&gt;
* some simpler equations of state such as MBWR or Peng-Robinson.&lt;br /&gt;
* more fluids of general interest.&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;
&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.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[Thermodynamics with ASCEND]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Proposed]]&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=FPROPS&amp;diff=716</id>
		<title>FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=FPROPS&amp;diff=716"/>
		<updated>2010-05-26T19:07:56Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: /* Adding new fluids */ - declaration of new component&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;
* {{src|models/johnpye/fprops/ammonia.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/hydrogen.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/nitrogen.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/water.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/carbondioxide.c}}&lt;br /&gt;
&lt;br /&gt;
* Some more, yet to be merged: [http://ascendcode.cheme.cmu.edu/viewvc.cgi/code/branches/hongke/models/johnpye/fprops/ &amp;lt;font color=&amp;quot;orange&amp;quot;&amp;gt;hongke&amp;lt;/font&amp;gt;:models/johnpye/fprops/]&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 evaluating thermodynamic properties of a number of pure substances via published data for the Helmholtz fundamental equation for those substances. It has been developed by [[User:Jpye|John Pye]] 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 at right. The properties that can be calculated are internal energy, entropy, pressure, enthalpy and Helmholtz energy, 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], EES, FLUIDCAL, [[freesteam]], SteamTab, and others, but is open source software and licensed under the [http://www.gnu.org/licenses/gpl.html GPL]. Contributions are most welcome!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT NOTE:&#039;&#039;&#039; FPROPS does not yet implement calculation of the saturation curve, so it gives incorrect property evaluations anywhere within the saturation region. This is because the code for evaluating the &#039;Maxwell criterion&#039; is not yet completely implemented.&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]] (there have been changes since the 0.9.5.116 release).&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
The calculation routines implement calculation of reduced Helmholtz energy &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&amp;amp;phi;&amp;lt;/span&amp;gt; by dividing it into ideal (&amp;lt;math&amp;gt;\phi^0&amp;lt;/math&amp;gt;) and residual (&amp;lt;math&amp;gt;\phi^r&amp;lt;/math&amp;gt;) parts, as described in IAPWS-95&amp;lt;sup id=&amp;quot;_ref-iapws95_0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-iapws95&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&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;
* power terms, &amp;lt;math&amp;gt;c_i T^{t_i}&amp;lt;/math&amp;gt;&lt;br /&gt;
* exponential terms, &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;&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;sup id=&amp;quot;_ref-0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-0&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&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 would in that case be determined using specified values of enthalpy &amp;lt;math&amp;gt;h_ref&amp;lt;/math&amp;gt; and entropy &amp;lt;math&amp;gt;s_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;
* power terms, &amp;lt;math&amp;gt;a_i \tau^{t_i}\delta^{d_i}&amp;lt;/math&amp;gt; (these are HelmoltzPowTerm with &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&#039;&#039;l&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt; = 0&amp;lt;/span&amp;gt;)&lt;br /&gt;
* exponential terms, &amp;lt;math&amp;gt;a_i \tau^{t_i} \delta^{d_i} exp(-\delta^{l_i})&amp;lt;/math&amp;gt; (these are HelmholtzPowTerm with &amp;lt;math&amp;gt;l_i \ne 0&amp;lt;/math&amp;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;&lt;br /&gt;
* critical terms, &amp;lt;math&amp;gt;n_i \Delta^{b_i} \delta \psi&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;\Delta = \theta^2 + B_i \left[ \left( \delta - 1 \right)^2 \right]^{a_i}&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;\theta = \left( 1- \tau \right) + A_i \left[ \left( \delta - 1 \right)^2 \right]^{\frac{1}{2 \beta_i}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\psi = exp \left[-C_i \left(\delta-1 \right)^2 - D_i \left( \tau - 1 \right)^2 \right]&amp;lt;/math&amp;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;.&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 as well as by Tillner Roth et al&amp;lt;sup id=&amp;quot;_ref-0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-0&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The source code for FPROPS is available via the ASCEND [[VersionManagement|subversion repository]], in the {{srcdir|models/johnpye/fprops}} directory. There is some further information on the implementation on the page about [[writing ASCEND external relations in C]].&lt;br /&gt;
&lt;br /&gt;
=== Maxwell criterion ===&lt;br /&gt;
&lt;br /&gt;
The Helmholtz function above applies for all regions outside the saturation region. The saturation region is determined by a set of equations call the Maxwell phase equilibrium criteria or Maxwell equal-area rule &amp;lt;sup id=&amp;quot;_ref-iapws95_0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-iapws95&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&amp;gt;&amp;lt;sup id=&amp;quot;_ref-0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-0&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calculation of the phase equilibrium conditions requires iterative solution of three equations; a suitable algorithm for efficiently performing this has not yet been incorporated into FPROPS; contributions are welcome.&lt;br /&gt;
&lt;br /&gt;
The Maxwell criterion is stated in IAPWS-95 as being the preferred approach for determining the location of the saturation line, but it could be possible that we can use equality of Gibbs Free Energy to work this out. Need to investigate this and work out a suitable approach.&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;
&lt;br /&gt;
Test code for each fluid is embedded at the end of the corresponding fluid file, for example {{src|models/johnpye/fprops/hydrogen.c}}.&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/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/hydrogen.h}}&lt;br /&gt;
&lt;br /&gt;
The new component have 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 &amp;lt;tt&amp;gt;helmholtz_p&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_u&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_h&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_p&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_s&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_a&amp;lt;/tt&amp;gt; to calculate the property you need.&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.&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;
== 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;font color=green&amp;gt;add support for &#039;&#039;&#039;calculation of the saturation curve&#039;&#039;&#039; using Maxwell phase-equilibrium condition&amp;lt;/font&amp;gt; (Assign to Ankit)&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.&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;
&lt;br /&gt;
Further down the track we would like to support:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;font color=green&amp;gt;reading property correlations from a &#039;&#039;&#039;database&#039;&#039;&#039; (SQLite?) or text file.&amp;lt;/font&amp;gt; (Assigned to Shrikanth)&lt;br /&gt;
* some simpler equations of state such as MBWR or Peng-Robinson.&lt;br /&gt;
* more fluids of general interest.&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;
&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.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[Thermodynamics with ASCEND]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Proposed]]&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Ankitml&amp;diff=694</id>
		<title>User:Ankitml</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Ankitml&amp;diff=694"/>
		<updated>2010-05-26T08:05:12Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: Created page with &amp;#039;Ankit Mittal  ankitml@gmail.com  GSOC 2010 Proposal : &amp;#039;&amp;#039;&amp;#039;FPROPS&amp;#039;&amp;#039;&amp;#039; [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626]  FPROPS wiki page…&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ankit Mittal&lt;br /&gt;
&lt;br /&gt;
ankitml@gmail.com&lt;br /&gt;
&lt;br /&gt;
GSOC 2010 Proposal :&lt;br /&gt;
&#039;&#039;&#039;FPROPS&#039;&#039;&#039; [http://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/ankitml/t127083474626]&lt;br /&gt;
&lt;br /&gt;
FPROPS wiki page [http://ascendwiki.cheme.cmu.edu/FPROPS]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Deliverables==&lt;br /&gt;
1. Add new components to FPROPS library.&lt;br /&gt;
&lt;br /&gt;
2. Add support for Maxwell-criterion to enable calculations at saturation curve &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Detailed Plan==&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=FPROPS&amp;diff=634</id>
		<title>FPROPS</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=FPROPS&amp;diff=634"/>
		<updated>2010-05-21T16:20:13Z</updated>

		<summary type="html">&lt;p&gt;Ankitml: &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;
* {{src|models/johnpye/fprops/ammonia.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/hydrogen.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/nitrogen.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/water.c}}&lt;br /&gt;
* {{src|models/johnpye/fprops/carbondioxide.c}}&lt;br /&gt;
&lt;br /&gt;
* Some more, yet to be merged: [http://ascendcode.cheme.cmu.edu/viewvc.cgi/code/branches/hongke/models/johnpye/fprops/ &amp;lt;font color=&amp;quot;orange&amp;quot;&amp;gt;hongke&amp;lt;/font&amp;gt;:models/johnpye/fprops/]&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 evaluating thermodynamic properties of a number of pure substances via published data for the Helmholtz fundamental equation for those substances. It has been developed by [[User:Jpye|John Pye]] 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 at right. The properties that can be calculated are internal energy, entropy, pressure, enthalpy and Helmholtz energy, 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], EES, FLUIDCAL, [[freesteam]], SteamTab, and others, but is open source software and licensed under the [http://www.gnu.org/licenses/gpl.html GPL]. Contributions are most welcome!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT NOTE:&#039;&#039;&#039; FPROPS does not yet implement calculation of the saturation curve, so it gives incorrect property evaluations anywhere within the saturation region. This is because the code for evaluating the &#039;Maxwell criterion&#039; is not yet completely implemented.&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]] (there have been changes since the 0.9.5.116 release).&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
The calculation routines implement calculation of reduced Helmholtz energy &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&amp;amp;phi;&amp;lt;/span&amp;gt; by dividing it into ideal (&amp;lt;math&amp;gt;\phi^0&amp;lt;/math&amp;gt;) and residual (&amp;lt;math&amp;gt;\phi^r&amp;lt;/math&amp;gt;) parts, as described in IAPWS-95&amp;lt;sup id=&amp;quot;_ref-iapws95_0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-iapws95&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&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;
* power terms, &amp;lt;math&amp;gt;c_i T^{t_i}&amp;lt;/math&amp;gt;&lt;br /&gt;
* exponential terms, &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;&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;sup id=&amp;quot;_ref-0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-0&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&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 would in that case be determined using specified values of enthalpy &amp;lt;math&amp;gt;h_ref&amp;lt;/math&amp;gt; and entropy &amp;lt;math&amp;gt;s_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;
* power terms, &amp;lt;math&amp;gt;a_i \tau^{t_i}\delta^{d_i}&amp;lt;/math&amp;gt; (these are HelmoltzPowTerm with &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&#039;&#039;l&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt; = 0&amp;lt;/span&amp;gt;)&lt;br /&gt;
* exponential terms, &amp;lt;math&amp;gt;a_i \tau^{t_i} \delta^{d_i} exp(-\delta^{l_i})&amp;lt;/math&amp;gt; (these are HelmholtzPowTerm with &amp;lt;math&amp;gt;l_i \ne 0&amp;lt;/math&amp;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;&lt;br /&gt;
* critical terms, &amp;lt;math&amp;gt;n_i \Delta^{b_i} \delta \psi&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;\Delta = \theta^2 + B_i \left[ \left( \delta - 1 \right)^2 \right]^{a_i}&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;\theta = \left( 1- \tau \right) + A_i \left[ \left( \delta - 1 \right)^2 \right]^{\frac{1}{2 \beta_i}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\psi = exp \left[-C_i \left(\delta-1 \right)^2 - D_i \left( \tau - 1 \right)^2 \right]&amp;lt;/math&amp;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;.&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 as well as by Tillner Roth et al&amp;lt;sup id=&amp;quot;_ref-0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-0&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The source code for FPROPS is available via the ASCEND [[VersionManagement|subversion repository]], in the {{srcdir|models/johnpye/fprops}} directory. There is some further information on the implementation on the page about [[writing ASCEND external relations in C]].&lt;br /&gt;
&lt;br /&gt;
=== Maxwell criterion ===&lt;br /&gt;
&lt;br /&gt;
The Helmholtz function above applies for all regions outside the saturation region. The saturation region is determined by a set of equations call the Maxwell phase equilibrium criteria or Maxwell equal-area rule &amp;lt;sup id=&amp;quot;_ref-iapws95_0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-iapws95&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&amp;gt;&amp;lt;sup id=&amp;quot;_ref-0&amp;quot; class=&amp;quot;reference&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#_note-0&amp;quot; title=&amp;quot;&amp;quot;&amp;gt;[1]&amp;lt;/a&amp;gt;&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calculation of the phase equilibrium conditions requires iterative solution of three equations; a suitable algorithm for efficiently performing this has not yet been incorporated into FPROPS; contributions are welcome.&lt;br /&gt;
&lt;br /&gt;
The Maxwell criterion is stated in IAPWS-95 as being the preferred approach for determining the location of the saturation line, but it could be possible that we can use equality of Gibbs Free Energy to work this out. Need to investigate this and work out a suitable approach.&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;
&lt;br /&gt;
Test code for each fluid is embedded at the end of the corresponding fluid file, for example {{src|models/johnpye/fprops/hydrogen.c}}.&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/hydrogen.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 &amp;lt;tt&amp;gt;helmholtz_p&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_u&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_h&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_p&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_s&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;helmholtz_a&amp;lt;/tt&amp;gt; to calculate the property you need.&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.&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;
== 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;font color=green&amp;gt;add support for &#039;&#039;&#039;calculation of the saturation curve&#039;&#039;&#039; using Maxwell phase-equilibrium condition&amp;lt;/font&amp;gt; (Assign to Ankit)&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.&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;
&lt;br /&gt;
Further down the track we would like to support:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;font color=green&amp;gt;reading property correlations from a &#039;&#039;&#039;database&#039;&#039;&#039; (SQLite?) or text file.&amp;lt;/font&amp;gt; (Assigned to Shrikanth)&lt;br /&gt;
* some simpler equations of state such as MBWR or Peng-Robinson.&lt;br /&gt;
* more fluids of general interest.&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;
&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.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[Thermodynamics with ASCEND]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Proposed]]&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>Ankitml</name></author>
	</entry>
</feed>