#include <cantera/thermo.h>
#include "cantera/IdealGasMix.h"
#include "cantera/zerodim.h"
#include <iostream>
#include <fstream>
using namespace Cantera;
int runSimplePSR() {
double mDot = 1.0; //The current mass flow rate [kg/s]
double Vol; //Volume of the PSR
double Tfinal = 1.0;
IdealGasMix gas("Mechanism.cti");
IdealGasMix gas2("Mechanism.cti");
IdealGasMix gas3("Mechanism.cti");
IdealGasMix gas4("Mechanism.cti");
IdealGasMix gasIn("Mechanism.cti");
gas.setState_TPX(1000.0, 30.0*OneAtm, "KERO_LUCHE:1, O2:15.0");
gasIn.setState_TPX(800.0, 30.0*OneAtm, "KERO_LUCHE:1, O2:15.0");
IdealGasReactor PSR; IdealGasReactor PSR2; IdealGasReactor PSR3; IdealGasReactor PSR4;
PSR.insert(gas); PSR2.insert(gas2); PSR3.insert(gas3); PSR4.insert(gas4);
Vol = 0.01;
PSR.setInitialVolume(Vol); PSR2.setInitialVolume(Vol); PSR3.setInitialVolume(Vol); PSR4.setInitialVolume(Vol);
Reservoir envIn; Reservoir envOut;
envIn.insert(gasIn); envOut.insert(gas);
Wall wall; Wall wall2; Wall wall3; Wall wall4;
wall.install(PSR, envIn); wall2.install(PSR, PSR2); wall3.install(PSR2, PSR3); wall4.install(PSR3, PSR4);
wall.setArea(1.0);
wall.setExpansionRateCoeff(1.0e6);
wall2.setArea(1.0);
wall2.setExpansionRateCoeff(1.0e6);
wall3.setArea(1.0);
wall3.setExpansionRateCoeff(1.0e6);
wall4.setArea(1.0);
wall4.setExpansionRateCoeff(1.0e6);
MassFlowController mfcIn;
MassFlowController mfcOut;
MassFlowController mfc1;
MassFlowController mfc2;
MassFlowController mfc3;
mfcIn.install(envIn, PSR);
mfc1.install(PSR, PSR2);
mfc2.install(PSR2, PSR3);
mfc3.install(PSR3, PSR4);
mfcOut.install(PSR, envOut);
mfcIn.setMassFlowRate(mDot);
mfc1.setMassFlowRate(mDot);
mfc2.setMassFlowRate(mDot);
mfc3.setMassFlowRate(mDot);
mfcOut.setMassFlowRate(mDot);
ReactorNet net;
/* Insert the PSR into the network */
net.addReactor(PSR);
net.addReactor(PSR2);
net.addReactor(PSR3);
net.addReactor(PSR4);
std::ofstream reactorStream;
reactorStream.open("CanteraResults.dat");
double t = 0.0;
double dt = 1.0e-3;
reactorStream << "time temperature pressure density volume MFR resTime ";
for (int i=0; i<gas.nSpecies(); i++) reactorStream << gas.speciesName(i) << " ";
reactorStream << std::endl;
while (net.time() < Tfinal) { //Time less than 1 seconds
ThermoPhase& conts = PSR.contents();
std::cout << net.time() << " " << PSR.temperature() << " " << PSR.pressure() << " " << PSR.density() << " " << PSR.volume() << " " << " " << mDot << " " << PSR.density()*PSR.volume()/mDot << std::endl;
reactorStream << net.time() << " " << PSR.temperature() << " " << PSR.pressure() << " " << PSR.density() << " " << PSR.volume() << " " << " " << mDot << " " << PSR.density()*PSR.volume()/mDot << " " ;
for (int i=0; i<gas.nSpecies(); i++) reactorStream << conts.moleFraction(i) << " ";
reactorStream << std::endl;
net.step(dt);
t += dt;
}
return 0;
}
int main() {
/* Try to run the PSR */
try {
runSimplePSR();
}
/* This *should* handle ANY exception thrown by Cantera */
catch (CanteraError& err) {
std::cout << err.what() << std::endl;
}
return 0;
}
...net.step(dt)net.step(Tfinal)double t = 0;
//while loop etc.
net.advance(t + dt);
t += dt;Hi,
I think the first thing you need to fix is how your MassFlowControllers are connected: mfcOut should presumably connect PSR4 to envOut, not PSR to envOut. You also probably want to set the initial state of the other IdealGasMix objects so that the initial pressure is the same in each reactor.
The issue with the expansion coefficients isn’t that you’re setting a delta-P, it’s that a delta-P always exists during the transient (since the pressure is an independent variable for each reactor) and that there is a time constant associated with equalizing that that is inversely proportional to the expansion rate coefficient.
That said, I think you want to avoid walls entirely here, since using them means that your steady state will end up with each reactor having some arbitrary volume based on how the walls move during the initial transient. Instead, what you should use is a MassFlowController connecting the inlet to the first PSR, then use PressureController to connect each successive PSR. For each PressureController, you need to call the “setMaster” to associate it with the mass flow controller, and setParameters to set the value of the pressure coefficient. For example:
PressureController pc1;
pc1.setMaster(&mfcIn);
double pressureCoeff = 0.1; // kg/s/Pa
pc1.setParameters(1, &pressureCoeff);
pc1.install(PSR, PSR2);
Regards,
Ray