From ec7f779434d705ea5097abdc88a723e1dd4c96e8 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 4 Mar 2019 20:29:42 -0500 Subject: [PATCH] [Input] Include more significant digits for Redlich-Kwong coefficients ctml_writer was severely truncating Redlich-Kwong coefficients when converting from CTI to XML formats, keeping only 5 significant digints in the "a" coefficients and two decimal digits in the "b" coefficients, which is less than what is used even in the example CTI files. The use of the "%f" format also meant that the precision depended on input units. --- interfaces/cython/cantera/ctml_writer.py | 8 ++-- test/thermo/RedlichKwongMFTP_Test.cpp | 54 ++++++++++++------------ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/interfaces/cython/cantera/ctml_writer.py b/interfaces/cython/cantera/ctml_writer.py index de1809607..da546e9f2 100644 --- a/interfaces/cython/cantera/ctml_writer.py +++ b/interfaces/cython/cantera/ctml_writer.py @@ -845,11 +845,11 @@ class pureFluidParameters(activityCoefficients): def build(self,a): f= a.addChild("pureFluidParameters") f['species'] = self._species - s = '%10.4E, %10.4E \n' % (self._acoeff[0], self._acoeff[1]) + s = '%.10g, %.10g\n' % (self._acoeff[0], self._acoeff[1]) ac = f.addChild("a_coeff",s) ac["units"] = _upres+'-'+_ulen+'6/'+_umol+'2' ac["model"] = "linear_a" - s = '%0.2f \n' % self._bcoeff + s = '%.10g\n' % self._bcoeff bc = f.addChild("b_coeff",s) bc["units"] = _ulen+'3/'+_umol @@ -864,12 +864,12 @@ class crossFluidParameters(activityCoefficients): f= a.addChild("crossFluidParameters") f["species2"] = self._species2 f["species1"] = self._species1 - s = '%10.4E, %10.4E \n' % (self._acoeff[0], self._acoeff[1]) + s = '%.10g, %.10g\n' % (self._acoeff[0], self._acoeff[1]) ac = f.addChild("a_coeff",s) ac["units"] = _upres+'-'+_ulen+'6/'+_umol+'2' ac["model"] = "linear_a" if self._bcoeff: - s = '%0.2f \n' % self._bcoeff + s = '%.10g\n' % self._bcoeff bc = f.addChild("b_coeff",s) bc["units"] = _ulen+'3/'+_umol diff --git a/test/thermo/RedlichKwongMFTP_Test.cpp b/test/thermo/RedlichKwongMFTP_Test.cpp index 3b26c62bf..75c88c41b 100644 --- a/test/thermo/RedlichKwongMFTP_Test.cpp +++ b/test/thermo/RedlichKwongMFTP_Test.cpp @@ -38,15 +38,15 @@ TEST_F(RedlichKwongMFTP_Test, chem_potentials) // where gamma_k is the activity coefficient. Run regression test against values calculated using // the model. const double expected_result[9] = { - -4.573578067074649e+008, - -4.573471163377696e+008, - -4.573375748803425e+008, - -4.573290065058332e+008, - -4.573212695326964e+008, - -4.573142485189869e+008, - -4.573078484551440e+008, - -4.573019904340246e+008, - -4.572966083775078e+008 + -4.573578072583122e+008, + -4.573471168532005e+008, + -4.573375753640399e+008, + -4.573290069609340e+008, + -4.573212699618942e+008, + -4.573142489246118e+008, + -4.573078488392255e+008, + -4.573019907983406e+008, + -4.572966087236250e+008 }; double xmin = 0.6; @@ -125,30 +125,30 @@ TEST_F(RedlichKwongMFTP_Test, setTP) // All sub-cooled liquid: const double p1[6] = { - 1.587029921158317e+002, - 1.541895558698696e+002, - 1.501572815648243e+002, - 1.465106359800041e+002, - 1.431807662747959e+002, - 1.401162435728261e+002 + 1.587112190732014e+002, + 1.541966713372675e+002, + 1.501635359781652e+002, + 1.465162036435630e+002, + 1.431857735462774e+002, + 1.401207850479111e+002 }; // Phase change between temperatures 4 & 5: const double p2[6] = { - 6.265136821574670e+002, - 5.991027079853330e+002, - 5.656903533839055e+002, - 5.196021189855490e+002, - 3.384435863009947e+002, - 2.755331531855265e+002 + 6.267097216456422e+002, + 5.993217207540168e+002, + 5.659501111117172e+002, + 5.199644273242080e+002, + 3.393007538579040e+002, + 2.756259035569044e+002 }; // Supercritical; no discontinuity in rho values: const double p3[6] = { - 6.839819449357851e+002, - 6.667277456641792e+002, - 6.483568057147166e+002, - 6.286479753170340e+002, - 6.073051275696215e+002, - 5.839223896051005e+002 + 6.841288400828764e+002, + 6.668789423328959e+002, + 6.485130892980700e+002, + 6.288103574172300e+002, + 6.074749284756613e+002, + 5.841013398471708e+002 }; for(int i=0; i<6; ++i)