implemented reportCSV in MolalityPSSTP and PureFluidPhase

This commit is contained in:
Christopher Lueth 2010-04-06 16:37:11 +00:00
parent 8f8b83e0a2
commit 20bf13dbd7
2 changed files with 232 additions and 138 deletions

View file

@ -916,95 +916,144 @@ namespace Cantera {
*/ */
void MolalityVPSSTP::reportCSV(std::ofstream& csvFile) const { void MolalityVPSSTP::reportCSV(std::ofstream& csvFile) const {
/*
csvFile.precision(6); csvFile.precision(3);
int tabS = 20; int tabS = 15;
int tabM = 30; int tabM = 30;
int tabL = 40; int tabL = 40;
try { try {
if (name() != "") { if (name() != "") {
textFile << "\n"+name()+"\n\n"; csvFile << "\n"+name()+"\n\n";
csvFile << "\n\n\n";
} }
textFile << setw(tabM) << "temperature (K)\n"; csvFile << setw(tabL) << "temperature (K) =" << setw(tabS) << temperature() << endl;
csvFile << setw(tabM) << temperature() << ",\n"; csvFile << setw(tabL) << "pressure (Pa) =" << setw(tabS) << pressure() << endl;
textFile << setw(tabM) << "pressure (Pa)\n"; csvFile << setw(tabL) << "density (kg/m^3) =" << setw(tabS) << density() << endl;
csvFile << setw(tabM) << pressure() << ",\n"; csvFile << setw(tabL) << "mean mol. weight (amu) =" << setw(tabS) << meanMolecularWeight() << endl;
textFile << setw(tabM) << "density (kg/m^3)\n"; csvFile << setw(tabL) << "potential (V) =" << setw(tabS) << electricPotential() << endl;
csvFile << setw(tabM) << density() << ",\n"; csvFile << endl;
textFile << setw(tabM) << "mean mol. weight (amu)\n";
csvFile << setw(tabM) << meanMolecularWeight() << ",\n"; csvFile << setw(tabL) << "enthalpy (J/kg) = " << setw(tabS) << enthalpy_mass() << setw(tabL) << "enthalpy (J/kmol) = " << setw(tabS) << enthalpy_mole() << endl;
textFile << setw(tabM) << "potential (V)\n"; csvFile << setw(tabL) << "internal E (J/kg) = " << setw(tabS) << intEnergy_mass() << setw(tabL) << "internal E (J/kmol) = " << setw(tabS) << intEnergy_mole() << endl;
csvFile << setw(tabM) << electricPotential() << ",\n"; csvFile << setw(tabL) << "entropy (J/kg) = " << setw(tabS) << entropy_mass() << setw(tabL) << "entropy (J/kmol) = " << setw(tabS) << entropy_mole() << endl;
csvFile << setw(tabL) << "Gibbs (J/kg) = " << setw(tabS) << gibbs_mass() << setw(tabL) << "Gibbs (J/kmol) = " << setw(tabS) << gibbs_mole() << endl;
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;
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;
csvFile.precision(8);
int kk = nSpecies(); int kk = nSpecies();
array_fp x(kk); double x[kk];
array_fp molal(kk); double molal[kk];
array_fp mu(kk); double mu[kk];
array_fp muss(kk); double muss[kk];
array_fp acMolal(kk); double aMolal[kk];
array_fp actMolal(kk); double acMolal[kk];
getMoleFractions(&x[0]); double hbar[kk];
getMolalities(&molal[0]); double sbar[kk];
getChemPotentials(&mu[0]); double ubar[kk];
getStandardChemPotentials(&muss[0]); double cpbar[kk];
getMolalityActivityCoefficients(&acMolal[0]); double vbar[kk];
getActivities(&actMolal[0]); vector<std::string> pNames;
vector<double*> data;
int iHp = speciesIndex("H+"); getMoleFractions(x);
if (iHp >= 0) { pNames.push_back("X");
double pH = -log(actMolal[iHp]) / log(10.0); data.push_back(x);
textFile << setw(tabM) << "pH\n"; try{
csvFile << setw(tabM) << pH << ",\n"; getMolalities(molal);
pNames.push_back("Molal");
data.push_back(molal);
} }
catch (CanteraError) {;}
try{
if (show_thermo) { getChemPotentials(mu);
textFile << endl; pNames.push_back("Chem. Pot. (J/kmol)");
csvFile << endl; data.push_back(mu);
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";
} }
catch (CanteraError) {;}
int k; try{
if (show_thermo) { getStandardChemPotentials(muss);
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"; pNames.push_back("Chem. Pot. SS (J/kmol)");
csvFile << "\n\n"; data.push_back(muss);
for (k = 0; k < kk; k++) { }
if (x[k] > SmallNumber) { catch (CanteraError) {;}
textFile << setw(tabS) << speciesName(k) << ",\n"; try{
csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << molal[k] << "," << setw(tabM) << mu[k] << "," << setw(tabM) << muss[k] << "," << setw(tabM) << acMolal[k] << ",\n"; getMolalityActivityCoefficients(acMolal);
} pNames.push_back("Molal Act. Coeff.");
else { data.push_back(acMolal);
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"; catch (CanteraError) {;}
} try{
getActivities(aMolal);
pNames.push_back("Molal Activity");
data.push_back(aMolal);
int iHp = speciesIndex("H+");
if (iHp >= 0) {
double pH = -log(aMolal[iHp]) / log(10.0);
csvFile << setw(tabL) << "pH = " << setw(tabS) << pH << endl;
} }
} }
else { catch (CanteraError) {;}
textFile << "\n" << setw(2*tabS) << "X" << "," << setw(tabS) << "Molalities\n"; try{
csvFile << "\n\n"; getPartialMolarEnthalpies(hbar);
for (k = 0; k < kk; k++) { pNames.push_back("Part. Mol Enthalpy (J/kmol)");
textFile << setw(tabS) << speciesName(k) << ",\n"; data.push_back(hbar);
csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << molal[k] << ",\n"; }
catch (CanteraError) {;}
try{
getPartialMolarEntropies(sbar);
pNames.push_back("Part. Mol. Entropy (J/K/kmol)");
data.push_back(sbar);
}
catch (CanteraError) {;}
try{
getPartialMolarIntEnergies(ubar);
pNames.push_back("Part. Mol. Energy (J/kmol)");
data.push_back(ubar);
}
catch (CanteraError) {;}
try{
getPartialMolarCp(cpbar);
pNames.push_back("Part. Mol. Cp (J/K/kmol");
data.push_back(cpbar);
}
catch (CanteraError) {;}
try{
getPartialMolarVolumes(vbar);
pNames.push_back("Part. Mol. Cv (J/K/kmol)");
data.push_back(vbar);
}
catch (CanteraError) {;}
csvFile << endl << setw(tabS) << "Species,";
for ( int i = 0; i < (int)pNames.size(); i++ ){
csvFile << setw(tabM) << pNames[i] << ",";
}
csvFile << endl;
/*
csvFile.fill('-');
csvFile << setw(tabS+(tabM+1)*pNames.size()) << "-\n";
csvFile.fill(' ');
*/
for (int k = 0; k < kk; k++) {
csvFile << setw(tabS) << speciesName(k) + ",";
if (x[k] > SmallNumber) {
for ( int i = 0; i < (int)pNames.size(); i++ ){
csvFile << setw(tabM) << data[i][k] << ",";
}
csvFile << endl;
}
else{
for ( int i = 0; i < (int)pNames.size(); i++ ){
csvFile << setw(tabM) << 0 << ",";
}
csvFile << endl;
} }
} }
} }
catch (CanteraError) { catch (CanteraError) {
; ;
} }
*/
} }
} }

View file

@ -434,91 +434,136 @@ namespace Cantera {
*/ */
void PureFluidPhase::reportCSV(std::ofstream& csvFile) const { void PureFluidPhase::reportCSV(std::ofstream& csvFile) const {
/*
csvFile.precision(6); csvFile.precision(3);
int tabS = 20; int tabS = 15;
int tabM = 30; int tabM = 30;
int tabL = 40; int tabL = 40;
try { try {
if (name() != "") { if (name() != "") {
textFile << "\n"+name()+"\n\n"; csvFile << "\n"+name()+"\n\n";
csvFile << "\n\n\n";
} }
textFile << setw(tabM) << "temperature (K)\n"; csvFile << setw(tabL) << "temperature (K) =" << setw(tabS) << temperature() << endl;
csvFile << setw(tabM) << temperature() << ",\n"; csvFile << setw(tabL) << "pressure (Pa) =" << setw(tabS) << pressure() << endl;
textFile << setw(tabM) << "pressure (Pa)\n"; csvFile << setw(tabL) << "density (kg/m^3) =" << setw(tabS) << density() << endl;
csvFile << setw(tabM) << pressure() << ",\n"; csvFile << setw(tabL) << "mean mol. weight (amu) =" << setw(tabS) << meanMolecularWeight() << endl;
textFile << setw(tabM) << "density (kg/m^3)\n"; csvFile << setw(tabL) << "potential (V) =" << setw(tabS) << electricPotential() << endl;
csvFile << setw(tabM) << density() << ",\n";
textFile << setw(tabM) << "mean mol. weight (amu)\n";
csvFile << setw(tabM) << meanMolecularWeight() << ",\n";
if (eosType() == cPureFluid) { if (eosType() == cPureFluid) {
double xx = ((PureFluidPhase *) (this))->vaporFraction(); double xx = ((PureFluidPhase *) (this))->vaporFraction();
textFile << setw(tabM) << "vapor fraction\n"; csvFile << setw(tabL) << "vapor fraction = " << setw(tabS) << xx << endl;
csvFile << setw(tabM) << xx << ",\n";
} }
csvFile << endl;
doublereal phi = electricPotential(); csvFile << setw(tabL) << "enthalpy (J/kg) = " << setw(tabS) << enthalpy_mass() << setw(tabL) << "enthalpy (J/kmol) = " << setw(tabS) << enthalpy_mole() << endl;
if (phi != 0.0) { csvFile << setw(tabL) << "internal E (J/kg) = " << setw(tabS) << intEnergy_mass() << setw(tabL) << "internal E (J/kmol) = " << setw(tabS) << intEnergy_mole() << endl;
textFile << setw(tabM) << "potential (V)\n"; csvFile << setw(tabL) << "entropy (J/kg) = " << setw(tabS) << entropy_mass() << setw(tabL) << "entropy (J/kmol) = " << setw(tabS) << entropy_mole() << endl;
csvFile << setw(tabM) << phi << ",\n"; csvFile << setw(tabL) << "Gibbs (J/kg) = " << setw(tabS) << gibbs_mass() << setw(tabL) << "Gibbs (J/kmol) = " << setw(tabS) << gibbs_mole() << endl;
} 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;
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;
if (show_thermo) { csvFile.precision(8);
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(); int kk = nSpecies();
array_fp x(kk); double x[kk];
array_fp y(kk); double y[kk];
array_fp mu(kk); double mu[kk];
getMoleFractions(&x[0]); double a[kk];
getMassFractions(&y[0]); double ac[kk];
getChemPotentials(&mu[0]); double hbar[kk];
doublereal rt = GasConstant * temperature(); double sbar[kk];
int k; double ubar[kk];
double cpbar[kk];
double vbar[kk];
vector<std::string> pNames;
vector<double*> data;
if (show_thermo) { getMoleFractions(x);
textFile << "\n" << setw(2*tabS) << "X" << "," << setw(tabS) << "Y" << "," << setw(tabS) << "Chem. Pot. / RT\n"; pNames.push_back("X");
csvFile << "\n\n"; data.push_back(x);
for (k = 0; k < kk; k++) { try{
if (x[k] > SmallNumber) { getMassFractions(y);
textFile << setw(tabS) << speciesName(k) << ",\n"; pNames.push_back("Y");
csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << y[k] << "," << setw(tabS) << mu[k]/rt << ",\n"; data.push_back(y);
}
else {
textFile << setw(tabS) << speciesName(k) << ",\n";
csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << y[k] << ",\n";
}
}
} }
else { catch (CanteraError) {;}
textFile << "\n" << setw(2*tabS) << "X" << "," << setw(tabS) << "Y\n"; try{
csvFile << "\n\n"; getChemPotentials(mu);
for (k = 0; k < kk; k++) { pNames.push_back("Chem. Pot (J/kmol)");
textFile << setw(tabS) << speciesName(k) << ",\n"; data.push_back(mu);
csvFile << setw(2*tabS) << x[k] << "," << setw(tabS) << y[k] << ",\n"; }
catch (CanteraError) {;}
try{
getActivities(a);
pNames.push_back("Activity");
data.push_back(a);
}
catch (CanteraError) {;}
try{
getActivityCoefficients(ac);
pNames.push_back("Act. Coeff.");
data.push_back(ac);
}
catch (CanteraError) {;}
try{
getPartialMolarEnthalpies(hbar);
pNames.push_back("Part. Mol Enthalpy (J/kmol)");
data.push_back(hbar);
}
catch (CanteraError) {;}
try{
getPartialMolarEntropies(sbar);
pNames.push_back("Part. Mol. Entropy (J/K/kmol)");
data.push_back(sbar);
}
catch (CanteraError) {;}
try{
getPartialMolarIntEnergies(ubar);
pNames.push_back("Part. Mol. Energy (J/kmol)");
data.push_back(ubar);
}
catch (CanteraError) {;}
try{
getPartialMolarCp(cpbar);
pNames.push_back("Part. Mol. Cp (J/K/kmol");
data.push_back(cpbar);
}
catch (CanteraError) {;}
try{
getPartialMolarVolumes(vbar);
pNames.push_back("Part. Mol. Cv (J/K/kmol)");
data.push_back(vbar);
}
catch (CanteraError) {;}
csvFile << endl << setw(tabS) << "Species,";
for ( int i = 0; i < (int)pNames.size(); i++ ){
csvFile << setw(tabM) << pNames[i] << ",";
}
csvFile << endl;
/*
csvFile.fill('-');
csvFile << setw(tabS+(tabM+1)*pNames.size()) << "-\n";
csvFile.fill(' ');
*/
for (int k = 0; k < kk; k++) {
csvFile << setw(tabS) << speciesName(k) + ",";
if (x[k] > SmallNumber) {
for ( int i = 0; i < (int)pNames.size(); i++ ){
csvFile << setw(tabM) << data[i][k] << ",";
}
csvFile << endl;
}
else{
for ( int i = 0; i < (int)pNames.size(); i++ ){
csvFile << setw(tabM) << 0 << ",";
}
csvFile << endl;
} }
} }
} }
catch (CanteraError) { catch (CanteraError) {
; ;
} }
*/
} }
} }