Cantera  2.1.2
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 
13 #include "cantera/equil/vcs_defs.h"
15 
18 
19 using namespace std;
20 
21 namespace VCSnonideal
22 {
23 VCS_SPECIES_THERMO::VCS_SPECIES_THERMO(size_t indexPhase,
24  size_t indexSpeciesPhase) :
25 
26  IndexPhase(indexPhase),
27  IndexSpeciesPhase(indexSpeciesPhase),
28  OwningPhase(0),
29  SS0_Model(VCS_SS0_CONSTANT),
30  SS0_feSave(0.0),
31  SS0_TSave(-90.0),
32  SS0_T0(273.15),
33  SS0_H0(0.0),
34  SS0_S0(0.0),
35  SS0_Cp0(0.0),
36  SS0_Pref(1.01325E5),
37  SS0_Params(0),
38  SSStar_Model(VCS_SSSTAR_CONSTANT),
39  SSStar_Params(0),
40  Activity_Coeff_Model(VCS_AC_CONSTANT),
41  Activity_Coeff_Params(0),
42  SSStar_Vol_Model(VCS_SSVOL_IDEALGAS),
43  SSStar_Vol_Params(0),
44  SSStar_Vol0(-1.0),
45  UseCanteraCalls(false),
46  m_VCS_UnitsFormat(VCS_UNITS_UNITLESS)
47 {
48  SS0_Pref = 1.01325E5;
49 }
50 
51 VCS_SPECIES_THERMO::~VCS_SPECIES_THERMO()
52 {
53 }
54 
55 VCS_SPECIES_THERMO::VCS_SPECIES_THERMO(const VCS_SPECIES_THERMO& b) :
56  IndexPhase(b.IndexPhase),
57  IndexSpeciesPhase(b.IndexSpeciesPhase),
58  OwningPhase(b.OwningPhase),
59  SS0_Model(b.SS0_Model),
60  SS0_feSave(b.SS0_feSave),
61  SS0_TSave(b.SS0_TSave),
62  SS0_T0(b.SS0_T0),
63  SS0_H0(b.SS0_H0),
64  SS0_S0(b.SS0_S0),
65  SS0_Cp0(b.SS0_Cp0),
66  SS0_Pref(b.SS0_Pref),
67  SS0_Params(0),
68  SSStar_Model(b.SSStar_Model),
69  SSStar_Params(0),
70  Activity_Coeff_Model(b.Activity_Coeff_Model),
71  Activity_Coeff_Params(0),
72  SSStar_Vol_Model(b.SSStar_Vol_Model),
73  SSStar_Vol_Params(0),
74  SSStar_Vol0(b.SSStar_Vol0),
75  UseCanteraCalls(b.UseCanteraCalls),
76  m_VCS_UnitsFormat(b.m_VCS_UnitsFormat)
77 {
78  SS0_Params = 0;
79 }
80 
81 VCS_SPECIES_THERMO&
82 VCS_SPECIES_THERMO::operator=(const VCS_SPECIES_THERMO& b)
83 {
84  if (&b != this) {
85  IndexPhase = b.IndexPhase;
86  IndexSpeciesPhase = b.IndexSpeciesPhase;
87  OwningPhase = b.OwningPhase;
88  SS0_Model = b.SS0_Model;
89  SS0_feSave = b.SS0_feSave;
90  SS0_TSave = b.SS0_TSave;
91  SS0_T0 = b.SS0_T0;
92  SS0_H0 = b.SS0_H0;
93  SS0_S0 = b.SS0_S0;
94  SS0_Cp0 = b.SS0_Cp0;
95  SS0_Pref = b.SS0_Pref;
96  SSStar_Model = b.SSStar_Model;
97  /*
98  * shallow copy because function is undeveloped.
99  */
100  SSStar_Params = b.SSStar_Params;
101  Activity_Coeff_Model = b.Activity_Coeff_Model;
102  /*
103  * shallow copy because function is undeveloped.
104  */
105  Activity_Coeff_Params = b.Activity_Coeff_Params;
106  SSStar_Vol_Model = b.SSStar_Vol_Model;
107  /*
108  * shallow copy because function is undeveloped.
109  */
110  SSStar_Vol_Params = b.SSStar_Vol_Params;
111  SSStar_Vol0 = b.SSStar_Vol0;
112  UseCanteraCalls = b.UseCanteraCalls;
113  m_VCS_UnitsFormat = b.m_VCS_UnitsFormat;
114  }
115  return *this;
116 }
117 
119 {
120  return new VCS_SPECIES_THERMO(*this);
121 }
122 
123 double VCS_SPECIES_THERMO::GStar_R_calc(size_t kglob, double TKelvin,
124  double pres)
125 {
126  char yo[] = "VCS_SPECIES_THERMO::GStar_R_calc ";
127  double fe, T;
128  fe = G0_R_calc(kglob, TKelvin);
129  T = TKelvin;
130  if (UseCanteraCalls) {
131  if (m_VCS_UnitsFormat != VCS_UNITS_MKS) {
132  throw Cantera::CanteraError("VCS_SPECIES_THERMO::GStar_R_calc",
133  "Possible inconsistency");
134  }
135  size_t kspec = IndexSpeciesPhase;
136  OwningPhase->setState_TP(TKelvin, pres);
137  fe = OwningPhase->GStar_calc_one(kspec);
138  double R = vcsUtil_gasConstant(m_VCS_UnitsFormat);
139  fe /= R;
140  } else {
141  double pref = SS0_Pref;
142  switch (SSStar_Model) {
143  case VCS_SSSTAR_CONSTANT:
144  break;
145  case VCS_SSSTAR_IDEAL_GAS:
146  fe += T * log(pres/ pref);
147  break;
148  default:
149  plogf("%sERROR: unknown SSStar model\n", yo);
150  exit(EXIT_FAILURE);
151  }
152  }
153  return fe;
154 }
155 
157 VolStar_calc(size_t kglob, double TKelvin, double presPA)
158 {
159  char yo[] = "VCS_SPECIES_THERMO::VStar_calc ";
160  double vol, T;
161 
162  T = TKelvin;
163  if (UseCanteraCalls) {
164  if (m_VCS_UnitsFormat != VCS_UNITS_MKS) {
165  throw Cantera::CanteraError("VCS_SPECIES_THERMO::VolStar_calc",
166  "Possible inconsistency");
167  }
168  size_t kspec = IndexSpeciesPhase;
169  OwningPhase->setState_TP(TKelvin, presPA);
170  vol = OwningPhase->VolStar_calc_one(kspec);
171  } else {
172  switch (SSStar_Vol_Model) {
173  case VCS_SSVOL_CONSTANT:
174  vol = SSStar_Vol0;
175  break;
176  case VCS_SSVOL_IDEALGAS:
177  vol= Cantera::GasConstant * T / presPA;
178  break;
179  default:
180  plogf("%sERROR: unknown SSVol model\n", yo);
181  exit(EXIT_FAILURE);
182  }
183  }
184  return vol;
185 }
186 
187 double VCS_SPECIES_THERMO::G0_R_calc(size_t kglob, double TKelvin)
188 {
189 #ifdef DEBUG_MODE
190  char yo[] = "VS_SPECIES_THERMO::G0_R_calc ";
191 #endif
192  double fe, H, S;
193  if (SS0_Model == VCS_SS0_CONSTANT) {
194  return SS0_feSave;
195  }
196  if (TKelvin == SS0_TSave) {
197  return SS0_feSave;
198  }
199  if (UseCanteraCalls) {
200  if (m_VCS_UnitsFormat != VCS_UNITS_MKS) {
201  throw Cantera::CanteraError("VCS_SPECIES_THERMO::G0_R_calc",
202  "Possible inconsistency");
203  }
204  size_t kspec = IndexSpeciesPhase;
205  OwningPhase->setState_T(TKelvin);
206  fe = OwningPhase->G0_calc_one(kspec);
207  double R = vcsUtil_gasConstant(m_VCS_UnitsFormat);
208  fe /= R;
209  } else {
210  switch (SS0_Model) {
211  case VCS_SS0_CONSTANT:
212  fe = SS0_feSave;
213  break;
214  case VCS_SS0_CONSTANT_CP:
215  H = SS0_H0 + (TKelvin - SS0_T0) * SS0_Cp0;
216  S = SS0_Cp0 + SS0_Cp0 * log((TKelvin / SS0_T0));
217  fe = H - TKelvin * S;
218  break;
219  default:
220 #ifdef DEBUG_MODE
221  plogf("%sERROR: unknown model\n", yo);
222 #endif
223  exit(EXIT_FAILURE);
224  }
225  }
226  SS0_feSave = fe;
227  SS0_TSave = TKelvin;
228  return fe;
229 }
230 
231 double VCS_SPECIES_THERMO::eval_ac(size_t kglob)
232 {
233 #ifdef DEBUG_MODE
234  char yo[] = "VCS_SPECIES_THERMO::eval_ac ";
235 #endif
236  double ac;
237  /*
238  * Activity coefficients are frequently evaluated on a per phase
239  * basis. If they are, then the currPhAC[] boolean may be used
240  * to reduce repeated work. Just set currPhAC[iph], when the
241  * activity coefficients for all species in the phase are reevaluated.
242  */
243  if (UseCanteraCalls) {
244  size_t kspec = IndexSpeciesPhase;
245  ac = OwningPhase->AC_calc_one(kspec);
246  } else {
247  switch (Activity_Coeff_Model) {
248  case VCS_AC_CONSTANT:
249  ac = 1.0;
250  break;
251  default:
252 #ifdef DEBUG_MODE
253  plogf("%sERROR: unknown model\n", yo);
254 #endif
255  exit(EXIT_FAILURE);
256  }
257  }
258  return ac;
259 }
260 
261 }
double SS0_Pref
Value of the pressure for the reference state.
double vcsUtil_gasConstant(int mu_units)
Returns the value of the gas constant in the units specified by parameter.
Definition: vcs_util.cpp:506
double SSStar_Vol0
parameter that is used in the VCS_SSVOL_CONSTANT model.
int SS0_Model
Integer representing the models for the species standard state Naught temperature dependence...
double SS0_S0
Base entropy used in the VCS_SS0_CONSTANT_CP model.
virtual double eval_ac(size_t kspec)
This function evaluates the activity coefficient for species, kspec.
int SSStar_Vol_Model
Models for the standard state volume of each species.
bool UseCanteraCalls
If true, this object will call Cantera to do its member calculations.
size_t IndexSpeciesPhase
Index of this species in the current phase.
int SSStar_Model
Integer value representing the star state model.
double VolStar_calc_one(size_t kspec) const
Molar volume calculation for standard state of one species.
int Activity_Coeff_Model
Integer value representing the activity coefficient model These are defined in vcs_VolPhase.h and start with VCS_AC_...
#define VCS_SSVOL_IDEALGAS
Models for the standard state volume of each species.
Definition: vcs_VolPhase.h:34
vcs_VolPhase * OwningPhase
Pointer to the owning phase object.
double GStar_calc_one(size_t kspec) const
Gibbs free energy calculation for standard state of one species.
void * SSStar_Params
Pointer to a list of parameters that is malloced for complicated reference star state calculation...
Header file for the internal object that holds the vcs equilibrium problem (see Class VCS_SOLVE and E...
Header for the object representing each phase within vcs.
Defines and definitions within the vcs package.
Internal declarations for the VCSnonideal package.
double SS0_Cp0
Base heat capacity used in the VCS_SS0_CONSTANT_CP model.
virtual double G0_R_calc(size_t kspec, double TKelvin)
This function calculates the standard state Gibbs free energy for species, kspec, at the temperature ...
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.
void * SSStar_Vol_Params
Pointer to a list of parameters that is malloced for volume models.
double AC_calc_one(size_t kspec) const
Evaluate activity coefficients and return the kspec coefficient.
double SS0_T0
Base temperature used in the VCS_SS0_CONSTANT_CP model.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
void setState_T(const double temperature_Kelvin)
Sets the temperature in this object and underlying ThermoPhase objects.
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 SS0_TSave
Internal storage of the last temperature used in the calculation of the reference naught Gibbs free e...
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 ...
void * Activity_Coeff_Params
Pointer to a list of parameters that is malloced for activity coefficient models. ...
double SS0_feSave
Internal storage of the last calculation of the reference naught Gibbs free energy at SS0_TSave...
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
#define plogf
define this Cantera function to replace printf
Definition: vcs_internal.h:30
virtual VCS_SPECIES_THERMO * duplMyselfAsVCS_SPECIES_THERMO()
Duplication function for derived classes.
void setState_TP(const double temperature_Kelvin, const double pressure_PA)
Sets the temperature and pressure in this object and underlying ThermoPhase objects.
size_t IndexPhase
Index of the phase that this species belongs to.
double SS0_H0
Base enthalpy used in the VCS_SS0_CONSTANT_CP model.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...