Cantera  2.0
vcs_prob.h
Go to the documentation of this file.
1 /**
2  * @file vcs_prob.h
3  * Header for the Interface class for the vcs thermo equilibrium solver package,
4  */
5 /*
6  * Copyright (2005) 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 
11 #ifndef _VCS_PROB_H
12 #define _VCS_PROB_H
13 
14 #include "vcs_DoubleStarStar.h"
15 #include "vcs_IntStarStar.h"
16 #include "cantera/equil/vcs_defs.h"
17 #include <vector>
18 #include <string>
19 
20 namespace VCSnonideal
21 {
22 
23 class vcs_VolPhase;
24 class VCS_SPECIES_THERMO;
25 
26 //! Interface class for the vcs thermo equilibrium solver package,
27 //! which generally describes the problem to be solved.
28 /*!
29  * HKM add:
30  * HaveEstimate -> 0 no estimate, or estimate that doesn't satisfy elem
31  * abundances
32  * 1 have an estimate that satisfies elem_abund.
33  * 2 Have an estimate that minimizes a subproblem
34  * and satisfies elem abund.
35  * solnFound -> True, soln to current problem found and included here
36  * False, soln has not been found.
37  */
38 class VCS_PROB
39 {
40 public:
41 
42  //! Problem type. I.e., the identity of what is held constant.
43  /*!
44  * Currently, T and P are held constant, and this input
45  * is ignored
46  */
47  int prob_type;
48 
49  //! Total number of species in the problems
50  size_t nspecies;
51 
52  //! Species number used to malloc data structures
53  size_t NSPECIES0;
54 
55  //! Number of element constraints in the equilibrium problem
56  size_t ne;
57 
58  //! Number of element constraints used to malloc data structures
59  //! involving elements
60  size_t NE0;
61 
62  //! Number of phases in the problem
63  size_t NPhase;
64 
65  //! Number of phases used to malloc data structures
66  size_t NPHASE0;
67 
68  //! Vector of chemical potentials of the species
69  /*!
70  * This is a calculated output quantity
71  * length = number of species
72  * units = m_VCS_UnitsFormat;
73  */
74  std::vector<double> m_gibbsSpecies;
75 
76  //! Total number of moles of the kth species.
77  /*!
78  * This is both an input and an output variable.
79  * On input, this is an estimate of the mole numbers.
80  * The actual element abundance vector contains the problem specification.
81  *
82  * On output, this contains the solution for the total number of moles
83  * of the kth species.
84  *
85  * units = m_VCS_UnitsFormat
86  */
87  std::vector<double> w;
88 
89  //! Mole fraction vector
90  /*!
91  * This is a calculated vector, calculated from w[]
92  * length number of species.
93  * -> Take out? -> No, useful for storage of a quantity often needed
94  */
95  std::vector<double> mf;
96 
97  //! Element abundances for jth element
98  /*!
99  * This is input from the input file and is considered a constant from
100  * thereon within the vcs_solve_TP().
101  * units = m_VCS_UnitsFormat
102  */
103  std::vector<double> gai;
104 
105  //! Formula Matrix for the problem
106  /*!
107  * FormulaMatrix[j][kspec] = Number of elements, j, in the kspec
108  * species
109  */
111 
112  //! Specifies the species unknown type
113  /*!
114  * There are two types. One is the straightforward
115  * species, with the mole number w[k], as the
116  * unknown. The second is the an interfacial
117  * voltage where w[k] refers to the interfacial
118  * voltage in volts.
119  * These species types correspond to metallic
120  * electrons corresponding to electrodes.
121  * The voltage and other interfacial conditions
122  * sets up an interfacial current, which is
123  * set to zero in this initial treatment.
124  * Later we may have non-zero interfacial currents.
125  */
126  std::vector<int> SpeciesUnknownType;
127 
128  //! Temperature (Kelvin)
129  /*!
130  * Specification of the temperature for the equilibrium problem
131  */
132  double T;
133 
134  //! Pressure
135  /*!
136  * units given by m_VCS_UnitsFormat
137  * -> are now PA
138  */
139  double PresPA;
140 
141  //! Volume of the entire system
142  /*!
143  * units given by m_VCS_UnitsFormat
144  * Note, this is an output variable atm
145  */
146  double Vol;
147 
148  //! Partial Molar Volumes of species
149  /*!
150  * This is a calculated vector, calculated from w[]
151  * length number of species.
152  * -> Take out? -> No, useful for storage of a quantity often needed
153  */
154  std::vector<double> VolPM;
155 
156  //! Units for the chemical potential data, pressure data, volume,
157  //! and species amounts
158  /*!
159  * All internally stored quantities will have these units. Also, printed
160  * quantities will display in these units.
161  *
162  * Chem_Pot Pres vol moles
163  * ----------------------------------------------------------------------
164  * -1 VCS_UNITS_KCALMOL = kcal/mol atm cm**3 gmol
165  * 0 VCS_UNITS_UNITLESS = MU / RT -> no units atm cm**3 gmol
166  * 1 VCS_UNITS_KJMOL = kJ / mol atm cm**3 gmol
167  * 2 VCS_UNITS_KELVIN = KELVIN -> MU / R atm cm**3 gmol
168  * 3 VCS_UNITS_MKS = Joules / Kmol (Cantera) Pa m**3 kmol
169  * ----------------------------------------------------------------------
170  *
171  * see vcs_defs.h for more information
172  */
174 
175  //! Specification of the initial estimate method
176  /*!
177  * iest = Initial estimate: 0 user estimate
178  * 1 user estimate if satisifies elements
179  * -1 machine estimate
180  */
181  int iest;
182 
183  //! Tolerance requirement for major species
184  double tolmaj;
185 
186  //! Tolerance requirement for minor species
187  double tolmin;
188 
189  //! Mapping between the species and the phases
190  std::vector<size_t> PhaseID;
191 
192  //! Vector of strings containing the species names
193  std::vector<std::string> SpName;
194 
195  //! vector of strings containing the element names
196  std::vector<std::string> ElName;
197 
198  //! vector of Element types
199  std::vector<int> m_elType;
200 
201  //! Specifies whether an element constraint is active
202  /*!
203  * The default is true
204  * Length = nelements
205  */
206  std::vector<int> ElActive;
207 
208  //! Molecular weight of species
209  /*!
210  * WtSpecies[k] = molecular weight of species in gm/mol
211  */
212  std::vector<double> WtSpecies;
213 
214  //! Charge of each species
215  std::vector<double> Charge;
216 
217  //! Array of phase structures
218  std::vector<vcs_VolPhase*> VPhaseList;
219 
220  // String containing the title of the run
221  std::string Title;
222 
223  //! Vector of pointers to thermo structures which identify the model
224  //! and parameters for evaluating the thermodynamic
225  //! functions for that particular species
226  std::vector<VCS_SPECIES_THERMO*> SpeciesThermo;
227 
228  //! Number of iterations
229  /*!
230  * This is an output variable
231  */
233 
234  //! Number of basis optimizations used
235  /*!
236  * This is an output variable
237  */
239 
240  //! Print level for print routines
242 
243  //! Debug print lvl
245 
246  //! Constructor
247  /*!
248  * This constructor initializes the sizes within the object
249  * to parameter values.
250  *
251  * @param nsp number of species
252  * @param nel number of elements
253  * @param nph number of phases
254  */
255  VCS_PROB(size_t nsp, size_t nel, size_t nph);
256 
257  //! Destructor
258  ~VCS_PROB();
259 
260  //! Resizes all of the phase lists within the structure
261  /*!
262  * Note, this doesn't change the number of phases in the problem.
263  * It will change NPHASE0 if nsp is greater than NPHASE0.
264  *
265  * @param nPhase size to dimension all the phase lists to
266  * @param force If true, this will dimension the size to be equal to nPhase
267  * even if nPhase is less than the current value of NPHASE0
268  */
269  void resizePhase(size_t nPhase, int force);
270 
271  //! Resizes all of the species lists within the structure
272  /*!
273  * Note, this doesn't change the number of species in the problem.
274  * It will change NSPECIES0 if nsp is greater than NSPECIES0.
275  *
276  * @param nsp size to dimension all the species lists to
277  * @param force If true, this will dimension the size to be equal to nsp
278  * even if nsp is less than the current value of NSPECIES0
279  */
280  void resizeSpecies(size_t nsp, int force);
281 
282  //! Resizes all of the element lists within the structure
283  /*!
284  * Note, this doesn't change the number of element constraints in the problem.
285  * It will change NE0 if nel is greater than NE0.
286  *
287  * @param nel size to dimension all the elements lists
288  * @param force If true, this will dimension the size to be equal to nel
289  * even if nel is less than the current value of NEL0
290  */
291  void resizeElements(size_t nel, int force);
292 
293 
294  //! Calculate the element abundance vector
295  /*!
296  * Calculates the element abundance vectors from the mole
297  * numbers
298  */
299  void set_gai();
300 
301  //! Print out the problem specification in all generality
302  //! as it currently exists in the VCS_PROB object
303  /*!
304  * @param print_lvl Parameter lvl for printing
305  * 0 - no printing
306  * 1 - all printing
307  */
308  void prob_report(int print_lvl);
309 
310  //! Add elements to the local element list
311  /*!
312  * This routine sorts through the elements defined in the
313  * vcs_VolPhase object. It then adds the new elements to
314  * the VCS_PROB object, and creates a global map, which is
315  * stored in the vcs_VolPhase object.
316  * Id and matching of elements is done strictly via the element name,
317  * with case not mattering.
318  *
319  * The routine also fills in the position of the element
320  * in the vcs_VolPhase object's ElGlobalIndex field.
321  *
322  * @param volPhase Object containing the phase to be added.
323  * The elements in this phase are parsed for
324  * addition to the global element list
325  */
326  void addPhaseElements(vcs_VolPhase* volPhase);
327 
328 
329  //! This routine resizes the number of elements in the VCS_PROB object by
330  //! adding a new element to the end of the element list
331  /*!
332  * The element name is added. Formula vector entries ang element
333  * abundances for the new element are set to zero.
334  *
335  * Returns the index number of the new element.
336  *
337  * @param elNameNew New name of the element
338  * @param elType Type of the element
339  * @param elactive boolean indicating whether the element is active
340  *
341  * @return returns the index number of the new element
342  */
343  size_t addElement(const char* elNameNew, int elType, int elactive);
344 
345 
346  //! This routines adds entries for the formula matrix for one species
347  /*!
348  * This routines adds entries for the formula matrix for this object
349  * for one species
350  *
351  * This object also fills in the index filed, IndSpecies, within
352  * the volPhase object.
353  *
354  * @param volPhase object containing the species
355  * @param k Species number within the volPhase k
356  * @param kT global Species number within this object
357  *
358  */
359  size_t addOnePhaseSpecies(vcs_VolPhase* volPhase, size_t k, size_t kT);
360 
361  void reportCSV(const std::string& reportFile);
362 
363  //! Set the debug level
364  /*!
365  * @param vcs_debug_print_lvl input debug level
366  */
368 };
369 
370 }
371 
372 #endif