From 46135f69b69d1367bf0398dfdd8d809593105fc4 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Sat, 6 Sep 2014 19:03:02 +0200 Subject: [PATCH] Broke up the critical determination term for easier debugging Signed-off-by: Ian Bell --- src/Backends/Helmholtz/PhaseEnvelopeRoutines.cpp | 8 +++++--- src/main.cxx | 14 ++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Backends/Helmholtz/PhaseEnvelopeRoutines.cpp b/src/Backends/Helmholtz/PhaseEnvelopeRoutines.cpp index 6b0dde17..6d114ed8 100644 --- a/src/Backends/Helmholtz/PhaseEnvelopeRoutines.cpp +++ b/src/Backends/Helmholtz/PhaseEnvelopeRoutines.cpp @@ -61,8 +61,8 @@ void PhaseEnvelopeRoutines::build(HelmholtzEOSMixtureBackend &HEOS) } else if (iter - iter0 == 2) { - IO.T = LinearInterp(env.rhomolar_vap,env.T,iter-2,iter-1,x); - IO.rhomolar_liq = LinearInterp(env.rhomolar_vap,env.rhomolar_liq,iter-2,iter-1,x); + IO.T = LinearInterp(env.rhomolar_vap, env.T, iter-2, iter-1, x); + IO.rhomolar_liq = LinearInterp(env.rhomolar_vap, env.rhomolar_liq, iter-2, iter-1, x); for (std::size_t i = 0; i < IO.x.size()-1; ++i) // First N-1 elements { IO.x[i] = LinearInterp(env.rhomolar_vap, env.x[i], iter-2, iter-1, x); @@ -96,9 +96,11 @@ void PhaseEnvelopeRoutines::build(HelmholtzEOSMixtureBackend &HEOS) env.store_variables(IO.T, IO.p, IO.rhomolar_liq, IO.rhomolar_vap, IO.x, IO.y); iter ++; + + long double abs_rho_difference = std::abs((IO.rhomolar_liq - IO.rhomolar_vap)/IO.rhomolar_liq); // Critical point jump - if (std::abs((IO.rhomolar_liq - IO.rhomolar_vap)/IO.rhomolar_liq) < 0.05 && IO.rhomolar_liq > IO.rhomolar_vap){ + if (abs_rho_difference < 0.01 && IO.rhomolar_liq > IO.rhomolar_vap){ //std::cout << "dv" << IO.rhomolar_vap << " dl " << IO.rhomolar_liq << " " << vec_to_string(IO.x, "%0.10Lg") << " " << vec_to_string(IO.y, "%0.10Lg") << std::endl; long double rhoc_approx = 0.5*IO.rhomolar_liq + 0.5*IO.rhomolar_vap; long double rho_vap_new = 2*rhoc_approx - IO.rhomolar_vap; diff --git a/src/main.cxx b/src/main.cxx index 909c1a66..8f73f9a5 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -429,14 +429,14 @@ int main() std::cin >> c; } #endif - #if 1 + #if 0 { double TTT0 = PropsSI("T","P",1e6,"Q",1,"REFPROP::Ethane[0.5]&Propane[0.5]"); double TTT1 = PropsSI("T","P",1e6,"Q",1,"HEOS::Ethane[0.5]&Propane[0.5]"); int rr =0; } #endif - #if 0 + #if 1 { // std::vector names(1, "n-Propane"); // shared_ptr HEOS(new HelmholtzEOSMixtureBackend(names)); @@ -456,20 +456,22 @@ int main() ::set_debug_level(0); - shared_ptr HEOS(AbstractState::factory("HEOS","Ethane&Nitrogen")); - std::vector z(2,0.2); z[1] = 1-z[0]; + shared_ptr HEOS(AbstractState::factory("HEOS","Ethanol&Water")); + std::vector z(2,0.25); z[1] = 1-z[0]; HEOS->set_mole_fractions(z); + std::cout << get_global_param_string("errstring") << std::endl; time_t t1, t2; t1 = clock(); try{ HEOS->build_phase_envelope("dummy"); } - catch(std::exception &e){} + catch(std::exception &e){ + std::cout << get_global_param_string("errstring") << std::endl; + } t2 = clock(); std::cout << format("value(all): %g s/call\n", ((double)(t2-t1))/CLOCKS_PER_SEC); exit(EXIT_SUCCESS); - std::cout << get_global_param_string("errstring") << std::endl; exit(EXIT_FAILURE); //double refretrte = PropsSI("P","Dmolar",107.9839357,"T",116.5360225,"Methane[0.5]&Propane[0.5]");