hips
Loading...
Searching...
No Matches
batchReactor_cantera.cc
Go to the documentation of this file.
2
11
12batchReactor_cantera::batchReactor_cantera(std::shared_ptr<Cantera::Solution> cantSol) {
13 gas = cantSol->thermo();
14 kin = cantSol->kinetics();
15
16 // Get the number of species in the system
17 nvar = gas->nSpecies();
18
19 // Initialize the integrator with CVODE
20 integrator.reset(Cantera::newIntegrator("CVODE")); // Use reset() instead of make_unique
21 integrator->setTolerances(1E-4, 1E-10); // Set tolerances for CVODE
22 integrator->setMaxSteps(5000); // Set maximum number of steps
23 integrator->initialize(0.0, *this); // Initialize the integrator
24}
25
34
35void batchReactor_cantera::react(double &h, std::vector<double> &y, const double tRun) {
36 // Set mass fractions and state
37 gas->setMassFractions(&y[0]);
38 gas->setState_HP(h, gas->pressure());
39
40 // Store fixed enthalpy and pressure
41 h_fixed = h;
42 P_fixed = gas->pressure();
43
44 // Reinitialize the integrator
45 integrator->reinitialize(0.0, *this);
46
47 // Integrate over the given time
48 integrator->integrate(tRun);
49
50 // Get the solution and update species mass fractions
51 double *solution = integrator->solution();
52 for (int k = 0; k < nvar; k++)
53 y[k] = solution[k];
54}
55
64
65void batchReactor_cantera::eval(double t, double *vars, double *dvarsdt, double *not_used) {
66 // Set mass fractions and state
67 gas->setMassFractions_NoNorm(vars);
68 gas->setState_HP(h_fixed, P_fixed);
69
70 // Calculate density and reaction rates
71 double rho = gas->density();
72 std::vector<double> rr(gas->nSpecies());
73 kin->getNetProductionRates(&rr[0]);
74 for (size_t k = 0; k < gas->nSpecies(); k++)
75 dvarsdt[k] = rr[k] * gas->molecularWeight(k) / rho;
76}
batchReactor_cantera(std::shared_ptr< Cantera::Solution > cantSol)
Constructor for batchReactor_cantera.
std::unique_ptr< Cantera::Integrator > integrator
Cantera cvode wrapper.
virtual void react(double &h, std::vector< double > &y, const double tRun)
Simulates a reaction in the batch reactor.
void eval(double t, double *vars, double *dvarsdt, double *not_used)
Evaluates the reaction rates.
int nvar
number of variables/equations solved
double rho
density during integrate
std::shared_ptr< Cantera::Kinetics > kin
Cantera kinetics object.
double P_fixed
pressure during integrate
std::shared_ptr< Cantera::ThermoPhase > gas
Cantera thermo object.
double h_fixed
adiabatic h during integrate