Cantera  2.3.0
vcs_nondim.cpp
Go to the documentation of this file.
1 /**
2  * @file vcs_nondim.cpp
3  * Nondimensionalization routines within VCSnonideal
4  */
5 
6 // This file is part of Cantera. See License.txt in the top-level directory or
7 // at http://www.cantera.org/license.txt for license and copyright information.
8 
13 
14 namespace Cantera
15 {
16 
18 {
21  double tf = 1.0 / (GasConstant * m_temperature);
22  for (size_t i = 0; i < m_numSpeciesTot; ++i) {
23  // Modify the standard state and total chemical potential data,
24  // FF(I), to make it dimensionless, i.e., mu / RT. Thus, we may
25  // divide it by the temperature.
26  m_SSfeSpecies[i] *= tf;
27  m_deltaGRxn_new[i] *= tf;
28  m_deltaGRxn_old[i] *= tf;
29  m_feSpecies_old[i] *= tf;
30  }
31 
32  m_Faraday_dim = ElectronCharge * Avogadro / (m_temperature * GasConstant);
33 
34  // Scale the total moles if necessary: First find out the total moles
35  double tmole_orig = vcs_tmoles();
36 
37  // Then add in the total moles of elements that are goals. Either one or
38  // the other is specified here.
39  double esum = 0.0;
40  for (size_t i = 0; i < m_numElemConstraints; ++i) {
41  if (m_elType[i] == VCS_ELEM_TYPE_ABSPOS) {
42  esum += fabs(m_elemAbundancesGoal[i]);
43  }
44  }
45  tmole_orig += esum;
46 
47  // Ok now test out the bounds on the total moles that this program can
48  // handle. These are a bit arbitrary. However, it would seem that any
49  // reasonable input would be between these two numbers below.
50  if (tmole_orig < 1.0E-200 || tmole_orig > 1.0E200) {
51  throw CanteraError("VCS_SOLVE::vcs_nondim_TP",
52  "Total input moles, {} is outside the range handled by vcs.\n",
53  tmole_orig);
54  }
55 
56  // Determine the scale of the problem
57  if (tmole_orig > 1.0E4) {
58  m_totalMoleScale = tmole_orig / 1.0E4;
59  } else if (tmole_orig < 1.0E-4) {
60  m_totalMoleScale = tmole_orig / 1.0E-4;
61  } else {
62  m_totalMoleScale = 1.0;
63  }
64 
65  if (m_totalMoleScale != 1.0) {
66  if (m_debug_print_lvl >= 2) {
67  plogf(" --- vcs_nondim_TP() called: USING A MOLE SCALE OF %g until further notice", m_totalMoleScale);
68  plogendl();
69  }
70  for (size_t i = 0; i < m_numSpeciesTot; ++i) {
73  }
74  }
75  for (size_t i = 0; i < m_numElemConstraints; ++i) {
77  }
78 
79  for (size_t iph = 0; iph < m_numPhases; iph++) {
80  TPhInertMoles[iph] *= (1.0 / m_totalMoleScale);
81  if (TPhInertMoles[iph] != 0.0) {
82  vcs_VolPhase* vphase = m_VolPhaseList[iph];
83  vphase->setTotalMolesInert(TPhInertMoles[iph]);
84  }
85  }
86  vcs_tmoles();
87  }
88  }
89 }
90 
92 {
95  double tf = m_temperature * GasConstant;
96  for (size_t i = 0; i < m_numSpeciesTot; ++i) {
97 
98  // Modify the standard state and total chemical potential data,
99  // FF(I), to make it have units, i.e. mu = RT * mu_star
100  m_SSfeSpecies[i] *= tf;
101  m_deltaGRxn_new[i] *= tf;
102  m_deltaGRxn_old[i] *= tf;
103  m_feSpecies_old[i] *= tf;
104  }
105  m_Faraday_dim *= tf;
106  }
107  if (m_totalMoleScale != 1.0) {
108  if (m_debug_print_lvl >= 2) {
109  plogf(" --- vcs_redim_TP() called: getting rid of mole scale of %g", m_totalMoleScale);
110  plogendl();
111  }
112  for (size_t i = 0; i < m_numSpeciesTot; ++i) {
115  }
116  }
117  for (size_t i = 0; i < m_numElemConstraints; ++i) {
119  }
120 
121  for (size_t iph = 0; iph < m_numPhases; iph++) {
123  if (TPhInertMoles[iph] != 0.0) {
124  vcs_VolPhase* vphase = m_VolPhaseList[iph];
125  vphase->setTotalMolesInert(TPhInertMoles[iph]);
126  }
127  }
128  vcs_tmoles();
129  }
130 }
131 
132 }
vector_int m_speciesUnknownType
Specifies the species unknown type.
Definition: vcs_solve.h:1511
double m_Faraday_dim
dimensionless value of Faraday&#39;s constant, F / RT (1/volt)
Definition: vcs_solve.h:1846
vector_fp m_SSfeSpecies
Standard state chemical potentials for species K at the current temperature and pressure.
Definition: vcs_solve.h:1465
vector_fp m_molNumSpecies_old
Total moles of the species.
Definition: vcs_solve.h:1498
std::vector< vcs_VolPhase * > m_VolPhaseList
Array of Phase Structures. Length = number of phases.
Definition: vcs_solve.h:1740
void vcs_nondim_TP()
Nondimensionalize the problem data.
Definition: vcs_nondim.cpp:17
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:91
vector_fp m_deltaGRxn_new
Delta G(irxn) for the noncomponent species in the mechanism.
Definition: vcs_solve.h:1539
#define VCS_NONDIMENSIONAL_G
nondimensional
Definition: vcs_defs.h:94
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:248
size_t m_numElemConstraints
Number of element constraints in the problem.
Definition: vcs_solve.h:1393
size_t m_numSpeciesTot
Total number of species in the problems.
Definition: vcs_solve.h:1387
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
vector_fp m_deltaGRxn_old
Last deltag[irxn] from the previous step.
Definition: vcs_solve.h:1542
vector_fp m_feSpecies_old
Free energy vector from the start of the current iteration.
Definition: vcs_solve.h:1472
vector_fp TPhInertMoles
Total kmoles of inert to add to each phase.
Definition: vcs_solve.h:1626
int m_debug_print_lvl
Debug printing lvl.
Definition: vcs_solve.h:1863
vector_fp m_elemAbundancesGoal
Element abundances vector Goals.
Definition: vcs_solve.h:1577
double m_temperature
Temperature (Kelvin)
Definition: vcs_solve.h:1616
Phase information and Phase calculations for vcs.
Definition: vcs_VolPhase.h:81
#define VCS_DIMENSIONAL_G
dimensioned
Definition: vcs_defs.h:96
const doublereal Avogadro
Avogadro&#39;s Number [number/kmol].
Definition: ct_defs.h:61
#define plogendl()
define this Cantera function to replace cout << endl;
Definition: vcs_internal.h:25
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
Contains declarations for string manipulation functions within Cantera.
#define plogf
define this Cantera function to replace printf
Definition: vcs_internal.h:18
#define VCS_SPECIES_TYPE_INTERFACIALVOLTAGE
Unknown refers to the voltage level of a phase.
Definition: vcs_defs.h:309
vector_int m_elType
Type of the element constraint.
Definition: vcs_solve.h:1731
Namespace for the Cantera kernel.
Definition: application.cpp:29
char m_unitsState
This specifies the current state of units for the Gibbs free energy properties in the program...
Definition: vcs_solve.h:1750
size_t m_numPhases
Number of Phases in the problem.
Definition: vcs_solve.h:1414
double m_totalMoleScale
Multiplier for the mole numbers within the nondimensional formulation.
Definition: vcs_solve.h:1759
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
void setTotalMolesInert(const double tMolesInert)
Sets the total moles of inert in the phase.