Skip to content

Commit

Permalink
Use newSolution rather than newPhase in tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Apr 5, 2022
1 parent fea3b1e commit 725c735
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
8 changes: 5 additions & 3 deletions pages/tutorials/cxx-guide/demo1a.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cantera/thermo.h"
#include "cantera/base/Solution.h"
#include "cantera/thermo/ThermoPhase.h"
#include <iostream>

using namespace Cantera;
Expand All @@ -7,8 +8,9 @@ using namespace Cantera;
// can be called from the main program.
void simple_demo()
{
// Create a new phase
std::unique_ptr<ThermoPhase> gas(newPhase("h2o2.yaml", "ohmech"));
// Create a new Solution object
auto sol = newSolution("h2o2.yaml", "ohmech", "None");
auto gas = sol->thermo();

// Set its state by specifying T (500 K) P (2 atm) and the mole
// fractions. Note that the mole fractions do not need to sum to
Expand Down
8 changes: 6 additions & 2 deletions pages/tutorials/cxx-guide/demoequil.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#include "cantera/thermo.h"
#include "cantera/base/Solution.h"
#include "cantera/thermo/ThermoPhase.h"
#include <iostream>

using namespace Cantera;

void equil_demo()
{
std::unique_ptr<ThermoPhase> gas(newPhase("h2o2.yaml"));
// Create a new Solution object
auto sol = newSolution("h2o2.yaml", "ohmech", "None");
auto gas = sol->thermo();

gas->setState_TPX(1500.0, 2.0*OneAtm, "O2:1.0, H2:3.0, AR:1.0");
gas->equilibrate("TP");
std::cout << gas->report() << std::endl;
Expand Down
50 changes: 23 additions & 27 deletions pages/tutorials/cxx-guide/factory_demo.cpp
Original file line number Diff line number Diff line change
@@ -1,52 +1,48 @@
#include "cantera/thermo.h"
#include "cantera/kinetics.h"
#include "cantera/transport.h"
#include "cantera/base/global.h"
#include "cantera/base/Solution.h"
#include "cantera/thermo/ThermoPhase.h"
#include "cantera/kinetics/Kinetics.h"
#include "cantera/transport/TransportBase.h"
#include <iostream>

using namespace Cantera;

// The actual code is put into a function that can be called from the main
// program.
// The actual code is put into a function that can be called from the main program.
void simple_demo2()
{
std::string inputFile = "gri30.yaml";
std::string phaseName = "gri30";
// Create a new 'Solution' object that provides access to ThermoPhase, Kinetics and
// Transport objects.
auto sol = newSolution("gri30.yaml", "gri30");

// Create a new ThermoPhase. Based on the phase definition in the input
// file, this will be an IdealGasPhase object.
std::unique_ptr<ThermoPhase> gas(newPhase(inputFile, phaseName));
// Access the ThermoPhase object. Based on the phase definition in the input file,
// this will be an IdealGasPhase object.
auto gas = sol->thermo();

// List of phases participating in reactions (just one for homogeneous
// kinetics)
std::vector<ThermoPhase*> phases{gas.get()};
// Access the Kinetics object. Based on the phase definition in the input file,
// this will be a GasKinetics object.
auto kin = sol->kinetics();

// Create the Kinetics object. Based on the phase definition in the input
// file, this will be a GasKinetics object.
std::unique_ptr<Kinetics> kin(newKinetics(phases, inputFile, phaseName));

// Set an "interesting" mixture state where we will observe non-zero reaction
// rates.
// Set an "interesting" state where we will observe non-zero reaction rates.
gas->setState_TPX(500.0, 2.0*OneAtm, "CH4:1.0, O2:1.0, N2:3.76");
gas->equilibrate("HP");
gas->setState_TP(gas->temperature() - 100, gas->pressure());

// Get the net reaction rates
// Get the net reaction rates.
vector_fp wdot(kin->nReactions());
kin->getNetRatesOfProgress(wdot.data());

writelog("Net reaction rates for reactions involving CO2\n");
size_t kCO2 = gas->speciesIndex("CO2");
for (size_t i = 0; i < kin->nReactions(); i++) {
if (kin->reactantStoichCoeff(kCO2, i)
|| kin->productStoichCoeff(kCO2, i)) {
writelog("{:3d} {:30s} {: .8e}\n",
i, kin->reactionString(i), wdot[i]);
if (kin->reactantStoichCoeff(kCO2, i) || kin->productStoichCoeff(kCO2, i)) {
writelog("{:3d} {:30s} {: .8e}\n", i, kin->reactionString(i), wdot[i]);
}
}
writelog("\n");

// Create a Transport object. Based on the phase definition in the input
// file, this will be a MixTransport object.
std::unique_ptr<Transport> trans(newDefaultTransportMgr(gas.get()));
// Create a Transport object. Based on the phase definition in the input file,
// this will be a MixTransport object.
auto trans = sol->transport();
writelog("T viscosity thermal conductivity\n");
writelog("------ ----------- --------------------\n");
for (size_t n = 0; n < 5; n++) {
Expand Down
8 changes: 6 additions & 2 deletions pages/tutorials/cxx-guide/thermodemo.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#include "cantera/thermo.h"
#include "cantera/base/Solution.h"
#include "cantera/thermo/ThermoPhase.h"
#include <iostream>

using namespace Cantera;

void thermo_demo(const std::string& file, const std::string& phase)
{
shared_ptr<ThermoPhase> gas(newPhase(file, phase));
// Create a new Solution object
auto sol = newSolution("h2o2.yaml", "ohmech", "None");
auto gas = sol->thermo();

gas->setState_TPX(1500.0, 2.0*OneAtm, "O2:1.0, H2:3.0, AR:1.0");

// temperature, pressure, and density
Expand Down

0 comments on commit 725c735

Please sign in to comment.