Cantera
2.2.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... | |
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 Throws an exception if n is greater than nDomains()-1. More... | |
void | checkDomainArraySize (size_t nn) const |
Check that an array size is at least nDomains() Throws an exception if nn is less than 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... | |
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... | |
void | resize () |
Call after one or more grids has been refined. More... | |
vector_int & | transientMask () |
double | timeStep (int nsteps, double dt, double *x, double *r, int loglevel) |
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 | 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... | |
void | setInterrupt (Func1 *interrupt) |
Set a function that will be called every time eval is called. More... | |
Protected Member Functions | |
void | evalSSJacobian (doublereal *x, doublereal *xnew) |
Protected Attributes | |
doublereal | m_tmin |
doublereal | m_tmax |
doublereal | m_tfactor |
MultiJac * | m_jac |
MultiNewton * | m_newt |
doublereal | m_rdt |
bool | m_jac_ok |
size_t | m_nd |
number of domains More... | |
size_t | m_bw |
size_t | m_size |
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... | |
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 |
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 28 of file OneDim.cpp.
References OneDim::addDomain(), OneDim::init(), and OneDim::resize().
void addDomain | ( | Domain1D * | d | ) |
Add a domain. Domains are added left-to-right.
Definition at line 56 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 86 of file OneDim.cpp.
MultiNewton & newton | ( | ) |
Return a reference to the Newton iterator.
Definition at line 90 of file OneDim.cpp.
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 199 of file OneDim.cpp.
References DATA_PTR, MultiJac::eval(), OneDim::eval(), Cantera::npos, and MultiNewton::solve().
Referenced by Sim1D::newtonSolve(), and OneDim::timeStep().
|
inline |
Number of domains.
Definition at line 48 of file OneDim.h.
References OneDim::m_nd.
Referenced by MultiNewton::boundStep(), MultiNewton::norm2(), and MultiNewton::step().
|
inline |
Return a reference to domain i.
Definition at line 53 of file OneDim.h.
Referenced by MultiNewton::boundStep(), Sim1D::finalize(), MultiNewton::norm2(), Sim1D::refine(), Sim1D::restore(), Sim1D::setFixedTemperature(), Sim1D::setFlatProfile(), Sim1D::setGridMin(), Sim1D::setInitialGuess(), 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.
Definition at line 61 of file OneDim.h.
References OneDim::m_nd.
|
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.
Definition at line 70 of file OneDim.h.
References OneDim::m_nd.
|
inline |
The index of the start of domain i in the solution vector.
Definition at line 77 of file OneDim.h.
Referenced by MultiNewton::boundStep(), Sim1D::finalize(), MultiNewton::norm2(), Sim1D::refine(), Sim1D::showSolution(), Sim1D::Sim1D(), and MultiNewton::step().
|
inline |
Total solution vector length;.
Definition at line 82 of file OneDim.h.
Referenced by MultiNewton::norm2(), OneDim::resize(), Sim1D::Sim1D(), and MultiNewton::step().
|
inline |
Pointer to left-most domain (first added).
Definition at line 87 of file OneDim.h.
Referenced by OneDim::init(), OneDim::initTimeInteg(), and OneDim::setSteadyMode().
|
inline |
Pointer to right-most domain (last added).
Definition at line 92 of file OneDim.h.
Referenced by OneDim::pointDomain().
|
inline |
Number of solution components at global point jg.
Definition at line 97 of file OneDim.h.
Referenced by MultiJac::eval().
|
inline |
Location in the solution vector of the first component of global point jg.
Definition at line 105 of file OneDim.h.
Referenced by MultiJac::eval(), and Sim1D::restore().
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 306 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 263 of file OneDim.cpp.
References OneDim::eval(), and Cantera::npos.
Referenced by MultiNewton::dampStep(), MultiNewton::solve(), and OneDim::timeStep().
|
inline |
Reciprocal of the time step.
Definition at line 134 of file OneDim.h.
Referenced by MultiNewton::solve().
void initTimeInteg | ( | doublereal | dt, |
doublereal * | x | ||
) |
Prepare for time stepping beginning with solution x and timestep dt.
Definition at line 273 of file OneDim.cpp.
References DATA_PTR, Domain1D::initTimeInteg(), OneDim::left(), Domain1D::right(), and Cantera::Tiny.
Referenced by OneDim::timeStep().
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 293 of file OneDim.cpp.
References DATA_PTR, OneDim::left(), Domain1D::right(), and Domain1D::setSteadyMode().
Referenced by OneDim::timeStep().
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 > 0, 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 232 of file OneDim.cpp.
References DATA_PTR, Func1::eval(), and OneDim::m_interrupt.
Referenced by MultiJac::eval(), 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 220 of file OneDim.cpp.
References Domain1D::left(), Domain1D::loc(), and OneDim::right().
Referenced by MultiNewton::step().
void resize | ( | ) |
Call after one or more grids has been refined.
Definition at line 142 of file OneDim.cpp.
References Domain1D::bandwidth(), Domain1D::loc(), OneDim::m_nd, Domain1D::nComponents(), Domain1D::nPoints(), Cantera::npos, MultiNewton::resize(), OneDim::saveStats(), and OneDim::size().
Referenced by OneDim::addDomain(), OneDim::OneDim(), Sim1D::refine(), Sim1D::restore(), and Sim1D::setFixedTemperature().
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 318 of file OneDim.cpp.
References OneDim::initTimeInteg(), OneDim::newton(), MultiNewton::setOptions(), OneDim::setSteadyMode(), 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 95 of file OneDim.cpp.
References Cantera::int2str(), OneDim::saveStats(), and Cantera::writelog().
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 115 of file OneDim.cpp.
References MultiJac::elapsedTime(), and MultiJac::nEvals().
Referenced by OneDim::resize(), and OneDim::writeStats().
void clearStats | ( | ) |
Clear saved statistics.
Definition at line 131 of file OneDim.cpp.
|
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 250 of file OneDim.h.
References OneDim::m_interrupt.
|
protected |
number of domains
Definition at line 268 of file OneDim.h.
Referenced by OneDim::checkDomainArraySize(), OneDim::checkDomainIndex(), Sim1D::finalize(), OneDim::nDomains(), Sim1D::refine(), OneDim::resize(), Sim1D::restore(), Sim1D::setFixedTemperature(), Sim1D::setGridMin(), Sim1D::setInitialGuess(), Sim1D::setRefineCriteria(), Sim1D::showSolution(), and Sim1D::Sim1D().
|
protected |
Function called at the start of every call to eval.
Definition at line 286 of file OneDim.h.
Referenced by OneDim::eval(), and OneDim::setInterrupt().