initial import
This commit is contained in:
parent
41a79ca93b
commit
f2b41f8794
2 changed files with 169 additions and 0 deletions
58
Cantera/cxx/demos/example_utils.h
Normal file
58
Cantera/cxx/demos/example_utils.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#ifndef CT_EXAMPLE_UTILS_H
|
||||
#define CT_EXAMPLE_UTILS_H
|
||||
|
||||
#include "kernel/Array.h"
|
||||
#include "kernel/plots.h"
|
||||
|
||||
// Save the temperature, density, pressure, and mole fractions at one
|
||||
// time
|
||||
template<class G, class A>
|
||||
void saveSoln(int i, double time, const G& gas, A& soln) {
|
||||
soln(0,i) = time;
|
||||
soln(1,i) = gas.temperature();
|
||||
soln(2,i) = gas.density();
|
||||
soln(3,i) = gas.pressure();
|
||||
gas.getMoleFractions(&soln(4,i));
|
||||
}
|
||||
|
||||
template<class G, class A>
|
||||
void saveSoln(double time, const G& gas, A& soln) {
|
||||
soln.resize(soln.nRows(), soln.nColumns() + 1);
|
||||
int back = soln.nColumns() - 1;
|
||||
soln(0,back) = time;
|
||||
soln(1,back) = gas.temperature();
|
||||
soln(2,back) = gas.density();
|
||||
soln(3,back) = gas.pressure();
|
||||
int nsp = gas.nSpecies();
|
||||
for (int k = 0; k < nsp; k++)
|
||||
soln(4+k,back) = gas.moleFraction(k);
|
||||
}
|
||||
|
||||
template<class G, class V>
|
||||
void makeDataLabels(const G& gas, V& names) {
|
||||
int nsp = gas.nSpecies();
|
||||
names.resize(nsp + 4);
|
||||
names[0] = "time (s)";
|
||||
names[1] = "Temperature (K)";
|
||||
names[2] = "Density (kg/m3)";
|
||||
names[3] = "Pressure (Pa)";
|
||||
int k;
|
||||
for (k = 0; k < nsp; k++) names[4+k] = gas.speciesName(k);
|
||||
}
|
||||
|
||||
template<class G, class A>
|
||||
void plotSoln(string fname, string fmt, string title, const G& gas, const A& soln) {
|
||||
vector<string> names;
|
||||
makeDataLabels(gas, names);
|
||||
writePlotFile(fname, fmt, title, names, soln);
|
||||
}
|
||||
|
||||
inline void writeCanteraHeader(ostream& s) {
|
||||
s << endl;
|
||||
s << " Cantera version " << CANTERA_VERSION << endl;
|
||||
s << " Copyright California Institute of Technology, 2002." << endl;
|
||||
s << " http://www.cantera.org" << endl;
|
||||
s << endl;
|
||||
}
|
||||
|
||||
#endif
|
||||
111
Cantera/cxx/demos/kinetics1.cpp
Normal file
111
Cantera/cxx/demos/kinetics1.cpp
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// zero-dimensional kinetics example program
|
||||
//
|
||||
// $Author$
|
||||
// $Revision$
|
||||
// $Date$
|
||||
//
|
||||
// copyright California Institute of Technology 2002
|
||||
//
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
// turn off warnings under Windows
|
||||
#ifdef WIN32
|
||||
#pragma warning(disable:4786)
|
||||
#pragma warning(disable:4503)
|
||||
#endif
|
||||
|
||||
#include <cantera/zerodim.h>
|
||||
#include <cantera/IdealGasMix.h>
|
||||
#include <time.h>
|
||||
#include "example_utils.h"
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
try {
|
||||
|
||||
cout << "Constant-pressure ignition of a "
|
||||
<< "hydrogen/oxygen/nitrogen"
|
||||
" mixture \nbeginning at T = 1001 K and P = 1 atm." << endl;
|
||||
|
||||
// create an ideal gas mixture that corresponds to GRI-Mech
|
||||
// 3.0
|
||||
IdealGasMix* gg = new IdealGasMix("gri30.cti", "gri30");
|
||||
IdealGasMix& gas = *gg;
|
||||
|
||||
// set the state
|
||||
gas.setState_TPX(1001.0, OneAtm, "H2:2.0, O2:1.0, N2:4.0");
|
||||
int nsp = gas.nSpecies();
|
||||
|
||||
// create a reactor
|
||||
Reactor r;
|
||||
|
||||
// create a reservoir to represent the environment
|
||||
Reservoir env;
|
||||
|
||||
// specify the thermodynamic property and kinetics managers
|
||||
r.insert(gas);
|
||||
env.insert(gas);
|
||||
|
||||
// create a flexible, insulating wall between the reactor and the
|
||||
// environment
|
||||
Wall w;
|
||||
w.install(r,env);
|
||||
|
||||
// set the "expansion rate coefficient" to a large value, in order to
|
||||
// approach the constant-pressure limit; see the documentation
|
||||
// for class Reactor
|
||||
w.setExpansionRateCoeff(1.e9);
|
||||
w.setArea(1.0);
|
||||
|
||||
double tm;
|
||||
double dt = 1.e-5; // interval at which output is written
|
||||
int nsteps = 100; // number of intervals
|
||||
|
||||
// create a 2D array to hold the output variables,
|
||||
// and store the values for the initial state
|
||||
Array2D soln(nsp+4, 1);
|
||||
saveSoln(0, 0.0, gas, soln);
|
||||
|
||||
// main loop
|
||||
clock_t t0 = clock();
|
||||
for (int i = 1; i <= nsteps; i++) {
|
||||
tm = i*dt;
|
||||
r.advance(tm);
|
||||
saveSoln(tm, gas, soln);
|
||||
}
|
||||
clock_t t1 = clock();
|
||||
|
||||
|
||||
// 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);
|
||||
|
||||
|
||||
// print final temperature and timing data
|
||||
doublereal tmm = 1.0*(t1 - t0)/CLOCKS_PER_SEC;
|
||||
cout << " Tfinal = " << r.temperature() << endl;
|
||||
cout << " time = " << tmm << endl;
|
||||
cout << " number of residual function evaluations = "
|
||||
<< r.integrator().nEvals() << endl;
|
||||
cout << " time per evaluation = " << tmm/r.integrator().nEvals()
|
||||
<< endl << endl;
|
||||
cout << "Output files:" << endl
|
||||
<< " kin1.csv (Excel CSV file)" << endl
|
||||
<< " kin1.dat (Tecplot data file)" << endl;
|
||||
|
||||
delete gg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// handle exceptions thrown by Cantera
|
||||
catch (CanteraError) {
|
||||
showErrors(cout);
|
||||
cout << " terminating... " << endl;
|
||||
appdelete();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue