18 ImplicitSurfChem::ImplicitSurfChem(vector<InterfaceKinetics*> k) :
22 m_numTotalBulkSpecies(0),
28 m_mediumSpeciesStart(-1),
29 m_bulkSpeciesStart(-1),
30 m_surfSpeciesStart(-1),
32 m_commonTempPressForPhases(true),
38 size_t kinSpIndex = 0;
40 for (
size_t n = 0; n <
m_nsurf; n++) {
43 ns = k[n]->surfacePhaseIndex();
46 "kinetics manager contains no surface phase");
49 nsp =
m_surf.back()->nSpecies();
52 nt = k[n]->nTotalSpecies();
53 ntmax = std::max(nt, ntmax);
54 m_specStartIndex.push_back(kinSpIndex);
57 size_t nPhases = kinPtr->
nPhases();
60 for (
size_t ip = 0; ip < nPhases; ip++) {
67 m_nspBulkPhases.push_back(nsp);
68 m_numTotalBulkSpecies += nsp;
71 pLocTmp[ip] = int(imatch);
73 pLocTmp[ip] = -int(n);
76 pLocVec.push_back(pLocTmp);
79 m_numTotalSpecies =
m_nv + m_numTotalBulkSpecies;
81 m_concSpeciesSave.resize(m_numTotalSpecies, 0.0);
83 m_integ = newIntegrator(
"CVODE");
96 int ImplicitSurfChem::checkMatch(std::vector<ThermoPhase*> m_vec,
ThermoPhase* thPtr)
99 for (
int i = 0; i < (int) m_vec.size(); i++) {
118 for (
size_t n = 0; n <
m_nsurf; n++) {
119 m_surf[n]->getCoverages(c + loc);
147 for (
size_t n = 0; n <
m_nsurf; n++) {
148 m_surf[n]->setCoverages(c + loc);
154 doublereal* ydot, doublereal* p)
158 size_t loc = 0, kstart;
159 for (
size_t n = 0; n <
m_nsurf; n++) {
160 rs0 = 1.0/
m_surf[n]->siteDensity();
164 for (
size_t k = 1; k <
m_nsp[n]; k++) {
165 ydot[k + loc] = m_work[kstart + k] * rs0 *
m_surf[n]->size(k);
174 doublereal timeScaleOverride)
185 doublereal time_scale = timeScaleOverride;
197 if (ifuncOverride >= 0) {
198 ifunc = ifuncOverride;
223 doublereal reltol = 1.0E-6;
224 doublereal atol = 1.0E-20;
232 for (
size_t k = 0; k <
m_nv; k++) {
252 copy(m_concSpeciesSave.begin(), m_concSpeciesSave.end(),
m_concSpecies.begin());
259 throw CanteraError(
"ImplicitSurfChem::solvePseudoSteadyStateProblem",
260 "solveSP return an error condition!");
268 for (
size_t ip = 0; ip <
m_nsurf; ip++) {
270 kstart = m_specStartIndex[ip];
274 for (
size_t ip = 0; ip < m_numBulkPhases; ip++) {
284 for (
size_t ip = 0; ip <
m_nsurf; ip++) {
286 kstart = m_specStartIndex[ip];
290 for (
size_t ip = 0; ip < m_numBulkPhases; ip++) {
299 for (
size_t ip = 0; ip <
m_nsurf; ip++) {
303 for (
size_t ip = 0; ip < m_numBulkPhases; ip++) {
Backward Differentiation.
Integrator * m_integ
Pointer to the CVODE integrator.
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase, assuming an ideal solution model (see Thermodynamic Properties and class SurfPhase).
std::vector< size_t > m_surfindex
index of the surface phase in each InterfaceKinetics object
thermo_t & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism...
void solvePseudoSteadyStateProblem(int ifuncOverride=-1, doublereal timeScaleOverride=1.0)
Solve for the pseudo steady-state of the surface problem.
virtual void setMaxStepSize(double hmax)
Set the maximum step size.
virtual void integrate(doublereal tout)
Integrate the system of equations.
std::vector< ThermoPhase * > m_bulkPhases
Vector of pointers to bulk phases.
Method to solve a pseudo steady state surface problem.
const size_t npos
index returned by functions to indicate "no position"
std::vector< size_t > m_nsp
Vector of number of species in each Surface Phase.
virtual void setTolerances(doublereal reltol, size_t n, doublereal *abstol)
Set or reset the number of equations.
const int BULK_ETCH
Etching of a bulk phase is to be expected.
void getConcentrations(doublereal *const c) const
Get the species concentrations (kmol/m^3).
virtual void initialize(doublereal t0, FuncEval &func)
Initialize the integrator for a new problem.
solveSP * m_surfSolver
Pointer to the helper method, Placid, which solves the surface problem.
std::vector< SurfPhase * > m_surf
vector of pointers to surface phases.
Base class for a phase with thermodynamic properties.
std::vector< int > vector_int
Vector of ints.
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
int solveSurfProb(int ifunc, doublereal time_scale, doublereal TKelvin, doublereal PGas, doublereal reltol, doublereal abstol)
Main routine that actually calculates the pseudo steady state of the surface problem.
int m_ioFlag
Controls the amount of printing from this routine and underlying routines.
virtual void setProblemType(int probtype)
Set the problem type.
bool m_commonTempPressForPhases
If true, a common temperature and pressure for all surface and bulk phases associated with the surfac...
const int SFLUX_INITIALIZE
This assumes that the initial guess supplied to the routine is far from the correct one...
size_t nPhases() const
The number of phases participating in the reaction mechanism.
A kinetics manager for heterogeneous reaction mechanisms.
const int SFLUX_RESIDUAL
Need to solve the surface problem in order to calculate the surface fluxes of gas-phase species...
virtual ~ImplicitSurfChem()
Destructor.
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.
Base class for exceptions thrown by Cantera classes.
virtual void eval(doublereal t, doublereal *y, doublereal *ydot, doublereal *p)
Evaluate the value of ydot[k] at the current conditions.
virtual void setConcentrations(const doublereal *const conc)
Set the concentrations to the specified values within the phase.
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.
Declarations for the implicit integration of surface site density equations (see Kinetics Managers an...
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
size_t nSpecies() const
Returns the number of species in the phase.
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
doublereal temperature() const
Temperature (K).
void getConcSpecies(doublereal *const vecConcSpecies) const
virtual void initialize(doublereal t0=0.0)
void setCommonState_TP(doublereal TKelvin, doublereal PresPa)
Sets the state variable in all thermodynamic phases (surface and surrounding bulk phases) to the inpu...
virtual doublereal & solution(size_t k)
The current value of the solution of equation k.
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).
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
size_t m_nsurf
Total number of surface phases.
std::vector< InterfaceKinetics * > m_vecKinPtrs
vector of pointers to InterfaceKinetics objects
virtual void setIterator(IterType t)
Set the linear iterator.
virtual void setMethod(MethodType t)
Set the solution method.
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.