Cantera  2.1.2
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 
13 #include "cantera/equil/vcs_prob.h"
14 
15 #include "cantera/base/clockWC.h"
16 
17 using namespace std;
18 
19 namespace VCSnonideal
20 {
21 
22 int VCS_SOLVE::vcs_PS(VCS_PROB* vprob, int iphase, int printLvl, double& feStable)
23 {
24 
25  /*
26  * ifunc determines the problem type
27  */
28  int ifunc = 0;
29  int iStab = 0;
30 
31  /*
32  * This function is called to create the private data
33  * using the public data.
34  */
35  size_t nspecies0 = vprob->nspecies + 10;
36  size_t nelements0 = vprob->ne;
37  size_t nphase0 = vprob->NPhase;
38 
39  vcs_initSizes(nspecies0, nelements0, nphase0);
40 
41 
42  if (ifunc < 0 || ifunc > 2) {
43  plogf("vcs: Unrecognized value of ifunc, %d: bailing!\n",
44  ifunc);
45  return VCS_PUB_BAD;
46  }
47 
48  /*
49  * This function is called to copy the public data
50  * and the current problem specification
51  * into the current object's data structure.
52  */
53  int retn = vcs_prob_specifyFully(vprob);
54  if (retn != 0) {
55  plogf("vcs_pub_to_priv returned a bad status, %d: bailing!\n",
56  retn);
57  return retn;
58  }
59  /*
60  * Prep the problem data
61  * - adjust the identity of any phases
62  * - determine the number of components in the problem
63  */
64  retn = vcs_prep_oneTime(printLvl);
65  if (retn != 0) {
66  plogf("vcs_prep_oneTime returned a bad status, %d: bailing!\n",
67  retn);
68  return retn;
69  }
70 
71 
72  /*
73  * This function is called to copy the current problem
74  * into the current object's data structure.
75  */
76  retn = vcs_prob_specify(vprob);
77  if (retn != 0) {
78  plogf("vcs_prob_specify returned a bad status, %d: bailing!\n",
79  retn);
80  return retn;
81  }
82 
83 
84  /*
85  * Prep the problem data for this particular instantiation of
86  * the problem
87  */
88  retn = vcs_prep();
89  if (retn != VCS_SUCCESS) {
90  plogf("vcs_prep returned a bad status, %d: bailing!\n", retn);
91  return retn;
92  }
93  /*
94  * Check to see if the current problem is well posed.
95  */
96  if (!vcs_wellPosed(vprob)) {
97  plogf("vcs has determined the problem is not well posed: Bailing\n");
98  return VCS_PUB_BAD;
99  }
100 
101  /*
102  * Store the temperature and pressure in the private global variables
103  */
104  m_temperature = vprob->T;
105  m_pressurePA = vprob->PresPA;
106  /*
107  * Evaluate the standard state free energies
108  * at the current temperatures and pressures.
109  */
110  vcs_evalSS_TP(printLvl, printLvl, m_temperature, m_pressurePA);
111 
112  /*
113  * Prepare the problem data:
114  * ->nondimensionalize the free energies using
115  * the divisor, R * T
116  */
117  vcs_nondim_TP();
118  /*
119  * Prep the fe field
120  */
121  vcs_fePrep_TP();
122 
123  /*
124  * Solve the problem at a fixed Temperature and Pressure
125  * (all information concerning Temperature and Pressure has already
126  * been derived. The free energies are now in dimensionless form.)
127  */
128  iStab = vcs_solve_phaseStability(iphase, ifunc, feStable, printLvl);
129 
130 
131  /*
132  * Redimensionalize the free energies using
133  * the reverse of vcs_nondim to add back units.
134  */
135  vcs_redim_TP();
136 
137  /*
138  vcs_VolPhase *Vphase = m_VolPhaseList[iphase];
139 
140  std::vector<double> mfPop = Vphase->moleFractions();
141  int nsp = Vphase->nSpecies();
142 
143  vcs_VolPhase *VPphase = vprob->VPhaseList[iphase];
144  int kstart = Vphase->spGlobalIndexVCS(0);
145  for (int k = 0; k < nsp; k++) {
146  vprob->mf[kstart + k] = mfPop[k];
147  }
148  VPphase->setMoleFractionsState(Vphase->totalMoles(),
149  VCS_DATA_PTR(Vphase->moleFractions()),
150  VCS_STATECALC_TMP);
151  */
152  vcs_prob_update(vprob);
153  /*
154  * Return the convergence success flag.
155  */
156  return iStab;
157 }
158 
159 int VCS_SOLVE::vcs_solve_phaseStability(const int iph, const int ifunc,
160  double& funcVal,
161  int printLvl)
162 {
163  double test = -1.0E-10;
164  bool usedZeroedSpecies;
165  // std::vector<size_t> phasePopPhaseIDs(0);
166  int iStab = 0;
167 
168  std::vector<double> sm(m_numElemConstraints*m_numElemConstraints, 0.0);
169  std::vector<double> ss(m_numElemConstraints, 0.0);
170  std::vector<double> sa(m_numElemConstraints, 0.0);
171 
172  std::vector<double> aw(m_numSpeciesTot, 0.0);
173  std::vector<double> wx(m_numElemConstraints, 0.0);
174 
175 
176  vcs_basopt(false, VCS_DATA_PTR(aw), VCS_DATA_PTR(sa), VCS_DATA_PTR(sm), VCS_DATA_PTR(ss),
177  test, &usedZeroedSpecies);
178  vcs_evaluate_speciesType();
179 
180  vcs_dfe(VCS_STATECALC_OLD, 0, 0, m_numSpeciesRdc);
181  if (printLvl > 3) {
182  vcs_printSpeciesChemPot(VCS_STATECALC_OLD);
183  }
184  vcs_deltag(0, true, VCS_STATECALC_OLD);
185 
186  if (printLvl > 3) {
187  vcs_printDeltaG(VCS_STATECALC_OLD);
188  }
189  vcs_dcopy(VCS_DATA_PTR(m_deltaGRxn_Deficient), VCS_DATA_PTR(m_deltaGRxn_old), m_numRxnRdc);
190  // phasePopPhaseIDs.clear();
191  // vcs_popPhaseID(phasePopPhaseIDs);
192  funcVal = vcs_phaseStabilityTest(iph);
193  if (funcVal > 0.0) {
194  iStab = 1;
195  } else {
196  iStab = 0;
197  }
198 
199  return iStab;
200 }
201 
202 }
Declarations for a simple class that implements an Ansi C wall clock timer (see Cantera::clockWC).
#define VCS_DATA_PTR(vvv)
Points to the data in a std::vector<> object.
Definition: vcs_internal.h:24
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.
Internal declarations for the VCSnonideal package.
#define VCS_SUCCESS
Definition: vcs_defs.h:37
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:381
#define plogf
define this Cantera function to replace printf
Definition: vcs_internal.h:30