Cantera
2.5.1
|
Container class for multiple-domain 1D problems. More...
#include <OneDim.h>
Public Member Functions | |
OneDim (std::vector< Domain1D * > domains) | |
Construct a OneDim container for the domains in the list domains. More... | |
OneDim (const OneDim &)=delete | |
OneDim & | operator= (const OneDim &)=delete |
void | addDomain (Domain1D *d) |
Add a domain. Domains are added left-to-right. More... | |
MultiJac & | jacobian () |
Return a reference to the Jacobian evaluator. More... | |
MultiNewton & | newton () |
Return a reference to the Newton iterator. More... | |
int | solve (doublereal *x0, doublereal *x1, int loglevel) |
Solve F(x) = 0, where F(x) is the multi-domain residual function. More... | |
size_t | nDomains () const |
Number of domains. More... | |
Domain1D & | domain (size_t i) const |
Return a reference to domain i. More... | |
size_t | domainIndex (const std::string &name) |
void | checkDomainIndex (size_t n) const |
Check that the specified domain index is in range. More... | |
void | checkDomainArraySize (size_t nn) const |
Check that an array size is at least nDomains(). More... | |
size_t | start (size_t i) const |
The index of the start of domain i in the solution vector. More... | |
size_t | size () const |
Total solution vector length;. More... | |
Domain1D * | left () |
Pointer to left-most domain (first added). More... | |
Domain1D * | right () |
Pointer to right-most domain (last added). More... | |
size_t | nVars (size_t jg) |
Number of solution components at global point jg. More... | |
size_t | loc (size_t jg) |
Location in the solution vector of the first component of global point jg. More... | |
std::tuple< std::string, size_t, std::string > | component (size_t i) |
Return the domain, local point index, and component name for the i-th component of the global solution vector. More... | |
size_t | bandwidth () const |
Jacobian bandwidth. More... | |
void | init () |
size_t | points () |
Total number of points. More... | |
doublereal | ssnorm (doublereal *x, doublereal *r) |
Steady-state max norm (infinity norm) of the residual evaluated using solution x. More... | |
doublereal | rdt () const |
Reciprocal of the time step. More... | |
void | initTimeInteg (doublereal dt, doublereal *x) |
Prepare for time stepping beginning with solution x and timestep dt. More... | |
bool | transient () const |
True if transient mode. More... | |
bool | steady () const |
True if steady mode. More... | |
void | setSteadyMode () |
void | eval (size_t j, double *x, double *r, doublereal rdt=-1.0, int count=1) |
Evaluate the multi-domain residual function. More... | |
Domain1D * | pointDomain (size_t i) |
Return a pointer to the domain global point i belongs to. More... | |
virtual void | resize () |
Call after one or more grids has changed size, e.g. after being refined. More... | |
vector_int & | transientMask () |
double | timeStep (int nsteps, double dt, double *x, double *r, int loglevel) |
void | resetBadValues (double *x) |
void | writeStats (int printTime=1) |
Write statistics about the number of iterations and Jacobians at each grid level. More... | |
void | save (const std::string &fname, std::string id, const std::string &desc, doublereal *sol, int loglevel) |
void | setMinTimeStep (doublereal tmin) |
void | setMaxTimeStep (doublereal tmax) |
void | setTimeStepFactor (doublereal tfactor) |
void | setMaxTimeStepCount (int nmax) |
Set the maximum number of timeteps allowed before successful steady-state solve. More... | |
int | maxTimeStepCount () const |
Return the maximum number of timeteps allowed before successful steady-state solve. More... | |
void | setJacAge (int ss_age, int ts_age=-1) |
void | saveStats () |
Save statistics on function and Jacobian evaluation, and reset the counters. More... | |
void | clearStats () |
Clear saved statistics. More... | |
const std::vector< size_t > & | gridSizeStats () |
Return total grid size in each call to solve() More... | |
const vector_fp & | jacobianTimeStats () |
Return CPU time spent evaluating Jacobians in each call to solve() More... | |
const vector_fp & | evalTimeStats () |
Return CPU time spent on non-Jacobian function evaluations in each call to solve() More... | |
const vector_int & | jacobianCountStats () |
Return number of Jacobian evaluations made in each call to solve() More... | |
const vector_int & | evalCountStats () |
Return number of non-Jacobian function evaluations made in each call to solve() More... | |
const vector_int & | timeStepStats () |
Return number of time steps taken in each call to solve() More... | |
void | setInterrupt (Func1 *interrupt) |
Set a function that will be called every time eval is called. More... | |
void | setTimeStepCallback (Func1 *callback) |
Set a function that will be called after each successful timestep. More... | |
Protected Member Functions | |
void | evalSSJacobian (doublereal *x, doublereal *xnew) |
Protected Attributes | |
doublereal | m_tmin |
minimum timestep size More... | |
doublereal | m_tmax |
maximum timestep size More... | |
doublereal | m_tfactor |
factor time step is multiplied by if time stepping fails ( < 1 ) More... | |
std::unique_ptr< MultiJac > | m_jac |
Jacobian evaluator. More... | |
std::unique_ptr< MultiNewton > | m_newt |
Newton iterator. More... | |
doublereal | m_rdt |
reciprocal of time step More... | |
bool | m_jac_ok |
if true, Jacobian is current More... | |
size_t | m_bw |
Jacobian bandwidth. More... | |
size_t | m_size |
solution vector size More... | |
std::vector< Domain1D * > | m_dom |
std::vector< Domain1D * > | m_connect |
std::vector< Domain1D * > | m_bulk |
bool | m_init |
std::vector< size_t > | m_nvars |
std::vector< size_t > | m_loc |
vector_int | m_mask |
size_t | m_pts |
doublereal | m_solve_time |
int | m_ss_jac_age |
int | m_ts_jac_age |
Func1 * | m_interrupt |
Function called at the start of every call to eval. More... | |
Func1 * | m_time_step_callback |
User-supplied function called after each successful timestep. More... | |
int | m_nsteps |
Number of time steps taken in the current call to solve() More... | |
int | m_nsteps_max |
Maximum number of timesteps allowed per call to solve() More... | |
Private Attributes | |
int | m_nevals |
doublereal | m_evaltime |
std::vector< size_t > | m_gridpts |
vector_int | m_jacEvals |
vector_fp | m_jacElapsed |
vector_int | m_funcEvals |
vector_fp | m_funcElapsed |
vector_int | m_timeSteps |
Number of time steps taken in each call to solve() (e.g. More... | |
Container class for multiple-domain 1D problems.
Each domain is represented by an instance of Domain1D.
Construct a OneDim container for the domains in the list domains.
Definition at line 32 of file OneDim.cpp.
References OneDim::addDomain(), OneDim::init(), OneDim::m_newt, and OneDim::resize().
void addDomain | ( | Domain1D * | d | ) |
Add a domain. Domains are added left-to-right.
Definition at line 79 of file OneDim.cpp.
References OneDim::resize(), and Domain1D::setContainer().
Referenced by OneDim::OneDim().
MultiJac & jacobian | ( | ) |
Return a reference to the Jacobian evaluator.
Definition at line 101 of file OneDim.cpp.
References OneDim::m_jac.
Referenced by Domain1D::needJacUpdate().
MultiNewton & newton | ( | ) |
Return a reference to the Newton iterator.
Definition at line 105 of file OneDim.cpp.
References OneDim::m_newt.
Referenced by OneDim::timeStep().
int solve | ( | doublereal * | x0, |
doublereal * | x1, | ||
int | loglevel | ||
) |
Solve F(x) = 0, where F(x) is the multi-domain residual function.
x0 | Starting estimate of solution. |
x1 | Final solution satisfying F(x1) = 0. |
loglevel | Controls amount of diagnostic output. |
Definition at line 224 of file OneDim.cpp.
References OneDim::eval(), OneDim::m_jac, OneDim::m_jac_ok, OneDim::m_newt, OneDim::m_rdt, and Cantera::npos.
Referenced by Sim1D::newtonSolve(), and OneDim::timeStep().
|
inline |
Number of domains.
Definition at line 54 of file OneDim.h.
Referenced by MultiNewton::boundStep(), OneDim::component(), Sim1D::finalize(), Sim1D::fixedTemperature(), Sim1D::fixedTemperatureLocation(), MultiNewton::norm2(), Sim1D::refine(), OneDim::resize(), Sim1D::restore(), Sim1D::restoreSteadySolution(), Sim1D::setFixedTemperature(), Sim1D::setGridMin(), Sim1D::setInitialGuess(), Sim1D::setMaxGridPoints(), Sim1D::setRefineCriteria(), Sim1D::showSolution(), Sim1D::Sim1D(), and MultiNewton::step().
|
inline |
Return a reference to domain i.
Definition at line 59 of file OneDim.h.
Referenced by MultiNewton::boundStep(), OneDim::component(), Sim1D::finalize(), Sim1D::fixedTemperature(), Sim1D::fixedTemperatureLocation(), Sim1D::getRefineCriteria(), Sim1D::maxGridPoints(), MultiNewton::norm2(), Sim1D::refine(), Sim1D::restore(), Sim1D::restoreSteadySolution(), Sim1D::setFixedTemperature(), Sim1D::setFlatProfile(), Sim1D::setGridMin(), Sim1D::setInitialGuess(), Sim1D::setMaxGridPoints(), Sim1D::setProfile(), Sim1D::setRefineCriteria(), Sim1D::setValue(), Sim1D::showSolution(), Sim1D::Sim1D(), MultiNewton::step(), and Sim1D::value().
|
inline |
Check that the specified domain index is in range.
Throws an exception if n is greater than nDomains()-1
|
inline |
Check that an array size is at least nDomains().
Throws an exception if nn is less than nDomains(). Used before calls which take an array pointer.
|
inline |
The index of the start of domain i in the solution vector.
Definition at line 85 of file OneDim.h.
Referenced by MultiNewton::boundStep(), OneDim::component(), Sim1D::finalize(), MultiNewton::norm2(), Sim1D::refine(), Sim1D::restore(), Sim1D::showSolution(), Sim1D::Sim1D(), and MultiNewton::step().
|
inline |
Total solution vector length;.
Definition at line 96 of file OneDim.h.
References OneDim::m_size.
Referenced by MultiNewton::norm2(), OneDim::resize(), Sim1D::resize(), and MultiNewton::step().
|
inline |
Pointer to left-most domain (first added).
Definition at line 101 of file OneDim.h.
Referenced by OneDim::init(), OneDim::initTimeInteg(), and OneDim::setSteadyMode().
|
inline |
Pointer to right-most domain (last added).
Definition at line 106 of file OneDim.h.
Referenced by OneDim::pointDomain().
|
inline |
|
inline |
std::tuple< std::string, size_t, std::string > component | ( | size_t | i | ) |
Return the domain, local point index, and component name for the i-th component of the global solution vector.
Definition at line 65 of file OneDim.cpp.
References Domain1D::componentName(), OneDim::domain(), Domain1D::nComponents(), OneDim::nDomains(), Cantera::npos, and OneDim::start().
Referenced by Sim1D::setInitialGuess().
|
inline |
void init | ( | ) |
Initialize all domains. On the first call, this methods calls the init method of each domain, proceeding from left to right. Subsequent calls do nothing.
Definition at line 336 of file OneDim.cpp.
References Domain1D::init(), OneDim::left(), and Domain1D::right().
Referenced by OneDim::OneDim().
doublereal ssnorm | ( | doublereal * | x, |
doublereal * | r | ||
) |
Steady-state max norm (infinity norm) of the residual evaluated using solution x.
On return, array r contains the steady-state residual values. Used only for diagnostic output.
Definition at line 290 of file OneDim.cpp.
References OneDim::eval(), OneDim::m_size, and Cantera::npos.
Referenced by MultiNewton::solve(), and OneDim::timeStep().
|
inline |
Reciprocal of the time step.
Definition at line 150 of file OneDim.h.
References OneDim::m_rdt.
Referenced by OneDim::eval(), and MultiNewton::solve().
void initTimeInteg | ( | doublereal | dt, |
doublereal * | x | ||
) |
Prepare for time stepping beginning with solution x and timestep dt.
Definition at line 300 of file OneDim.cpp.
References Domain1D::initTimeInteg(), OneDim::left(), OneDim::m_jac, OneDim::m_rdt, Domain1D::right(), and Cantera::Tiny.
Referenced by OneDim::timeStep().
|
inline |
|
inline |
void setSteadyMode | ( | ) |
Prepare to solve the steady-state problem. After invoking this method, subsequent calls to solve() will solve the steady-state problem. Sets the reciprocal of the time step to zero, and, if it was previously non- zero, signals that a new Jacobian will be needed.
Definition at line 319 of file OneDim.cpp.
References OneDim::left(), OneDim::m_jac, OneDim::m_rdt, Domain1D::right(), and Domain1D::setSteadyMode().
void eval | ( | size_t | j, |
double * | x, | ||
double * | r, | ||
doublereal | rdt = -1.0 , |
||
int | count = 1 |
||
) |
Evaluate the multi-domain residual function.
j | if j != npos, only evaluate residual for points j-1, j, and j + 1; otherwise, evaluate at all grid points. |
x | solution vector |
r | on return, contains the residual vector |
rdt | Reciprocal of the time step. if omitted, then the default value is used. |
count | Set to zero to omit this call from the statistics |
Definition at line 258 of file OneDim.cpp.
References Func1::eval(), OneDim::m_interrupt, OneDim::m_rdt, OneDim::m_size, Cantera::npos, and OneDim::rdt().
Referenced by OneDim::solve(), MultiNewton::solve(), OneDim::ssnorm(), and MultiNewton::step().
Domain1D * pointDomain | ( | size_t | i | ) |
Return a pointer to the domain global point i belongs to.
The domains are scanned right-to-left, and the first one with starting location less or equal to i is returned.
Definition at line 246 of file OneDim.cpp.
References Domain1D::left(), Domain1D::loc(), and OneDim::right().
|
virtual |
Call after one or more grids has changed size, e.g. after being refined.
Reimplemented in Sim1D.
Definition at line 168 of file OneDim.cpp.
References Domain1D::bandwidth(), Domain1D::loc(), OneDim::m_bw, OneDim::m_jac, OneDim::m_jac_ok, OneDim::m_newt, OneDim::m_size, Domain1D::nComponents(), OneDim::nDomains(), Domain1D::nPoints(), Cantera::npos, OneDim::saveStats(), and OneDim::size().
Referenced by OneDim::addDomain(), OneDim::OneDim(), and Sim1D::resize().
doublereal timeStep | ( | int | nsteps, |
double | dt, | ||
double * | x, | ||
double * | r, | ||
int | loglevel | ||
) |
Take time steps using Backward Euler.
nsteps | number of steps |
dt | initial step size |
x | current solution vector |
r | solution vector after time stepping |
loglevel | controls amount of printed diagnostics |
Definition at line 348 of file OneDim.cpp.
References Cantera::debuglog(), Func1::eval(), OneDim::initTimeInteg(), OneDim::m_nsteps, OneDim::m_nsteps_max, OneDim::m_size, OneDim::m_tfactor, OneDim::m_time_step_callback, OneDim::m_tmax, OneDim::m_tmin, OneDim::newton(), MultiNewton::setOptions(), OneDim::solve(), OneDim::ssnorm(), and Cantera::writelog().
void writeStats | ( | int | printTime = 1 | ) |
Write statistics about the number of iterations and Jacobians at each grid level.
printTime | Boolean that indicates whether time should be printed out The default is true. It's turned off for test problems where we don't want to print any times |
Definition at line 120 of file OneDim.cpp.
References OneDim::m_timeSteps, OneDim::saveStats(), and Cantera::writelog().
|
inline |
Set the maximum number of timeteps allowed before successful steady-state solve.
Definition at line 243 of file OneDim.h.
References OneDim::m_nsteps_max.
|
inline |
Return the maximum number of timeteps allowed before successful steady-state solve.
Definition at line 249 of file OneDim.h.
References OneDim::m_nsteps_max.
void saveStats | ( | ) |
Save statistics on function and Jacobian evaluation, and reset the counters.
Statistics are saved only if the number of Jacobian evaluations is greater than zero. The statistics saved are:
Definition at line 137 of file OneDim.cpp.
References OneDim::m_jac, OneDim::m_nsteps, and OneDim::m_timeSteps.
Referenced by OneDim::evalCountStats(), OneDim::evalTimeStats(), OneDim::gridSizeStats(), OneDim::jacobianCountStats(), OneDim::jacobianTimeStats(), Domain1D::needJacUpdate(), OneDim::resize(), OneDim::timeStepStats(), and OneDim::writeStats().
void clearStats | ( | ) |
Clear saved statistics.
Definition at line 155 of file OneDim.cpp.
References OneDim::m_nsteps, and OneDim::m_timeSteps.
|
inline |
Return total grid size in each call to solve()
Definition at line 273 of file OneDim.h.
References OneDim::saveStats().
|
inline |
Return CPU time spent evaluating Jacobians in each call to solve()
Definition at line 279 of file OneDim.h.
References OneDim::saveStats().
|
inline |
Return CPU time spent on non-Jacobian function evaluations in each call to solve()
Definition at line 286 of file OneDim.h.
References OneDim::saveStats().
|
inline |
Return number of Jacobian evaluations made in each call to solve()
Definition at line 292 of file OneDim.h.
References OneDim::saveStats().
|
inline |
Return number of non-Jacobian function evaluations made in each call to solve()
Definition at line 299 of file OneDim.h.
References OneDim::saveStats().
|
inline |
Return number of time steps taken in each call to solve()
Definition at line 305 of file OneDim.h.
References OneDim::m_timeSteps, and OneDim::saveStats().
|
inline |
Set a function that will be called every time eval is called.
Can be used to provide keyboard interrupt support in the high-level language interfaces.
Definition at line 313 of file OneDim.h.
References OneDim::m_interrupt.
|
inline |
Set a function that will be called after each successful timestep.
The function will be called with the size of the timestep as the argument. Intended to be used for observing solver progress for debugging purposes.
Definition at line 321 of file OneDim.h.
References OneDim::m_time_step_callback.
|
protected |
|
protected |
|
protected |
factor time step is multiplied by if time stepping fails ( < 1 )
Definition at line 332 of file OneDim.h.
Referenced by OneDim::timeStep().
|
protected |
Jacobian evaluator.
Definition at line 334 of file OneDim.h.
Referenced by OneDim::initTimeInteg(), OneDim::jacobian(), OneDim::resize(), OneDim::saveStats(), OneDim::setSteadyMode(), and OneDim::solve().
|
protected |
Newton iterator.
Definition at line 335 of file OneDim.h.
Referenced by OneDim::newton(), OneDim::OneDim(), OneDim::resize(), and OneDim::solve().
|
protected |
reciprocal of time step
Definition at line 336 of file OneDim.h.
Referenced by OneDim::eval(), OneDim::initTimeInteg(), OneDim::rdt(), OneDim::setSteadyMode(), OneDim::solve(), OneDim::steady(), and OneDim::transient().
|
protected |
if true, Jacobian is current
Definition at line 337 of file OneDim.h.
Referenced by OneDim::resize(), and OneDim::solve().
|
protected |
Jacobian bandwidth.
Definition at line 339 of file OneDim.h.
Referenced by OneDim::bandwidth(), and OneDim::resize().
|
protected |
solution vector size
Definition at line 340 of file OneDim.h.
Referenced by OneDim::eval(), OneDim::resize(), OneDim::size(), OneDim::ssnorm(), and OneDim::timeStep().
|
protected |
Function called at the start of every call to eval.
Definition at line 355 of file OneDim.h.
Referenced by OneDim::eval(), and OneDim::setInterrupt().
|
protected |
User-supplied function called after each successful timestep.
Definition at line 358 of file OneDim.h.
Referenced by OneDim::setTimeStepCallback(), and OneDim::timeStep().
|
protected |
Number of time steps taken in the current call to solve()
Definition at line 361 of file OneDim.h.
Referenced by OneDim::clearStats(), OneDim::saveStats(), and OneDim::timeStep().
|
protected |
Maximum number of timesteps allowed per call to solve()
Definition at line 364 of file OneDim.h.
Referenced by OneDim::maxTimeStepCount(), OneDim::setMaxTimeStepCount(), and OneDim::timeStep().
|
private |
Number of time steps taken in each call to solve() (e.g.
for each successive grid refinement)
Definition at line 378 of file OneDim.h.
Referenced by OneDim::clearStats(), OneDim::saveStats(), OneDim::timeStepStats(), and OneDim::writeStats().