Cantera  2.1.2
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 
16 
17 namespace VCSnonideal
18 {
19 double VCS_SOLVE::vcs_nondim_Farad(int mu_units, double TKelvin) const
20 {
21  double Farad;
22  if (TKelvin <= 0.0) {
23  TKelvin = 293.15;
24  }
25  switch (mu_units) {
26  case VCS_UNITS_MKS:
27  case VCS_UNITS_KJMOL:
28  case VCS_UNITS_KCALMOL:
29  Farad = Cantera::ElectronCharge * Cantera::Avogadro /
30  (TKelvin * Cantera::GasConstant);
31  break;
32  case VCS_UNITS_UNITLESS:
33  Farad = Cantera::ElectronCharge * Cantera::Avogadro;
34  break;
35  case VCS_UNITS_KELVIN:
36  Farad = Cantera::ElectronCharge * Cantera::Avogadro/ TKelvin;
37  break;
38  default:
39  plogf("vcs_nondim_Farad error: unknown units: %d\n", mu_units);
40  plogendl();
41  exit(EXIT_FAILURE);
42  }
43  return Farad;
44 }
45 
46 double VCS_SOLVE::vcs_nondimMult_TP(int mu_units, double TKelvin) const
47 {
48  double rt;
49  if (TKelvin <= 0.0) {
50  TKelvin = 293.15;
51  }
52  switch (mu_units) {
53  case VCS_UNITS_KCALMOL:
54  rt = TKelvin * Cantera::GasConst_cal_mol_K * 1e-3;
55  break;
56  case VCS_UNITS_UNITLESS:
57  rt = 1.0;
58  break;
59  case VCS_UNITS_KJMOL:
60  rt = TKelvin * Cantera::GasConstant * 1e-6;
61  break;
62  case VCS_UNITS_KELVIN:
63  rt = TKelvin;
64  break;
65  case VCS_UNITS_MKS:
66  rt = TKelvin * Cantera::GasConstant;
67  break;
68  default:
69  plogf("vcs_nondimMult_TP error: unknown units: %d\n", mu_units);
70  plogendl();
71  exit(EXIT_FAILURE);
72  }
73  return rt;
74 }
75 
77 {
78  double tf;
82  for (size_t i = 0; i < m_numSpeciesTot; ++i) {
83  /*
84  * Modify the standard state and total chemical potential data,
85  * FF(I), to make it dimensionless, i.e., mu / RT.
86  * Thus, we may divide it by the temperature.
87  */
88  m_SSfeSpecies[i] *= tf;
89  m_deltaGRxn_new[i] *= tf;
90  m_deltaGRxn_old[i] *= tf;
91  m_feSpecies_old[i] *= tf;
92  }
93 
95 
96  /*
97  * Scale the total moles if necessary:
98  * First find out the total moles
99  */
100  double tmole_orig = vcs_tmoles();
101 
102  /*
103  * Then add in the total moles of elements that are goals. Either one
104  * or the other is specified here.
105  */
106  double esum = 0.0;
107  for (size_t i = 0; i < m_numElemConstraints; ++i) {
108  if (m_elType[i] == VCS_ELEM_TYPE_ABSPOS) {
109  esum += fabs(m_elemAbundancesGoal[i]);
110  }
111  }
112  tmole_orig += esum;
113 
114  /*
115  * Ok now test out the bounds on the total moles that this program can
116  * handle. These are a bit arbitrary. However, it would seem that any
117  * reasonable input would be between these two numbers below.
118  */
119  if (tmole_orig < 1.0E-200 || tmole_orig > 1.0E200) {
120  plogf(" VCS_SOLVE::vcs_nondim_TP ERROR: Total input moles , %g, is outside the range handled by vcs. exit",
121  tmole_orig);
122  plogendl();
123  throw Cantera::CanteraError("VCS_SOLVE::vcs_nondim_TP",
124  " Total input moles ," + Cantera::fp2str(tmole_orig) +
125  "is outside the range handled by vcs.\n");
126  }
127 
128  // Determine the scale of the problem
129  if (tmole_orig > 1.0E4) {
130  m_totalMoleScale = tmole_orig / 1.0E4;
131  } else if (tmole_orig < 1.0E-4) {
132  m_totalMoleScale = tmole_orig / 1.0E-4;
133  } else {
134  m_totalMoleScale = 1.0;
135  }
136 
137  if (m_totalMoleScale != 1.0) {
138  if (m_VCS_UnitsFormat == VCS_UNITS_MKS) {
139 #ifdef DEBUG_MODE
140  if (m_debug_print_lvl >= 2) {
141  plogf(" --- vcs_nondim_TP() called: USING A MOLE SCALE OF %g until further notice", m_totalMoleScale);
142  plogendl();
143  }
144 #endif
145  for (size_t i = 0; i < m_numSpeciesTot; ++i) {
148  }
149  }
150  for (size_t i = 0; i < m_numElemConstraints; ++i) {
152  }
153 
154  for (size_t iph = 0; iph < m_numPhases; iph++) {
155  TPhInertMoles[iph] *= (1.0 / m_totalMoleScale);
156  if (TPhInertMoles[iph] != 0.0) {
157  vcs_VolPhase* vphase = m_VolPhaseList[iph];
158  vphase->setTotalMolesInert(TPhInertMoles[iph]);
159  }
160  }
161  }
162  vcs_tmoles();
163  }
164  }
165 }
166 
168 {
169  double tf;
173  for (size_t i = 0; i < m_numSpeciesTot; ++i) {
174  /*
175  * Modify the standard state and total chemical potential data,
176  * FF(I), to make it have units, i.e. mu = RT * mu_star
177  */
178  m_SSfeSpecies[i] *= tf;
179  m_deltaGRxn_new[i] *= tf;
180  m_deltaGRxn_old[i] *= tf;
181  m_feSpecies_old[i] *= tf;
182  }
183  m_Faraday_dim *= tf;
184  }
185  if (m_totalMoleScale != 1.0) {
186  if (m_VCS_UnitsFormat == VCS_UNITS_MKS) {
187 #ifdef DEBUG_MODE
188  if (m_debug_print_lvl >= 2) {
189  plogf(" --- vcs_redim_TP() called: getting rid of mole scale of %g", m_totalMoleScale);
190  plogendl();
191  }
192 #endif
193  for (size_t i = 0; i < m_numSpeciesTot; ++i) {
196  }
197  }
198  for (size_t i = 0; i < m_numElemConstraints; ++i) {
200  }
201 
202  for (size_t iph = 0; iph < m_numPhases; iph++) {
204  if (TPhInertMoles[iph] != 0.0) {
205  vcs_VolPhase* vphase = m_VolPhaseList[iph];
206  vphase->setTotalMolesInert(TPhInertMoles[iph]);
207  }
208  }
209  vcs_tmoles();
210  }
211  }
212 }
213 
214 void VCS_SOLVE::vcs_printChemPotUnits(int unitsFormat) const
215 {
216  switch (unitsFormat) {
217  case VCS_UNITS_KCALMOL:
218  plogf("kcal/gmol");
219  break;
220  case VCS_UNITS_UNITLESS:
221  plogf("dimensionless");
222  break;
223  case VCS_UNITS_KJMOL:
224  plogf("kJ/gmol");
225  break;
226  case VCS_UNITS_KELVIN:
227  plogf("Kelvin");
228  break;
229  case VCS_UNITS_MKS:
230  plogf("J/kmol");
231  break;
232  default:
233  plogf("unknown units!");
234  exit(EXIT_FAILURE);
235  }
236 }
237 
238 }
std::vector< double > m_SSfeSpecies
Standard state chemical potentials for species K at the current temperature and pressure.
Definition: vcs_solve.h:1581
char m_unitsState
This specifies the current state of units for the Gibbs free energy properties in the program...
Definition: vcs_solve.h:1883
int m_debug_print_lvl
Debug printing lvl.
Definition: vcs_solve.h:1999
double m_temperature
Temperature (Kelvin)
Definition: vcs_solve.h:1738
std::vector< double > m_feSpecies_old
Free energy vector from the start of the current iteration.
Definition: vcs_solve.h:1588
int m_VCS_UnitsFormat
Units for the chemical potential data.
Definition: vcs_solve.h:2018
std::vector< double > m_deltaGRxn_new
Delta G(irxn) for the noncomponent species in the mechanism.
Definition: vcs_solve.h:1658
std::vector< double > m_elemAbundancesGoal
Element abundances vector Goals.
Definition: vcs_solve.h:1699
#define VCS_NONDIMENSIONAL_G
nondimensional
Definition: vcs_defs.h:116
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:306
Phase information and Phase calculations for vcs.
Definition: vcs_VolPhase.h:97
void vcs_printChemPotUnits(int unitsFormat) const
Print the string representing the Chemical potential units.
Definition: vcs_nondim.cpp:214
Internal declarations for the VCSnonideal package.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:29
std::vector< double > m_molNumSpecies_old
Total moles of the species.
Definition: vcs_solve.h:1616
size_t m_numSpeciesTot
Total number of species in the problems.
Definition: vcs_solve.h:1497
double m_Faraday_dim
dimensionless value of Faraday's constant, F / RT (1/volt)
Definition: vcs_solve.h:1980
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
std::vector< double > m_deltaGRxn_old
Last deltag[irxn] from the previous step.
Definition: vcs_solve.h:1661
void setTotalMolesInert(const double tMolesInert)
Sets the total moles of inert in the phase.
size_t m_numElemConstraints
Number of element constraints in the problem.
Definition: vcs_solve.h:1503
std::vector< vcs_VolPhase * > m_VolPhaseList
Array of Phase Structures. Length = number of phases.
Definition: vcs_solve.h:1873
double m_totalMoleScale
Multiplier for the mole numbers within the nondimensionless formulation.
Definition: vcs_solve.h:1892
size_t m_numPhases
Number of Phases in the problem.
Definition: vcs_solve.h:1530
double vcs_nondim_Farad(int mu_units, double TKelvin) const
Returns the multiplier for electric charge terms.
Definition: vcs_nondim.cpp:19
#define VCS_DIMENSIONAL_G
dimensioned
Definition: vcs_defs.h:118
void vcs_nondim_TP()
Nondimensionalize the problem data.
Definition: vcs_nondim.cpp:76
const doublereal Avogadro
Avogadro's Number [number/kmol].
Definition: ct_defs.h:63
double vcs_nondimMult_TP(int mu_units, double TKelvin) const
Returns the multiplier for the nondimensionalization of the equations.
Definition: vcs_nondim.cpp:46
#define plogendl()
define this Cantera function to replace cout << endl;
Definition: vcs_internal.h:37
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:167
std::vector< double > TPhInertMoles
Total kmoles of inert to add to each phase.
Definition: vcs_solve.h:1759
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
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:75
#define plogf
define this Cantera function to replace printf
Definition: vcs_internal.h:30
std::vector< int > m_elType
Type of the element constraint.
Definition: vcs_solve.h:1864
#define VCS_SPECIES_TYPE_INTERFACIALVOLTAGE
Unknown refers to the voltage level of a phase.
Definition: vcs_defs.h:368
std::vector< int > m_speciesUnknownType
Specifies the species unknown type.
Definition: vcs_solve.h:1629
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...