|
5 | 5 | #include "cantera/core.h"
|
6 | 6 | #include "cantera/onedim.h"
|
7 | 7 | #include "cantera/oneD/DomainFactory.h"
|
| 8 | +#include "cantera/oneD/StFlow.h" |
8 | 9 | #include "cantera/oneD/IonFlow.h"
|
9 | 10 |
|
10 | 11 | using namespace Cantera;
|
@@ -102,6 +103,97 @@ TEST(onedim, freeflame)
|
102 | 103 | }
|
103 | 104 | }
|
104 | 105 |
|
| 106 | +TEST(onedim, legacy) |
| 107 | +{ |
| 108 | + auto sol = newSolution("h2o2.yaml", "ohmech", "mixture-averaged"); |
| 109 | + auto gas = sol->thermo(); |
| 110 | + size_t nsp = gas->nSpecies(); |
| 111 | + |
| 112 | + // reactants |
| 113 | + double uin = .3; |
| 114 | + double T = 300; |
| 115 | + double P = 101325; |
| 116 | + string X = "H2:0.65, O2:0.5, AR:2"; |
| 117 | + gas->setState_TPX(T, P, X); |
| 118 | + double rho_in = gas->density(); |
| 119 | + vector<double> yin(nsp); |
| 120 | + gas->getMassFractions(&yin[0]); |
| 121 | + |
| 122 | + // product estimate |
| 123 | + gas->equilibrate("HP"); |
| 124 | + vector<double> yout(nsp); |
| 125 | + gas->getMassFractions(&yout[0]); |
| 126 | + double rho_out = gas->density(); |
| 127 | + double Tad = gas->temperature(); |
| 128 | + |
| 129 | + // flow |
| 130 | + suppress_deprecation_warnings(); |
| 131 | + auto flow = newDomain<StFlow>("legacy-flow", sol); |
| 132 | + make_deprecation_warnings_fatal(); |
| 133 | + flow->setID("flow"); |
| 134 | + flow->setFreeFlow(); |
| 135 | + |
| 136 | + // grid |
| 137 | + int nz = 21; |
| 138 | + double lz = 0.02; |
| 139 | + vector<double> z(nz); |
| 140 | + double dz = lz; |
| 141 | + dz /= (double)(nz - 1); |
| 142 | + for (int iz = 0; iz < nz; iz++) { |
| 143 | + z[iz] = iz * dz; |
| 144 | + } |
| 145 | + flow->setupGrid(nz, &z[0]); |
| 146 | + |
| 147 | + // inlet |
| 148 | + auto inlet = newDomain<Inlet1D>("inlet", sol); |
| 149 | + inlet->setMoleFractions(X); |
| 150 | + inlet->setMdot(uin * rho_in); |
| 151 | + inlet->setTemperature(T); |
| 152 | + |
| 153 | + // outlet |
| 154 | + auto outlet = newDomain<Outlet1D>("outlet", sol); |
| 155 | + double uout = inlet->mdot() / rho_out; |
| 156 | + |
| 157 | + // set up simulation |
| 158 | + vector<shared_ptr<Domain1D>> domains { inlet, flow, outlet }; |
| 159 | + Sim1D flame(domains); |
| 160 | + int dom = static_cast<int>(flame.domainIndex("flow")); |
| 161 | + ASSERT_EQ(dom, 1); |
| 162 | + |
| 163 | + // set up initial guess |
| 164 | + vector<double> locs{0.0, 0.3, 0.7, 1.0}; |
| 165 | + vector<double> value{uin, uin, uout, uout}; |
| 166 | + flame.setInitialGuess("velocity", locs, value); |
| 167 | + value = {T, T, Tad, Tad}; |
| 168 | + flame.setInitialGuess("T", locs, value); |
| 169 | + for (size_t i = 0; i < nsp; i++) { |
| 170 | + value = {yin[i], yin[i], yout[i], yout[i]}; |
| 171 | + flame.setInitialGuess(gas->speciesName(i), locs, value); |
| 172 | + } |
| 173 | + |
| 174 | + // simulation settings |
| 175 | + double ratio = 15.0; |
| 176 | + double slope = 0.3; |
| 177 | + double curve = 0.5; |
| 178 | + flame.setRefineCriteria(dom, ratio, slope, curve); |
| 179 | + flame.setFixedTemperature(0.85 * T + .15 * Tad); |
| 180 | + |
| 181 | + // solve |
| 182 | + flow->solveEnergyEqn(); |
| 183 | + bool refine_grid = false; |
| 184 | + int loglevel = 0; |
| 185 | + flame.solve(loglevel, refine_grid); |
| 186 | + |
| 187 | + ASSERT_EQ(flow->nPoints(), static_cast<size_t>(nz + 1)); |
| 188 | + size_t comp = flow->componentIndex("T"); |
| 189 | + double Tprev = flame.value(dom, comp, 0); |
| 190 | + for (size_t n = 0; n < flow->nPoints(); n++) { |
| 191 | + T = flame.value(dom, comp, n); |
| 192 | + ASSERT_GE(T, Tprev); |
| 193 | + Tprev = T; |
| 194 | + } |
| 195 | +} |
| 196 | + |
105 | 197 | TEST(onedim, flame_types)
|
106 | 198 | {
|
107 | 199 | auto sol = newSolution("h2o2.yaml", "ohmech", "mixture-averaged");
|
|
0 commit comments