Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vcs_species_thermo.cpp
Go to the documentation of this file.
1 /**
2  * @file vcs_species_thermo.cpp Implementation for the VCS_SPECIES_THERMO
3  * object.
4  */
5 /*
6  * Copyright (2005) Sandia Corporation. Under the terms of
7  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
8  * U.S. Government retains certain rights in this software.
9  */
10 
12 #include "cantera/equil/vcs_defs.h"
14 
17 
18 using namespace std;
19 namespace Cantera
20 {
21 VCS_SPECIES_THERMO::VCS_SPECIES_THERMO(size_t indexPhase,
22  size_t indexSpeciesPhase) :
23 
24  IndexPhase(indexPhase),
25  IndexSpeciesPhase(indexSpeciesPhase),
26  OwningPhase(0),
27  SS0_Model(VCS_SS0_CONSTANT),
28  SS0_feSave(0.0),
29  SS0_TSave(-90.0),
30  SS0_T0(273.15),
31  SS0_H0(0.0),
32  SS0_S0(0.0),
33  SS0_Cp0(0.0),
34  SS0_Pref(1.01325E5),
35  SSStar_Model(VCS_SSSTAR_CONSTANT),
36  SSStar_Vol_Model(VCS_SSVOL_IDEALGAS),
37  SSStar_Vol0(-1.0),
38  UseCanteraCalls(false),
39  m_VCS_UnitsFormat(VCS_UNITS_UNITLESS)
40 {
41  SS0_Pref = 1.01325E5;
42 }
43 
44 VCS_SPECIES_THERMO::VCS_SPECIES_THERMO(const VCS_SPECIES_THERMO& b) :
45  IndexPhase(b.IndexPhase),
46  IndexSpeciesPhase(b.IndexSpeciesPhase),
47  OwningPhase(b.OwningPhase),
48  SS0_Model(b.SS0_Model),
49  SS0_feSave(b.SS0_feSave),
50  SS0_TSave(b.SS0_TSave),
51  SS0_T0(b.SS0_T0),
52  SS0_H0(b.SS0_H0),
53  SS0_S0(b.SS0_S0),
54  SS0_Cp0(b.SS0_Cp0),
55  SS0_Pref(b.SS0_Pref),
56  SSStar_Model(b.SSStar_Model),
57  SSStar_Vol_Model(b.SSStar_Vol_Model),
58  SSStar_Vol0(b.SSStar_Vol0),
59  UseCanteraCalls(b.UseCanteraCalls),
60  m_VCS_UnitsFormat(b.m_VCS_UnitsFormat)
61 {
62 }
63 
64 VCS_SPECIES_THERMO&
65 VCS_SPECIES_THERMO::operator=(const VCS_SPECIES_THERMO& b)
66 {
67  if (&b != this) {
68  IndexPhase = b.IndexPhase;
69  IndexSpeciesPhase = b.IndexSpeciesPhase;
70  OwningPhase = b.OwningPhase;
71  SS0_Model = b.SS0_Model;
72  SS0_feSave = b.SS0_feSave;
73  SS0_TSave = b.SS0_TSave;
74  SS0_T0 = b.SS0_T0;
75  SS0_H0 = b.SS0_H0;
76  SS0_S0 = b.SS0_S0;
77  SS0_Cp0 = b.SS0_Cp0;
78  SS0_Pref = b.SS0_Pref;
79  SSStar_Model = b.SSStar_Model;
80  SSStar_Vol_Model = b.SSStar_Vol_Model;
81  SSStar_Vol0 = b.SSStar_Vol0;
82  UseCanteraCalls = b.UseCanteraCalls;
83  m_VCS_UnitsFormat = b.m_VCS_UnitsFormat;
84  }
85  return *this;
86 }
87 
89 {
90  return new VCS_SPECIES_THERMO(*this);
91 }
92 
93 double VCS_SPECIES_THERMO::GStar_R_calc(size_t kglob, double TKelvin,
94  double pres)
95 {
96  double fe = G0_R_calc(kglob, TKelvin);
97  double T = TKelvin;
98  if (UseCanteraCalls) {
99  if (m_VCS_UnitsFormat != VCS_UNITS_MKS) {
100  throw CanteraError("VCS_SPECIES_THERMO::GStar_R_calc",
101  "Possible inconsistency");
102  }
103  size_t kspec = IndexSpeciesPhase;
104  OwningPhase->setState_TP(TKelvin, pres);
105  fe = OwningPhase->GStar_calc_one(kspec);
106  double R = vcsUtil_gasConstant(m_VCS_UnitsFormat);
107  fe /= R;
108  } else {
109  double pref = SS0_Pref;
110  switch (SSStar_Model) {
111  case VCS_SSSTAR_CONSTANT:
112  break;
113  case VCS_SSSTAR_IDEAL_GAS:
114  fe += T * log(pres/ pref);
115  break;
116  default:
117  throw CanteraError("VCS_SPECIES_THERMO::GStar_R_calc",
118  "unknown SSStar model");
119  }
120  }
121  return fe;
122 }
123 
124 double VCS_SPECIES_THERMO::VolStar_calc(size_t kglob, double TKelvin,
125  double presPA)
126 {
127  double vol;
128 
129  double T = TKelvin;
130  if (UseCanteraCalls) {
131  if (m_VCS_UnitsFormat != VCS_UNITS_MKS) {
132  throw CanteraError("VCS_SPECIES_THERMO::VolStar_calc",
133  "Possible inconsistency");
134  }
135  size_t kspec = IndexSpeciesPhase;
136  OwningPhase->setState_TP(TKelvin, presPA);
137  vol = OwningPhase->VolStar_calc_one(kspec);
138  } else {
139  switch (SSStar_Vol_Model) {
140  case VCS_SSVOL_CONSTANT:
141  vol = SSStar_Vol0;
142  break;
143  case VCS_SSVOL_IDEALGAS:
144  vol= GasConstant * T / presPA;
145  break;
146  default:
147  throw CanteraError("VCS_SPECIES_THERMO::VolStar_calc",
148  "unknown SSVol model");
149  }
150  }
151  return vol;
152 }
153 
154 double VCS_SPECIES_THERMO::G0_R_calc(size_t kglob, double TKelvin)
155 {
156  double fe, H, S;
157  if (SS0_Model == VCS_SS0_CONSTANT) {
158  return SS0_feSave;
159  }
160  if (TKelvin == SS0_TSave) {
161  return SS0_feSave;
162  }
163  if (UseCanteraCalls) {
164  if (m_VCS_UnitsFormat != VCS_UNITS_MKS) {
165  throw CanteraError("VCS_SPECIES_THERMO::G0_R_calc",
166  "Possible inconsistency");
167  }
168  size_t kspec = IndexSpeciesPhase;
169  OwningPhase->setState_T(TKelvin);
170  fe = OwningPhase->G0_calc_one(kspec);
171  double R = vcsUtil_gasConstant(m_VCS_UnitsFormat);
172  fe /= R;
173  } else {
174  switch (SS0_Model) {
175  case VCS_SS0_CONSTANT:
176  fe = SS0_feSave;
177  break;
178  case VCS_SS0_CONSTANT_CP:
179  H = SS0_H0 + (TKelvin - SS0_T0) * SS0_Cp0;
180  S = SS0_Cp0 + SS0_Cp0 * log((TKelvin / SS0_T0));
181  fe = H - TKelvin * S;
182  break;
183  default:
184  throw CanteraError("VCS_SPECIES_THERMO::G0_R_calc",
185  "unknown model");
186  }
187  }
188  SS0_feSave = fe;
189  SS0_TSave = TKelvin;
190  return fe;
191 }
192 
193 double VCS_SPECIES_THERMO::eval_ac(size_t kglob)
194 {
195  double ac;
196  /*
197  * Activity coefficients are frequently evaluated on a per phase
198  * basis. If they are, then the currPhAC[] boolean may be used
199  * to reduce repeated work. Just set currPhAC[iph], when the
200  * activity coefficients for all species in the phase are reevaluated.
201  */
202  if (UseCanteraCalls) {
203  size_t kspec = IndexSpeciesPhase;
204  ac = OwningPhase->AC_calc_one(kspec);
205  } else {
206  ac = 1.0;
207  }
208  return ac;
209 }
210 
211 }
double G0_calc_one(size_t kspec) const
Gibbs free energy calculation at a temperature for the reference state of a species, return a value for one species.
double GStar_calc_one(size_t kspec) const
Gibbs free energy calculation for standard state of one species.
vcs_VolPhase * OwningPhase
Pointer to the owning phase object.
virtual double GStar_R_calc(size_t kspec, double TKelvin, double pres)
This function calculates the standard state Gibbs free energy for species, kspec, at the temperature ...
double SS0_Cp0
Base heat capacity used in the VCS_SS0_CONSTANT_CP model.
double AC_calc_one(size_t kspec) const
Evaluate activity coefficients and return the kspec coefficient.
size_t IndexSpeciesPhase
Index of this species in the current phase.
#define VCS_SSVOL_IDEALGAS
Models for the standard state volume of each species.
Definition: vcs_VolPhase.h:23
virtual double VolStar_calc(size_t kglob, double TKelvin, double Pres)
This function calculates the standard state molar volume for species, kspec, at the temperature TKelv...
double vcsUtil_gasConstant(int mu_units)
Returns the value of the gas constant in the units specified by parameter.
Definition: vcs_util.cpp:76
Header for the object representing each phase within vcs.
double SSStar_Vol0
parameter that is used in the VCS_SSVOL_CONSTANT model.
Defines and definitions within the vcs package.
int SSStar_Vol_Model
Models for the standard state volume of each species.
double SS0_S0
Base entropy used in the VCS_SS0_CONSTANT_CP model.
Internal declarations for the VCSnonideal package.
size_t IndexPhase
Index of the phase that this species belongs to.
virtual double eval_ac(size_t kspec)
This function evaluates the activity coefficient for species, kspec.
virtual VCS_SPECIES_THERMO * duplMyselfAsVCS_SPECIES_THERMO()
Duplication function for derived classes.
double SS0_H0
Base enthalpy used in the VCS_SS0_CONSTANT_CP model.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
virtual double G0_R_calc(size_t kglob, double TKelvin)
This function calculates the standard state Gibbs free energy for species, kspec, at the temperature ...
double SS0_T0
Base temperature used in the VCS_SS0_CONSTANT_CP model.
int SSStar_Model
Integer value representing the star state model.
int SS0_Model
Integer representing the models for the species standard state Naught temperature dependence...
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
bool UseCanteraCalls
If true, this object will call Cantera to do its member calculations.
double VolStar_calc_one(size_t kspec) const
Molar volume calculation for standard state of one species.
void setState_T(const double temperature_Kelvin)
Sets the temperature in this object and underlying ThermoPhase objects.
void setState_TP(const double temperature_Kelvin, const double pressure_PA)
Sets the temperature and pressure in this object and underlying ThermoPhase objects.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
double SS0_TSave
Internal storage of the last temperature used in the calculation of the reference naught Gibbs free e...
double SS0_feSave
Internal storage of the last calculation of the reference naught Gibbs free energy at SS0_TSave...
double SS0_Pref
Value of the pressure for the reference state.