From 0542e694a986c8510c07bb0342e7e6baa935fc39 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sun, 18 Oct 2015 23:59:26 -0400 Subject: [PATCH] [Thermo] Merge classes StoichSubstance and StoichSubstanceSSTP Use the implementation of StoichSubstanceSSTP (descended from SingleSpeciesTP) but change the name to StoichSubstance. --- doc/doxygen/thermoprops.dox | 2 +- include/cantera/thermo/MineralEQ3.h | 12 +- include/cantera/thermo/StoichSubstance.h | 597 ++++++++++-------- include/cantera/thermo/StoichSubstanceSSTP.h | 443 +------------ src/thermo/MineralEQ3.cpp | 2 +- src/thermo/StoichSubstance.cpp | 286 ++++----- src/thermo/StoichSubstanceSSTP.cpp | 230 ------- src/thermo/ThermoFactory.cpp | 11 - test_problems/.gitignore | 2 +- test_problems/SConscript | 4 +- .../LatticeSolid_LiSi/Li_Liquid.xml | 10 +- .../VCSnonideal/NaCl_equil/nacl_equil.cpp | 4 +- .../NaCl_Solid.xml | 0 .../output_blessed.txt | 0 .../stoichSub.cpp} | 4 +- 15 files changed, 492 insertions(+), 1115 deletions(-) delete mode 100644 src/thermo/StoichSubstanceSSTP.cpp rename test_problems/cathermo/{stoichSubSSTP => stoichSub}/NaCl_Solid.xml (100%) rename test_problems/cathermo/{stoichSubSSTP => stoichSub}/output_blessed.txt (100%) rename test_problems/cathermo/{stoichSubSSTP/stoichSubSSTP.cpp => stoichSub/stoichSub.cpp} (96%) diff --git a/doc/doxygen/thermoprops.dox b/doc/doxygen/thermoprops.dox index a28c8e3f7..21d4ef06e 100644 --- a/doc/doxygen/thermoprops.dox +++ b/doc/doxygen/thermoprops.dox @@ -140,7 +140,7 @@ * phase density or the phase pressure. * Lists of classes in this group are given below. * - * - StoichSubstanceSSTP in StoichSubstanceSSTP.h + * - StoichSubstance in StoichSubstance.h * - WaterSSTP in WaterSSTP.h * * The reader may note that there are duplications in functionality in the diff --git a/include/cantera/thermo/MineralEQ3.h b/include/cantera/thermo/MineralEQ3.h index e608405a4..d27531f59 100644 --- a/include/cantera/thermo/MineralEQ3.h +++ b/include/cantera/thermo/MineralEQ3.h @@ -15,7 +15,7 @@ #ifndef CT_MINERALEQ3_H #define CT_MINERALEQ3_H -#include "StoichSubstanceSSTP.h" +#include "StoichSubstance.h" namespace Cantera { @@ -91,13 +91,13 @@ namespace Cantera * * @ingroup thermoprops */ -class MineralEQ3 : public StoichSubstanceSSTP +class MineralEQ3 : public StoichSubstance { public: - //! Default constructor for the StoichSubstanceSSTP class + //! Default constructor for the MineralEQ3 class MineralEQ3() {} - //! Construct and initialize a StoichSubstanceSSTP ThermoPhase object + //! Construct and initialize a MineralEQ3 ThermoPhase object //! directly from an ASCII input file /*! * @param infile name of the input file @@ -106,10 +106,10 @@ public: */ MineralEQ3(const std::string& infile, const std::string& id = ""); - //! Construct and initialize a StoichSubstanceSSTP ThermoPhase object + //! Construct and initialize a MineralEQ3 ThermoPhase object //! directly from an XML database /*! - * @param phaseRef XML node pointing to a StoichSubstanceSSTP description + * @param phaseRef XML node pointing to a MineralEQ3 description * @param id Id of the phase. */ MineralEQ3(XML_Node& phaseRef, const std::string& id = ""); diff --git a/include/cantera/thermo/StoichSubstance.h b/include/cantera/thermo/StoichSubstance.h index 03f17fc70..faefb91ef 100644 --- a/include/cantera/thermo/StoichSubstance.h +++ b/include/cantera/thermo/StoichSubstance.h @@ -1,355 +1,432 @@ /** - * @file StoichSubstance.h - * This file contains the class declarations for the StoichSubstance - * ThermoPhase class. + * @file StoichSubstance.h + * Header file for the StoichSubstance class, which represents a fixed-composition + * incompressible substance (see \ref thermoprops and + * class \link Cantera::StoichSubstance StoichSubstance\endlink) */ -// Copyright 2001 California Institute of Technology - +/* + * Copyright (2005) Sandia Corporation. Under the terms of + * Contract DE-AC04-94AL85000 with Sandia Corporation, the + * U.S. Government retains certain rights in this software. + */ #ifndef CT_STOICHSUBSTANCE_H #define CT_STOICHSUBSTANCE_H -#include "mix_defs.h" -#include "ThermoPhase.h" +#include "SingleSpeciesTP.h" namespace Cantera { -/** - * @ingroup thermoprops +//! Class StoichSubstance represents a stoichiometric (fixed +//! composition) incompressible substance. +/*! + * This class internally changes the independent degree of freedom from density + * to pressure. This is necessary because the phase is incompressible. It uses + * a constant volume approximation. * - * Class StoichSubstance represents a stoichiometric (fixed composition) - * incompressible substance. + * Specification of Species Standard State Properties + * + * This class inherits from SingleSpeciesTP. It is assumed that the reference + * state thermodynamics may be obtained by a pointer to a populated species + * thermodynamic property manager class (see ThermoPhase::m_spthermo). How to + * relate pressure changes to the reference state thermodynamics is resolved at + * this level. + * + * For an incompressible, stoichiometric substance, the molar internal energy is + * independent of pressure. Since the thermodynamic properties are specified by + * giving the standard-state enthalpy, the term \f$ P_0 \hat v\f$ is subtracted + * from the specified molar enthalpy to compute the molar internal energy. The + * entropy is assumed to be independent of the pressure. + * + * The enthalpy function is given by the following relation. + * + * \f[ + * h^o_k(T,P) = + * h^{ref}_k(T) + \tilde v \left( P - P_{ref} \right) + * \f] + * + * For an incompressible, stoichiometric substance, the molar internal energy is + * independent of pressure. Since the thermodynamic properties are specified by + * giving the standard-state enthalpy, the term \f$ P_{ref} \tilde v\f$ is + * subtracted from the specified reference molar enthalpy to compute the molar + * internal energy. + * + * \f[ + * u^o_k(T,P) = h^{ref}_k(T) - P_{ref} \tilde v + * \f] + * + * The standard state heat capacity and entropy are independent of pressure. The + * standard state Gibbs free energy is obtained from the enthalpy and entropy + * functions. + * + * Specification of Solution Thermodynamic Properties + * + * All solution properties are obtained from the standard state species + * functions, since there is only one species in the phase. + * + * Application within Kinetics Managers + * + * The standard concentration is equal to 1.0. This means that the kinetics + * operator works on an (activities basis). Since this is a stoichiometric + * substance, this means that the concentration of this phase drops out of + * kinetics expressions. + * + * An example of a reaction using this is a sticking coefficient reaction of a + * substance in an ideal gas phase on a surface with a bulk phase species in + * this phase. In this case, the rate of progress for this reaction, + * \f$ R_s \f$, may be expressed via the following equation: + * \f[ + * R_s = k_s C_{gas} + * \f] + * where the units for \f$ R_s \f$ are kmol m-2 s-1. \f$ C_{gas} \f$ has units + * of kmol m-3. Therefore, the kinetic rate constant, \f$ k_s \f$, has units of + * m s-1. Nowhere does the concentration of the bulk phase appear in the rate + * constant expression, since it's a stoichiometric phase and the activity is + * always equal to 1.0. + * + * Instantiation of the Class + * + * The constructor for this phase is NOT located in the default ThermoFactory + * for %Cantera. However, a new StoichSubstance may be created by + * the following code snippets: + * + * @code + * XML_Node *xm = get_XML_NameID("phase", iFile + "#NaCl(S)", 0); + * StoichSubstance *solid = new StoichSubstance(*xm); + * @endcode + * + * or by the following call to importPhase(): + * + * @code + * XML_Node *xm = get_XML_NameID("phase", iFile + "#NaCl(S)", 0); + * StoichSubstance solid; + * importPhase(*xm, &solid); + * @endcode + * + * XML Example + * + * The phase model name for this is called StoichSubstance. It must be supplied + * as the model attribute of the thermo XML element entry. Within the phase XML + * block, the density of the phase must be specified. An example of an XML file + * this phase is given below. + * + * @code + * + * + * + * Na Cl + * + * NaCl(S) + * + * 2.165 + * + * + * + * + * + * + * + * + * + * Na:1 Cl:1 + * + * + * + * 50.72389, 6.672267, -2.517167, + * 10.15934, -0.200675, -427.2115, + * 130.3973 + * + * + * + * 2.165 + * + * @endcode + * + * The model attribute, "StoichSubstance", on the thermo element + * identifies the phase as being a StoichSubstance object. + * + * @ingroup thermoprops */ -class StoichSubstance : public ThermoPhase +class StoichSubstance : public SingleSpeciesTP { public: - //! Default empty constructor - StoichSubstance(); + //! Default constructor for the StoichSubstance class + StoichSubstance() {} - //! Copy Constructor + //! Construct and initialize a StoichSubstance ThermoPhase object directly + //! from an ASCII input file /*! - * Copy constructor for the object. Constructed - * object will be a clone of this object, but will - * also own all of its data. - * This is a wrapper around the assignment operator - * - * @param right Object to be copied. + * @param infile name of the input file + * @param id name of the phase id in the file. + * If this is blank, the first phase in the file is used. + */ + StoichSubstance(const std::string& infile, const std::string& id = ""); + + //! Construct and initialize a StoichSubstance ThermoPhase object directly + //! from an XML database + /*! + * @param phaseRef XML node pointing to a StoichSubstance description + * @param id Id of the phase. + */ + StoichSubstance(XML_Node& phaseRef, const std::string& id = ""); + + //! Copy constructor + /*! + * @param right Object to be copied */ StoichSubstance(const StoichSubstance& right); //! Assignment operator /*! - * Assignment operator for the object. Constructed - * object will be a clone of this object, but will - * also own all of its data. - * - * @param right Object to be copied. + * @param right Object to be copied */ StoichSubstance& operator=(const StoichSubstance& right); - //! Duplicator from the ThermoPhase parent class - /* - * Given a pointer to a ThermoPhase object, this function will - * duplicate the ThermoPhase object and all underlying structures. - * This is basically a wrapper around the copy constructor. + //! Duplication function + /*! + * This virtual function is used to create a duplicate of the current phase. + * It's used to duplicate the phase when given a ThermoPhase pointer to the + * phase. * - * @return returns a pointer to a ThermoPhase + * @return It returns a ThermoPhase pointer. */ ThermoPhase* duplMyselfAsThermoPhase() const; /** - * Equation of state flag. Returns the value cStoichSubstance, - * defined in mix_defs.h. + * Equation of state flag. + * + * Returns the value cStoichSubstance, defined in mix_defs.h. */ - virtual int eosType() const { - return cStoichSubstance; - } + virtual int eosType() const; - //! @name Molar Thermodynamic Properties of the Solution - //! @{ - - /** - * Molar enthalpy. Units: J/kmol. For an incompressible, - * stoichiometric substance, the internal energy is - * independent of pressure, and therefore the molar enthalpy - * is \f[ \hat h(T, P) = \hat u(T) + P \hat v \f], where the - * molar specific volume is constant. - */ - virtual doublereal enthalpy_mole() const; - - /** - * Molar internal energy. J/kmol. For an incompressible, - * stoichiometric substance, the molar internal energy is - * independent of pressure. Since the thermodynamic properties - * are specified by giving the standard-state enthalpy, the - * term \f$ P_0 \hat v\f$ is subtracted from the specified molar - * enthalpy to compute the molar internal energy. - */ - virtual doublereal intEnergy_mole() const; - - /** - * Molar entropy. Units: J/kmol/K. For an incompressible, - * stoichiometric substance, the molar entropy depends only on - * the temperature. - */ - virtual doublereal entropy_mole() const; - - /** - * Molar heat capacity at constant pressure. Units: J/kmol/K. - * For an incompressible substance, \f$ \hat c_p = \hat c_v\f$. - */ - virtual doublereal cp_mole() const; - - /** - * Molar heat capacity at constant volume. Units: J/kmol/K. - * For an incompressible substance, \f$ \hat c_p = \hat c_v\f$. - */ - virtual doublereal cv_mole() const; - - //! @} //! @name Mechanical Equation of State //! @{ //! Report the Pressure. Units: Pa. /*! - * For an incompressible substance, the density is independent - * of pressure. This method simply returns the stored - * pressure value. + * For an incompressible substance, the density is independent of pressure. + * This method simply returns the stored pressure value. */ virtual doublereal pressure() const; //! Set the pressure at constant temperature. Units: Pa. /*! - * For an incompressible substance, the density is - * independent of pressure. Therefore, this method only - * stores the specified pressure value. It does not - * modify the density. + * For an incompressible substance, the density is independent of pressure. + * Therefore, this method only stores the specified pressure value. It does + * not modify the density. * * @param p Pressure (units - Pa) */ virtual void setPressure(doublereal p); - //! @} - //! @name Chemical Potentials and Activities - //! @{ + //! Returns the isothermal compressibility. Units: 1/Pa. + /*! + * The isothermal compressibility is defined as + * \f[ + * \kappa_T = -\frac{1}{v}\left(\frac{\partial v}{\partial P}\right)_T + * \f] + */ + virtual doublereal isothermalCompressibility() const; + + //! Return the volumetric thermal expansion coefficient. Units: 1/K. + /*! + * The thermal expansion coefficient is defined as + * \f[ + * \beta = \frac{1}{v}\left(\frac{\partial v}{\partial T}\right)_P + * \f] + */ + virtual doublereal thermalExpansionCoeff() const; /** - * This method returns the array of generalized - * concentrations. For a stoichiometric substance, there is - * only one species, and the generalized concentration is 1.0. + * @} + * @name Activities, Standard States, and Activity Concentrations + * + * This section is largely handled by parent classes, since there + * is only one species. Therefore, the activity is equal to one. + * @{ + */ + + //! This method returns an array of generalized concentrations + /*! + * \f$ C^a_k\f$ are defined such that \f$ a_k = C^a_k / C^0_k, \f$ where + * \f$ C^0_k \f$ is a standard concentration defined below and \f$ a_k \f$ + * are activities used in the thermodynamic functions. These activity (or + * generalized) concentrations are used by kinetics manager classes to + * compute the forward and reverse rates of elementary reactions. + * + * For a stoichiometric substance, there is only one species, and the + * generalized concentration is 1.0. + * + * @param c Output array of generalized concentrations. The + * units depend upon the implementation of the + * reaction rate expressions within the phase. */ virtual void getActivityConcentrations(doublereal* c) const; - /** - * The standard concentration. This is defined as the concentration - * by which the generalized concentration is normalized to produce - * the activity. + //! Return the standard concentration for the kth species + /*! + * The standard concentration \f$ C^0_k \f$ used to normalize the activity + * (i.e., generalized) concentration. This phase assumes that the kinetics + * operator works on an dimensionless basis. Thus, the standard + * concentration is equal to 1.0. + * + * @param k Optional parameter indicating the species. The default + * is to assume this refers to species 0. + * @return + * Returns The standard Concentration as 1.0 */ virtual doublereal standardConcentration(size_t k=0) const; - /** - * Returns the natural logarithm of the standard - * concentration of the kth species + //! Natural logarithm of the standard concentration of the kth species. + /*! + * @param k index of the species (defaults to zero) */ virtual doublereal logStandardConc(size_t k=0) const; - /** - * Get the array of chemical potentials at unit activity - * \f$ \mu^0_k \f$. + //! Get the array of chemical potentials at unit activity for the species + //! at their standard states at the current T and P of the + //! solution. + /*! + * For a stoichiometric substance, there is no activity term in the chemical + * potential expression, and therefore the standard chemical potential and + * the chemical potential are both equal to the molar Gibbs function. * - * For a stoichiometric substance, there is no activity term in - * the chemical potential expression, and therefore the - * standard chemical potential and the chemical potential - * are both equal to the molar Gibbs function. + * These are the standard state chemical potentials \f$ \mu^0_k(T,P) \f$. + * The values are evaluated at the current temperature and pressure of the + * solution + * + * @param mu0 Output vector of chemical potentials. + * Length: m_kk. */ virtual void getStandardChemPotentials(doublereal* mu0) const; - //@} - /// @name Partial Molar Properties of the Solution - //@{ - - /** - * Get the array of non-dimensional chemical potentials - * \f$ \mu_k / \hat R T \f$. - */ - virtual void getChemPotentials_RT(doublereal* mu) const; - - /** - * For a stoichiometric substance, there is only one species. - * This method returns the molar Gibbs function in the - * first element of array \c mu. - */ - virtual void getChemPotentials(doublereal* mu) const; - - /** - * Get the species electrochemical potentials. Units: J/kmol. - * This method adds a term \f$ Fz_k \phi_k \f$ to the - * to each chemical potential. - */ - void getElectrochemPotentials(doublereal* mu) const; - - /** - * Returns an array of partial molar enthalpies for the species - * in the mixture. - * Units (J/kmol) - */ - virtual void getPartialMolarEnthalpies(doublereal* hbar) const; - - /** - * Returns an array of partial molar entropies of the species in the - * solution. Units: J/kmol/K. - */ - virtual void getPartialMolarEntropies(doublereal* sbar) const; - - //! Get the species partial molar enthalpies. Units: J/kmol. - /*! - * @param ubar Output vector of species partial molar internal energies. - * Length = m_kk. units are J/kmol. - */ - virtual void getPartialMolarIntEnergies(doublereal* ubar) const; - - //! Get the partial molar heat capacities Units: J/kmol/K - /*! - * @param cpbar Output vector of species partial molar heat capacities - * at constant pressure. - * Length = m_kk. units are J/kmol/K. - */ - virtual void getPartialMolarCp(doublereal* cpbar) const; - - /** - * returns an array of partial molar volumes of the species - * in the solution. Units: m^3 kmol-1. - */ - virtual void getPartialMolarVolumes(doublereal* vbar) const; - //@} /// @name Properties of the Standard State of the Species in the Solution //@{ - /** - * Get the nondimensional Enthalpy functions for the species - * at their standard states at the current - * T and P of the solution. + + //! Get the nondimensional Enthalpy functions for the species + //! at their standard states at the current T and P of the solution. + /*! + * @param hrt Output vector of nondimensional standard state enthalpies. + * Length: m_kk. */ virtual void getEnthalpy_RT(doublereal* hrt) const; - /** - * Get the array of nondimensional Enthalpy functions for the - * standard state species - * at the current T and P of the solution. + //! Get the array of nondimensional Entropy functions for the + //! standard state species at the current T and P of the solution. + /*! + * @param sr Output vector of nondimensional standard state entropies. + * Length: m_kk. */ virtual void getEntropy_R(doublereal* sr) const; - /** - * Get the nondimensional Gibbs functions for the species - * at their standard states of solution at the current T and P - * of the solution. + //! Get the nondimensional Gibbs functions for the species + //! in their standard states at the current T and P of the solution. + /*! + * @param grt Output vector of nondimensional standard state Gibbs free energies + * Length: m_kk. */ virtual void getGibbs_RT(doublereal* grt) const; - //! Get the Gibbs functions for the standard - //! state of the species at the current T and P of the solution + //! Get the nondimensional Heat Capacities at constant pressure for the + //! species standard states at the current T and P of the solution /*! - * Units are Joules/kmol - * @param gpure Output vector of standard state Gibbs free energies - * Length: m_kk. - */ - virtual void getPureGibbs(doublereal* gpure) const; - - /** - * Get the nondimensional Heat Capacities at constant - * pressure for the standard state of the species - * at the current T and P. + * @param cpr Output vector of nondimensional standard state heat capacities + * Length: m_kk. */ virtual void getCp_R(doublereal* cpr) const; - /** - * Get the standard volumes for the standard state of the species - * at the current T and P + //! Returns the vector of nondimensional Internal Energies of the standard + //! state species at the current T and P of the solution + /*! + * For an incompressible, stoichiometric substance, the molar internal + * energy is independent of pressure. Since the thermodynamic properties + * are specified by giving the standard-state enthalpy, the term + * \f$ P_{ref} \hat v\f$ is subtracted from the specified reference molar + * enthalpy to compute the standard state molar internal energy. + * + * @param urt output vector of nondimensional standard state + * internal energies of the species. Length: m_kk. */ - virtual void getStandardVolumes(doublereal* vol) const; + virtual void getIntEnergy_RT(doublereal* urt) const; //@} /// @name Thermodynamic Values for the Species Reference States //@{ - /** - * Returns the vector of nondimensional - * enthalpies of the reference state at the current temperature - * of the solution and the reference pressure for the species. - * - * This function fills in its one entry in hrt[] by calling - * the underlying species thermo function for the - * dimensionless enthalpy. - */ - virtual void getEnthalpy_RT_ref(doublereal* hrt) const; - - /** - * Returns the vector of nondimensional - * enthalpies of the reference state at the current temperature - * of the solution and the reference pressure for the species. - * - * This function fills in its one entry in hrt[] by calling - * the underlying species thermo function for the - * dimensionless Gibbs free energy, calculated from the - * dimensionless enthalpy and entropy. - */ - virtual void getGibbs_RT_ref(doublereal* grt) const; - - /** - * Returns the vector of the - * Gibbs function of the reference state at the current temperature - * of the solution and the reference pressure for the species. - * units = J/kmol - * - * This function fills in its one entry in g[] by calling - * the underlying species thermo functions for the - * Gibbs free energy, calculated from enthalpy and the - * entropy, and the multiplying by RT. - */ - virtual void getGibbs_ref(doublereal* g) const; - - /** - * Returns the vector of nondimensional - * entropies of the reference state at the current temperature - * of the solution and the reference pressure for the species. - * - * This function fills in its one entry in hrt[] by calling - * the underlying species thermo function for the - * dimensionless entropy. - */ - virtual void getEntropy_R_ref(doublereal* er) const; - - //! Returns the vector of nondimensional - //! constant pressure heat capacities of the reference state - //! at the current temperature of the solution - //! and reference pressure for each species. + //! Returns the vector of nondimensional internal Energies of the reference + //! state at the current temperature of the solution and the reference + //! pressure for each species. /*! - * @param cprt Output vector of nondimensional reference state - * heat capacities at constant pressure for the species. + * @param urt Output vector of nondimensional reference state + * internal energies of the species. * Length: m_kk */ - virtual void getCp_R_ref(doublereal* cprt) const; - //! @} + virtual void getIntEnergy_RT_ref(doublereal* urt) const; + // @} + /* + * @internal Initialize. This method is provided to allow subclasses to + * perform any initialization required after all species have been added. + * For example, it might be used to resize internal work arrays that must + * have an entry for each species. The base class implementation does + * nothing, and subclasses that do not require initialization do not need to + * overload this method. When importing a CTML phase description, this + * method is called just prior to returning from function importPhase(). + */ virtual void initThermo(); - virtual void setParameters(int n, double* const c); + virtual void initThermoXML(XML_Node& phaseNode, const std::string& id); - virtual void getParameters(int& n, double* const c) const; + //! Set the equation of state parameters + /*! + * @internal + * The number and meaning of these depends on the subclass. + * + * @param n number of parameters + * @param c array of \a n coefficients + * c[0] = density of phase [ kg/m3 ] + */ + virtual void setParameters(int n, doublereal* const c); + //! Get the equation of state parameters in a vector + /*! + * @internal + * + * @param n number of parameters + * @param c array of \a n coefficients + * + * For this phase: + * - n = 1 + * - c[0] = density of phase [ kg/m3 ] + */ + virtual void getParameters(int& n, doublereal* const c) const; + + //! Set equation of state parameter values from XML entries. + /*! + * This method is called by function importPhase() when processing a phase + * definition in an input file. It should be overloaded in subclasses to set + * any parameters that are specific to that particular phase model. Note, + * this method is called before the phase is initialized with elements + * and/or species. + * + * For this phase, the density of the phase is specified in this block. + * + * @param eosdata An XML_Node object corresponding to + * the "thermo" entry for this phase in the input file. + * + * eosdata points to the thermo block, and looks like this: + * + * @code + * + * + * 3.52 + * + * + * @endcode + */ virtual void setParametersFromXML(const XML_Node& eosdata); - -protected: - doublereal m_press; - doublereal m_p0; - - mutable vector_fp m_h0_RT; - mutable vector_fp m_cp0_R; - mutable vector_fp m_s0_R; - -private: - void _updateThermo() const; }; } diff --git a/include/cantera/thermo/StoichSubstanceSSTP.h b/include/cantera/thermo/StoichSubstanceSSTP.h index 246d899d5..193ea1da7 100644 --- a/include/cantera/thermo/StoichSubstanceSSTP.h +++ b/include/cantera/thermo/StoichSubstanceSSTP.h @@ -1,447 +1,12 @@ -/** - * @file StoichSubstanceSSTP.h - * Header file for the StoichSubstanceSSTP class, which represents a fixed-composition - * incompressible substance (see \ref thermoprops and - * class \link Cantera::StoichSubstanceSSTP StoichSubstanceSSTP\endlink) - */ - -/* - * Copyright (2005) Sandia Corporation. Under the terms of - * Contract DE-AC04-94AL85000 with Sandia Corporation, the - * U.S. Government retains certain rights in this software. - */ #ifndef CT_STOICHSUBSTANCESSTP_H #define CT_STOICHSUBSTANCESSTP_H -#include "SingleSpeciesTP.h" +#include "StoichSubstance.h" -namespace Cantera -{ - -//! Class StoichSubstanceSSTP represents a stoichiometric (fixed -//! composition) incompressible substance. -/*! - * This class internally changes the independent degree of freedom from - * density to pressure. This is necessary because the phase is - * incompressible. It uses a constant volume approximation. - * - * Specification of Species Standard State Properties - * - * This class inherits from SingleSpeciesTP. - * It is assumed that the reference state thermodynamics may be - * obtained by a pointer to a populated species thermodynamic property - * manager class (see ThermoPhase::m_spthermo). How to relate pressure - * changes to the reference state thermodynamics is resolved at this level. - * - * For an incompressible, - * stoichiometric substance, the molar internal energy is - * independent of pressure. Since the thermodynamic properties - * are specified by giving the standard-state enthalpy, the - * term \f$ P_0 \hat v\f$ is subtracted from the specified molar - * enthalpy to compute the molar internal energy. The entropy is - * assumed to be independent of the pressure. - * - * The enthalpy function is given by the following relation. - * - * \f[ - * h^o_k(T,P) = - * h^{ref}_k(T) + \tilde v \left( P - P_{ref} \right) - * \f] - * - * For an incompressible, - * stoichiometric substance, the molar internal energy is - * independent of pressure. Since the thermodynamic properties - * are specified by giving the standard-state enthalpy, the - * term \f$ P_{ref} \tilde v\f$ is subtracted from the specified reference molar - * enthalpy to compute the molar internal energy. - * - * \f[ - * u^o_k(T,P) = h^{ref}_k(T) - P_{ref} \tilde v - * \f] - * - * The standard state heat capacity and entropy are independent - * of pressure. The standard state Gibbs free energy is obtained - * from the enthalpy and entropy functions. - * - * Specification of Solution Thermodynamic Properties - * - * All solution properties are obtained from the standard state - * species functions, since there is only one species in the phase. - * - * Application within Kinetics Managers - * - * The standard concentration is equal to 1.0. This means that the - * kinetics operator works on an (activities basis). Since this - * is a stoichiometric substance, this means that the concentration - * of this phase drops out of kinetics expressions. - * - * An example of a reaction using this is a sticking coefficient - * reaction of a substance in an ideal gas phase on a surface with a bulk phase - * species in this phase. In this case, the rate of progress for this - * reaction, \f$ R_s \f$, may be expressed via the following equation: - * \f[ - * R_s = k_s C_{gas} - * \f] - * where the units for \f$ R_s \f$ are kmol m-2 s-1. \f$ C_{gas} \f$ has units - * of kmol m-3. Therefore, the kinetic rate constant, \f$ k_s \f$, has - * units of m s-1. Nowhere does the concentration of the bulk phase - * appear in the rate constant expression, since it's a stoichiometric - * phase and the activity is always equal to 1.0. - * - * Instantiation of the Class - * - * The constructor for this phase is NOT located in the default ThermoFactory - * for %Cantera. However, a new StoichSubstanceSSTP may be created by - * the following code snippets: - * - * @code - * XML_Node *xm = get_XML_NameID("phase", iFile + "#NaCl(S)", 0); - * StoichSubstanceSSTP *solid = new StoichSubstanceSSTP(*xm); - * @endcode - * - * or by the following call to importPhase(): - * - * @code - * XML_Node *xm = get_XML_NameID("phase", iFile + "#NaCl(S)", 0); - * StoichSubstanceSSTP solid; - * importPhase(*xm, &solid); - * @endcode - * - * XML Example - * - * The phase model name for this is called StoichSubstance. It must be supplied - * as the model attribute of the thermo XML element entry. - * Within the phase XML block, - * the density of the phase must be specified. An example of an XML file - * this phase is given below. - * - * @code - * - * - * - * Na Cl - * - * NaCl(S) - * - * 2.165 - * - * - * - * - * - * - * - * - * - * Na:1 Cl:1 - * - * - * - * 50.72389, 6.672267, -2.517167, - * 10.15934, -0.200675, -427.2115, - * 130.3973 - * - * - * - * 2.165 - * - * @endcode - * - * The model attribute, "StoichSubstanceSSTP", on the thermo element - * identifies the phase as being a StoichSubstanceSSTP object. - * - * @ingroup thermoprops - */ -class StoichSubstanceSSTP : public SingleSpeciesTP -{ -public: - //! Default constructor for the StoichSubstanceSSTP class - StoichSubstanceSSTP() {} - - //! Construct and initialize a StoichSubstanceSSTP ThermoPhase object - //! directly from an ASCII input file - /*! - * @param infile name of the input file - * @param id name of the phase id in the file. - * If this is blank, the first phase in the file is used. - */ - StoichSubstanceSSTP(const std::string& infile, const std::string& id = ""); - - //! Construct and initialize a StoichSubstanceSSTP ThermoPhase object - //! directly from an XML database - /*! - * @param phaseRef XML node pointing to a StoichSubstanceSSTP description - * @param id Id of the phase. - */ - StoichSubstanceSSTP(XML_Node& phaseRef, const std::string& id = ""); - - //! Copy constructor - /*! - * @param right Object to be copied - */ - StoichSubstanceSSTP(const StoichSubstanceSSTP& right); - - //! Assignment operator - /*! - * @param right Object to be copied - */ - StoichSubstanceSSTP& operator=(const StoichSubstanceSSTP& right); - - //! Duplication function - /*! - * This virtual function is used to create a duplicate of the - * current phase. It's used to duplicate the phase when given - * a ThermoPhase pointer to the phase. - * - * @return It returns a ThermoPhase pointer. - */ - ThermoPhase* duplMyselfAsThermoPhase() const; - - /** - * Equation of state flag. - * - * Returns the value cStoichSubstance, defined in mix_defs.h. - */ - virtual int eosType() const; - - //! @name Mechanical Equation of State - //! @{ - - //! Report the Pressure. Units: Pa. - /*! - * For an incompressible substance, the density is independent - * of pressure. This method simply returns the stored - * pressure value. - */ - virtual doublereal pressure() const; - - //! Set the pressure at constant temperature. Units: Pa. - /*! - * For an incompressible substance, the density is - * independent of pressure. Therefore, this method only - * stores the specified pressure value. It does not - * modify the density. - * - * @param p Pressure (units - Pa) - */ - virtual void setPressure(doublereal p); - - //! Returns the isothermal compressibility. Units: 1/Pa. - /*! - * The isothermal compressibility is defined as - * \f[ - * \kappa_T = -\frac{1}{v}\left(\frac{\partial v}{\partial P}\right)_T - * \f] - */ - virtual doublereal isothermalCompressibility() const; - - //! Return the volumetric thermal expansion coefficient. Units: 1/K. - /*! - * The thermal expansion coefficient is defined as - * \f[ - * \beta = \frac{1}{v}\left(\frac{\partial v}{\partial T}\right)_P - * \f] - */ - virtual doublereal thermalExpansionCoeff() const; - - /** - * @} - * @name Activities, Standard States, and Activity Concentrations - * - * This section is largely handled by parent classes, since there - * is only one species. Therefore, the activity is equal to one. - * @{ - */ - - //! This method returns an array of generalized concentrations - /*! - * \f$ C^a_k\f$ are defined such that \f$ a_k = C^a_k / - * C^0_k, \f$ where \f$ C^0_k \f$ is a standard concentration - * defined below and \f$ a_k \f$ are activities used in the - * thermodynamic functions. These activity (or generalized) - * concentrations are used - * by kinetics manager classes to compute the forward and - * reverse rates of elementary reactions. - * - * For a stoichiometric substance, there is - * only one species, and the generalized concentration is 1.0. - * - * @param c Output array of generalized concentrations. The - * units depend upon the implementation of the - * reaction rate expressions within the phase. - */ - virtual void getActivityConcentrations(doublereal* c) const; - - //! Return the standard concentration for the kth species - /*! - * The standard concentration \f$ C^0_k \f$ used to normalize - * the activity (i.e., generalized) concentration. - * This phase assumes that the kinetics operator works on an - * dimensionless basis. Thus, the standard concentration is - * equal to 1.0. - * - * @param k Optional parameter indicating the species. The default - * is to assume this refers to species 0. - * @return - * Returns The standard Concentration as 1.0 - */ - virtual doublereal standardConcentration(size_t k=0) const; - - //! Natural logarithm of the standard concentration of the kth species. - /*! - * @param k index of the species (defaults to zero) - */ - virtual doublereal logStandardConc(size_t k=0) const; - - //! Get the array of chemical potentials at unit activity for the species - //! at their standard states at the current T and P of the solution. - /*! - * For a stoichiometric substance, there is no activity term in - * the chemical potential expression, and therefore the - * standard chemical potential and the chemical potential - * are both equal to the molar Gibbs function. - * - * These are the standard state chemical potentials \f$ \mu^0_k(T,P) - * \f$. The values are evaluated at the current - * temperature and pressure of the solution - * - * @param mu0 Output vector of chemical potentials. - * Length: m_kk. - */ - virtual void getStandardChemPotentials(doublereal* mu0) const; - - //@} - /// @name Properties of the Standard State of the Species in the Solution - //@{ - - //! Get the nondimensional Enthalpy functions for the species - //! at their standard states at the current T and P of the solution. - /*! - * @param hrt Output vector of nondimensional standard state enthalpies. - * Length: m_kk. - */ - virtual void getEnthalpy_RT(doublereal* hrt) const; - - //! Get the array of nondimensional Entropy functions for the - //! standard state species at the current T and P of the solution. - /*! - * @param sr Output vector of nondimensional standard state entropies. - * Length: m_kk. - */ - virtual void getEntropy_R(doublereal* sr) const; - - //! Get the nondimensional Gibbs functions for the species - //! in their standard states at the current T and P of the solution. - /*! - * @param grt Output vector of nondimensional standard state Gibbs free energies - * Length: m_kk. - */ - virtual void getGibbs_RT(doublereal* grt) const; - - //! Get the nondimensional Heat Capacities at constant - //! pressure for the species standard states - //! at the current T and P of the solution - /*! - * @param cpr Output vector of nondimensional standard state heat capacities - * Length: m_kk. - */ - virtual void getCp_R(doublereal* cpr) const; - - //! Returns the vector of nondimensional Internal Energies of the standard - //! state species at the current T and P of the solution - /*! - * For an incompressible, - * stoichiometric substance, the molar internal energy is - * independent of pressure. Since the thermodynamic properties - * are specified by giving the standard-state enthalpy, the - * term \f$ P_{ref} \hat v\f$ is subtracted from the specified reference molar - * enthalpy to compute the standard state molar internal energy. - * - * @param urt output vector of nondimensional standard state - * internal energies of the species. Length: m_kk. - */ - virtual void getIntEnergy_RT(doublereal* urt) const; - - //@} - /// @name Thermodynamic Values for the Species Reference States - //@{ - - //! Returns the vector of nondimensional - //! internal Energies of the reference state at the current temperature - //! of the solution and the reference pressure for each species. - /*! - * @param urt Output vector of nondimensional reference state - * internal energies of the species. - * Length: m_kk - */ - virtual void getIntEnergy_RT_ref(doublereal* urt) const; - // @} - - /* - * @internal Initialize. This method is provided to allow - * subclasses to perform any initialization required after all - * species have been added. For example, it might be used to - * resize internal work arrays that must have an entry for - * each species. The base class implementation does nothing, - * and subclasses that do not require initialization do not - * need to overload this method. When importing a CTML phase - * description, this method is called just prior to returning - * from function importPhase(). - */ - virtual void initThermo(); - - virtual void initThermoXML(XML_Node& phaseNode, const std::string& id); - - //! Set the equation of state parameters - /*! - * @internal - * The number and meaning of these depends on the subclass. - * - * @param n number of parameters - * @param c array of \a n coefficients - * c[0] = density of phase [ kg/m3 ] - */ - virtual void setParameters(int n, doublereal* const c); - - //! Get the equation of state parameters in a vector - /*! - * @internal - * - * @param n number of parameters - * @param c array of \a n coefficients - * - * For this phase: - * - n = 1 - * - c[0] = density of phase [ kg/m3 ] - */ - virtual void getParameters(int& n, doublereal* const c) const; - - //! Set equation of state parameter values from XML entries. - /*! - * This method is called by function importPhase() when processing a phase - * definition in an input file. It should be overloaded in subclasses to set - * any parameters that are specific to that particular phase - * model. Note, this method is called before the phase is - * initialized with elements and/or species. - * - * For this phase, the density of the phase is specified in this block. - * - * @param eosdata An XML_Node object corresponding to - * the "thermo" entry for this phase in the input file. - * - * eosdata points to the thermo block, and looks like this: - * - * @code - * - * - * 3.52 - * - * - * @endcode - */ - virtual void setParametersFromXML(const XML_Node& eosdata); -}; +#pragma message "cantera/thermo/StoichSubstanceSSTP.h and class StoichSubstanceSSTP are deprecated. Use StoichSubstance.h and class StoichSubstance instead. To be removed after Cantera 2.3." +namespace Cantera { + typedef StoichSubstance StoichSubstanceSSTP; } #endif diff --git a/src/thermo/MineralEQ3.cpp b/src/thermo/MineralEQ3.cpp index 74998f272..b7e7d4f89 100644 --- a/src/thermo/MineralEQ3.cpp +++ b/src/thermo/MineralEQ3.cpp @@ -48,7 +48,7 @@ MineralEQ3::operator=(const MineralEQ3& right) if (&right == this) { return *this; } - StoichSubstanceSSTP::operator=(right); + StoichSubstance::operator=(right); m_Mu0_pr_tr = right.m_Mu0_pr_tr; m_Entrop_pr_tr = right.m_Entrop_pr_tr; m_deltaG_formation_pr_tr = right.m_deltaG_formation_pr_tr; diff --git a/src/thermo/StoichSubstance.cpp b/src/thermo/StoichSubstance.cpp index e2486be45..e08a4ea66 100644 --- a/src/thermo/StoichSubstance.cpp +++ b/src/thermo/StoichSubstance.cpp @@ -1,38 +1,49 @@ /** * @file StoichSubstance.cpp - * This file contains the class definitions for the StoichSubstance - * ThermoPhase class. + * Definition file for the StoichSubstance class, which represents a fixed-composition + * incompressible substance (see \ref thermoprops and + * class \link Cantera::StoichSubstance StoichSubstance\endlink) */ -// Copyright 2001 California Institute of Technology - +/* + * Copyright (2005) Sandia Corporation. Under the terms of + * Contract DE-AC04-94AL85000 with Sandia Corporation, the + * U.S. Government retains certain rights in this software. + * + * Copyright 2001 California Institute of Technology + */ #include "cantera/thermo/StoichSubstance.h" +#include "cantera/thermo/mix_defs.h" +#include "cantera/thermo/ThermoFactory.h" #include "cantera/base/ctml.h" namespace Cantera { -StoichSubstance::StoichSubstance() : - m_press(OneAtm), - m_p0(OneAtm) + +/* + * ---- Constructors ------- + */ + +StoichSubstance::StoichSubstance(const std::string& infile, const std::string& id_) { + initThermoFile(infile, id_); } -StoichSubstance::StoichSubstance(const StoichSubstance& right) : - m_press(OneAtm), - m_p0(OneAtm) +StoichSubstance::StoichSubstance(XML_Node& xmlphase, const std::string& id_) +{ + importPhase(xmlphase, this); +} + +StoichSubstance::StoichSubstance(const StoichSubstance& right) { *this = right; } -StoichSubstance& StoichSubstance::operator=(const StoichSubstance& right) +StoichSubstance& +StoichSubstance::operator=(const StoichSubstance& right) { if (&right != this) { - ThermoPhase::operator=(right); - m_press = right.m_press; - m_p0 = right.m_p0; - m_h0_RT = right.m_h0_RT; - m_cp0_R = right.m_cp0_R; - m_s0_R = right.m_s0_R; + SingleSpeciesTP::operator=(right); } return *this; } @@ -42,69 +53,18 @@ ThermoPhase* StoichSubstance::duplMyselfAsThermoPhase() const return new StoichSubstance(*this); } -doublereal StoichSubstance::enthalpy_mole() const +/* + * ---- Utilities ----- + */ + +int StoichSubstance::eosType() const { - return intEnergy_mole() + m_press / molarDensity(); + return cStoichSubstance; } -doublereal StoichSubstance::intEnergy_mole() const -{ - _updateThermo(); - return GasConstant * temperature() * m_h0_RT[0] - - m_p0 / molarDensity(); -} - -doublereal StoichSubstance::entropy_mole() const -{ - _updateThermo(); - return GasConstant * m_s0_R[0]; -} - -doublereal StoichSubstance::cp_mole() const -{ - _updateThermo(); - return GasConstant * m_cp0_R[0]; -} - -doublereal StoichSubstance::cv_mole() const -{ - return cp_mole(); -} - -void StoichSubstance::initThermo() -{ - ThermoPhase::initThermo(); - if (m_kk > 1) { - throw CanteraError("initThermo", - "stoichiometric substances may only contain one species."); - } - doublereal tmin = m_spthermo->minTemp(); - doublereal tmax = m_spthermo->maxTemp(); - m_p0 = refPressure(); - - m_h0_RT.resize(m_kk); - m_cp0_R.resize(m_kk); - m_s0_R.resize(m_kk); - - // Put the object on a valid temperature point. - double tnow = 300.; - if (tnow > tmin && tnow < tmax) { - - } else { - tnow = 0.1 * (9 * tmin + tmax); - } - setState_TP(tnow, m_p0); -} - -void StoichSubstance::_updateThermo() const -{ - doublereal tnow = temperature(); - if (m_tlast != tnow) { - m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0], - &m_s0_R[0]); - m_tlast = tnow; - } -} +/* + * ----- Mechanical Equation of State ------ + */ doublereal StoichSubstance::pressure() const { @@ -116,6 +76,20 @@ void StoichSubstance::setPressure(doublereal p) m_press = p; } +doublereal StoichSubstance::isothermalCompressibility() const +{ + return 0.0; +} + +doublereal StoichSubstance::thermalExpansionCoeff() const +{ + return 0.0; +} + +/* + * ---- Chemical Potentials and Activities ---- + */ + void StoichSubstance::getActivityConcentrations(doublereal* c) const { c[0] = 1.0; @@ -131,128 +105,126 @@ doublereal StoichSubstance::logStandardConc(size_t k) const return 0.0; } +/* + * Properties of the Standard State of the Species in the Solution + */ + void StoichSubstance::getStandardChemPotentials(doublereal* mu0) const { - mu0[0] = gibbs_mole(); -} - -void StoichSubstance::getChemPotentials_RT(doublereal* mu) const -{ - mu[0] = gibbs_mole() / (GasConstant * temperature()); -} - -void StoichSubstance::getChemPotentials(doublereal* mu) const -{ - mu[0] = gibbs_mole(); -} - -void StoichSubstance::getElectrochemPotentials(doublereal* mu) const -{ - getChemPotentials(mu); -} - -void StoichSubstance::getPartialMolarEnthalpies(doublereal* hbar) const -{ - hbar[0] = enthalpy_mole(); -} - -void StoichSubstance::getPartialMolarEntropies(doublereal* sbar) const -{ - sbar[0] = entropy_mole(); -} - -void StoichSubstance::getPartialMolarIntEnergies(doublereal* ubar) const -{ - ubar[0] = intEnergy_mole(); -} - -void StoichSubstance::getPartialMolarCp(doublereal *cpbar) const -{ - cpbar[0] = cp_mole(); -} - -void StoichSubstance::getPartialMolarVolumes(doublereal* vbar) const -{ - vbar[0] = 1.0 / molarDensity(); + getGibbs_RT(mu0); + mu0[0] *= GasConstant * temperature(); } void StoichSubstance::getEnthalpy_RT(doublereal* hrt) const { - hrt[0] = enthalpy_mole() / (GasConstant * temperature()); + getEnthalpy_RT_ref(hrt); + doublereal presCorrect = (m_press - m_p0) / molarDensity(); + hrt[0] += presCorrect / (GasConstant * temperature()); } void StoichSubstance::getEntropy_R(doublereal* sr) const { - sr[0] = entropy_mole() / GasConstant; + getEntropy_R_ref(sr); } void StoichSubstance::getGibbs_RT(doublereal* grt) const { - grt[0] = gibbs_mole() / (GasConstant * temperature()); -} - -void StoichSubstance::getPureGibbs(doublereal* gpure) const -{ - gpure[0] = gibbs_mole(); + getEnthalpy_RT(grt); + grt[0] -= m_s0_R[0]; } void StoichSubstance::getCp_R(doublereal* cpr) const { - cpr[0] = cp_mole() / GasConstant; + _updateThermo(); + cpr[0] = m_cp0_R[0]; } -void StoichSubstance::getStandardVolumes(doublereal* vol) const -{ - vol[0] = 1.0 / molarDensity(); -} - -void StoichSubstance::getEnthalpy_RT_ref(doublereal* hrt) const +void StoichSubstance::getIntEnergy_RT(doublereal* urt) const { _updateThermo(); - hrt[0] = m_h0_RT[0]; + urt[0] = m_h0_RT[0] - m_p0 / molarDensity() / (GasConstant * temperature()); } -void StoichSubstance::getGibbs_RT_ref(doublereal* grt) const +/* + * ---- Thermodynamic Values for the Species Reference States ---- + */ + +void StoichSubstance::getIntEnergy_RT_ref(doublereal* urt) const { _updateThermo(); - grt[0] = m_h0_RT[0] - m_s0_R[0]; + urt[0] = m_h0_RT[0] - m_p0 / molarDensity() / (GasConstant * temperature()); } -void StoichSubstance::getGibbs_ref(doublereal* g) const +/* + * ---- Initialization and Internal functions + */ + +void StoichSubstance::initThermo() { - getGibbs_RT_ref(g); - g[0] *= GasConstant * temperature(); + /* + * Make sure there is one and only one species in this phase. + */ + if (m_kk != 1) { + throw CanteraError("initThermo", + "stoichiometric substances may only contain one species."); + } + /* + * Store the reference pressure in the variables for the class. + */ + m_p0 = refPressure(); + + /* + * Resize temporary arrays. + */ + int leng = 1; + m_h0_RT.resize(leng); + m_cp0_R.resize(leng); + m_s0_R.resize(leng); + /* + * Call the base class thermo initializer + */ + SingleSpeciesTP::initThermo(); } -void StoichSubstance::getEntropy_R_ref(doublereal* er) const +void StoichSubstance::initThermoXML(XML_Node& phaseNode, const std::string& id_) { - _updateThermo(); - er[0] = m_s0_R[0]; + /* + * Find the Thermo XML node + */ + if (!phaseNode.hasChild("thermo")) { + throw CanteraError("StoichSubstance::initThermoXML", + "no thermo XML node"); + } + XML_Node& tnode = phaseNode.child("thermo"); + std::string model = tnode["model"]; + if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") { + throw CanteraError("StoichSubstance::initThermoXML", + "thermo model attribute must be StoichSubstance"); + } + double dens = getFloatDefaultUnits(tnode, "density", "kg/m3"); + setDensity(dens); + SingleSpeciesTP::initThermoXML(phaseNode, id_); } -void StoichSubstance::getCp_R_ref(doublereal* cprt) const +void StoichSubstance::setParameters(int n, doublereal* const c) { - _updateThermo(); - cprt[0] = m_cp0_R[0]; + setDensity(c[0]); } -void StoichSubstance::setParameters(int n, double* const c) +void StoichSubstance::getParameters(int& n, doublereal* const c) const { - double rho = c[0]; - setDensity(rho); -} - -void StoichSubstance::getParameters(int& n, double* const c) const -{ - double rho = density(); - c[0] = rho; + n = 1; + c[0] = density(); } void StoichSubstance::setParametersFromXML(const XML_Node& eosdata) { - eosdata._require("model","StoichSubstance"); - doublereal rho = getFloat(eosdata, "density", "toSI"); - setDensity(rho); + std::string model = eosdata["model"]; + if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") { + throw CanteraError("StoichSubstance::setParametersFromXML", + "thermo model attribute must be StoichSubstance"); + } + setDensity(getFloat(eosdata, "density", "toSI")); } } diff --git a/src/thermo/StoichSubstanceSSTP.cpp b/src/thermo/StoichSubstanceSSTP.cpp deleted file mode 100644 index 6c167a5c9..000000000 --- a/src/thermo/StoichSubstanceSSTP.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/** - * @file StoichSubstanceSSTP.cpp - * Definition file for the StoichSubstanceSSTP class, which represents a fixed-composition - * incompressible substance (see \ref thermoprops and - * class \link Cantera::StoichSubstanceSSTP StoichSubstanceSSTP\endlink) - */ - -/* - * Copyright (2005) Sandia Corporation. Under the terms of - * Contract DE-AC04-94AL85000 with Sandia Corporation, the - * U.S. Government retains certain rights in this software. - * - * Copyright 2001 California Institute of Technology - */ -#include "cantera/thermo/StoichSubstanceSSTP.h" -#include "cantera/thermo/mix_defs.h" -#include "cantera/thermo/ThermoFactory.h" -#include "cantera/base/ctml.h" - -namespace Cantera -{ - -/* - * ---- Constructors ------- - */ - -StoichSubstanceSSTP::StoichSubstanceSSTP(const std::string& infile, const std::string& id_) -{ - initThermoFile(infile, id_); -} - -StoichSubstanceSSTP::StoichSubstanceSSTP(XML_Node& xmlphase, const std::string& id_) -{ - importPhase(xmlphase, this); -} - -StoichSubstanceSSTP::StoichSubstanceSSTP(const StoichSubstanceSSTP& right) -{ - *this = right; -} - -StoichSubstanceSSTP& -StoichSubstanceSSTP::operator=(const StoichSubstanceSSTP& right) -{ - if (&right != this) { - SingleSpeciesTP::operator=(right); - } - return *this; -} - -ThermoPhase* StoichSubstanceSSTP::duplMyselfAsThermoPhase() const -{ - return new StoichSubstanceSSTP(*this); -} - -/* - * ---- Utilities ----- - */ - -int StoichSubstanceSSTP::eosType() const -{ - return cStoichSubstance; -} - -/* - * ----- Mechanical Equation of State ------ - */ - -doublereal StoichSubstanceSSTP::pressure() const -{ - return m_press; -} - -void StoichSubstanceSSTP::setPressure(doublereal p) -{ - m_press = p; -} - -doublereal StoichSubstanceSSTP::isothermalCompressibility() const -{ - return 0.0; -} - -doublereal StoichSubstanceSSTP::thermalExpansionCoeff() const -{ - return 0.0; -} - -/* - * ---- Chemical Potentials and Activities ---- - */ - -void StoichSubstanceSSTP::getActivityConcentrations(doublereal* c) const -{ - c[0] = 1.0; -} - -doublereal StoichSubstanceSSTP::standardConcentration(size_t k) const -{ - return 1.0; -} - -doublereal StoichSubstanceSSTP::logStandardConc(size_t k) const -{ - return 0.0; -} - -/* - * Properties of the Standard State of the Species in the Solution - */ - -void StoichSubstanceSSTP::getStandardChemPotentials(doublereal* mu0) const -{ - getGibbs_RT(mu0); - mu0[0] *= GasConstant * temperature(); -} - -void StoichSubstanceSSTP::getEnthalpy_RT(doublereal* hrt) const -{ - getEnthalpy_RT_ref(hrt); - doublereal presCorrect = (m_press - m_p0) / molarDensity(); - hrt[0] += presCorrect / (GasConstant * temperature()); -} - -void StoichSubstanceSSTP::getEntropy_R(doublereal* sr) const -{ - getEntropy_R_ref(sr); -} - -void StoichSubstanceSSTP::getGibbs_RT(doublereal* grt) const -{ - getEnthalpy_RT(grt); - grt[0] -= m_s0_R[0]; -} - -void StoichSubstanceSSTP::getCp_R(doublereal* cpr) const -{ - _updateThermo(); - cpr[0] = m_cp0_R[0]; -} - -void StoichSubstanceSSTP::getIntEnergy_RT(doublereal* urt) const -{ - _updateThermo(); - urt[0] = m_h0_RT[0] - m_p0 / molarDensity() / (GasConstant * temperature()); -} - -/* - * ---- Thermodynamic Values for the Species Reference States ---- - */ - -void StoichSubstanceSSTP::getIntEnergy_RT_ref(doublereal* urt) const -{ - _updateThermo(); - urt[0] = m_h0_RT[0] - m_p0 / molarDensity() / (GasConstant * temperature()); -} - -/* - * ---- Initialization and Internal functions - */ - -void StoichSubstanceSSTP::initThermo() -{ - /* - * Make sure there is one and only one species in this phase. - */ - if (m_kk != 1) { - throw CanteraError("initThermo", - "stoichiometric substances may only contain one species."); - } - /* - * Store the reference pressure in the variables for the class. - */ - m_p0 = refPressure(); - - /* - * Resize temporary arrays. - */ - int leng = 1; - m_h0_RT.resize(leng); - m_cp0_R.resize(leng); - m_s0_R.resize(leng); - /* - * Call the base class thermo initializer - */ - SingleSpeciesTP::initThermo(); -} - -void StoichSubstanceSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_) -{ - /* - * Find the Thermo XML node - */ - if (!phaseNode.hasChild("thermo")) { - throw CanteraError("StoichSubstanceSSTP::initThermoXML", - "no thermo XML node"); - } - XML_Node& tnode = phaseNode.child("thermo"); - std::string model = tnode["model"]; - if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") { - throw CanteraError("StoichSubstanceSSTP::initThermoXML", - "thermo model attribute must be StoichSubstance"); - } - double dens = getFloatDefaultUnits(tnode, "density", "kg/m3"); - setDensity(dens); - SingleSpeciesTP::initThermoXML(phaseNode, id_); -} - -void StoichSubstanceSSTP::setParameters(int n, doublereal* const c) -{ - setDensity(c[0]); -} - -void StoichSubstanceSSTP::getParameters(int& n, doublereal* const c) const -{ - n = 1; - c[0] = density(); -} - -void StoichSubstanceSSTP::setParametersFromXML(const XML_Node& eosdata) -{ - std::string model = eosdata["model"]; - if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") { - throw CanteraError("StoichSubstanceSSTP::setParametersFromXML", - "thermo model attribute must be StoichSubstance"); - } - setDensity(getFloat(eosdata, "density", "toSI")); -} - -} diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index 4092b0225..5550abc3a 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -28,14 +28,7 @@ #include "cantera/thermo/EdgePhase.h" #include "cantera/thermo/MetalPhase.h" #include "cantera/thermo/SemiconductorPhase.h" - -#undef USE_SSTP -#ifdef USE_SSTP -#include "cantera/thermo/StoichSubstanceSSTP.h" -#else #include "cantera/thermo/StoichSubstance.h" -#endif - #include "cantera/thermo/MineralEQ3.h" #include "cantera/thermo/MetalSHEelectrons.h" #include "cantera/thermo/FixedChemPotSSTP.h" @@ -119,11 +112,7 @@ ThermoPhase* ThermoFactory::newThermoPhase(const std::string& model) case cMetal: return new MetalPhase; case cStoichSubstance: -#ifdef USE_SSTP - return new StoichSubstanceSSTP; -#else return new StoichSubstance; -#endif case cFixedChemPot: return new FixedChemPotSSTP; case cMineralEQ3: diff --git a/test_problems/.gitignore b/test_problems/.gitignore index b0714f7c7..cc6f22f92 100644 --- a/test_problems/.gitignore +++ b/test_problems/.gitignore @@ -35,7 +35,7 @@ cathermo/HMW_test_3/HMW_test_3 cathermo/VPissp/ISSPTester2 cathermo/ims/IMSTester cathermo/issp/ISSPTester -cathermo/stoichSubSSTP/stoichSubSSTP +cathermo/stoichSub/stoichSub cathermo/testIAPWS/testIAPWSphi cathermo/testIAPWSPres/testIAPWSPres cathermo/testIAPWSTripP/testIAPWSTripP diff --git a/test_problems/SConscript b/test_problems/SConscript index d2ccaac55..35ea7e9a6 100644 --- a/test_problems/SConscript +++ b/test_problems/SConscript @@ -204,8 +204,8 @@ CompileAndTest('HMW_test_3', 'cathermo/HMW_test_3', 'HMW_test_3', 'output_noD_blessed.txt') CompileAndTest('IMSTester', 'cathermo/ims', 'IMSTester', 'output_blessed.txt') CompileAndTest('ISSPTester', 'cathermo/issp', 'ISSPTester', 'output_blessed.txt') -CompileAndTest('stoichSubSSTP', 'cathermo/stoichSubSSTP', - 'stoichSubSSTP', 'output_blessed.txt') +CompileAndTest('stoichSub', 'cathermo/stoichSub', + 'stoichSub', 'output_blessed.txt') CompileAndTest('IAPWSphi', 'cathermo/testIAPWS', 'testIAPWSphi', 'output_blessed.txt') CompileAndTest('IAPWSPres', 'cathermo/testIAPWSPres', diff --git a/test_problems/VCSnonideal/LatticeSolid_LiSi/Li_Liquid.xml b/test_problems/VCSnonideal/LatticeSolid_LiSi/Li_Liquid.xml index a5f99266c..b188f442c 100644 --- a/test_problems/VCSnonideal/LatticeSolid_LiSi/Li_Liquid.xml +++ b/test_problems/VCSnonideal/LatticeSolid_LiSi/Li_Liquid.xml @@ -10,6 +10,10 @@ 0.48 + + 300.0 + 101325.0 + @@ -23,10 +27,10 @@ Li:1 - + 0.536504, -1.04279e-4, 3.84825e-9, -5.2853e-12 - + @@ -37,7 +41,7 @@ - 22.6832, 10.476, -6.5428, 1.3255, 0.8783, -2.0426, 62.8859 + 22.6832, 10.476, -6.5428, 1.3255, 0.8783, -2.0426, 62.8859 diff --git a/test_problems/VCSnonideal/NaCl_equil/nacl_equil.cpp b/test_problems/VCSnonideal/NaCl_equil/nacl_equil.cpp index 8b71fa497..a4e370f53 100644 --- a/test_problems/VCSnonideal/NaCl_equil/nacl_equil.cpp +++ b/test_problems/VCSnonideal/NaCl_equil/nacl_equil.cpp @@ -7,7 +7,7 @@ #include "cantera/thermo/ThermoFactory.h" #include "cantera/thermo/IdealGasPhase.h" #include "cantera/thermo/HMWSoln.h" -#include "cantera/thermo/StoichSubstanceSSTP.h" +#include "cantera/thermo/StoichSubstance.h" using namespace Cantera; using namespace std; @@ -105,7 +105,7 @@ int main(int argc, char** argv) gas->setState_TPX(T, pres, Xmol.data()); - StoichSubstanceSSTP ss("NaCl_Solid.xml", ""); + StoichSubstance ss("NaCl_Solid.xml", ""); ss.setState_TP(T, pres); diff --git a/test_problems/cathermo/stoichSubSSTP/NaCl_Solid.xml b/test_problems/cathermo/stoichSub/NaCl_Solid.xml similarity index 100% rename from test_problems/cathermo/stoichSubSSTP/NaCl_Solid.xml rename to test_problems/cathermo/stoichSub/NaCl_Solid.xml diff --git a/test_problems/cathermo/stoichSubSSTP/output_blessed.txt b/test_problems/cathermo/stoichSub/output_blessed.txt similarity index 100% rename from test_problems/cathermo/stoichSubSSTP/output_blessed.txt rename to test_problems/cathermo/stoichSub/output_blessed.txt diff --git a/test_problems/cathermo/stoichSubSSTP/stoichSubSSTP.cpp b/test_problems/cathermo/stoichSub/stoichSub.cpp similarity index 96% rename from test_problems/cathermo/stoichSubSSTP/stoichSubSSTP.cpp rename to test_problems/cathermo/stoichSub/stoichSub.cpp index a2c416515..ad270131f 100644 --- a/test_problems/cathermo/stoichSubSSTP/stoichSubSSTP.cpp +++ b/test_problems/cathermo/stoichSub/stoichSub.cpp @@ -4,7 +4,7 @@ */ #include "cantera/thermo.h" -#include "cantera/thermo/StoichSubstanceSSTP.h" +#include "cantera/thermo/StoichSubstance.h" #include "TemperatureTable.h" @@ -19,7 +19,7 @@ int main(int argc, char** argv) std::string iFile = (argc > 1) ? argv[1] : "NaCl_Solid.xml"; std::string file_ID = iFile + "#NaCl(S)"; XML_Node* xm = get_XML_NameID("phase", file_ID, 0); - StoichSubstanceSSTP* solid = new StoichSubstanceSSTP(*xm); + StoichSubstance* solid = new StoichSubstance(*xm); size_t nsp = solid->nSpecies(); if (nsp != 1) {