Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vcs_solve_phaseStability.cpp
Go to the documentation of this file.
1 //! @file vcs_solve_phaseStability.cpp
2 
3 /*
4  * Copyright (2005) Sandia Corporation. Under the terms of
5  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
6  * U.S. Government retains certain rights in this software.
7  */
8 
10 #include "cantera/equil/vcs_prob.h"
11 
12 using namespace std;
13 
14 namespace Cantera
15 {
16 
17 int VCS_SOLVE::vcs_PS(VCS_PROB* vprob, int iphase, int printLvl, double& feStable)
18 {
19 
20  /*
21  * ifunc determines the problem type
22  */
23  int ifunc = 0;
24  int iStab = 0;
25 
26  /*
27  * This function is called to create the private data
28  * using the public data.
29  */
30  size_t nspecies0 = vprob->nspecies + 10;
31  size_t nelements0 = vprob->ne;
32  size_t nphase0 = vprob->NPhase;
33 
34  vcs_initSizes(nspecies0, nelements0, nphase0);
35 
36 
37  if (ifunc < 0 || ifunc > 2) {
38  plogf("vcs: Unrecognized value of ifunc, %d: bailing!\n",
39  ifunc);
40  return VCS_PUB_BAD;
41  }
42 
43  /*
44  * This function is called to copy the public data
45  * and the current problem specification
46  * into the current object's data structure.
47  */
48  int retn = vcs_prob_specifyFully(vprob);
49  if (retn != 0) {
50  plogf("vcs_pub_to_priv returned a bad status, %d: bailing!\n",
51  retn);
52  return retn;
53  }
54  /*
55  * Prep the problem data
56  * - adjust the identity of any phases
57  * - determine the number of components in the problem
58  */
59  retn = vcs_prep_oneTime(printLvl);
60  if (retn != 0) {
61  plogf("vcs_prep_oneTime returned a bad status, %d: bailing!\n",
62  retn);
63  return retn;
64  }
65 
66 
67  /*
68  * This function is called to copy the current problem
69  * into the current object's data structure.
70  */
71  retn = vcs_prob_specify(vprob);
72  if (retn != 0) {
73  plogf("vcs_prob_specify returned a bad status, %d: bailing!\n",
74  retn);
75  return retn;
76  }
77 
78 
79  /*
80  * Prep the problem data for this particular instantiation of
81  * the problem
82  */
83  retn = vcs_prep();
84  if (retn != VCS_SUCCESS) {
85  plogf("vcs_prep returned a bad status, %d: bailing!\n", retn);
86  return retn;
87  }
88  /*
89  * Check to see if the current problem is well posed.
90  */
91  if (!vcs_wellPosed(vprob)) {
92  plogf("vcs has determined the problem is not well posed: Bailing\n");
93  return VCS_PUB_BAD;
94  }
95 
96  /*
97  * Store the temperature and pressure in the private global variables
98  */
99  m_temperature = vprob->T;
100  m_pressurePA = vprob->PresPA;
101  /*
102  * Evaluate the standard state free energies
103  * at the current temperatures and pressures.
104  */
105  vcs_evalSS_TP(printLvl, printLvl, m_temperature, m_pressurePA);
106 
107  /*
108  * Prepare the problem data:
109  * ->nondimensionalize the free energies using
110  * the divisor, R * T
111  */
112  vcs_nondim_TP();
113  /*
114  * Prep the fe field
115  */
116  vcs_fePrep_TP();
117 
118  /*
119  * Solve the problem at a fixed Temperature and Pressure
120  * (all information concerning Temperature and Pressure has already
121  * been derived. The free energies are now in dimensionless form.)
122  */
123  iStab = vcs_solve_phaseStability(iphase, ifunc, feStable, printLvl);
124 
125 
126  /*
127  * Redimensionalize the free energies using
128  * the reverse of vcs_nondim to add back units.
129  */
130  vcs_redim_TP();
131 
132  vcs_prob_update(vprob);
133  /*
134  * Return the convergence success flag.
135  */
136  return iStab;
137 }
138 
139 int VCS_SOLVE::vcs_solve_phaseStability(const int iph, const int ifunc,
140  double& funcVal,
141  int printLvl)
142 {
143  double test = -1.0E-10;
144  bool usedZeroedSpecies;
145  int iStab = 0;
146 
147  std::vector<double> sm(m_numElemConstraints*m_numElemConstraints, 0.0);
148  std::vector<double> ss(m_numElemConstraints, 0.0);
149  std::vector<double> sa(m_numElemConstraints, 0.0);
150 
151  std::vector<double> aw(m_numSpeciesTot, 0.0);
152  std::vector<double> wx(m_numElemConstraints, 0.0);
153 
154 
155  vcs_basopt(false, VCS_DATA_PTR(aw), VCS_DATA_PTR(sa), VCS_DATA_PTR(sm), VCS_DATA_PTR(ss),
156  test, &usedZeroedSpecies);
157  vcs_evaluate_speciesType();
158 
159  vcs_dfe(VCS_STATECALC_OLD, 0, 0, m_numSpeciesRdc);
160  if (printLvl > 3) {
161  vcs_printSpeciesChemPot(VCS_STATECALC_OLD);
162  }
163  vcs_deltag(0, true, VCS_STATECALC_OLD);
164 
165  if (printLvl > 3) {
166  vcs_printDeltaG(VCS_STATECALC_OLD);
167  }
168  m_deltaGRxn_Deficient = m_deltaGRxn_old;
169  funcVal = vcs_phaseStabilityTest(iph);
170  if (funcVal > 0.0) {
171  iStab = 1;
172  } else {
173  iStab = 0;
174  }
175 
176  return iStab;
177 }
178 
179 }
#define VCS_DATA_PTR(vvv)
Points to the data in a std::vector<> object.
Definition: vcs_internal.h:18
Header file for the internal object that holds the vcs equilibrium problem (see Class VCS_SOLVE and E...
#define VCS_SUCCESS
Definition: vcs_defs.h:21
Header for the Interface class for the vcs thermo equilibrium solver package,.
#define VCS_STATECALC_OLD
State Calculation based on the old or base mole numbers.
Definition: vcs_defs.h:365
#define plogf
define this Cantera function to replace printf
Definition: vcs_internal.h:24