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