From 58719349cb7130dafc5ffdc32275f0ced7488bc7 Mon Sep 17 00:00:00 2001 From: Christopher Lueth Date: Thu, 1 Apr 2010 23:05:39 +0000 Subject: [PATCH] added reportCSV method to ThermoPhase class and all other derived classes that currently contain the report method. reportCSV will output phase data to a text file and a comma separated file that are passed in. --- Cantera/src/thermo/GibbsExcessVPSSTP.cpp | 96 +++++++++++++++++++ Cantera/src/thermo/GibbsExcessVPSSTP.h | 12 +++ Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp | 96 +++++++++++++++++++ Cantera/src/thermo/IonsFromNeutralVPSSTP.h | 11 +++ Cantera/src/thermo/MargulesVPSSTP.cpp | 97 +++++++++++++++++++- Cantera/src/thermo/MargulesVPSSTP.h | 11 +++ Cantera/src/thermo/MolalityVPSSTP.cpp | 94 +++++++++++++++++++ Cantera/src/thermo/MolalityVPSSTP.h | 12 +++ Cantera/src/thermo/PureFluidPhase.cpp | 92 ++++++++++++++++++- Cantera/src/thermo/PureFluidPhase.h | 12 +++ Cantera/src/thermo/ThermoPhase.cpp | 84 +++++++++++++++++ Cantera/src/thermo/ThermoPhase.h | 11 +++ 12 files changed, 626 insertions(+), 2 deletions(-) diff --git a/Cantera/src/thermo/GibbsExcessVPSSTP.cpp b/Cantera/src/thermo/GibbsExcessVPSSTP.cpp index 35bd66136..fe7a5549d 100644 --- a/Cantera/src/thermo/GibbsExcessVPSSTP.cpp +++ b/Cantera/src/thermo/GibbsExcessVPSSTP.cpp @@ -23,6 +23,7 @@ #include "GibbsExcessVPSSTP.h" +#include using namespace std; namespace Cantera { @@ -406,6 +407,101 @@ namespace Cantera { return s; } + /* + * Format a summary of the mixture state for output. + */ + void GibbsExcessVPSSTP::reportCSV(std::ofstream& textFile, std::ofstream& csvFile, bool show_thermo) const { + + csvFile.precision(6); + int tabS = 20; + int tabM = 30; + int tabL = 40; + try { + if (name() != "") { + textFile << "\n"+name()+"\n\n"; + csvFile << "\n\n\n"; + } + textFile << setw(tabM) << "temperature (K)\n"; + csvFile << setw(tabM) << temperature() << ",\n"; + textFile << setw(tabM) << "pressure (Pa)\n"; + csvFile << setw(tabM) << pressure() << ",\n"; + textFile << setw(tabM) << "density (kg/m^3)\n"; + csvFile << setw(tabM) << density() << ",\n"; + textFile << setw(tabM) << "mean mol. weight (amu)\n"; + csvFile << setw(tabM) << meanMolecularWeight() << ",\n"; + textFile << setw(tabM) << "potential (V)\n"; + csvFile << setw(tabM) << electricPotential() << ",\n"; + + if (show_thermo) { + textFile << endl; + csvFile << endl; + textFile << setw(tabM) << "enthalpy (J/kg)" << "," << setw(tabM) << "enthalpy (J/kmol)\n"; + csvFile << setw(tabM) << enthalpy_mass() << "," << setw(tabM) << enthalpy_mole() << ",\n"; + textFile << setw(tabM) << "internal E (J/kg)" << "," << setw(tabM) << "internal E (J/kmol)\n"; + csvFile << setw(tabM) << intEnergy_mass() << "," << setw(tabM) << intEnergy_mole() << ",\n"; + textFile << setw(tabM) << "entropy (J/kg)" << "," << setw(tabM) << "entropy (J/kmol)\n"; + csvFile << setw(tabM) << entropy_mass() << "," << setw(tabM) << entropy_mole() << ",\n"; + textFile << setw(tabM) << "Gibbs (J/kg)" << "," << setw(tabM) << "Gibbs (J/kmol)\n"; + csvFile << setw(tabM) << gibbs_mass() << "," << setw(tabM) << gibbs_mole() << ",\n"; + textFile << setw(tabL) << "heat capacity c_p (J/K/kg)" << "," << setw(tabL) << "heat capacity c_p (J/K/kmol)\n"; + csvFile << setw(tabL) << cp_mass() << "," << setw(tabL) << cp_mole() << ",\n"; + textFile << setw(tabL) << "heat capacity c_v (J/K/kg)" << "," << setw(tabL) << "heat capacity c_v (J/K/kmol)\n"; + csvFile << setw(tabL) << cv_mass() << "," << setw(tabL) << cv_mole() << ",\n"; + } + /* + // NOT USED!!!!! + int kk = nSpecies(); + array_fp x(kk); + array_fp y(kk); + array_fp mu(kk); + getMoleFractions(&x[0]); + getMassFractions(&y[0]); + getChemPotentials(&mu[0]); + doublereal rt = GasConstant * temperature(); + int k; + +// ThermoPhase original above...changed to below comments in GibbsExcessVPSSTP::report() +// int kk = nSpecies(); +// array_fp x(kk); +// array_fp molal(kk); +// array_fp mu(kk); +// array_fp muss(kk); +// array_fp acMolal(kk); +// array_fp actMolal(kk); +// getMoleFractions(&x[0]); +// +// getChemPotentials(&mu[0]); +// getStandardChemPotentials(&muss[0]); +// getActivities(&actMolal[0]); + + if (show_thermo) { + textFile << "\n" << setw(40) << "X" << "," << setw(tabS) << "Y" << "," << setw(tabS) << "Chem. Pot. / RT\n"; + csvFile << "\n\n"; + for (k = 0; k < kk; k++) { + if (x[k] > SmallNumber) { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(40) << x[k] << "," << setw(tabS) << y[k] << "," << setw(tabS) << mu[k]/rt << ",\n"; + } + else { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(40) << x[k] << "," << setw(tabS) << y[k] << ",\n"; + } + } + } + else { + textFile << "\n" << setw(40) << "X" << "," << setw(tabS) << "Y\n"; + csvFile << "\n\n"; + for (k = 0; k < kk; k++) { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(40) << x[k] << "," << setw(tabS) << y[k] << ",\n"; + } + } + */ + } + catch (CanteraError) { + ; + } + } } diff --git a/Cantera/src/thermo/GibbsExcessVPSSTP.h b/Cantera/src/thermo/GibbsExcessVPSSTP.h index 0a94de3cb..eb0c9b8d6 100644 --- a/Cantera/src/thermo/GibbsExcessVPSSTP.h +++ b/Cantera/src/thermo/GibbsExcessVPSSTP.h @@ -541,6 +541,18 @@ namespace Cantera { */ virtual std::string report(bool show_thermo = true) const; + //! returns a summary of the state of the phase to specified + //! comma separated files + /*! + * @param textFile ofstream file to print textual variable names that + * will correspod to data in comma separated file (csv). + * @param csvFile ofstream file to print comma separated data for + * the phase + * @param show_thermo If true, extra information is printed out + * about the thermodynamic state of the system. + */ + virtual void reportCSV(std::ofstream& textFile, std::ofstream& csvFile, bool show_thermo = true) const; + private: diff --git a/Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp b/Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp index 601a937e8..492c2a8f1 100644 --- a/Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp +++ b/Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp @@ -28,6 +28,7 @@ #include "mix_defs.h" #include +#include using namespace std; @@ -1765,6 +1766,101 @@ namespace Cantera { return s; } + /* + * Format a summary of the mixture state for output. + */ + void IonsFromNeutralVPSSTP::reportCSV(std::ofstream& textFile, std::ofstream& csvFile, bool show_thermo) const { + + csvFile.precision(6); + int tabS = 20; + int tabM = 30; + int tabL = 40; + try { + if (name() != "") { + textFile << "\n"+name()+"\n\n"; + csvFile << "\n\n\n"; + } + textFile << setw(tabM) << "temperature (K)\n"; + csvFile << setw(tabM) << temperature() << ",\n"; + textFile << setw(tabM) << "pressure (Pa)\n"; + csvFile << setw(tabM) << pressure() << ",\n"; + textFile << setw(tabM) << "density (kg/m^3)\n"; + csvFile << setw(tabM) << density() << ",\n"; + textFile << setw(tabM) << "mean mol. weight (amu)\n"; + csvFile << setw(tabM) << meanMolecularWeight() << ",\n"; + textFile << setw(tabM) << "potential (V)\n"; + csvFile << setw(tabM) << electricPotential() << ",\n"; + + if (show_thermo) { + textFile << endl; + csvFile << endl; + textFile << setw(tabM) << "enthalpy (J/kg)" << "," << setw(tabM) << "enthalpy (J/kmol)\n"; + csvFile << setw(tabM) << enthalpy_mass() << "," << setw(tabM) << enthalpy_mole() << ",\n"; + textFile << setw(tabM) << "internal E (J/kg)" << "," << setw(tabM) << "internal E (J/kmol)\n"; + csvFile << setw(tabM) << intEnergy_mass() << "," << setw(tabM) << intEnergy_mole() << ",\n"; + textFile << setw(tabM) << "entropy (J/kg)" << "," << setw(tabM) << "entropy (J/kmol)\n"; + csvFile << setw(tabM) << entropy_mass() << "," << setw(tabM) << entropy_mole() << ",\n"; + textFile << setw(tabM) << "Gibbs (J/kg)" << "," << setw(tabM) << "Gibbs (J/kmol)\n"; + csvFile << setw(tabM) << gibbs_mass() << "," << setw(tabM) << gibbs_mole() << ",\n"; + textFile << setw(tabL) << "heat capacity c_p (J/K/kg)" << "," << setw(tabL) << "heat capacity c_p (J/K/kmol)\n"; + csvFile << setw(tabL) << cp_mass() << "," << setw(tabL) << cp_mole() << ",\n"; + textFile << setw(tabL) << "heat capacity c_v (J/K/kg)" << "," << setw(tabL) << "heat capacity c_v (J/K/kmol)\n"; + csvFile << setw(tabL) << cv_mass() << "," << setw(tabL) << cv_mole() << ",\n"; + } + /* + // NOT USED!!!!! + int kk = nSpecies(); + array_fp x(kk); + array_fp y(kk); + array_fp mu(kk); + getMoleFractions(&x[0]); + getMassFractions(&y[0]); + getChemPotentials(&mu[0]); + doublereal rt = GasConstant * temperature(); + int k; + +// ThermoPhase original above...changed to below comments in GibbsExcessVPSSTP::report() +// int kk = nSpecies(); +// array_fp x(kk); +// array_fp molal(kk); +// array_fp mu(kk); +// array_fp muss(kk); +// array_fp acMolal(kk); +// array_fp actMolal(kk); +// getMoleFractions(&x[0]); +// +// getChemPotentials(&mu[0]); +// getStandardChemPotentials(&muss[0]); +// getActivities(&actMolal[0]); + + if (show_thermo) { + textFile << "\n" << setw(40) << "X" << "," << setw(tabS) << "Y" << "," << setw(tabS) << "Chem. Pot. / RT\n"; + csvFile << "\n\n"; + for (k = 0; k < kk; k++) { + if (x[k] > SmallNumber) { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(40) << x[k] << "," << setw(tabS) << y[k] << "," << setw(tabS) << mu[k]/rt << ",\n"; + } + else { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(40) << x[k] << "," << setw(tabS) << y[k] << ",\n"; + } + } + } + else { + textFile << "\n" << setw(40) << "X" << "," << setw(tabS) << "Y\n"; + csvFile << "\n\n"; + for (k = 0; k < kk; k++) { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(40) << x[k] << "," << setw(tabS) << y[k] << ",\n"; + } + } + */ + } + catch (CanteraError) { + ; + } + } } diff --git a/Cantera/src/thermo/IonsFromNeutralVPSSTP.h b/Cantera/src/thermo/IonsFromNeutralVPSSTP.h index ffaed580d..b0af99f10 100644 --- a/Cantera/src/thermo/IonsFromNeutralVPSSTP.h +++ b/Cantera/src/thermo/IonsFromNeutralVPSSTP.h @@ -720,6 +720,17 @@ namespace Cantera { */ virtual std::string report(bool show_thermo = true) const; + //! returns a summary of the state of the phase to specified + //! comma separated files + /*! + * @param textFile ofstream file to print textual variable names that + * will correspod to data in comma separated file (csv). + * @param csvFile ofstream file to print comma separated data for + * the phase + * @param show_thermo If true, extra information is printed out + * about the thermodynamic state of the system. + */ + virtual void reportCSV(std::ofstream& textFile, std::ofstream& csvFile, bool show_thermo = true) const; private: diff --git a/Cantera/src/thermo/MargulesVPSSTP.cpp b/Cantera/src/thermo/MargulesVPSSTP.cpp index a6340b7ae..d9caca8e5 100644 --- a/Cantera/src/thermo/MargulesVPSSTP.cpp +++ b/Cantera/src/thermo/MargulesVPSSTP.cpp @@ -19,7 +19,7 @@ #include "MargulesVPSSTP.h" #include "ThermoFactory.h" - +#include using namespace std; @@ -1171,6 +1171,101 @@ namespace Cantera { return s; } + /* + * Format a summary of the mixture state for output. + */ + void MargulesVPSSTP::reportCSV(std::ofstream& textFile, std::ofstream& csvFile, bool show_thermo) const { + + csvFile.precision(6); + int tabS = 20; + int tabM = 30; + int tabL = 40; + try { + if (name() != "") { + textFile << "\n"+name()+"\n\n"; + csvFile << "\n\n\n"; + } + textFile << setw(tabM) << "temperature (K)\n"; + csvFile << setw(tabM) << temperature() << ",\n"; + textFile << setw(tabM) << "pressure (Pa)\n"; + csvFile << setw(tabM) << pressure() << ",\n"; + textFile << setw(tabM) << "density (kg/m^3)\n"; + csvFile << setw(tabM) << density() << ",\n"; + textFile << setw(tabM) << "mean mol. weight (amu)\n"; + csvFile << setw(tabM) << meanMolecularWeight() << ",\n"; + textFile << setw(tabM) << "potential (V)\n"; + csvFile << setw(tabM) << electricPotential() << ",\n"; + + if (show_thermo) { + textFile << endl; + csvFile << endl; + textFile << setw(tabM) << "enthalpy (J/kg)" << "," << setw(tabM) << "enthalpy (J/kmol)\n"; + csvFile << setw(tabM) << enthalpy_mass() << "," << setw(tabM) << enthalpy_mole() << ",\n"; + textFile << setw(tabM) << "internal E (J/kg)" << "," << setw(tabM) << "internal E (J/kmol)\n"; + csvFile << setw(tabM) << intEnergy_mass() << "," << setw(tabM) << intEnergy_mole() << ",\n"; + textFile << setw(tabM) << "entropy (J/kg)" << "," << setw(tabM) << "entropy (J/kmol)\n"; + csvFile << setw(tabM) << entropy_mass() << "," << setw(tabM) << entropy_mole() << ",\n"; + textFile << setw(tabM) << "Gibbs (J/kg)" << "," << setw(tabM) << "Gibbs (J/kmol)\n"; + csvFile << setw(tabM) << gibbs_mass() << "," << setw(tabM) << gibbs_mole() << ",\n"; + textFile << setw(tabL) << "heat capacity c_p (J/K/kg)" << "," << setw(tabL) << "heat capacity c_p (J/K/kmol)\n"; + csvFile << setw(tabL) << cp_mass() << "," << setw(tabL) << cp_mole() << ",\n"; + textFile << setw(tabL) << "heat capacity c_v (J/K/kg)" << "," << setw(tabL) << "heat capacity c_v (J/K/kmol)\n"; + csvFile << setw(tabL) << cv_mass() << "," << setw(tabL) << cv_mole() << ",\n"; + } + /* + // NOT USED!!!!! + int kk = nSpecies(); + array_fp x(kk); + array_fp y(kk); + array_fp mu(kk); + getMoleFractions(&x[0]); + getMassFractions(&y[0]); + getChemPotentials(&mu[0]); + doublereal rt = GasConstant * temperature(); + int k; + +// ThermoPhase original above...changed to below comments in GibbsExcessVPSSTP::report() +// int kk = nSpecies(); +// array_fp x(kk); +// array_fp molal(kk); +// array_fp mu(kk); +// array_fp muss(kk); +// array_fp acMolal(kk); +// array_fp actMolal(kk); +// getMoleFractions(&x[0]); +// +// getChemPotentials(&mu[0]); +// getStandardChemPotentials(&muss[0]); +// getActivities(&actMolal[0]); + + if (show_thermo) { + textFile << "\n" << setw(40) << "X" << "," << setw(tabS) << "Y" << "," << setw(tabS) << "Chem. Pot. / RT\n"; + csvFile << "\n\n"; + for (k = 0; k < kk; k++) { + if (x[k] > SmallNumber) { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(40) << x[k] << "," << setw(tabS) << y[k] << "," << setw(tabS) << mu[k]/rt << ",\n"; + } + else { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(40) << x[k] << "," << setw(tabS) << y[k] << ",\n"; + } + } + } + else { + textFile << "\n" << setw(40) << "X" << "," << setw(tabS) << "Y\n"; + csvFile << "\n\n"; + for (k = 0; k < kk; k++) { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(40) << x[k] << "," << setw(tabS) << y[k] << ",\n"; + } + } + */ + } + catch (CanteraError) { + ; + } + } } diff --git a/Cantera/src/thermo/MargulesVPSSTP.h b/Cantera/src/thermo/MargulesVPSSTP.h index 4d8a40776..c3a8e60bd 100644 --- a/Cantera/src/thermo/MargulesVPSSTP.h +++ b/Cantera/src/thermo/MargulesVPSSTP.h @@ -738,6 +738,17 @@ namespace Cantera { */ virtual std::string report(bool show_thermo = true) const; + //! returns a summary of the state of the phase to specified + //! comma separated files + /*! + * @param textFile ofstream file to print textual variable names that + * will correspod to data in comma separated file (csv). + * @param csvFile ofstream file to print comma separated data for + * the phase + * @param show_thermo If true, extra information is printed out + * about the thermodynamic state of the system. + */ + virtual void reportCSV(std::ofstream& textFile, std::ofstream& csvFile, bool show_thermo = true) const; private: diff --git a/Cantera/src/thermo/MolalityVPSSTP.cpp b/Cantera/src/thermo/MolalityVPSSTP.cpp index 285289a9e..32752036e 100644 --- a/Cantera/src/thermo/MolalityVPSSTP.cpp +++ b/Cantera/src/thermo/MolalityVPSSTP.cpp @@ -24,6 +24,7 @@ #include "MolalityVPSSTP.h" +#include using namespace std; namespace Cantera { @@ -910,6 +911,99 @@ namespace Cantera { return s; } + /* + * Format a summary of the mixture state for output. + */ + void MolalityVPSSTP::reportCSV(std::ofstream& textFile, std::ofstream& csvFile, bool show_thermo) const { + + csvFile.precision(6); + int tabS = 20; + int tabM = 30; + int tabL = 40; + try { + if (name() != "") { + textFile << "\n"+name()+"\n\n"; + csvFile << "\n\n\n"; + } + textFile << setw(tabM) << "temperature (K)\n"; + csvFile << setw(tabM) << temperature() << ",\n"; + textFile << setw(tabM) << "pressure (Pa)\n"; + csvFile << setw(tabM) << pressure() << ",\n"; + textFile << setw(tabM) << "density (kg/m^3)\n"; + csvFile << setw(tabM) << density() << ",\n"; + textFile << setw(tabM) << "mean mol. weight (amu)\n"; + csvFile << setw(tabM) << meanMolecularWeight() << ",\n"; + textFile << setw(tabM) << "potential (V)\n"; + csvFile << setw(tabM) << electricPotential() << ",\n"; + + int kk = nSpecies(); + array_fp x(kk); + array_fp molal(kk); + array_fp mu(kk); + array_fp muss(kk); + array_fp acMolal(kk); + array_fp actMolal(kk); + getMoleFractions(&x[0]); + getMolalities(&molal[0]); + getChemPotentials(&mu[0]); + getStandardChemPotentials(&muss[0]); + getMolalityActivityCoefficients(&acMolal[0]); + getActivities(&actMolal[0]); + + int iHp = speciesIndex("H+"); + if (iHp >= 0) { + double pH = -log(actMolal[iHp]) / log(10.0); + textFile << setw(tabM) << "pH\n"; + csvFile << setw(tabM) << pH << ",\n"; + } + + + if (show_thermo) { + textFile << endl; + csvFile << endl; + textFile << setw(tabM) << "enthalpy (J/kg)" << "," << setw(tabM) << "enthalpy (J/kmol)\n"; + csvFile << setw(tabM) << enthalpy_mass() << "," << setw(tabM) << enthalpy_mole() << ",\n"; + textFile << setw(tabM) << "internal E (J/kg)" << "," << setw(tabM) << "internal E (J/kmol)\n"; + csvFile << setw(tabM) << intEnergy_mass() << "," << setw(tabM) << intEnergy_mole() << ",\n"; + textFile << setw(tabM) << "entropy (J/kg)" << "," << setw(tabM) << "entropy (J/kmol)\n"; + csvFile << setw(tabM) << entropy_mass() << "," << setw(tabM) << entropy_mole() << ",\n"; + textFile << setw(tabM) << "Gibbs (J/kg)" << "," << setw(tabM) << "Gibbs (J/kmol)\n"; + csvFile << setw(tabM) << gibbs_mass() << "," << setw(tabM) << gibbs_mole() << ",\n"; + textFile << setw(tabL) << "heat capacity c_p (J/K/kg)" << "," << setw(tabL) << "heat capacity c_p (J/K/kmol)\n"; + csvFile << setw(tabL) << cp_mass() << "," << setw(tabL) << cp_mole() << ",\n"; + textFile << setw(tabL) << "heat capacity c_v (J/K/kg)" << "," << setw(tabL) << "heat capacity c_v (J/K/kmol)\n"; + csvFile << setw(tabL) << cv_mass() << "," << setw(tabL) << cv_mole() << ",\n"; + } + + int k; + if (show_thermo) { + textFile << "\n" << setw(2*tabS) << "X" << "," << setw(tabS) << "Molalities" << "," << setw(tabM) << "Chem. Pot. (J/kmol)" << "," << setw(tabM) << "Chem Pot SS (J/kmol)" << "," << setw(tabS) << "ActCoeffMolal\n"; + csvFile << "\n\n"; + for (k = 0; k < kk; k++) { + if (x[k] > SmallNumber) { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << molal[k] << "," << setw(tabM) << mu[k] << "," << setw(tabM) << muss[k] << "," << setw(tabM) << acMolal[k] << ",\n"; + } + else { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << molal[k] << "," << setw(tabM) << 0 << "," << setw(tabM) << muss[k] << "," << setw(tabM) << acMolal[k] << ",\n"; + } + } + } + else { + textFile << "\n" << setw(2*tabS) << "X" << "," << setw(tabS) << "Molalities\n"; + csvFile << "\n\n"; + for (k = 0; k < kk; k++) { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << molal[k] << ",\n"; + + } + } + } + catch (CanteraError) { + ; + } + } } diff --git a/Cantera/src/thermo/MolalityVPSSTP.h b/Cantera/src/thermo/MolalityVPSSTP.h index f9eb439d9..50d68302c 100644 --- a/Cantera/src/thermo/MolalityVPSSTP.h +++ b/Cantera/src/thermo/MolalityVPSSTP.h @@ -800,6 +800,18 @@ namespace Cantera { */ virtual std::string report(bool show_thermo = true) const; + //! returns a summary of the state of the phase to specified + //! comma separated files + /*! + * @param textFile ofstream file to print textual variable names that + * will correspod to data in comma separated file (csv). + * @param csvFile ofstream file to print comma separated data for + * the phase + * @param show_thermo If true, extra information is printed out + * about the thermodynamic state of the system. + */ + virtual void reportCSV(std::ofstream& textFile, std::ofstream& csvFile, bool show_thermo = true) const; + protected: //! Get the array of unscaled non-dimensional molality based diff --git a/Cantera/src/thermo/PureFluidPhase.cpp b/Cantera/src/thermo/PureFluidPhase.cpp index a0748e18c..14c54ef39 100644 --- a/Cantera/src/thermo/PureFluidPhase.cpp +++ b/Cantera/src/thermo/PureFluidPhase.cpp @@ -17,6 +17,7 @@ #include "../../../ext/tpx/utils.h" #include +#include namespace Cantera { @@ -427,8 +428,97 @@ namespace Cantera { } return s; } + + /* + * Format a summary of the mixture state for output. + */ + void PureFluidPhase::reportCSV(std::ofstream& textFile, std::ofstream& csvFile, bool show_thermo) const { + + csvFile.precision(6); + int tabS = 20; + int tabM = 30; + int tabL = 40; + try { + if (name() != "") { + textFile << "\n"+name()+"\n\n"; + csvFile << "\n\n\n"; + } + textFile << setw(tabM) << "temperature (K)\n"; + csvFile << setw(tabM) << temperature() << ",\n"; + textFile << setw(tabM) << "pressure (Pa)\n"; + csvFile << setw(tabM) << pressure() << ",\n"; + textFile << setw(tabM) << "density (kg/m^3)\n"; + csvFile << setw(tabM) << density() << ",\n"; + textFile << setw(tabM) << "mean mol. weight (amu)\n"; + csvFile << setw(tabM) << meanMolecularWeight() << ",\n"; + + if (eosType() == cPureFluid) { + double xx = ((PureFluidPhase *) (this))->vaporFraction(); + textFile << setw(tabM) << "vapor fraction\n"; + csvFile << setw(tabM) << xx << ",\n"; + } + + doublereal phi = electricPotential(); + if (phi != 0.0) { + textFile << setw(tabM) << "potential (V)\n"; + csvFile << setw(tabM) << phi << ",\n"; + } + + if (show_thermo) { + textFile << endl; + csvFile << endl; + textFile << setw(tabM) << "enthalpy (J/kg)" << "," << setw(tabM) << "enthalpy (J/kmol)\n"; + csvFile << setw(tabM) << enthalpy_mass() << "," << setw(tabM) << enthalpy_mole() << ",\n"; + textFile << setw(tabM) << "internal E (J/kg)" << "," << setw(tabM) << "internal E (J/kmol)\n"; + csvFile << setw(tabM) << intEnergy_mass() << "," << setw(tabM) << intEnergy_mole() << ",\n"; + textFile << setw(tabM) << "entropy (J/kg)" << "," << setw(tabM) << "entropy (J/kmol)\n"; + csvFile << setw(tabM) << entropy_mass() << "," << setw(tabM) << entropy_mole() << ",\n"; + textFile << setw(tabM) << "Gibbs (J/kg)" << "," << setw(tabM) << "Gibbs (J/kmol)\n"; + csvFile << setw(tabM) << gibbs_mass() << "," << setw(tabM) << gibbs_mole() << ",\n"; + textFile << setw(tabL) << "heat capacity c_p (J/K/kg)" << "," << setw(tabL) << "heat capacity c_p (J/K/kmol)\n"; + csvFile << setw(tabL) << cp_mass() << "," << setw(tabL) << cp_mole() << ",\n"; + textFile << setw(tabL) << "heat capacity c_v (J/K/kg)" << "," << setw(tabL) << "heat capacity c_v (J/K/kmol)\n"; + csvFile << setw(tabL) << cv_mass() << "," << setw(tabL) << cv_mole() << ",\n"; + } + + int kk = nSpecies(); + array_fp x(kk); + array_fp y(kk); + array_fp mu(kk); + getMoleFractions(&x[0]); + getMassFractions(&y[0]); + getChemPotentials(&mu[0]); + doublereal rt = GasConstant * temperature(); + int k; + + if (show_thermo) { + textFile << "\n" << setw(2*tabS) << "X" << "," << setw(tabS) << "Y" << "," << setw(tabS) << "Chem. Pot. / RT\n"; + csvFile << "\n\n"; + for (k = 0; k < kk; k++) { + if (x[k] > SmallNumber) { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << y[k] << "," << setw(tabS) << mu[k]/rt << ",\n"; + } + else { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << y[k] << ",\n"; + } + } + } + else { + textFile << "\n" << setw(2*tabS) << "X" << "," << setw(tabS) << "Y\n"; + csvFile << "\n\n"; + for (k = 0; k < kk; k++) { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << y[k] << ",\n"; + } + } + } + catch (CanteraError) { + ; + } + } - } #endif // WITH_PURE_FLUIDS diff --git a/Cantera/src/thermo/PureFluidPhase.h b/Cantera/src/thermo/PureFluidPhase.h index 2e2c626c1..2e1943494 100644 --- a/Cantera/src/thermo/PureFluidPhase.h +++ b/Cantera/src/thermo/PureFluidPhase.h @@ -303,6 +303,18 @@ namespace Cantera { */ virtual std::string report(bool show_thermo = true) const; + //! returns a summary of the state of the phase to specified + //! comma separated files + /*! + * @param textFile ofstream file to print textual variable names that + * will correspod to data in comma separated file (csv). + * @param csvFile ofstream file to print comma separated data for + * the phase + * @param show_thermo If true, extra information is printed out + * about the thermodynamic state of the system. + */ + virtual void reportCSV(std::ofstream& textFile, std::ofstream& csvFile, bool show_thermo = true) const; + protected: //! Main call to the tpx level to set the state of the system diff --git a/Cantera/src/thermo/ThermoPhase.cpp b/Cantera/src/thermo/ThermoPhase.cpp index 61088dcd2..74e332d3a 100644 --- a/Cantera/src/thermo/ThermoPhase.cpp +++ b/Cantera/src/thermo/ThermoPhase.cpp @@ -21,6 +21,7 @@ #endif #include "ThermoPhase.h" +#include //@{ #ifndef MAX @@ -1135,5 +1136,88 @@ namespace Cantera { return s; } + /* + * Format a summary of the mixture state for output. + */ + void ThermoPhase::reportCSV(std::ofstream& textFile, std::ofstream& csvFile, bool show_thermo) const { + + csvFile.precision(6); + int tabS = 20; + int tabM = 30; + int tabL = 40; + try { + if (name() != "") { + textFile << "\n"+name()+"\n\n"; + csvFile << "\n\n\n"; + } + textFile << setw(tabM) << "temperature (K)\n"; + csvFile << setw(tabM) << temperature() << ",\n"; + textFile << setw(tabM) << "pressure (Pa)\n"; + csvFile << setw(tabM) << pressure() << ",\n"; + textFile << setw(tabM) << "density (kg/m^3)\n"; + csvFile << setw(tabM) << density() << ",\n"; + textFile << setw(tabM) << "mean mol. weight (amu)\n"; + csvFile << setw(tabM) << meanMolecularWeight() << ",\n"; + + doublereal phi = electricPotential(); + if (phi != 0.0) { + textFile << setw(tabM) << "potential (V)\n"; + csvFile << setw(tabM) << phi << ",\n"; + } + if (show_thermo) { + textFile << endl; + csvFile << endl; + textFile << setw(tabM) << "enthalpy (J/kg)" << "," << setw(tabM) << "enthalpy (J/kmol)\n"; + csvFile << setw(tabM) << enthalpy_mass() << "," << setw(tabM) << enthalpy_mole() << ",\n"; + textFile << setw(tabM) << "internal E (J/kg)" << "," << setw(tabM) << "internal E (J/kmol)\n"; + csvFile << setw(tabM) << intEnergy_mass() << "," << setw(tabM) << intEnergy_mole() << ",\n"; + textFile << setw(tabM) << "entropy (J/kg)" << "," << setw(tabM) << "entropy (J/kmol)\n"; + csvFile << setw(tabM) << entropy_mass() << "," << setw(tabM) << entropy_mole() << ",\n"; + textFile << setw(tabM) << "Gibbs (J/kg)" << "," << setw(tabM) << "Gibbs (J/kmol)\n"; + csvFile << setw(tabM) << gibbs_mass() << "," << setw(tabM) << gibbs_mole() << ",\n"; + textFile << setw(tabL) << "heat capacity c_p (J/K/kg)" << "," << setw(tabL) << "heat capacity c_p (J/K/kmol)\n"; + csvFile << setw(tabL) << cp_mass() << "," << setw(tabL) << cp_mole() << ",\n"; + textFile << setw(tabL) << "heat capacity c_v (J/K/kg)" << "," << setw(tabL) << "heat capacity c_v (J/K/kmol)\n"; + csvFile << setw(tabL) << cv_mass() << "," << setw(tabL) << cv_mole() << ",\n"; + } + + int kk = nSpecies(); + array_fp x(kk); + array_fp y(kk); + array_fp mu(kk); + getMoleFractions(&x[0]); + getMassFractions(&y[0]); + getChemPotentials(&mu[0]); + doublereal rt = GasConstant * temperature(); + int k; + + if (show_thermo) { + textFile << "\n" << setw(2*tabS) << "X" << "," << setw(tabS) << "Y" << "," << setw(tabS) << "Chem. Pot. / RT\n"; + csvFile << "\n\n"; + for (k = 0; k < kk; k++) { + if (x[k] > SmallNumber) { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << y[k] << "," << setw(tabS) << mu[k]/rt << ",\n"; + } + else { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << y[k] << ",\n"; + } + } + } + else { + textFile << "\n" << setw(2*tabS) << "X" << "," << setw(tabS) << "Y\n"; + csvFile << "\n\n"; + for (k = 0; k < kk; k++) { + textFile << setw(tabS) << speciesName(k) << ",\n"; + csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << y[k] << ",\n"; + } + } + } + catch (CanteraError) { + ; + } + } + } diff --git a/Cantera/src/thermo/ThermoPhase.h b/Cantera/src/thermo/ThermoPhase.h index 2df0b8546..1fcfeefa1 100644 --- a/Cantera/src/thermo/ThermoPhase.h +++ b/Cantera/src/thermo/ThermoPhase.h @@ -2111,6 +2111,17 @@ namespace Cantera { * about the thermodynamic state of the system. */ virtual std::string report(bool show_thermo = true) const; + + //! returns a summary of the state of the phase to a comma separated file + /*! + * @param textFile ofstream file to print textual variable names that + * will correspod to data in comma separated file (csv). + * @param csvFile ofstream file to print comma separated data for + * the phase + * @param show_thermo If true, extra information is printed out + * about the thermodynamic state of the system. + */ + virtual void reportCSV(std::ofstream& textFile, std::ofstream& csvFile, bool show_thermo = true) const; protected: