[dwsim-users] DTL entropy is always 0
Simulate chemical processes using advanced thermodynamic models
Brought to you by:
danwbr
|
From: Urs W. <or...@gm...> - 2019-11-11 13:09:53
|
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div> </div> <div>Hello</div> <div> </div> <div>In my code the entropy is always 0.</div> <div>And it is very slow over one minute. Is there a faster variant?</div> <div> </div> <div>My Source</div> <div> </div> <div> <div> <div>using DTL.Thermodynamics;<br/> using System;<br/> using System.Diagnostics;<br/> using System.IO;<br/> using System.Text;</div> <div>namespace DTLTest4<br/> {<br/> class Program<br/> {<br/> static void Main(string[] args)<br/> {<br/> new Program().Test();<br/> }</div> <div> private string FormatDouble(double value)<br/> {<br/> if (value < 0.0)<br/> return value.ToString("0.0000000E+00");</div> <div> return value.ToString("0.00000000E+00");<br/> }</div> <div> public void Test()<br/> {</div> <div> var dtlc = new Calculator();<br/> dtlc.Initialize();</div> <div> var prpp = dtlc.GetPropPackInstance("Lee-Kesler-Plöcker");</div> <div> var pFrom = 1.0;<br/> var pTo = 100.0;<br/> var pIteration = 20;<br/> var tFrom = 270.0;<br/> var tTo = 450.0;<br/> var tIteration = 20;</div> <div> var comps = new string[] { "Oxygen", "Nitrogen", "Water" };<br/> var fracs = new double[] { 0.065421, 0.747663, 0.186916 };</div> <div> // flash algorithm type<br/> // 0 or 2 = NL VLE, 1 = IO VLE, 3 = IO VLLE, 4 = Gibbs VLE, 5 = Gibbs VLLE, 6 = NL VLLE, 7 = NL SLE, 8 = NL Immisc., 9 = Simple LLE </div> <div> int flashalg = 0;</div> <div> Stopwatch sw = new Stopwatch();</div> <div> sw.Start();</div> <div> var dp = Math.Pow(pTo / pFrom, 1.0 / (pIteration - 1));<br/> var dt = (tTo - tFrom) / (tIteration - 1);</div> <div> var lines = new StringBuilder();<br/> lines.Append("** DTL Thermodynamics Library LKP **" + Environment.NewLine);<br/> lines.Append(" mol weight" + Environment.NewLine);<br/> for (int i = 0; i < pIteration; i++)<br/> {<br/> var p = pFrom * Math.Pow(dp, i);</div> <div> for (var j = 0; j < tIteration; j++)<br/> {<br/> var t = tFrom + j * dt;<br/> var result = dtlc.PTFlash(prpp, flashalg, p, t, comps, fracs);</div> <div> var molFraction1 = double.Parse(result[2, 0].ToString());<br/> var molFraction2 = double.Parse(result[3, 0].ToString());<br/> var molFraction3 = double.Parse(result[4, 0].ToString());<br/> var moleFractions = new[] { molFraction1, molFraction2, molFraction3 };</div> <div> var values = dtlc.CalcProp(prpp, "volume", "Mole", "Vapor", comps, t, p, moleFractions);<br/> var specificVolume = double.Parse(values[0].ToString());<br/> values = dtlc.CalcProp(prpp, "enthalpy", "Mole", "Vapor", comps, t, p, moleFractions);<br/> var enthalpy = double.Parse(values[0].ToString()) / 1000.0;<br/> values = dtlc.CalcProp(prpp, "entropy", "Mole", "Vapor", comps, t, p, moleFractions);<br/> var entropy = double.Parse(values[0].ToString());<br/> values = dtlc.CalcProp(prpp, "viscosity", "Mole", "Vapor", comps, t, p, moleFractions);<br/> var dynamicViscosity = double.Parse(values[0].ToString());</div> <div> lines.Append(" " + FormatDouble(p) + " " + FormatDouble(t) + " " +<br/> FormatDouble(specificVolume) + " " +<br/> FormatDouble(enthalpy) + " " + FormatDouble(entropy) + " " +<br/> FormatDouble(dynamicViscosity));</div> <div> if (i == pIteration - 1 && j == tIteration - 1)<br/> lines.Append(" END");<br/> else<br/> lines.Append(Environment.NewLine);<br/> }<br/> }</div> <div> File.WriteAllText("gasmatrice", lines.ToString());</div> <div> sw.Stop();</div> <div> Console.WriteLine(sw.ElapsedMilliseconds.ToString());<br/> Console.ReadKey();<br/> }</div> <div> }<br/> }</div> <div> </div> </div> </div></div></body></html> |