Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vcs_nondim.cpp
Go to the documentation of this file.
1 /**
2  * @file vcs_nondim.cpp
3  * Nondimensionalization routines within VCSnonideal
4  */
5 /*
6  * Copyright (2007) 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 
15 
16 namespace Cantera
17 {
18 double VCS_SOLVE::vcs_nondim_Farad(int mu_units, double TKelvin) const
19 {
20  if (TKelvin <= 0.0) {
21  TKelvin = 293.15;
22  }
23  switch (mu_units) {
24  case VCS_UNITS_MKS:
25  case VCS_UNITS_KJMOL:
26  case VCS_UNITS_KCALMOL:
27  return ElectronCharge * Avogadro / (TKelvin * GasConstant);
28  case VCS_UNITS_UNITLESS:
29  return ElectronCharge * Avogadro;
30  case VCS_UNITS_KELVIN:
31  return ElectronCharge * Avogadro/ TKelvin;
32  default:
33  throw CanteraError("vcs_nondim_Farad",
34  "unknown units: " + int2str(mu_units));
35  }
36 }
37 
38 double VCS_SOLVE::vcs_nondimMult_TP(int mu_units, double TKelvin) const
39 {
40  if (TKelvin <= 0.0) {
41  TKelvin = 293.15;
42  }
43  switch (mu_units) {
44  case VCS_UNITS_KCALMOL:
45  return TKelvin * GasConst_cal_mol_K * 1e-3;
46  case VCS_UNITS_UNITLESS:
47  return 1.0;
48  case VCS_UNITS_KJMOL:
49  return TKelvin * GasConstant * 1e-6;
50  case VCS_UNITS_KELVIN:
51  return TKelvin;
52  case VCS_UNITS_MKS:
53  return TKelvin * GasConstant;
54  default:
55  throw CanteraError("vcs_nondimMult_TP",
56  "unknown units: " + int2str(mu_units));
57  }
58 }
59 
61 {
65  for (size_t i = 0; i < m_numSpeciesTot; ++i) {
66  /*
67  * Modify the standard state and total chemical potential data,
68  * FF(I), to make it dimensionless, i.e., mu / RT.
69  * Thus, we may divide it by the temperature.
70  */
71  m_SSfeSpecies[i] *= tf;
72  m_deltaGRxn_new[i] *= tf;
73  m_deltaGRxn_old[i] *= tf;
74  m_feSpecies_old[i] *= tf;
75  }
76 
78 
79  /*
80  * Scale the total moles if necessary:
81  * First find out the total moles
82  */
83  double tmole_orig = vcs_tmoles();
84 
85  /*
86  * Then add in the total moles of elements that are goals. Either one
87  * or the other is specified here.
88  */
89  double esum = 0.0;
90  for (size_t i = 0; i < m_numElemConstraints; ++i) {
91  if (m_elType[i] == VCS_ELEM_TYPE_ABSPOS) {
92  esum += fabs(m_elemAbundancesGoal[i]);
93  }
94  }
95  tmole_orig += esum;
96 
97  /*
98  * Ok now test out the bounds on the total moles that this program can
99  * handle. These are a bit arbitrary. However, it would seem that any
100  * reasonable input would be between these two numbers below.
101  */
102  if (tmole_orig < 1.0E-200 || tmole_orig > 1.0E200) {
103  throw CanteraError("VCS_SOLVE::vcs_nondim_TP",
104  "Total input moles ," + fp2str(tmole_orig) +
105  "is outside the range handled by vcs.\n");
106  }
107 
108  // Determine the scale of the problem
109  if (tmole_orig > 1.0E4) {
110  m_totalMoleScale = tmole_orig / 1.0E4;
111  } else if (tmole_orig < 1.0E-4) {
112  m_totalMoleScale = tmole_orig / 1.0E-4;
113  } else {
114  m_totalMoleScale = 1.0;
115  }
116 
117  if (m_totalMoleScale != 1.0) {
118  if (m_VCS_UnitsFormat == VCS_UNITS_MKS) {
119  if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
120  plogf(" --- vcs_nondim_TP() called: USING A MOLE SCALE OF %g until further notice", m_totalMoleScale);
121  plogendl();
122  }
123  for (size_t i = 0; i < m_numSpeciesTot; ++i) {
126  }
127  }
128  for (size_t i = 0; i < m_numElemConstraints; ++i) {
130  }
131 
132  for (size_t iph = 0; iph < m_numPhases; iph++) {
133  TPhInertMoles[iph] *= (1.0 / m_totalMoleScale);
134  if (TPhInertMoles[iph] != 0.0) {
135  vcs_VolPhase* vphase = m_VolPhaseList[iph];
136  vphase->setTotalMolesInert(TPhInertMoles[iph]);
137  }
138  }
139  }
140  vcs_tmoles();
141  }
142  }
143 }
144 
146 {
150  for (size_t i = 0; i < m_numSpeciesTot; ++i) {
151  /*
152  * Modify the standard state and total chemical potential data,
153  * FF(I), to make it have units, i.e. mu = RT * mu_star
154  */
155  m_SSfeSpecies[i] *= tf;
156  m_deltaGRxn_new[i] *= tf;
157  m_deltaGRxn_old[i] *= tf;
158  m_feSpecies_old[i] *= tf;
159  }
160  m_Faraday_dim *= tf;
161  }
162  if (m_totalMoleScale != 1.0) {
163  if (m_VCS_UnitsFormat == VCS_UNITS_MKS) {
164  if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
165  plogf(" --- vcs_redim_TP() called: getting rid of mole scale of %g", m_totalMoleScale);
166  plogendl();
167  }
168  for (size_t i = 0; i < m_numSpeciesTot; ++i) {
171  }
172  }
173  for (size_t i = 0; i < m_numElemConstraints; ++i) {
175  }
176 
177  for (size_t iph = 0; iph < m_numPhases; iph++) {
179  if (TPhInertMoles[iph] != 0.0) {
180  vcs_VolPhase* vphase = m_VolPhaseList[iph];
181  vphase->setTotalMolesInert(TPhInertMoles[iph]);
182  }
183  }
184  vcs_tmoles();
185  }
186  }
187 }
188 
189 void VCS_SOLVE::vcs_printChemPotUnits(int unitsFormat) const
190 {
191  switch (unitsFormat) {
192  case VCS_UNITS_KCALMOL:
193  plogf("kcal/gmol");
194  break;
195  case VCS_UNITS_UNITLESS:
196  plogf("dimensionless");
197  break;
198  case VCS_UNITS_KJMOL:
199  plogf("kJ/gmol");
200  break;
201  case VCS_UNITS_KELVIN:
202  plogf("Kelvin");
203  break;
204  case VCS_UNITS_MKS:
205  plogf("J/kmol");
206  break;
207  default:
208  throw CanteraError("VCS_SOLVE::vcs_printChemPotUnits", "unknown units!");
209  }
210 }
211 
212 }
double vcs_nondimMult_TP(int mu_units, double TKelvin) const
Returns the multiplier for the nondimensionalization of the equations.
Definition: vcs_nondim.cpp:38
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:39
std::vector< int > m_elType
Type of the element constraint.
Definition: vcs_solve.h:1860
double vcs_nondim_Farad(int mu_units, double TKelvin) const
Returns the multiplier for electric charge terms.
Definition: vcs_nondim.cpp:18
double m_Faraday_dim
dimensionless value of Faraday's constant, F / RT (1/volt)
Definition: vcs_solve.h:1976
std::vector< vcs_VolPhase * > m_VolPhaseList
Array of Phase Structures. Length = number of phases.
Definition: vcs_solve.h:1869
void vcs_nondim_TP()
Nondimensionalize the problem data.
Definition: vcs_nondim.cpp:60
double vcs_tmoles()
Calculates the total number of moles of species in all phases.
void vcs_redim_TP()
Redimensionalize the problem data.
Definition: vcs_nondim.cpp:145
void vcs_printChemPotUnits(int unitsFormat) const
Print the string representing the Chemical potential units.
Definition: vcs_nondim.cpp:189
int m_VCS_UnitsFormat
Units for the chemical potential data.
Definition: vcs_solve.h:2014
std::vector< double > m_molNumSpecies_old
Total moles of the species.
Definition: vcs_solve.h:1612
#define VCS_NONDIMENSIONAL_G
nondimensional
Definition: vcs_defs.h:100
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.
#define VCS_ELEM_TYPE_ABSPOS
Normal element constraint consisting of positive coefficients for the formula matrix.
Definition: vcs_defs.h:290
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:28
size_t m_numElemConstraints
Number of element constraints in the problem.
Definition: vcs_solve.h:1499
size_t m_numSpeciesTot
Total number of species in the problems.
Definition: vcs_solve.h:1493
std::vector< int > m_speciesUnknownType
Specifies the species unknown type.
Definition: vcs_solve.h:1625
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
int m_debug_print_lvl
Debug printing lvl.
Definition: vcs_solve.h:1995
std::vector< double > m_SSfeSpecies
Standard state chemical potentials for species K at the current temperature and pressure.
Definition: vcs_solve.h:1577
double m_temperature
Temperature (Kelvin)
Definition: vcs_solve.h:1734
Phase information and Phase calculations for vcs.
Definition: vcs_VolPhase.h:86
#define VCS_DIMENSIONAL_G
dimensioned
Definition: vcs_defs.h:102
const doublereal Avogadro
Avogadro's Number [number/kmol].
Definition: ct_defs.h:61
#define plogendl()
define this Cantera function to replace cout << endl;
Definition: vcs_internal.h:31
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
Contains declarations for string manipulation functions within Cantera.
const doublereal GasConst_cal_mol_K
Universal gas constant in cal/mol/K.
Definition: ct_defs.h:73
#define plogf
define this Cantera function to replace printf
Definition: vcs_internal.h:24
#define VCS_SPECIES_TYPE_INTERFACIALVOLTAGE
Unknown refers to the voltage level of a phase.
Definition: vcs_defs.h:352
char m_unitsState
This specifies the current state of units for the Gibbs free energy properties in the program...
Definition: vcs_solve.h:1879
size_t m_numPhases
Number of Phases in the problem.
Definition: vcs_solve.h:1526
double m_totalMoleScale
Multiplier for the mole numbers within the nondimensionless formulation.
Definition: vcs_solve.h:1888
std::vector< double > TPhInertMoles
Total kmoles of inert to add to each phase.
Definition: vcs_solve.h:1755
std::vector< double > m_elemAbundancesGoal
Element abundances vector Goals.
Definition: vcs_solve.h:1695
std::vector< double > m_feSpecies_old
Free energy vector from the start of the current iteration.
Definition: vcs_solve.h:1584
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
std::vector< double > m_deltaGRxn_new
Delta G(irxn) for the noncomponent species in the mechanism.
Definition: vcs_solve.h:1654
void setTotalMolesInert(const double tMolesInert)
Sets the total moles of inert in the phase.
std::vector< double > m_deltaGRxn_old
Last deltag[irxn] from the previous step.
Definition: vcs_solve.h:1657