From 0e1405092e11dc1446fd37ccfb7ec6bdfb9e7ebc Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Mon, 4 Apr 2022 13:05:50 -0500 Subject: [PATCH] Use newSolution rather than newPhase in tutorials --- pages/tutorials/cxx-guide/demo1a.cpp | 27 ++++++------ pages/tutorials/cxx-guide/demoequil.cpp | 8 +++- pages/tutorials/cxx-guide/factory_demo.cpp | 50 ++++++++++------------ pages/tutorials/cxx-guide/thermodemo.cpp | 8 +++- 4 files changed, 48 insertions(+), 45 deletions(-) diff --git a/pages/tutorials/cxx-guide/demo1a.cpp b/pages/tutorials/cxx-guide/demo1a.cpp index 3db93e16b..6eb8aae6f 100644 --- a/pages/tutorials/cxx-guide/demo1a.cpp +++ b/pages/tutorials/cxx-guide/demo1a.cpp @@ -1,28 +1,28 @@ -#include "cantera/thermo.h" +#include "cantera/base/Solution.h" +#include "cantera/thermo/ThermoPhase.h" #include 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_demo() { - // Create a new phase - std::unique_ptr 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 - // 1.0 - they will be normalized internally. Also, the values for - // any unspecified species will be set to zero. + // Set the thermodynamic state by specifying T (500 K) P (2 atm) and the mole + // fractions. Note that the mole fractions do not need to sum to 1.0 - they will + // be normalized internally. Also, the values for any unspecified species will be + // set to zero. gas->setState_TPX(500.0, 2.0*OneAtm, "H2O:1.0, H2:8.0, AR:1.0"); - // Print a summary report of the state of the gas + // Print a summary report of the state of the gas. std::cout << gas->report() << std::endl; } -// the main program just calls function simple_demo within -// a 'try' block, and catches CanteraError exceptions that -// might be thrown +// The main program just calls function simple_demo within a 'try' block, and catches +// CanteraError exceptions that might be thrown. int main() { try { @@ -31,4 +31,3 @@ int main() std::cout << err.what() << std::endl; } } - diff --git a/pages/tutorials/cxx-guide/demoequil.cpp b/pages/tutorials/cxx-guide/demoequil.cpp index 345b4224c..df862e060 100644 --- a/pages/tutorials/cxx-guide/demoequil.cpp +++ b/pages/tutorials/cxx-guide/demoequil.cpp @@ -1,11 +1,15 @@ -#include "cantera/thermo.h" +#include "cantera/base/Solution.h" +#include "cantera/thermo/ThermoPhase.h" #include using namespace Cantera; void equil_demo() { - std::unique_ptr 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; diff --git a/pages/tutorials/cxx-guide/factory_demo.cpp b/pages/tutorials/cxx-guide/factory_demo.cpp index c65c64a3e..890d805cd 100644 --- a/pages/tutorials/cxx-guide/factory_demo.cpp +++ b/pages/tutorials/cxx-guide/factory_demo.cpp @@ -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 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 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 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 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 trans(newDefaultTransportMgr(gas.get())); + // Access the 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++) { diff --git a/pages/tutorials/cxx-guide/thermodemo.cpp b/pages/tutorials/cxx-guide/thermodemo.cpp index 2c74e68d7..d08e484f4 100644 --- a/pages/tutorials/cxx-guide/thermodemo.cpp +++ b/pages/tutorials/cxx-guide/thermodemo.cpp @@ -1,11 +1,15 @@ -#include "cantera/thermo.h" +#include "cantera/base/Solution.h" +#include "cantera/thermo/ThermoPhase.h" #include using namespace Cantera; void thermo_demo(const std::string& file, const std::string& phase) { - shared_ptr 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