Skip to content

Commit

Permalink
[samples] Update cxx samples
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Sep 15, 2024
1 parent f778d3e commit c17b309
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 37 deletions.
58 changes: 26 additions & 32 deletions samples/cxx/combustor/combustor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,30 @@ void runexample()

// create a reservoir for the fuel inlet, and set to pure methane.
gas->setState_TPX(300.0, OneAtm, "CH4:1.0");
Reservoir fuel_in(sol);
auto fuel_in = Reservoir::create(sol);
double fuel_mw = gas->meanMolecularWeight();

auto air = newSolution("air.yaml", "air", "none");
double air_mw = air->thermo()->meanMolecularWeight();

// create a reservoir for the air inlet
Reservoir air_in(air);
auto air_in = Reservoir::create(air);

// to ignite the fuel/air mixture, we'll introduce a pulse of radicals.
// The steady-state behavior is independent of how we do this, so we'll
// just use a stream of pure atomic hydrogen.
gas->setState_TPX(300.0, OneAtm, "H:1.0");
Reservoir igniter(sol);
auto igniter = Reservoir::create(sol);


// create the combustor, and fill it in initially with N2
gas->setState_TPX(300.0, OneAtm, "N2:1.0");
Reactor combustor(sol);
combustor.setInitialVolume(1.0);
auto combustor = Reactor::create(sol);
combustor->setInitialVolume(1.0);


// create a reservoir for the exhaust. The initial composition
// doesn't matter.
Reservoir exhaust(sol);
// create a reservoir for the exhaust. The initial composition does not matter.
auto exhaust = Reservoir::create(sol);


// lean combustion, phi = 0.5
Expand All @@ -63,38 +62,33 @@ void runexample()
double air_mdot = factor*9.52*air_mw;
double fuel_mdot = factor*equiv_ratio*fuel_mw;

// create and install the mass flow controllers. Controllers
// m1 and m2 provide constant mass flow rates, and m3 provides
// a short Gaussian pulse only to ignite the mixture
MassFlowController m1;
m1.install(fuel_in, combustor);
m1.setMassFlowRate(fuel_mdot);
// create and install the mass flow controllers. Controllers m1 and m2
// provide constant mass flow rates, and m3 provides a short Gaussian
// pulse only to ignite the mixture.
auto m1 = MassFlowController::create(fuel_in, combustor);
m1->setMassFlowRate(fuel_mdot);

// Now create the air mass flow controller. Note that this connects
// two reactors with different reaction mechanisms and different
// numbers of species. Downstream and upstream species are matched by
// name.
MassFlowController m2;
m2.install(air_in, combustor);
m2.setMassFlowRate(air_mdot);
// Now create the air mass flow controller. Note that this connects two
// reactors with different reaction mechanisms and different numbers of
// species. Downstream and upstream species are matched by name.
auto m2 = MassFlowController::create(air_in, combustor);
m2->setMassFlowRate(air_mdot);


// The igniter will use a Gaussian 'functor' object to specify the
// time-dependent igniter mass flow rate.
double A = 0.1;
double FWHM = 0.2;
double t0 = 0.5;
Gaussian1 igniter_mdot(A, t0, FWHM);
auto igniter_mdot = make_shared<Gaussian1>(A, t0, FWHM);

MassFlowController m3;
m3.install(igniter, combustor);
m3.setTimeFunction(&igniter_mdot);
auto m3 = MassFlowController::create(igniter, combustor);
m3->setTimeFunction(igniter_mdot);

// put a valve on the exhaust line to regulate the pressure
Valve v;
v.install(combustor, exhaust);
auto v = Valve::create(combustor, exhaust);
double Kv = 1.0;
v.setValveCoeff(Kv);
v->setValveCoeff(Kv);

// the simulation only contains one reactor
ReactorNet sim;
Expand All @@ -121,13 +115,13 @@ void runexample()
while (tnow < tfinal) {
tnow += 0.005;
sim.advance(tnow);
tres = combustor.mass()/v.massFlowRate();
tres = combustor->mass() / v->massFlowRate();
f << tnow << ", "
<< combustor.temperature() << ", "
<< combustor->temperature() << ", "
<< tres << ", ";
ThermoPhase& c = combustor.contents();
auto c = combustor->contents3()->thermo();
for (size_t i = 0; i < k_out.size(); i++) {
f << c.moleFraction(k_out[i]) << ", ";
f << c->moleFraction(k_out[i]) << ", ";
}
f << std::endl;
}
Expand Down
4 changes: 2 additions & 2 deletions samples/cxx/kinetics1/kinetics1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int kinetics1(int np, void* p)
// Note that it is ok to insert the same gas object into multiple reactors
// or reservoirs. All this means is that this object will be used to evaluate
// thermodynamic or kinetic quantities needed.
IdealGasConstPressureReactor r(sol);
auto r = IdealGasConstPressureReactor::create(sol);

double dt = 1.e-5; // interval at which output is written
int nsteps = 100; // number of intervals
Expand Down Expand Up @@ -68,7 +68,7 @@ int kinetics1(int np, void* p)

// print final temperature and timing data
double tmm = 1.0*(t1 - t0)/CLOCKS_PER_SEC;
cout << " Tfinal = " << r.temperature() << endl;
cout << " Tfinal = " << r->temperature() << endl;
cout << " time = " << tmm << endl;
cout << " number of residual function evaluations = "
<< sim.integrator().nEvals() << endl;
Expand Down
6 changes: 3 additions & 3 deletions samples/cxx/openmp_ignition/openmp_ignition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ void run()
// to have its own set of linked Cantera objects. Multiple threads accessing
// the same objects at the same time will cause errors.
vector<shared_ptr<Solution>> sols;
vector<unique_ptr<IdealGasConstPressureReactor>> reactors;
vector<shared_ptr<Reactor>> reactors;
vector<unique_ptr<ReactorNet>> nets;

// Create and link the Cantera objects for each thread. This step should be
// done in serial
for (int i = 0; i < nThreads; i++) {
auto sol = newSolution("gri30.yaml", "gri30", "none");
sols.emplace_back(sol);
reactors.emplace_back(new IdealGasConstPressureReactor(sol));
reactors.emplace_back(IdealGasConstPressureReactor::create(sol));
nets.emplace_back(new ReactorNet());
nets.back()->addReactor(*reactors.back());
nets.back()->addReactor(reactors.back());
}

// Points at which to compute ignition delay time
Expand Down

0 comments on commit c17b309

Please sign in to comment.