#include <cantera/Cantera.h>
#include <cantera/zerodim.h>
#include <cantera/IdealGasMix.h>
#include <iomanip>
#include "wsr.h"
using namespace CanteraZeroD;
OutputStructure wsr(InputStructure input, int i, int j) {
OutputStructure output;
double tign = 0;
// Reaction mechanism
IdealGasMix gas(input.KinMech + ".cti", input.KinMech);
int nsp = gas.nSpecies();
// Create a reservoir for the fuel inlet, and set to pure methane.
Reservoir fuel_in;
gas.setState_TPX(300.0, OneAtm, input.MolecularFormula + ":1.0");
fuel_in.insert(gas);
double fuel_mw = gas.meanMolecularWeight();
// Create a reservoir for the air inlet
Reservoir air_in;
IdealGasMix air("air.cti");
gas.setState_TPX(300.0, OneAtm, "N2:0.78, O2:0.21, AR:0.01");
double air_mw = air.meanMolecularWeight();
air_in.insert(gas);
// To ignite the fuel/air mixture, we'll introduce heat through a
wall.
// We'll create a reservoir to represent the environment and the
wall
// that separates the reactor from the environment.
gas.setState_TPX(300.0, OneAtm, "N2:0.78, O2:0.21, AR:0.01");
Reservoir env;
env.insert(gas);
// Create a reservoir for the exhaust. The initial composition
// doesn't matter.
Reservoir exhaust;
exhaust.insert(gas);
// Create the combustor, and fill it in initially with N2
double* MoleFArray = &input.MoleF[0]; //Converstion Vector to
Array
// input.MoleF is read from csv file containing 53 species mole
fraction evalueted in previous run of software
gas.setState_TPX(input.Temperature, input.Pressure, MoleFArray);
Reactor combustor;
combustor.insert(gas);
combustor.setInitialVolume(input.CombustorVolume);
// Create the wall through which passes the heat flux that allows
the ignition of the mixture
// The wall will use a Guassian 'functor' object to specify the
time-dependent heat flux.
Gaussian heat(input.A, input.t_0, input.FWHM);
Wall w;
w.install(env, combustor);
w.setArea(1.0);
w.setHeatFlux(&heat);
// Compute fuel and air mass flow rates
air_mdot ....
fuel_mdot ....
// Create and install the mass flow controllers. Controllers
// m1 and m2 provide constant mass flow rates
// Fuel mass flow controller.
MassFlowController m1;
m1.install(fuel_in, combustor);
m1.setFunction(&fuel_mdot);
// Now create the air mass flow controller.
MassFlowController m2;
m2.install(air_in, combustor);
m2.setFunction(&air_mdot);
// Put a valve on the exhaust line to regulate the pressure
PressureController v;
v.install(combustor, exhaust);
double Kv = 1e1;
v.setParameters(1, &Kv);
v.setMaster(&m2);
// Define the simulation time.
double tnow = input.ISimTime;
double ttot = 0.0;
double tres, tresnom; // Residence Time and Nominal Residence Time
double phi; // Equivalence Ratio
double Xf_in, Xair_in; // Fuel and Air Inlet Molar Fraction
// The simulation only contains one reactor
ReactorNet sim;
sim.addReactor(&combustor);
sim.setMaxTimeStep(0.5); // Set Max Time Step
sim.initialize(tnow); // Use this to assign the desired initial
time
//sim.setInitialTime(tnow);
// Simulation
double dt = 0.1; // Time step
double nsteps = (input.FSimTime - input.ISimTime)/dt;
for (int n = 1; n <= nsteps; n++) {
tnow += dt;
sim.advance(tnow); // Time to the current step
....
}
return output;