[test_problems] replace convenience wrapper classes by C++ Solution

- Remove dependence on IdealGasMix.h
This commit is contained in:
Ingmar Schoegl 2019-10-26 18:30:09 -05:00 committed by Ray Speth
parent 40ae5b5fb5
commit a0350925a7
16 changed files with 170 additions and 145 deletions

View file

@ -1,6 +1,9 @@
#include "cantera/IdealGasMix.h"
// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.
#include <cstdio>
#include "cantera/thermo/IdealGasPhase.h"
#include <iostream>
using namespace std;
using namespace Cantera;
@ -11,8 +14,8 @@ int main(int argc, char** argv)
_set_output_format(_TWO_DIGIT_EXPONENT);
#endif
try {
suppress_deprecation_warnings();
IdealGasPhase* gas = new IdealGasMix("air_below6000K.cti","air_below6000K");
auto sol = newSolution("air_below6000K.cti", "air_below6000K");
auto gas = getIdealGasPhasePtr(sol);
vector_fp IndVar2(6, 0.0);
IndVar2[0] = 1.5E5;
@ -79,7 +82,6 @@ int main(int argc, char** argv)
fprintf(FF,"\n");
}
}
delete gas;
fclose(FF);
} catch (CanteraError& err) {
std::cout << err.what() << std::endl;

View file

@ -1,7 +1,9 @@
// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.
#include "cantera/IdealGasMix.h"
#include "cantera/thermo/IdealGasPhase.h"
#include <iostream>
using namespace std;
using namespace Cantera;
@ -12,17 +14,18 @@ int main(int argc, char** argv)
_set_output_format(_TWO_DIGIT_EXPONENT);
#endif
try {
IdealGasMix g("bad_air.xml", "air");
auto sol = newSolution("bad_air.xml", "air");
auto gas = getIdealGasPhasePtr(sol);
double pres = 1.0E5;
g.setState_TPX(1000.1, pres, "O2:0.4, N2:0.6");
g.equilibrate("TP", "auto");
double enth = g.enthalpy_mass();
gas->setState_TPX(1000.1, pres, "O2:0.4, N2:0.6");
gas->equilibrate("TP", "auto");
double enth = gas->enthalpy_mass();
printf(" enth = %g\n", enth);
enth -= 2.0E2;
printf("attempted equil at (H,P) = %10.5g, %10.5g\n", enth, pres);
g.setState_HP(enth, pres);
g.equilibrate("HP", "auto");
enth = g.enthalpy_mass();
gas->setState_HP(enth, pres);
gas->equilibrate("HP", "auto");
enth = gas->enthalpy_mass();
printf(" enth = %g\n", enth);

View file

@ -1,10 +1,11 @@
// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.
#include "cantera/IdealGasMix.h"
#include "cantera/thermo/IdealSolnGasVPSS.h"
#include "cantera/thermo/ThermoFactory.h"
#include <iostream>
using namespace std;
using namespace Cantera;

View file

@ -9,7 +9,10 @@
#include "example_utils.h"
#include "cantera/IdealGasMix.h"
#include "cantera/base/Solution.h"
#include "cantera/thermo/IdealGasPhase.h"
#include <iostream>
using namespace Cantera;
//-------------------------------------------------------------------
@ -19,12 +22,12 @@ using namespace Cantera;
template<class G, class V>
void makeEquilDataLabels(const G& gas, V& names)
{
size_t nsp = gas.nSpecies();
size_t nsp = gas->nSpecies();
names.resize(nsp + 2);
names[0] = "Temperature (K)";
names[1] = "Pressure (Pa)";
for (size_t k = 0; k < nsp; k++) {
names[2+k] = gas.speciesName(k);
names[2+k] = gas->speciesName(k);
}
}
@ -59,29 +62,30 @@ int equil_example1(int job)
}
// create a gas mixture, and set its state
IdealGasMix gas("silane.xml", "silane");
size_t nsp = gas.nSpecies();
auto sol = newSolution("silane.xml", "silane");
auto gas = getIdealGasPhasePtr(sol);
size_t nsp = gas->nSpecies();
int ntemps = 50; // number of temperatures
Array2D output(nsp+2, ntemps);
// main loop
doublereal temp;
doublereal thigh = gas.maxTemp();
doublereal thigh = gas->maxTemp();
doublereal tlow = 500.0;
doublereal dt = (thigh - tlow)/(ntemps);
doublereal pres = 0.01*OneAtm;
for (int i = 0; i < ntemps; i++) {
temp = tlow + dt*i;
if (temp > gas.maxTemp()) {
if (temp > gas->maxTemp()) {
break;
}
gas.setState_TPX(temp, pres, "SIH4:0.01, H2:0.99");
gas->setState_TPX(temp, pres, "SIH4:0.01, H2:0.99");
gas.equilibrate("TP");
gas->equilibrate("TP");
output(0,i) = temp;
output(1,i) = gas.pressure();
gas.getMoleFractions(&output(2,i));
output(1,i) = gas->pressure();
gas->getMoleFractions(&output(2,i));
}

View file

@ -8,7 +8,7 @@
// at https://cantera.org/license.txt for license and copyright information.
#include "cantera/zerodim.h"
#include "cantera/IdealGasMix.h"
#include "cantera/thermo/IdealGasPhase.h"
#include "example_utils.h"
using namespace Cantera;
using namespace std;
@ -27,8 +27,8 @@ int kinetics_example1(int job)
{
try {
cout << "Ignition simulation using class IdealGasMix "
<< "with file gri30.cti."
cout << "Ignition simulation using class IdealGasPhase "
<< "with file gri30.yaml."
<< endl;
if (job >= 1) {
@ -42,22 +42,20 @@ int kinetics_example1(int job)
// create an ideal gas mixture that corresponds to GRI-Mech
// 3.0
IdealGasMix gas("gri30.xml", "gri30");
auto sol = newSolution("gri30.yaml", "gri30", "None");
auto gas = getIdealGasPhasePtr(sol);
// set the state
gas.setState_TPX(1001.0, OneAtm, "H2:2.0, O2:1.0, N2:4.0");
size_t kk = gas.nSpecies();
gas->setState_TPX(1001.0, OneAtm, "H2:2.0, O2:1.0, N2:4.0");
size_t kk = gas->nSpecies();
// create a reactor
Reactor r;
r.insert(sol);
// create a reservoir to represent the environment
Reservoir env;
// specify the thermodynamic property and kinetics managers
r.setThermoMgr(gas);
r.setKineticsMgr(gas);
env.setThermoMgr(gas);
env.insert(sol);
// create a flexible, insulating wall between the reactor and the
// environment
@ -83,19 +81,19 @@ int kinetics_example1(int job)
// create a 2D array to hold the output variables,
// and store the values for the initial state
Array2D soln(kk+4, 1);
saveSoln(0, 0.0, gas, soln);
saveSoln(0, 0.0, sol->thermo(), soln);
// main loop
for (int i = 1; i <= nsteps; i++) {
tm = i*dt;
sim.advance(tm);
saveSoln(tm, gas, soln);
saveSoln(tm, sol->thermo(), soln);
}
// make a Tecplot data file and an Excel spreadsheet
string plotTitle = "kinetics example 1: constant-pressure ignition";
plotSoln("kin1.dat", "TEC", plotTitle, gas, soln);
plotSoln("kin1.csv", "XL", plotTitle, gas, soln);
plotSoln("kin1.dat", "TEC", plotTitle, sol->thermo(), soln);
plotSoln("kin1.csv", "XL", plotTitle, sol->thermo(), soln);
// print final temperature
cout << " Tfinal = " << r.temperature() << endl;

View file

@ -8,7 +8,7 @@
// at https://cantera.org/license.txt for license and copyright information.
#include "cantera/zerodim.h"
#include "cantera/IdealGasMix.h"
#include "cantera/thermo/IdealGasPhase.h"
#include "example_utils.h"
using namespace Cantera;
@ -29,8 +29,8 @@ int kinetics_example3(int job)
{
try {
cout << "Ignition simulation using class IdealGasMix "
<< "with file gri30.cti."
cout << "Ignition simulation using class IdealGasPhase "
<< "with file gri30.yaml."
<< endl;
if (job >= 1) {
@ -44,22 +44,20 @@ int kinetics_example3(int job)
// create an ideal gas mixture that corresponds to GRI-Mech
// 3.0
IdealGasMix gas("gri30.xml", "gri30");
auto sol = newSolution("gri30.yaml", "gri30", "None");
auto gas = getIdealGasPhasePtr(sol);
// set the state
gas.setState_TPX(1001.0, OneAtm, "H2:2.0, O2:1.0, N2:4.0");
size_t kk = gas.nSpecies();
gas->setState_TPX(1001.0, OneAtm, "H2:2.0, O2:1.0, N2:4.0");
size_t kk = gas->nSpecies();
// create a reactor
ConstPressureReactor r;
r.insert(sol);
// create a reservoir to represent the environment
Reservoir env;
// specify the thermodynamic property and kinetics managers
r.setThermoMgr(gas);
r.setKineticsMgr(gas);
env.setThermoMgr(gas);
env.insert(sol);
// create a flexible, insulating wall between the reactor and the
// environment
@ -81,19 +79,19 @@ int kinetics_example3(int job)
// create a 2D array to hold the output variables,
// and store the values for the initial state
Array2D soln(kk+4, 1);
saveSoln(0, 0.0, gas, soln);
saveSoln(0, 0.0, sol->thermo(), soln);
// main loop
for (int i = 1; i <= nsteps; i++) {
tm = i*dt;
sim.advance(tm);
saveSoln(tm, gas, soln);
saveSoln(tm, sol->thermo(), soln);
}
// make a Tecplot data file and an Excel spreadsheet
std::string plotTitle = "kinetics example 3: constant-pressure ignition";
plotSoln("kin3.dat", "TEC", plotTitle, gas, soln);
plotSoln("kin3.csv", "XL", plotTitle, gas, soln);
plotSoln("kin3.dat", "TEC", plotTitle, sol->thermo(), soln);
plotSoln("kin3.csv", "XL", plotTitle, sol->thermo(), soln);
// print final temperature

View file

@ -9,7 +9,7 @@
>>>>> example 1
Description:
Ignition simulation using class IdealGasMix with file gri30.cti.
Ignition simulation using class IdealGasPhase with file gri30.yaml.
Constant-pressure ignition of a hydrogen/oxygen/nitrogen mixture
beginning at T = 1001 K and P = 1 atm.
Tfinal = 2663.78
@ -23,7 +23,7 @@ Output files:
>>>>> example 2
Description:
Ignition simulation using class IdealGasMix with file gri30.cti.
Ignition simulation using class IdealGasPhase with file gri30.yaml.
Constant-pressure ignition of a hydrogen/oxygen/nitrogen mixture
beginning at T = 1001 K and P = 1 atm.
Tfinal = 2663.78
@ -82,7 +82,7 @@ Output files:
>>>>> example 5
>>>>> example 4
Description:
Mixture-averaged transport properties.
@ -95,7 +95,7 @@ Output files:
>>>>> example 6
>>>>> example 5
Description:
Multicomponent transport properties.

View file

@ -9,15 +9,15 @@
#include "cantera/zerodim.h"
#include "example_utils.h"
#include "cantera/reactionpaths.h"
#include "cantera/IdealGasMix.h"
#include "cantera/kinetics/ReactionPath.h"
#include "cantera/thermo/IdealGasPhase.h"
using namespace Cantera;
using std::cout;
using std::endl;
void writeRxnPathDiagram(double time, ReactionPathBuilder& b,
IdealGasMix& gas, std::ostream& logfile, std::ostream& outfile)
Kinetics& kin, std::ostream& logfile, std::ostream& outfile)
{
// create a new empty diagram
ReactionPathDiagram d;
@ -63,7 +63,7 @@ void writeRxnPathDiagram(double time, ReactionPathBuilder& b,
d.title = fmt::format("time = {} (s)", time);
// build the diagram following elemental nitrogen
b.build(gas, "N", logfile, d);
b.build(kin, "N", logfile, d);
// write an input file for 'dot'
d.exportToDot(outfile);
@ -88,19 +88,17 @@ int rxnpath_example1(int job)
// create an ideal gas mixture that corresponds to GRI-Mech
// 3.0
IdealGasMix gas("gri30.xml", "gri30");
gas.setState_TPX(1001.0, OneAtm, "H2:2.0, O2:1.0, N2:4.0");
auto sol = newSolution("gri30.yaml", "gri30", "None");
auto gas = getIdealGasPhasePtr(sol);
gas->setState_TPX(1001.0, OneAtm, "H2:2.0, O2:1.0, N2:4.0");
// create a reactor
Reactor r;
r.insert(sol);
// create a reservoir to represent the environment
Reservoir env;
// specify the thermodynamic property and kinetics managers
r.setThermoMgr(gas);
r.setKineticsMgr(gas);
env.setThermoMgr(gas);
env.insert(sol);
// create a flexible, insulating wall between the reactor and the
// environment
@ -126,13 +124,13 @@ int rxnpath_example1(int job)
ReactionPathBuilder b;
std::ofstream rplog("rp1.log"); // log file
std::ofstream rplot("rp1.dot"); // output file
b.init(rplog, gas); // initialize
b.init(rplog, sol->kinetics()); // initialize
// main loop
for (int i = 1; i <= nsteps; i++) {
tm = i*dt;
sim.advance(tm);
writeRxnPathDiagram(tm, b, gas, rplog, rplot);
writeRxnPathDiagram(tm, b, sol->kinetics(), rplog, rplot);
}
// print final temperature

View file

@ -9,7 +9,7 @@
#include "cantera/transport.h"
#include "example_utils.h"
#include "cantera/IdealGasMix.h"
#include "cantera/thermo/IdealGasPhase.h"
using namespace Cantera;
using std::cout;
@ -30,17 +30,18 @@ int transport_example1(int job)
// create a gas mixture, and set its state
IdealGasMix gas("gri30.xml", "gri30");
auto sol = newSolution("gri30.yaml", "gri30", "Mix");
auto gas = getIdealGasPhasePtr(sol);
doublereal temp = 500.0;
doublereal pres = 2.0*OneAtm;
gas.setState_TPX(temp, pres, "H2:1.0, CH4:0.1");
gas->setState_TPX(temp, pres, "H2:1.0, CH4:0.1");
// create a transport manager that implements
// mixture-averaged transport properties
Transport* tr = newTransportMgr("Mix", &gas);
auto tr = sol->transportPtr();
size_t nsp = gas.nSpecies();
size_t nsp = gas->nSpecies();
// create a 2D array to hold the outputs
@ -50,7 +51,7 @@ int transport_example1(int job)
// main loop
for (int i = 0; i < ntemps; i++) {
temp = 500.0 + 100.0*i;
gas.setState_TP(temp, pres);
gas->setState_TP(temp, pres);
output(0,i) = temp;
output(1,i) = tr->viscosity();
output(2,i) = tr->thermalConductivity();
@ -60,8 +61,8 @@ int transport_example1(int job)
// make a Tecplot data file and an Excel spreadsheet
std::string plotTitle = "transport example 1: "
"mixture-averaged transport properties";
plotTransportSoln("tr1.dat", "TEC", plotTitle, gas, output);
plotTransportSoln("tr1.csv", "XL", plotTitle, gas, output);
plotTransportSoln("tr1.dat", "TEC", plotTitle, sol->thermo(), output);
plotTransportSoln("tr1.csv", "XL", plotTitle, sol->thermo(), output);
// print final temperature
cout << "Output files:" << endl

View file

@ -9,7 +9,7 @@
#include "cantera/transport.h"
#include "example_utils.h"
#include "cantera/IdealGasMix.h"
#include "cantera/thermo/IdealGasPhase.h"
using namespace Cantera;
using std::cout;
@ -30,17 +30,18 @@ int transport_example2(int job)
// create a gas mixture, and set its state
IdealGasMix gas("gri30.xml", "gri30");
auto sol = newSolution("gri30.yaml", "gri30", "Multi");
auto gas = getIdealGasPhasePtr(sol);
doublereal temp = 2000.0;
doublereal pres = 2.0*OneAtm;
gas.setState_TPX(temp, pres, "H2:1.0, O2:0.5, CH4:0.1, N2:0.2");
gas.equilibrate("TP");
gas->setState_TPX(temp, pres, "H2:1.0, O2:0.5, CH4:0.1, N2:0.2");
gas->equilibrate("TP");
// create a transport manager that implements
// multicomponent transport properties
Transport* tr = newTransportMgr("Multi", &gas);
size_t nsp = gas.nSpecies();
auto tr = sol->transportPtr();
size_t nsp = gas->nSpecies();
// create a 2D array to hold the outputs
int ntemps = 20;
@ -49,7 +50,7 @@ int transport_example2(int job)
// main loop
for (int i = 0; i < ntemps; i++) {
temp = 500.0 + 100.0*i;
gas.setState_TP(temp, pres);
gas->setState_TP(temp, pres);
output(0,i) = temp;
output(1,i) = tr->viscosity();
output(2,i) = tr->thermalConductivity();
@ -59,8 +60,8 @@ int transport_example2(int job)
// make a Tecplot data file and an Excel spreadsheet
std::string plotTitle = "transport example 2: "
"multicomponent transport properties";
plotTransportSoln("tr2.dat", "TEC", plotTitle, gas, output);
plotTransportSoln("tr2.csv", "XL", plotTitle, gas, output);
plotTransportSoln("tr2.dat", "TEC", plotTitle, sol->thermo(), output);
plotTransportSoln("tr2.csv", "XL", plotTitle, sol->thermo(), output);
// print final temperature
cout << "Output files:" << endl

View file

@ -3,6 +3,9 @@
* test problem for mixture transport
*/
// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.
// Example
//
// Test case for mixture transport in a gas
@ -17,10 +20,10 @@
// perhaps, later, an analytical solution could be added
#include "cantera/transport.h"
#include "cantera/thermo/IdealGasPhase.h"
#include "cantera/transport/MixTransport.h"
#include "cantera/IdealGasMix.h"
#include <cstdio>
#include <iostream>
using namespace std;
using namespace Cantera;
@ -33,8 +36,9 @@ int main(int argc, char** argv)
string infile = "diamond.xml";
try {
IdealGasMix g("gri30.xml", "gri30_mix");
size_t nsp = g.nSpecies();
auto sol = newSolution("gri30.yaml", "gri30", "Mix");
auto gas = getIdealGasPhasePtr(sol);
size_t nsp = gas->nSpecies();
double pres = 1.0E5;
vector_fp Xset(nsp, 0.0);
Xset[0] = 0.269205 ;
@ -129,17 +133,16 @@ int main(int argc, char** argv)
grad_T[0] = (T2 - T1) / dist;
grad_T[1] = (T3 - T1) / dist;
int log_level = 0;
Transport* tran = newTransportMgr("Mix", &g, log_level=0);
MixTransport* tranMix = dynamic_cast<MixTransport*>(tran);
g.setState_TPX(1500.0, pres, Xset.data());
auto tran = sol->transportPtr();
auto tranMix = dynamic_pointer_cast<MixTransport>(tran);
gas->setState_TPX(1500.0, pres, Xset.data());
vector_fp mixDiffs(nsp, 0.0);
tranMix->getMixDiffCoeffs(mixDiffs.data());
printf(" Dump of the mixture Diffusivities:\n");
for (size_t k = 0; k < nsp; k++) {
string sss = g.speciesName(k);
string sss = gas->speciesName(k);
printf(" %15s %13.5g\n", sss.c_str(), mixDiffs[k]);
}
@ -148,7 +151,7 @@ int main(int argc, char** argv)
tranMix->getSpeciesViscosities(specVisc.data());
printf(" Dump of the species viscosities:\n");
for (size_t k = 0; k < nsp; k++) {
string sss = g.speciesName(k);
string sss = gas->speciesName(k);
printf(" %15s %13.5g\n", sss.c_str(), specVisc[k]);
}
@ -156,27 +159,27 @@ int main(int argc, char** argv)
tranMix->getThermalDiffCoeffs(thermDiff.data());
printf(" Dump of the Thermal Diffusivities :\n");
for (size_t k = 0; k < nsp; k++) {
string sss = g.speciesName(k);
string sss = gas->speciesName(k);
printf(" %15s %13.5g\n", sss.c_str(), thermDiff[k]);
}
printf("Viscosity and thermal Cond vs. T\n");
for (size_t k = 0; k < 10; k++) {
T1 = 400. + 100. * k;
g.setState_TPX(T1, pres, Xset.data());
gas->setState_TPX(T1, pres, Xset.data());
double visc = tran->viscosity();
double cond = tran->thermalConductivity();
printf(" %13.4g %13.4g %13.4g\n", T1, visc, cond);
}
g.setState_TPX(T1, pres, Xset.data());
gas->setState_TPX(T1, pres, Xset.data());
Array2D Bdiff(nsp, nsp, 0.0);
printf("Binary Diffusion Coefficients H2 vs species\n");
tranMix->getBinaryDiffCoeffs(nsp, Bdiff.ptrColumn(0));
for (size_t k = 0; k < nsp; k++) {
string sss = g.speciesName(k);
string sss = gas->speciesName(k);
printf(" H2 - %15s %13.4g %13.4g\n", sss.c_str(), Bdiff(0,k), Bdiff(k,0));
}
@ -186,7 +189,7 @@ int main(int argc, char** argv)
tranMix->getMobilities(specMob.data());
printf(" Dump of the species mobilities:\n");
for (size_t k = 0; k < nsp; k++) {
string sss = g.speciesName(k);
string sss = gas->speciesName(k);
printf(" %15s %13.4g\n", sss.c_str(), specMob[k]);
}
@ -200,7 +203,7 @@ int main(int argc, char** argv)
double max1 = 0.0;
double max2 = 0.0;
for (size_t k = 0; k < nsp; k++) {
string sss = g.speciesName(k);
string sss = gas->speciesName(k);
printf(" %15s %13.4g %13.4g\n", sss.c_str(), fluxes(k,0), fluxes(k,1));
sum1 += fluxes(k,0);
if (fabs(fluxes(k,0)) > max1) {

View file

@ -3,6 +3,9 @@
* test problem for multi transport
*/
// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.
// Example
//
// Test case for mixture transport in a gas
@ -17,11 +20,10 @@
// perhaps, later, an analytical solution could be added
#include "cantera/transport.h"
#include "cantera/thermo/IdealGasPhase.h"
#include "cantera/transport/MultiTransport.h"
#include "cantera/IdealGasMix.h"
#include <cstdio>
#include <iostream>
using namespace std;
using namespace Cantera;
@ -42,8 +44,9 @@ int main(int argc, char** argv)
string infile = "diamond.xml";
try {
IdealGasMix g("gri30.xml", "gri30_mix");
size_t nsp = g.nSpecies();
auto sol = newSolution("gri30.yaml", "gri30", "Multi");
auto gas = getIdealGasPhasePtr(sol);
size_t nsp = gas->nSpecies();
double pres = 1.0E5;
vector_fp Xset(nsp, 0.0);
Xset[0] = 0.269205 ;
@ -138,16 +141,15 @@ int main(int argc, char** argv)
grad_T[0] = (T2 - T1) / dist;
grad_T[1] = (T3 - T1) / dist;
int log_level = 0;
Transport* tran = newTransportMgr("Multi", &g, log_level=0);
MultiTransport* tranMix = dynamic_cast<MultiTransport*>(tran);
g.setState_TPX(1500.0, pres, Xset.data());
auto tran = sol->transportPtr();
auto tranMix = dynamic_pointer_cast<MultiTransport>(tran);
gas->setState_TPX(1500.0, pres, Xset.data());
vector_fp mixDiffs(nsp, 0.0);
tranMix->getMixDiffCoeffs(mixDiffs.data());
printf(" Dump of the mixture Diffusivities:\n");
for (size_t k = 0; k < nsp; k++) {
string sss = g.speciesName(k);
string sss = gas->speciesName(k);
printf(" %15s %13.2g\n", sss.c_str(), mixDiffs[k]);
}
@ -155,7 +157,7 @@ int main(int argc, char** argv)
tranMix->getSpeciesViscosities(specVisc.data());
printf(" Dump of the species viscosities:\n");
for (size_t k = 0; k < nsp; k++) {
string sss = g.speciesName(k);
string sss = gas->speciesName(k);
printf(" %15s %13.4g\n", sss.c_str(), specVisc[k]);
}
@ -163,7 +165,7 @@ int main(int argc, char** argv)
tranMix->getThermalDiffCoeffs(thermDiff.data());
printf(" Dump of the Thermal Diffusivities :\n");
for (size_t k = 0; k < nsp; k++) {
string sss = g.speciesName(k);
string sss = gas->speciesName(k);
double ddd = cutoff(thermDiff[k]);
printf(" %15s %13.4g\n", sss.c_str(), ddd);
}
@ -171,20 +173,20 @@ int main(int argc, char** argv)
printf("Viscosity and thermal Cond vs. T\n");
for (size_t k = 0; k < 10; k++) {
T1 = 400. + 100. * k;
g.setState_TPX(T1, pres, Xset.data());
gas->setState_TPX(T1, pres, Xset.data());
double visc = tran->viscosity();
double cond = tran->thermalConductivity();
printf(" %13g %13.4g %13.4g\n", T1, visc, cond);
}
g.setState_TPX(T1, pres, Xset.data());
gas->setState_TPX(T1, pres, Xset.data());
Array2D Bdiff(nsp, nsp, 0.0);
printf("Binary Diffusion Coefficients H2 vs species\n");
tranMix->getBinaryDiffCoeffs(nsp, Bdiff.ptrColumn(0));
for (size_t k = 0; k < nsp; k++) {
string sss = g.speciesName(k);
string sss = gas->speciesName(k);
printf(" H2 - %15s %13.4g %13.4g\n", sss.c_str(), Bdiff(0,k), Bdiff(k,0));
}
@ -192,7 +194,7 @@ int main(int argc, char** argv)
printf(" Dump of the species mobilities:\n");
for (size_t k = 0; k < nsp; k++) {
string sss = g.speciesName(k);
string sss = gas->speciesName(k);
printf(" %15s %13.4g\n", sss.c_str(), specMob[k]);
}
@ -205,7 +207,7 @@ int main(int argc, char** argv)
double max1 = 0.0;
double max2 = 0.0;
for (size_t k = 0; k < nsp; k++) {
string sss = g.speciesName(k);
string sss = gas->speciesName(k);
double ddd = cutoff(fluxes(k,0));
double eee = cutoff(fluxes(k,1));
printf(" %15s %13.4g %13.4g\n", sss.c_str(), ddd, eee);
@ -237,7 +239,7 @@ int main(int argc, char** argv)
tranMix->getMultiDiffCoeffs(nsp, MDdiff.ptrColumn(0));
for (size_t k = 0; k < nsp; k++) {
string sss = g.speciesName(k);
string sss = gas->speciesName(k);
printf(" H2 - %15s %13.4g %13.4g\n", sss.c_str(), MDdiff(0,k), MDdiff(k,0));
}

View file

@ -1,7 +1,9 @@
// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.
#include "cantera/IdealGasMix.h"
#include "cantera/thermo/IdealGasPhase.h"
#include <iostream>
using namespace std;
using namespace Cantera;
@ -12,9 +14,10 @@ int main(int argc, char** argv)
_set_output_format(_TWO_DIGIT_EXPONENT);
#endif
try {
IdealGasMix g("silane.xml", "silane");
g.setState_TPX(1500.0, 100.0, "SIH4:0.01, H2:0.99");
g.equilibrate("TP");
auto sol = newSolution("silane.xml", "silane");
auto gas = getIdealGasPhasePtr(sol);
gas->setState_TPX(1500.0, 100.0, "SIH4:0.01, H2:0.99");
gas->equilibrate("TP");
return 0;
} catch (CanteraError& err) {
std::cerr << err.what() << std::endl;

View file

@ -12,9 +12,10 @@
// using Placid.
//
#include "cantera/Interface.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/kinetics.h"
#include "cantera/kinetics/ImplicitSurfChem.h"
#include "cantera/kinetics/InterfaceKinetics.h"
#include "cantera/kinetics/solveSP.h"
#include "cantera/base/fmt.h"
#include <cstdio>

View file

@ -21,9 +21,10 @@ static void printUsage()
{
}
#include "cantera/Interface.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/kinetics.h"
#include "cantera/kinetics/ImplicitSurfChem.h"
#include "cantera/kinetics/InterfaceKinetics.h"
#include "cantera/kinetics/solveSP.h"
#include "cantera/base/fmt.h"
#include <cstdio>

View file

@ -1,10 +1,16 @@
// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.
/*
* Sample program that solves an implicit problem for surface
* site fractions.
*/
#include "cantera/IdealGasMix.h"
#include "cantera/Interface.h"
#include "cantera/thermo/IdealGasPhase.h"
#include "cantera/thermo/SurfPhase.h"
#include "cantera/kinetics/InterfaceKinetics.h"
#include <iostream>
using namespace Cantera;
using namespace std;
@ -12,24 +18,27 @@ using namespace std;
int main()
{
try {
IdealGasMix gas("gri30.xml", "gri30");
gas.setState_TPX(1200.0, OneAtm,
"H2:2, O2:1, OH:0.01, H:0.01, O:0.01");
auto sol = newSolution("gri30.yaml", "gri30");
auto gas = getIdealGasPhasePtr(sol);
gas->setState_TPX(1200.0, OneAtm,
"H2:2, O2:1, OH:0.01, H:0.01, O:0.01");
auto surf = newSolution("surface.xml", "surface", "None", {sol});
auto surf_ph = getSurfPhasePtr(surf);
auto surf_kin = getInterfaceKineticsPtr(surf);
vector<ThermoPhase*> phases { &gas };
Interface surf("surface.xml", "surface", phases);
vector_fp cov { 0.8, 0.2 };
cout.precision(4);
surf.setCoverages(cov.data());
vector_fp wdot(gas.nSpecies() + surf.nSpecies());
surf.getNetProductionRates(wdot.data());
for (size_t k = 0; k < gas.nSpecies(); k++) {
cout << gas.speciesName(k) << " " << wdot[k] << endl;
surf_ph->setCoverages(cov.data());
vector_fp wdot(gas->nSpecies() + surf_ph->nSpecies());
surf_kin->getNetProductionRates(wdot.data());
for (size_t k = 0; k < gas->nSpecies(); k++) {
cout << gas->speciesName(k) << " " << wdot[k] << endl;
}
for (size_t k = 0; k < surf.nSpecies(); k++) {
cout << surf.speciesName(k) << " "
<< wdot[k+gas.nSpecies()] << endl;
for (size_t k = 0; k < surf_ph->nSpecies(); k++) {
cout << surf_ph->speciesName(k) << " "
<< wdot[k+gas->nSpecies()] << endl;
}
} catch (CanteraError& err) {
std::cout << err.what() << std::endl;