From c17b309d8b3a4d2ac8caa1f15bc1346a09417f1f Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Sat, 24 Aug 2024 16:01:58 -0500 Subject: [PATCH] [samples] Update cxx samples --- samples/cxx/combustor/combustor.cpp | 58 +++++++++---------- samples/cxx/kinetics1/kinetics1.cpp | 4 +- .../cxx/openmp_ignition/openmp_ignition.cpp | 6 +- 3 files changed, 31 insertions(+), 37 deletions(-) diff --git a/samples/cxx/combustor/combustor.cpp b/samples/cxx/combustor/combustor.cpp index 865d8964f1..4ce230b511 100644 --- a/samples/cxx/combustor/combustor.cpp +++ b/samples/cxx/combustor/combustor.cpp @@ -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 @@ -63,20 +62,17 @@ 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 @@ -84,17 +80,15 @@ void runexample() double A = 0.1; double FWHM = 0.2; double t0 = 0.5; - Gaussian1 igniter_mdot(A, t0, FWHM); + auto igniter_mdot = make_shared(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; @@ -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; } diff --git a/samples/cxx/kinetics1/kinetics1.cpp b/samples/cxx/kinetics1/kinetics1.cpp index 8587157604..6d492c4fc1 100644 --- a/samples/cxx/kinetics1/kinetics1.cpp +++ b/samples/cxx/kinetics1/kinetics1.cpp @@ -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 @@ -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; diff --git a/samples/cxx/openmp_ignition/openmp_ignition.cpp b/samples/cxx/openmp_ignition/openmp_ignition.cpp index db105f3c43..dd616a5fec 100644 --- a/samples/cxx/openmp_ignition/openmp_ignition.cpp +++ b/samples/cxx/openmp_ignition/openmp_ignition.cpp @@ -28,7 +28,7 @@ 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> sols; - vector> reactors; + vector> reactors; vector> nets; // Create and link the Cantera objects for each thread. This step should be @@ -36,9 +36,9 @@ void run() 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