Re: [dwsim-users] DTL entropy is always 0
Simulate chemical processes using advanced thermodynamic models
Brought to you by:
danwbr
|
From: Daniel W. <dan...@gm...> - 2019-11-11 13:33:34
|
Hi Urs, Check your P and T units, they should be in Pa and K. LKP is slow indeed, the fastest rigorous model is Peng-Robinson. Regards Daniel Em seg., 11 de nov. de 2019 às 09:10, Urs Wagner <or...@gm...> escreveu: > > Hello > > In my code the entropy is always 0. > And it is very slow over one minute. Is there a faster variant? > > My Source > > using DTL.Thermodynamics; > using System; > using System.Diagnostics; > using System.IO; > using System.Text; > namespace DTLTest4 > { > class Program > { > static void Main(string[] args) > { > new Program().Test(); > } > private string FormatDouble(double value) > { > if (value < 0.0) > return value.ToString("0.0000000E+00"); > return value.ToString("0.00000000E+00"); > } > public void Test() > { > var dtlc = new Calculator(); > dtlc.Initialize(); > var prpp = dtlc.GetPropPackInstance("Lee-Kesler-Plöcker"); > var pFrom = 1.0; > var pTo = 100.0; > var pIteration = 20; > var tFrom = 270.0; > var tTo = 450.0; > var tIteration = 20; > var comps = new string[] { "Oxygen", "Nitrogen", "Water" }; > var fracs = new double[] { 0.065421, 0.747663, 0.186916 }; > // flash algorithm type > // 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 > int flashalg = 0; > Stopwatch sw = new Stopwatch(); > sw.Start(); > var dp = Math.Pow(pTo / pFrom, 1.0 / (pIteration - 1)); > var dt = (tTo - tFrom) / (tIteration - 1); > var lines = new StringBuilder(); > lines.Append("** DTL Thermodynamics Library LKP **" + > Environment.NewLine); > lines.Append(" mol weight" + Environment.NewLine); > for (int i = 0; i < pIteration; i++) > { > var p = pFrom * Math.Pow(dp, i); > for (var j = 0; j < tIteration; j++) > { > var t = tFrom + j * dt; > var result = dtlc.PTFlash(prpp, flashalg, p, t, comps, > fracs); > var molFraction1 = double.Parse(result[2, > 0].ToString()); > var molFraction2 = double.Parse(result[3, > 0].ToString()); > var molFraction3 = double.Parse(result[4, > 0].ToString()); > var moleFractions = new[] { molFraction1, > molFraction2, molFraction3 }; > var values = dtlc.CalcProp(prpp, "volume", "Mole", > "Vapor", comps, t, p, moleFractions); > var specificVolume = > double.Parse(values[0].ToString()); > values = dtlc.CalcProp(prpp, "enthalpy", "Mole", > "Vapor", comps, t, p, moleFractions); > var enthalpy = double.Parse(values[0].ToString()) / > 1000.0; > values = dtlc.CalcProp(prpp, "entropy", "Mole", > "Vapor", comps, t, p, moleFractions); > var entropy = double.Parse(values[0].ToString()); > values = dtlc.CalcProp(prpp, "viscosity", "Mole", > "Vapor", comps, t, p, moleFractions); > var dynamicViscosity = > double.Parse(values[0].ToString()); > lines.Append(" " + FormatDouble(p) + " " + > FormatDouble(t) + " " + > FormatDouble(specificVolume) + > " " + > FormatDouble(enthalpy) + " " > + FormatDouble(entropy) + " " + > > FormatDouble(dynamicViscosity)); > if (i == pIteration - 1 && j == tIteration - 1) > lines.Append(" END"); > else > lines.Append(Environment.NewLine); > } > } > File.WriteAllText("gasmatrice", lines.ToString()); > sw.Stop(); > Console.WriteLine(sw.ElapsedMilliseconds.ToString()); > Console.ReadKey(); > } > } > } > > _______________________________________________ > Dwsim-users mailing list > Dws...@li... > https://lists.sourceforge.net/lists/listinfo/dwsim-users > |