Cantera  2.0
ImplicitSurfChem.h
Go to the documentation of this file.
1 /**
2  * @file ImplicitSurfChem.h
3  * Declarations for the implicit integration of surface site density equations
4  * (see \ref kineticsmgr and class
5  * \link Cantera::ImplicitSurfChem ImplicitSurfChem\endlink).
6  */
7 // Copyright 2001 California Institute of Technology
8 
9 #ifndef CT_IMPSURFCHEM_H
10 #define CT_IMPSURFCHEM_H
11 
16 #include "solveSP.h"
17 
18 namespace Cantera
19 {
20 
21 class solveSP;
22 
23 
24 //! Advances the surface coverages of the associated set of SurfacePhase
25 //! objects in time
26 /*!
27  * This function advances a set of SurfacePhase objects, each
28  * associated with one InterfaceKinetics object, in time.
29  * The following equation is used for each surface phase, <I>i</I>.
30  *
31  * \f[
32  * \dot \theta_k = \dot s_k (\sigma_k / s_0)
33  * \f]
34  *
35  * In this equation,
36  * \f$ \theta_k \f$ is the site coverage for the kth species.
37  * \f$ \dot s_k \f$ is the source term for the kth species
38  * \f$ \sigma_k \f$ is the number of surface sites covered by
39  * each species k.
40  * \f$ s_0 \f$ is the total site density of the interfacial phase.
41  *
42  * Additionally, the 0'th equation in the set is discarded. Instead the
43  * alternate equation is solved for
44  *
45  * \f[
46  * \sum_{k=0}^{N-1} \dot \theta_k = 0
47  * \f]
48  *
49  * This last equation serves to ensure that sum of the \f$ \theta_k \f$
50  * values stays constant.
51  *
52  * The object uses the CVODE software to advance the surface equations.
53  *
54  * The solution vector used by this object is as follows.
55  * For each surface phase with \f$ N_s \f$ surface sites,
56  * it consists of the surface coverages
57  * \f$ \theta_k \f$ for \f$ k = 0, N_s - 1 \f$
58  *
59  * @ingroup kineticsmgr
60  *
61  */
62 class ImplicitSurfChem : public FuncEval
63 {
64 
65 public:
66 
67 
68  //! Constructor for multiple surfaces.
69  /*!
70  * @param k Vector of pointers to InterfaceKinetics objects
71  * Each object consists of a surface or an edge containing
72  * internal degrees of freedom representing the concentration
73  * of surface adsorbates.
74  */
75  ImplicitSurfChem(std::vector<InterfaceKinetics*> k);
76 
77  /**
78  * Destructor. Deletes the integrator.
79  */
80  virtual ~ImplicitSurfChem();
81 
82  /**
83  * Overloads the virtual function
84  * declared in FuncEval.
85  */
86  virtual void initialize(doublereal t0 = 0.0);
87 
88 
89  //! Integrate from t0 to t1. The integrator is reinitialized first.
90  /*!
91  * This routine does a time accurate solve from t = t0 to t = t1.
92  * of the surface problem.
93  *
94  * @param t0 Initial Time -> this is an input
95  * @param t1 Final Time -> This is an input
96  */
97  void integrate(doublereal t0, doublereal t1);
98 
99 
100  //! Integrate from t0 to t1 without reinitializing the integrator.
101  /*!
102  * Use when the coverages have not changed from
103  * their values on return from the last call to integrate or
104  * integrate0.
105  *
106  * @param t0 Initial Time -> this is an input
107  * @param t1 Final Time -> This is an input
108  */
109  void integrate0(doublereal t0, doublereal t1);
110 
111 
112  //! Solve for the pseudo steady-state of the surface problem
113  /*!
114  * Solve for the steady state of the surface problem.
115  * This is the same thing as the advanceCoverages() function,
116  * but at infinite times.
117  *
118  * Note, a direct solve is carried out under the hood here,
119  * to reduce the computational time.
120  *
121  * @param ifuncOverride 4 values are possible
122  * 1 SFLUX_INITIALIZE
123  * 2 SFLUX_RESIDUAL
124  * 3 SFLUX_JACOBIAN
125  * 4 SFLUX_TRANSIENT
126  * The default is -1, which means that the program
127  * will decide.
128  * @param timeScaleOverride When a pseudo transient is
129  * selected this value can be used to override
130  * the default time scale for integration which
131  * is one.
132  * When SFLUX_TRANSIENT is used, this is equal to the
133  * time over which the equations are integrated.
134  * When SFLUX_INITIALIZE is used, this is equal to the
135  * time used in the initial transient algorithm,
136  * before the equation system is solved directly.
137  */
138  void solvePseudoSteadyStateProblem(int ifuncOverride = -1,
139  doublereal timeScaleOverride = 1.0);
140 
141 
142  // overloaded methods of class FuncEval
143 
144  //! Return the number of equations
145  virtual size_t neq() {
146  return m_nv;
147  }
148 
149  //! Evaluate the value of ydot[k] at the current conditions
150  /*!
151  * @param t Time (seconds)
152  * @param y Vector containing the current solution vector
153  * @param ydot Output vector containing the value of the
154  * derivative of the surface coverages.
155  * @param p Unused parameter pass-through parameter vector
156  */
157  virtual void eval(doublereal t, doublereal* y, doublereal* ydot,
158  doublereal* p);
159 
160  //! Set the initial conditions for the solution vector
161  /*!
162  * @param t0 Initial time
163  * @param leny Length of the solution vector
164  * @param y Value of the solution vector to be used.
165  * On output, this contains the initial value
166  * of the solution.
167  */
168  virtual void getInitialConditions(doublereal t0,
169  size_t leny, doublereal* y);
170 
171  /*
172  * Get the specifications for the problem from the values
173  * in the ThermoPhase objects for all phases.
174  *
175  * 1) concentrations of all species in all phases, m_concSpecies[]
176  * 2) Temperature and pressure
177  *
178  *
179  * @param vecConcSpecies Vector of concentrations. The
180  * phase concentration vectors are contiguous
181  * within the object, in the same order as the
182  * unknown vector.
183  */
184  void getConcSpecies(doublereal* const vecConcSpecies) const;
185 
186  //! Sets the concentrations within phases that are unknowns in
187  //! the surface problem
188  /*!
189  * Fills the local concentration vector for all of the
190  * species in all of the phases that are unknowns in the surface
191  * problem.
192  *
193  * @param vecConcSpecies Vector of concentrations. The
194  * phase concentration vectors are contiguous
195  * within the object, in the same order as the
196  * unknown vector.
197  */
198  void setConcSpecies(const doublereal* const vecConcSpecies);
199 
200  //! Sets the state variable in all thermodynamic phases (surface and
201  //! surrounding bulk phases) to the input temperature and pressure
202  /*!
203  * @param TKelvin input temperature (kelvin)
204  * @param PresPa input pressure in pascal.
205  */
206  void setCommonState_TP(doublereal TKelvin, doublereal PresPa);
207 
208 
209  //! Returns a reference to the vector of pointers to the
210  //! InterfaceKinetics objects
211  /*!
212  * This should probably go away in the future, as it opens up the
213  * class.
214  */
215  std::vector<InterfaceKinetics*> & getObjects() {
216  return m_vecKinPtrs;
217  }
218 
219  int checkMatch(std::vector<ThermoPhase*> m_vec, ThermoPhase* thPtr);
220 
221  void setIOFlag(int ioFlag) {
222  m_ioFlag = ioFlag;
223  }
224 
225 protected:
226 
227 
228  //! Set the mixture to a state consistent with solution
229  //! vector y.
230  /*!
231  * This function will set the surface site factions
232  * in the underlying %SurfPhase objects to the current
233  * value of the solution vector.
234  *
235  * @param y Current value of the solution vector.
236  * The lenth is equal to the sum of the number of surface
237  * sites in all the surface phases
238  */
239  void updateState(doublereal* y);
240 
241  //! vector of pointers to surface phases.
242  std::vector<SurfPhase*> m_surf;
243 
244  //! Vector of pointers to bulk phases
245  std::vector<ThermoPhase*> m_bulkPhases;
246 
247  //! vector of pointers to InterfaceKinetics objects
248  std::vector<InterfaceKinetics*> m_vecKinPtrs;
249 
250  //! Vector of number of species in each Surface Phase
251  std::vector<size_t> m_nsp;
252 
253  //! index of the surface phase in each InterfaceKinetics object
254  std::vector<size_t> m_surfindex;
255 
256  std::vector<size_t> m_specStartIndex;
257 
258  //! Total number of surface phases.
259  /*!
260  * This is also equal to the number of InterfaceKinetics objects
261  * as there is a 1-1 correspondence between InterfaceKinetics objects
262  * and surface phases.
263  */
264  size_t m_nsurf;
265 
266  //! Total number of surface species in all surface phases
267  /*!
268  * This is the total number of unknowns in m_mode 0 problem
269  */
270  size_t m_nv;
271 
272  size_t m_numBulkPhases;
273  std::vector<size_t> m_nspBulkPhases;
274  size_t m_numTotalBulkSpecies;
275  size_t m_numTotalSpecies;
276 
277  std::vector<vector_int> pLocVec;
278  //! Pointer to the cvode integrator
280  doublereal m_atol, m_rtol; // tolerances
281  doublereal m_maxstep; // max step size
282  vector_fp m_work;
283 
284 
285 
286  /**
287  * Temporary vector - length num species in the Kinetics object.
288  * This is the sum of the number of species
289  * in each phase included in the kinetics object.
290  */
292  vector_fp m_concSpeciesSave;
293 
294  //std::vector<vector_fp> m_vectorConcKinSpecies;
295  //std::vector<vector_fp> m_vectorNetSpeciesProdRate;
296  /**
297  * Index into the species vector of the kinetics manager,
298  * pointing to the first species from the surrounding medium.
299  */
301  /**
302  * Index into the species vector of the kinetics manager,
303  * pointing to the first species from the condensed phase
304  * of the particles.
305  */
307  /**
308  * Index into the species vector of the kinetics manager,
309  * pointing to the first species from the surface
310  * of the particles
311  */
313  /**
314  * Pointer to the helper method, Placid, which solves the
315  * surface problem.
316  */
318 
319  //! If true, a common temperature and pressure for all
320  //! surface and bulk phases associated with the surface problem
321  //! is imposed
323 
324  //! We make the solveSS class a friend because we need
325  //! to access all of the above information directly.
326  //! Adding the members into the class is also a possibility.
327  friend class solveSS;
328 
329 private:
330 
331  //! Controls the amount of printing from this routine
332  //! and underlying routines.
333  int m_ioFlag;
334 };
335 }
336 
337 #endif
338