/*! * @file flamespeed.cpp * C++ demo program to compute flame speeds using GRI-Mech. */ #include "cantera/oneD/Sim1D.h" #include "cantera/oneD/Inlet1D.h" #include "cantera/oneD/StFlow.h" #include "cantera/IdealGasMix.h" #include "cantera/transport.h" #include using namespace Cantera; using fmt::print; int flamespeed(double phi) { try { IdealGasMix gas("gri30.cti","gri30_mix"); doublereal temp = 300.0; // K doublereal pressure = 1.0*OneAtm; //atm doublereal uin = 0.3; //m/sec size_t nsp = gas.nSpecies(); vector_fp x(nsp, 0.0); doublereal C_atoms = 1.0; doublereal H_atoms = 4.0; doublereal ax = C_atoms + H_atoms / 4.0; doublereal fa_stoic = 1.0 / (4.76 * ax); x[gas.speciesIndex("CH4")] = 1.0; x[gas.speciesIndex("O2")] = 0.21 / phi / fa_stoic; x[gas.speciesIndex("N2")] = 0.79 / phi/ fa_stoic; gas.setState_TPX(temp, pressure, x.data()); doublereal rho_in = gas.density(); vector_fp yin(nsp); gas.getMassFractions(&yin[0]); gas.equilibrate("HP"); vector_fp yout(nsp); gas.getMassFractions(&yout[0]); doublereal rho_out = gas.density(); doublereal Tad = gas.temperature(); print("phi = {}, Tad = {}\n", phi, Tad); //============= build each domain ======================== //-------- step 1: create the flow ------------- StFlow flow(&gas); flow.setFreeFlow(); // create an initial grid int nz = 6; doublereal lz = 0.1; vector_fp z(nz); doublereal dz = lz/((doublereal)(nz-1)); for (int iz = 0; iz < nz; iz++) { z[iz] = ((doublereal)iz)*dz; } flow.setupGrid(nz, &z[0]); // specify the objects to use to compute kinetic rates and // transport properties std::unique_ptr trmix(newTransportMgr("Mix", &gas)); std::unique_ptr trmulti(newTransportMgr("Multi", &gas)); flow.setTransport(*trmix); flow.setKinetics(gas); flow.setPressure(pressure); //------- step 2: create the inlet ----------------------- Inlet1D inlet; inlet.setMoleFractions(x.data()); doublereal mdot=uin*rho_in; inlet.setMdot(mdot); inlet.setTemperature(temp); //------- step 3: create the outlet --------------------- Outlet1D outlet; //=================== create the container and insert the domains ===== std::vector domains { &inlet, &flow, &outlet }; Sim1D flame(domains); //----------- Supply initial guess---------------------- vector_fp locs{0.0, 0.3, 0.7, 1.0}; vector_fp value; double uout = inlet.mdot()/rho_out; value = {uin, uin, uout, uout}; flame.setInitialGuess("u",locs,value); value = {temp, temp, Tad, Tad}; flame.setInitialGuess("T",locs,value); for (size_t i=0; i> phi; return flamespeed(phi); }