11 #include "cantera/tpx/Sub.h"
12 #include "cantera/tpx/utils.h"
96 "could not create new substance object.");
102 double cp0_R, h0_RT, s0_R, T0, p;
104 if (T0 < m_sub->Tcrit()) {
105 m_sub->Set(tpx::TX, T0, 1.0);
108 p = 0.001*
m_sub->Pcrit();
111 m_sub->Set(tpx::TP, T0, p);
118 writelog(
"PureFluidPhase::initThermo: initialized phase "
126 eosdata.
_require(
"model",
"PureFluid");
127 m_subflag = atoi(eosdata[
"fluid_type"].c_str());
129 throw CanteraError(
"PureFluidPhase::setParametersFromXML",
130 "missing or negative substance flag");
191 doublereal p =
m_sub->P();
208 }
catch (tpx::TPX_Error) {
221 throw CanteraError(
"PureFluidPhase",
string(tpx::errorMsg(
228 string msg = tpx::TPX_Error::ErrorMessage;
229 string proc =
"tpx::"+tpx::TPX_Error::ErrorProcedure;
236 return m_sub->isothermalCompressibility();
241 return m_sub->thermalExpansionCoeff();
348 doublereal rt =
_RT();
373 doublereal rt =
_RT();
392 double plow = 1.0E-8;
393 Set(tpx::TP, t, plow);
395 Set(tpx::TP, t, psave);
410 double plow = 1.0E-8;
411 Set(tpx::TP, t, plow);
413 grt[0] += log(pref/plow);
414 Set(tpx::TP, t, psave);
442 double plow = 1.0E-8;
443 Set(tpx::TP, t, plow);
445 er[0] -= log(pref/plow);
446 Set(tpx::TP, t, psave);
452 return m_sub->Tcrit();
458 return m_sub->Pcrit();
464 return 1.0/
m_sub->Vcrit();
472 doublereal ts =
m_sub->Tsat(p);
474 }
catch (tpx::TPX_Error) {
515 doublereal vsv =
m_sub->v();
518 doublereal ps =
m_sub->Ps();
520 }
catch (tpx::TPX_Error) {
529 doublereal x =
m_sub->x();
564 sprintf(p,
" \n %s:\n",
name().c_str());
567 sprintf(p,
" \n temperature %12.6g K\n",
temperature());
569 sprintf(p,
" pressure %12.6g Pa\n",
pressure());
571 sprintf(p,
" density %12.6g kg/m^3\n",
density());
578 sprintf(p,
" vapor fraction %12.6g \n",
585 sprintf(p,
" potential %12.6g V\n", phi);
591 sprintf(p,
" 1 kg 1 kmol\n");
593 sprintf(p,
" ----------- ------------\n");
595 sprintf(p,
" enthalpy %12.6g %12.4g J\n",
598 sprintf(p,
" internal energy %12.6g %12.4g J\n",
601 sprintf(p,
" entropy %12.6g %12.4g J/K\n",
604 sprintf(p,
" Gibbs function %12.6g %12.4g J\n",
607 sprintf(p,
" heat capacity c_p %12.6g %12.4g J/K\n",
611 sprintf(p,
" heat capacity c_v %12.6g %12.4g J/K\n",
616 sprintf(p,
" heat capacity c_v <not implemented> \n");
633 " Y Chem. Pot. / RT \n");
635 sprintf(p,
" ------------- "
636 "------------ ------------\n");
638 for (
size_t k = 0; k < kk; k++) {
640 sprintf(p,
"%18s %12.6g %12.6g %12.6g\n",
643 sprintf(p,
"%18s %12.6g %12.6g \n",
652 sprintf(p,
" -------------"
655 for (
size_t k = 0; k < kk; k++) {
656 sprintf(p,
"%18s %12.6g %12.6g\n",
676 csvFile.precision(3);
682 csvFile <<
"\n"+
name()+
"\n\n";
684 csvFile << setw(tabL) <<
"temperature (K) =" << setw(tabS) <<
temperature() << endl;
685 csvFile << setw(tabL) <<
"pressure (Pa) =" << setw(tabS) <<
pressure() << endl;
686 csvFile << setw(tabL) <<
"density (kg/m^3) =" << setw(tabS) <<
density() << endl;
687 csvFile << setw(tabL) <<
"mean mol. weight (amu) =" << setw(tabS) <<
meanMolecularWeight() << endl;
688 csvFile << setw(tabL) <<
"potential (V) =" << setw(tabS) <<
electricPotential() << endl;
691 csvFile << setw(tabL) <<
"vapor fraction = " << setw(tabS) << xx << endl;
695 csvFile << setw(tabL) <<
"enthalpy (J/kg) = " << setw(tabS) <<
enthalpy_mass() << setw(tabL) <<
"enthalpy (J/kmol) = " << setw(tabS) <<
enthalpy_mole() << endl;
696 csvFile << setw(tabL) <<
"internal E (J/kg) = " << setw(tabS) <<
intEnergy_mass() << setw(tabL) <<
"internal E (J/kmol) = " << setw(tabS) <<
intEnergy_mole() << endl;
697 csvFile << setw(tabL) <<
"entropy (J/kg) = " << setw(tabS) <<
entropy_mass() << setw(tabL) <<
"entropy (J/kmol) = " << setw(tabS) <<
entropy_mole() << endl;
698 csvFile << setw(tabL) <<
"Gibbs (J/kg) = " << setw(tabS) <<
gibbs_mass() << setw(tabL) <<
"Gibbs (J/kmol) = " << setw(tabS) <<
gibbs_mole() << endl;
699 csvFile << setw(tabL) <<
"heat capacity c_p (J/K/kg) = " << setw(tabS) <<
cp_mass() << setw(tabL) <<
"heat capacity c_p (J/K/kmol) = " << setw(tabS) <<
cp_mole() << endl;
700 csvFile << setw(tabL) <<
"heat capacity c_v (J/K/kg) = " << setw(tabS) <<
cv_mass() << setw(tabL) <<
"heat capacity c_v (J/K/kmol) = " << setw(tabS) <<
cv_mole() << endl;
702 csvFile.precision(8);
705 std::vector<double> x(kk, 0.0);
706 std::vector<double> y(kk, 0.0);
707 std::vector<double> mu(kk, 0.0);
708 std::vector<double> a(kk, 0.0);
709 std::vector<double> ac(kk, 0.0);
710 std::vector<double> hbar(kk, 0.0);
711 std::vector<double> sbar(kk, 0.0);
712 std::vector<double> ubar(kk, 0.0);
713 std::vector<double> cpbar(kk, 0.0);
714 std::vector<double> vbar(kk, 0.0);
715 std::vector<std::string> pNames;
716 std::vector<std::vector<double> > data;
719 pNames.push_back(
"X");
723 pNames.push_back(
"Y");
730 pNames.push_back(
"Chem. Pot (J/kmol)");
737 pNames.push_back(
"Activity");
744 pNames.push_back(
"Act. Coeff.");
751 pNames.push_back(
"Part. Mol Enthalpy (J/kmol)");
752 data.push_back(hbar);
758 pNames.push_back(
"Part. Mol. Entropy (J/K/kmol)");
759 data.push_back(sbar);
765 pNames.push_back(
"Part. Mol. Energy (J/kmol)");
766 data.push_back(ubar);
772 pNames.push_back(
"Part. Mol. Cp (J/K/kmol");
773 data.push_back(cpbar);
779 pNames.push_back(
"Part. Mol. Cv (J/K/kmol)");
780 data.push_back(vbar);
785 csvFile << endl << setw(tabS) <<
"Species,";
786 for (
int i = 0; i < (int)pNames.size(); i++) {
787 csvFile << setw(tabM) << pNames[i] <<
",";
795 for (
size_t k = 0; k < kk; k++) {
798 for (
int i = 0; i < (int)pNames.size(); i++) {
799 csvFile << setw(tabM) << data[i][k] <<
",";
803 for (
int i = 0; i < (int)pNames.size(); i++) {
804 csvFile << setw(tabM) << 0 <<
",";