Calculate enthalpy and entropy as part of phase envelope

Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
Ian Bell
2014-09-06 19:56:54 +02:00
parent 46135f69b6
commit e9297e8dc5
4 changed files with 38 additions and 23 deletions

View File

@@ -7,7 +7,7 @@ class PhaseEnvelopeData
{
public:
std::vector< std::vector<long double> > K, lnK, x, y;
std::vector<long double> T, p, lnT, lnp, rhomolar_liq, rhomolar_vap, lnrhomolar_liq, lnrhomolar_vap;
std::vector<long double> T, p, lnT, lnp, rhomolar_liq, rhomolar_vap, lnrhomolar_liq, lnrhomolar_vap, hmolar_liq, hmolar_vap, smolar_liq, smolar_vap;
void resize(std::size_t N)
{
K.resize(N);
@@ -19,6 +19,10 @@ public:
const long double p,
const long double rhomolar_liq,
const long double rhomolar_vap,
const long double hmolar_liq,
const long double hmolar_vap,
const long double smolar_liq,
const long double smolar_vap,
const std::vector<long double> & x,
const std::vector<long double> & y)
{
@@ -30,6 +34,10 @@ public:
this->lnp.push_back(log(p));
this->rhomolar_liq.push_back(rhomolar_liq);
this->rhomolar_vap.push_back(rhomolar_vap);
this->hmolar_liq.push_back(hmolar_liq);
this->hmolar_vap.push_back(hmolar_vap);
this->smolar_liq.push_back(smolar_liq);
this->smolar_vap.push_back(smolar_vap);
this->lnrhomolar_liq.push_back(log(rhomolar_liq));
this->lnrhomolar_vap.push_back(log(rhomolar_vap));
for (unsigned int i = 0; i < N; i++)

View File

@@ -92,8 +92,8 @@ void PhaseEnvelopeRoutines::build(HelmholtzEOSMixtureBackend &HEOS)
// Dewpoint calculation, liquid (x) is incipient phase
NR.call(HEOS, IO.y, IO.x, IO);
std::cout << "dv " << IO.rhomolar_vap << " dl " << IO.rhomolar_liq << " T " << IO.T << " p " << IO.p << " x " << vec_to_string(IO.x, "%0.10Lg") << " y " << vec_to_string(IO.y, "%0.10Lg") << " Ns " << IO.Nsteps << std::endl;
env.store_variables(IO.T, IO.p, IO.rhomolar_liq, IO.rhomolar_vap, IO.x, IO.y);
std::cout << "dv " << IO.rhomolar_vap << " dl " << IO.rhomolar_liq << " T " << IO.T << " p " << IO.p << " hl " << IO.hmolar_liq << " hv " << IO.hmolar_vap << " sl " << IO.smolar_liq << " sv " << IO.smolar_vap << " x " << vec_to_string(IO.x, "%0.10Lg") << " Ns " << IO.Nsteps << std::endl;
env.store_variables(IO.T, IO.p, IO.rhomolar_liq, IO.rhomolar_vap, IO.hmolar_liq, IO.hmolar_vap, IO.smolar_liq, IO.smolar_vap, IO.x, IO.y);
iter ++;

View File

@@ -857,28 +857,31 @@ void SaturationSolvers::newton_raphson_saturation::check_Jacobian()
std::cout << "numerical: " << vec_to_string(difffn, "%0.11Lg") << std::endl;
std::cout << "analytic: " << vec_to_string(get_col(J0, N), "%0.11Lg") << std::endl;
// Derivatives with respect to x0
double dx = 1e-5;
x = x0; x[0] += dx; x[1] -= dx;
this->T = T0;
this->rhomolar_liq = rhomolar_liq;
this->rhomolar_vap = rhomolar_vap;
rSatL.set_mole_fractions(x);
build_arrays(); r1 = r;
for (std::size_t i = 0; i < x.size()-1; ++i)
{
// Derivatives with respect to x0
double dx = 1e-5;
x = x0; x[i] += dx; x[x.size()-1] -= dx;
this->T = T0;
this->rhomolar_liq = rhomolar_liq;
this->rhomolar_vap = rhomolar_vap;
rSatL.set_mole_fractions(x);
build_arrays(); r1 = r;
x = x0; x[0] -= dx; x[1] += dx;
rSatL.set_mole_fractions(x);
this->T = T0;
this->rhomolar_liq = rhomolar_liq;
this->rhomolar_vap = rhomolar_vap;
build_arrays(); r2 = r;
x = x0; x[i] -= dx; x[x.size()-1] += dx;
rSatL.set_mole_fractions(x);
this->T = T0;
this->rhomolar_liq = rhomolar_liq;
this->rhomolar_vap = rhomolar_vap;
build_arrays(); r2 = r;
for (std::size_t i = 0; i < N+1; ++i){
diffn[i] = (r1[i]-r2[i])/(2*dx);
for (std::size_t j = 0; j < N+1; ++j){
diffn[i] = (r1[j]-r2[j])/(2*dx);
}
std::cout << format("For x%d\n", i);
std::cout << "numerical: " << vec_to_string(diffn, "%0.11Lg") << std::endl;
std::cout << "analytic: " << vec_to_string(get_col(J0, i), "%0.11Lg") << std::endl;
}
std::cout << format("For x0\n");
std::cout << "numerical: " << vec_to_string(diffn, "%0.11Lg") << std::endl;
std::cout << "analytic: " << vec_to_string(get_col(J0, 0), "%0.11Lg") << std::endl;
}
void SaturationSolvers::newton_raphson_saturation::call(HelmholtzEOSMixtureBackend &HEOS, const std::vector<long double> &z, std::vector<long double> &z_incipient, newton_raphson_saturation_options &IO)
{
@@ -950,6 +953,10 @@ void SaturationSolvers::newton_raphson_saturation::call(HelmholtzEOSMixtureBacke
IO.T = T;
IO.rhomolar_liq = rhomolar_liq;
IO.rhomolar_vap = rhomolar_vap;
IO.hmolar_liq = HEOS.SatL.get()->hmolar();
IO.hmolar_vap = HEOS.SatV.get()->hmolar();
IO.smolar_liq = HEOS.SatL.get()->smolar();
IO.smolar_vap = HEOS.SatV.get()->smolar();
}
void SaturationSolvers::newton_raphson_saturation::build_arrays()

View File

@@ -198,7 +198,7 @@ namespace SaturationSolvers
int Nstep_max;
bool bubble_point;
std::size_t Nsteps;
long double omega, rhomolar_liq, rhomolar_vap, pL, pV, p, T;
long double omega, rhomolar_liq, rhomolar_vap, pL, pV, p, T, hmolar_liq, hmolar_vap, smolar_liq, smolar_vap;
imposed_variable_options imposed_variable;
std::vector<long double> x, y;
newton_raphson_saturation_options(){ Nsteps = 0;} // Defaults