Skip to content

Commit

Permalink
Add base class functions to set density and pressure simultaneously
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bryanwweber authored and speth committed Jun 15, 2015
1 parent 2f7e050 commit 5d215b7
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
90 changes: 90 additions & 0 deletions include/cantera/thermo/ThermoPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,96 @@ class ThermoPhase : public Phase
*/
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:
Expand Down
36 changes: 36 additions & 0 deletions src/thermo/ThermoPhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5d215b7

Please sign in to comment.