10#if defined(WITH_CANTERA)
23 m_speciesName(std::move(speciesName)) {
25#if not defined(WITH_CANTERA)
38#if defined(WITH_CANTERA)
45 std::vector<MFloat> X(noSpecies, 0.0);
50 std::vector<MFloat> YInlet(noSpecies, F0);
51 for(
MUint s = 0; s < noSpecies; ++s) {
62 std::vector<MFloat> YOutlet(noSpecies);
75 std::vector<MFloat> z(nz);
77 for(
int iz = 0; iz < nz; iz++) {
81 flow.setupGrid(nz, &z[0]);
83 std::unique_ptr<Cantera::Transport> trmix(
86 flow.setTransport(*trmix);
91 Cantera::Inlet1D inlet;
93 inlet.setMoleFractions(X.data());
95 inlet.setMdot(massFlow);
99 Cantera::Outlet1D outlet;
102 std::vector<Cantera::Domain1D*> domains{&inlet, &flow, &outlet};
103 Cantera::Sim1D flame(domains);
106 std::vector<MFloat> locs{0.0, 0.3, 0.7, 1.0};
107 std::vector<MFloat> value;
109 const double UOutlet = inlet.mdot() / rhoOutlet;
110 value = {UInlet, UInlet, UOutlet, UOutlet};
111 flame.setInitialGuess(
"velocity", locs, value);
113 flame.setInitialGuess(
"T", locs, value);
115 for(
size_t i = 0; i < noSpecies; i++) {
120 inlet.setMoleFractions(X.data());
121 inlet.setMdot(massFlow);
131 flame.setRefineCriteria(flowdomain, gridRatio, gridSlope, gridCurve, gridPrune);
133 flame.setMaxTimeStepCount(10000);
134 flame.setMaxGridPoints(flowdomain, 10000);
136 flame.setFixedTemperature(0.5 * (
m_TInlet + adiabaticT));
138 flame.solve(loglevel,
false);
139 flow.solveEnergyEqn();
140 flame.solve(loglevel,
true);
142 MFloat flameSpeedNew = flame.value(flowdomain, flow.componentIndex(
"velocity"), 0);
143 MFloat flameSpeedOld = 0.0;
146 MInt noIterations = 10;
149 for(
MInt iteration = 0; iteration < noIterations; ++iteration) {
153 flame.setRefineCriteria(flowdomain, gridRatio, gridSlope, gridCurve, gridPrune);
155 flame.solve(loglevel,
true);
157 flameSpeedOld = flameSpeedNew;
159 flameSpeedNew = flame.value(flowdomain, flow.componentIndex(
"velocity"), 0);
161 MFloat relError = fabs(flameSpeedNew - flameSpeedOld) / fabs(flameSpeedNew);
166 MInt noGridPoints = flow.nPoints();
170 mAlloc(
m_profile.temperature, noGridPoints,
"temperature", -9999.9, AT_);
171 mAlloc(
m_profile.massFractions, noSpecies * noGridPoints,
"massFractions", -9999.9, AT_);
173 for(
MInt n = 0; n < noGridPoints; ++n) {
174 m_profile.velocity[n] = flame.value(flowdomain, flow.componentIndex(
"velocity"), n);
175 m_profile.temperature[n] = flame.value(flowdomain, flow.componentIndex(
"T"), n);
176 m_grid.push_back(flow.grid(n));
178 for(
MUint s = 0; s < noSpecies; ++s) {
179 m_profile.massFractions[noSpecies * n + s] = flame.value(flowdomain, flow.componentIndex(
m_speciesName[s]), n);
184 "Vector m_oneGridSize has incorrect number of values, terminating now...");
186 std::vector<MFloat> dTdx(noGridPoints, 0.0);
187 MFloat maximumSlope = 0.0;
188 for(
MInt n = 1; n < (noGridPoints - 1); ++n) {
191 dTdx[n] = deltaT / deltaX;
192 if(dTdx[n] > maximumSlope) maximumSlope = dTdx[n];
202 const MFloat requiredFlameResolution = 10.0;
205 std::cerr <<
"Resolution at maximum refinement level: " << cellLengthAtMaxRfnLevel << std::endl;
206 std::cerr <<
"Flame front resolved by a total of " <<
m_laminarFlameThickness / cellLengthAtMaxRfnLevel <<
" cells"
210 <<
"Flame front is underresolved! Increase the refinement level to get an accurate solution! A resolution "
212 << requiredFlameResolution <<
"cells inside the flame front is required." << std::endl;
217#if defined(WITH_CANTERA)
void mAlloc(T *&a, const MLong N, const MString &objectName, MString function)
allocates memory for one-dimensional array 'a' of size N
const std::vector< MString > m_speciesName
struct OneDFlame::@22 m_profile
std::vector< MFloat > m_grid
PtrCanteraThermo m_canteraThermo
PtrCanteraSolution m_canteraSolution
MFloat m_fixedTemperatureLocation
MFloat m_laminarFlameThickness
void setCanteraObjects(PtrCanteraSolution, PtrCanteraThermo, PtrCanteraKinetics, PtrCanteraTransport)
PtrCanteraTransport m_canteraTransport
PtrCanteraKinetics m_canteraKinetics
OneDFlame(MFloat, MFloat, MFloat *, MInt, MInt, std::vector< MString >)
typename std::shared_ptr< Cantera::Transport > PtrCanteraTransport
typename std::shared_ptr< Cantera::ThermoPhase > PtrCanteraThermo
typename std::shared_ptr< Cantera::Kinetics > PtrCanteraKinetics
typename std::shared_ptr< Cantera::Solution > PtrCanteraSolution
typename std::shared_ptr< Cantera::Transport > PtrCanteraTransport
typename std::shared_ptr< Cantera::ThermoPhase > PtrCanteraThermo
typename std::shared_ptr< Cantera::Kinetics > PtrCanteraKinetics
typename std::shared_ptr< Cantera::Solution > PtrCanteraSolution