From 5d215b7e864d177917899f85b1fe2087b65329e6 Mon Sep 17 00:00:00 2001 From: "Bryan W. Weber" Date: Sat, 13 Jun 2015 19:42:47 -0400 Subject: [PATCH] Add base class functions to set density and pressure simultaneously They have the names setState_RP, setState_RPX, and setState_RPY. These base class functions mirror the TP, TPX, TPY set, except that RP is not implemented, because it depends on the EOS of the system. We cannot use the normal setPressure because it sets the state by calculating the density, but RP will specify the density. --- include/cantera/thermo/ThermoPhase.h | 90 ++++++++++++++++++++++++++++ src/thermo/ThermoPhase.cpp | 36 +++++++++++ 2 files changed, 126 insertions(+) diff --git a/include/cantera/thermo/ThermoPhase.h b/include/cantera/thermo/ThermoPhase.h index 55bdd0d0a..f93b16cd7 100644 --- a/include/cantera/thermo/ThermoPhase.h +++ b/include/cantera/thermo/ThermoPhase.h @@ -1097,6 +1097,96 @@ public: */ virtual void setState_SV(doublereal s, doublereal v, doublereal tol = 1.e-4); + //! Set the density (kg/m**3) and pressure (Pa) at constant + //! composition + /*! + * This method must be reimplemented in derived classes, where it + * may involve the solution of a nonlinear equation. Within %Cantera, + * the independent variable is the density. Therefore, this function + * solves for the temperature that will yield the desired input pressure + * and density. The composition is held constant during this process. + * + * This base class function will print an error, if not overwritten. + * + * @param rho Density (kg/m^3) + * @param p Pressure (Pa) + */ + virtual void setState_RP(doublereal rho, doublereal p){ + throw NotImplementedError("ThermoPhase::setState_RP"); + } + + //! Set the density (kg/m**3), pressure (Pa) and mole fractions + /*! + * Note, the mole fractions are set first before the density and pressure + * are set. Setting the pressure may involve the solution of a nonlinear equation. + * + * @param rho Density (kg/m^3) + * @param p Pressure (Pa) + * @param x Vector of mole fractions. + * Length is equal to m_kk. + */ + virtual void setState_RPX(doublereal rho, doublereal p, const doublereal* x); + + //! Set the density (kg/m**3), pressure (Pa) and mole fractions + /*! + * Note, the mole fractions are set first before the density and pressure + * are set. Setting the pressure may involve the solution of a nonlinear equation. + * + * @param rho Density (kg/m^3) + * @param p Pressure (Pa) + * @param x Composition map of mole fractions. Species not in + * the composition map are assumed to have zero mole fraction + */ + virtual void setState_RPX(doublereal rho, doublereal p, const compositionMap& x); + + //! Set the density (kg/m**3), pressure (Pa) and mole fractions + /*! + * Note, the mole fractions are set first before the density and pressure + * are set. Setting the pressure may involve the solution of a nonlinear equation. + * + * @param rho Density (kg/m^3) + * @param p Pressure (Pa) + * @param x String containing a composition map of the mole fractions. Species not in + * the composition map are assumed to have zero mole fraction + */ + virtual void setState_RPX(doublereal rho, doublereal p, const std::string& x); + + //! Set the density (kg/m**3), pressure (Pa) and mass fractions + /*! + * Note, the mass fractions are set first before the density and pressure + * are set. Setting the pressure may involve the solution of a nonlinear equation. + * + * @param rho Density (kg/m^3) + * @param p Pressure (Pa) + * @param y Vector of mole fractions. + * Length is equal to m_kk. + */ + virtual void setState_RPY(doublereal rho, doublereal p, const doublereal* y); + + //! Set the density (kg/m**3), pressure (Pa) and mass fractions + /*! + * Note, the mass fractions are set first before the density and pressure + * are set. Setting the pressure may involve the solution of a nonlinear equation. + * + * @param rho Density (kg/m^3) + * @param p Pressure (Pa) + * @param y Composition map of mole fractions. Species not in + * the composition map are assumed to have zero mole fraction + */ + virtual void setState_RPY(doublereal rho, doublereal p, const compositionMap& y); + + //! Set the density (kg/m**3), pressure (Pa) and mass fractions + /*! + * Note, the mass fractions are set first before the density and pressure + * are set. Setting the pressure may involve the solution of a nonlinear equation. + * + * @param rho Density (kg/m^3) + * @param p Pressure (Pa) + * @param y String containing a composition map of the mole fractions. Species not in + * the composition map are assumed to have zero mole fraction + */ + virtual void setState_RPY(doublereal rho, doublereal p, const std::string& y); + //@} private: diff --git a/src/thermo/ThermoPhase.cpp b/src/thermo/ThermoPhase.cpp index b24282630..56a05bfce 100644 --- a/src/thermo/ThermoPhase.cpp +++ b/src/thermo/ThermoPhase.cpp @@ -180,6 +180,42 @@ void ThermoPhase::setState_TP(doublereal t, doublereal p) setPressure(p); } +void ThermoPhase::setState_RPX(doublereal rho, doublereal p, const doublereal* x) +{ + setMoleFractions(x); + setState_RP(rho, p); +} + +void ThermoPhase::setState_RPX(doublereal rho, doublereal p, const compositionMap& x) +{ + setMoleFractionsByName(x); + setState_RP(rho,p); +} + +void ThermoPhase::setState_RPX(doublereal rho, doublereal p, const std::string& x) +{ + setMoleFractionsByName(x); + setState_RP(rho,p); +} + +void ThermoPhase::setState_RPY(doublereal rho, doublereal p, const doublereal* y) +{ + setMassFractions(y); + setState_RP(rho,p); +} + +void ThermoPhase::setState_RPY(doublereal rho, doublereal p, const compositionMap& y) +{ + setMassFractionsByName(y); + setState_RP(rho,p); +} + +void ThermoPhase::setState_RPY(doublereal rho, doublereal p, const std::string& y) +{ + setMassFractionsByName(y); + setState_RP(rho,p); +} + void ThermoPhase::setState_PX(doublereal p, doublereal* x) { setMoleFractions(x);