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