From cf315f7c5e41879b15a704c46ca816b575a85e71 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Tue, 5 Nov 2019 16:17:25 -0600 Subject: [PATCH] [oneD] change thermo type passed to StFlow constructor - allow for 'ThermoPhase`, and cast to 'IdealGasPhase' internally --- include/cantera/oneD/StFlow.h | 7 ++++++- samples/cxx/flamespeed/flamespeed.cpp | 4 ++-- src/oneD/StFlow.cpp | 9 +++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/cantera/oneD/StFlow.h b/include/cantera/oneD/StFlow.h index fc4313ec0..aeaf0b668 100644 --- a/include/cantera/oneD/StFlow.h +++ b/include/cantera/oneD/StFlow.h @@ -45,7 +45,12 @@ public: //! to evaluate all thermodynamic, kinetic, and transport properties. //! @param nsp Number of species. //! @param points Initial number of grid points - StFlow(IdealGasPhase* ph = 0, size_t nsp = 1, size_t points = 1); + StFlow(ThermoPhase* ph = 0, size_t nsp = 1, size_t points = 1); + + //! Delegating constructor + StFlow(shared_ptr th, size_t nsp = 1, size_t points = 1) : + StFlow(th.get(), nsp, points) { + } //! @name Problem Specification //! @{ diff --git a/samples/cxx/flamespeed/flamespeed.cpp b/samples/cxx/flamespeed/flamespeed.cpp index 6ad4c2a37..bc62bf054 100644 --- a/samples/cxx/flamespeed/flamespeed.cpp +++ b/samples/cxx/flamespeed/flamespeed.cpp @@ -17,7 +17,7 @@ int flamespeed(double phi) { try { auto sol = newSolution("gri30.yaml", "gri30", "None"); - auto gas = std::dynamic_pointer_cast(sol->thermo()); + auto gas = sol->thermo(); double temp = 300.0; // K double pressure = 1.0*OneAtm; //atm double uin = 0.3; //m/sec @@ -51,7 +51,7 @@ int flamespeed(double phi) //-------- step 1: create the flow ------------- - StFlow flow(gas.get()); + StFlow flow(gas); flow.setFreeFlow(); // create an initial grid diff --git a/src/oneD/StFlow.cpp b/src/oneD/StFlow.cpp index 881d0f615..15e65da8f 100644 --- a/src/oneD/StFlow.cpp +++ b/src/oneD/StFlow.cpp @@ -13,7 +13,7 @@ using namespace std; namespace Cantera { -StFlow::StFlow(IdealGasPhase* ph, size_t nsp, size_t points) : +StFlow::StFlow(ThermoPhase* ph, size_t nsp, size_t points) : Domain1D(nsp+c_offset_Y, points), m_press(-1.0), m_nsp(nsp), @@ -30,9 +30,14 @@ StFlow::StFlow(IdealGasPhase* ph, size_t nsp, size_t points) : m_zfixed(Undef), m_tfixed(Undef) { + if (ph->type() == "IdealGas") { + m_thermo = (IdealGasPhase*)ph; + } else { + throw CanteraError("StFlow::StFlow", + "Unsupported phase type: need 'IdealGasPhase'"); + } m_type = cFlowType; m_points = points; - m_thermo = ph; if (ph == 0) { return; // used to create a dummy object