Cantera
2.0
|
One-dimensional simulations. More...
#include <Sim1D.h>
Public Member Functions | |
Sim1D () | |
Default constructor. | |
Sim1D (std::vector< Domain1D * > &domains) | |
Standard constructor. | |
virtual | ~Sim1D () |
Destructor. Does nothing. | |
void | save (std::string fname, std::string id, std::string desc) |
void | showSolution (std::ostream &s) |
Print to stream s the current solution for all domains. | |
void | showSolution () |
const doublereal * | solution () |
void | setTimeStep (doublereal stepsize, size_t n, integer *tsteps) |
void | solve (int loglevel=0, bool refine_grid=true) |
void | eval (doublereal rdt=-1.0, int count=1) |
int | refine (int loglevel=0) |
Refine the grid in all domains. | |
int | setFixedTemperature (doublereal t) |
Add node for fixed temperature point of freely propagating flame. | |
void | setAdiabaticFlame (void) |
void | setRefineCriteria (int dom=-1, doublereal ratio=10.0, doublereal slope=0.8, doublereal curve=0.8, doublereal prune=-0.1) |
Set the criteria for grid refinement. | |
void | setMaxGridPoints (int dom=-1, int npoints=300) |
void | restore (std::string fname, std::string id) |
Initialize the solution with a previously-saved solution. | |
void | setGridMin (int dom, double gridmin) |
Set the minimum grid spacing in the specified domain(s). | |
void | getInitialSoln () |
void | setSolution (const doublereal *soln) |
const doublereal * | solution () const |
doublereal | jacobian (int i, int j) |
void | evalSSJacobian () |
void | addDomain (Domain1D *d) |
Add a domain. | |
MultiJac & | jacobian () |
Return a reference to the Jacobian evaluator. | |
MultiNewton & | newton () |
Return a reference to the Newton iterator. | |
int | solve (doublereal *x0, doublereal *x1, int loglevel) |
Solve F(x) = 0, where F(x) is the multi-domain residual function. | |
size_t | nDomains () const |
Number of domains. | |
Domain1D & | domain (size_t i) const |
Return a reference to domain i. | |
size_t | domainIndex (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. | |
void | checkDomainArraySize (size_t nn) const |
Check that an array size is at least nDomains() Throws an exception if nn is less than nDomains(). | |
size_t | start (size_t i) const |
The index of the start of domain i in the solution vector. | |
size_t | size () const |
Total solution vector length;. | |
Domain1D * | left () |
Pointer to left-most domain (first added). | |
Domain1D * | right () |
Pointer to right-most domain (last added). | |
size_t | nVars (size_t jg) |
Number of solution components at global point jg. | |
size_t | loc (size_t jg) |
Location in the solution vector of the first component of global point jg. | |
size_t | bandwidth () const |
Jacobian bandwidth. | |
void | init () |
Initialize. | |
size_t | points () |
Total number of points. | |
doublereal | ssnorm (doublereal *x, doublereal *r) |
Steady-state max norm of the residual evaluated using solution x. | |
doublereal | rdt () const |
Reciprocal of the time step. | |
void | initTimeInteg (doublereal dt, doublereal *x) |
Prepare for time stepping beginning with solution x. | |
bool | transient () const |
True if transient mode. | |
bool | steady () const |
True if steady mode. | |
void | setSteadyMode () |
Set steady mode. | |
void | eval (size_t j, double *x, double *r, doublereal rdt=-1.0, int count=1) |
Evaluate the multi-domain residual function. | |
Domain1D * | pointDomain (size_t i) |
Pointer to the domain global point i belongs to. | |
void | resize () |
Call after one or more grids has been refined. | |
vector_int & | transientMask () |
double | timeStep (int nsteps, double dt, double *x, double *r, int loglevel) |
Take time steps using Backward Euler. | |
void | writeStats (int printTime=1) |
Write statistics about the number of iterations and Jacobians at each grid level. | |
void | save (std::string fname, std::string id, std::string desc, doublereal *sol) |
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 Jacobiab evaulation, and reset the counters. | |
Setting initial values | |
These methods are used to set the initial values of solution components. | |
void | setInitialGuess (std::string component, vector_fp &locs, vector_fp &vals) |
Set initial guess based on equilibrium. | |
void | setValue (size_t dom, size_t comp, size_t localPoint, doublereal value) |
Set one entry in the solution vector. | |
doublereal | value (size_t dom, size_t comp, size_t localPoint) const |
Get one entry in the solution vector. | |
doublereal | workValue (size_t dom, size_t comp, size_t localPoint) const |
void | setProfile (size_t dom, size_t comp, const vector_fp &pos, const vector_fp &values) |
Specify a profile for one component of one domain. | |
void | setFlatProfile (size_t dom, size_t comp, doublereal v) |
Set component 'comp' of domain 'dom' to value 'v' at all points. | |
Protected Member Functions | |
void | evalSSJacobian (doublereal *x, doublereal *xnew) |
Protected Attributes | |
vector_fp | m_x |
vector_fp | m_xnew |
doublereal | m_tstep |
vector_int | m_steps |
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 | |
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 |
Private Member Functions | |
void | finalize () |
Calls method _finalize in each domain. | |
int | newtonSolve (int loglevel) |
One-dimensional simulations.
Class Sim1D extends class OneDim by storing the solution vector, and by adding a hybrid Newton/time-stepping solver.
Sim1D | ( | ) |
Standard constructor.
domains | A vector of pointers to the domains to be linked together. The domain pointers must be entered in left-to-right order — i.e., the pointer to the leftmost domain is domain[0], the pointer to the domain to its right is domain[1], etc. |
Definition at line 30 of file Sim1D.cpp.
References Domain1D::_getInitialSoln(), DATA_PTR, OneDim::domain(), OneDim::m_nd, OneDim::size(), and OneDim::start().
Set initial guess based on equilibrium.
Definition at line 56 of file Sim1D.cpp.
References Domain1D::componentName(), OneDim::domain(), OneDim::m_nd, Domain1D::nComponents(), and Sim1D::setProfile().
void setValue | ( | size_t | dom, |
size_t | comp, | ||
size_t | localPoint, | ||
doublereal | value | ||
) |
Set one entry in the solution vector.
Set a single value in the solution vector.
dom | domain number, beginning with 0 for the leftmost domain. |
comp | component number |
localPoint | grid point within the domain, beginning with 0 for the leftmost grid point in the domain. |
value | the value. |
Definition at line 79 of file Sim1D.cpp.
References OneDim::domain(), Domain1D::loc(), and Sim1D::value().
Referenced by Sim1D::setFlatProfile(), and Sim1D::setProfile().
doublereal value | ( | size_t | dom, |
size_t | comp, | ||
size_t | localPoint | ||
) | const |
Get one entry in the solution vector.
dom | domain number, beginning with 0 for the leftmost domain. |
comp | component number |
localPoint | grid point within the domain, beginning with 0 for the leftmost grid point in the domain. |
Definition at line 92 of file Sim1D.cpp.
References OneDim::domain(), Cantera::int2str(), and Domain1D::loc().
Referenced by Sim1D::refine(), Sim1D::setFixedTemperature(), and Sim1D::setValue().
Specify a profile for one component of one domain.
dom | domain number, beginning with 0 for the leftmost domain. |
comp | component number |
pos | A vector of relative positions, beginning with 0.0 at the left of the domain, and ending with 1.0 at the right of the domain. |
values | A vector of values corresponding to the relative position locations. |
Note that the vector pos and values can have lengths different than the number of grid points, but their lengths must be equal. The values at the grid points will be linearly interpolated based on the (pos, values) specification.
Definition at line 129 of file Sim1D.cpp.
References OneDim::domain(), Cantera::linearInterp(), Domain1D::nPoints(), and Sim1D::setValue().
Referenced by Sim1D::setInitialGuess().
void setFlatProfile | ( | size_t | dom, |
size_t | comp, | ||
doublereal | v | ||
) |
Set component 'comp' of domain 'dom' to value 'v' at all points.
Definition at line 198 of file Sim1D.cpp.
References OneDim::domain(), Domain1D::nPoints(), and Sim1D::setValue().
void showSolution | ( | std::ostream & | s | ) |
Print to stream s the current solution for all domains.
Definition at line 208 of file Sim1D.cpp.
References DATA_PTR, OneDim::domain(), OneDim::m_nd, and OneDim::start().
int refine | ( | int | loglevel = 0 | ) |
Refine the grid in all domains.
Definition at line 351 of file Sim1D.cpp.
References DATA_PTR, OneDim::domain(), Sim1D::finalize(), Cantera::fp2str(), OneDim::m_nd, Domain1D::nComponents(), Domain1D::nPoints(), Domain1D::refiner(), OneDim::resize(), OneDim::start(), Sim1D::value(), and Cantera::writelog().
int setFixedTemperature | ( | doublereal | t | ) |
Add node for fixed temperature point of freely propagating flame.
Definition at line 449 of file Sim1D.cpp.
References DATA_PTR, OneDim::domain(), Sim1D::finalize(), OneDim::m_nd, Domain1D::nComponents(), Domain1D::nPoints(), OneDim::resize(), and Sim1D::value().
void setRefineCriteria | ( | int | dom = -1 , |
doublereal | ratio = 10.0 , |
||
doublereal | slope = 0.8 , |
||
doublereal | curve = 0.8 , |
||
doublereal | prune = -0.1 |
||
) |
Set the criteria for grid refinement.
Set grid refinement criteria.
If dom >= 0, then the settings apply only to the specified domain. If dom < 0, the settings are applied to each domain.
Definition at line 567 of file Sim1D.cpp.
References OneDim::domain(), OneDim::m_nd, and Domain1D::refiner().
void restore | ( | std::string | fname, |
std::string | id | ||
) |
Initialize the solution with a previously-saved solution.
Definition at line 154 of file Sim1D.cpp.
References XML_Node::build(), DATA_PTR, OneDim::domain(), Sim1D::finalize(), XML_Node::findID(), Cantera::intValue(), OneDim::loc(), OneDim::m_nd, Domain1D::nComponents(), OneDim::resize(), and Cantera::writelog().
void setGridMin | ( | int | dom, |
double | gridmin | ||
) |
Set the minimum grid spacing in the specified domain(s).
dom | Domain index. If dom == -1, the specified spacing is applied to all domains. |
gridmin | The minimum allowable grid spacing [m] |
Definition at line 581 of file Sim1D.cpp.
References OneDim::domain(), OneDim::m_nd, and Domain1D::refiner().
|
private |
Calls method _finalize in each domain.
Definition at line 235 of file Sim1D.cpp.
References Domain1D::_finalize(), DATA_PTR, OneDim::domain(), OneDim::m_nd, and OneDim::start().
Referenced by Sim1D::refine(), Sim1D::restore(), and Sim1D::setFixedTemperature().
|
private |
Wrapper around the Newton solver.
Definition at line 253 of file Sim1D.cpp.
References DATA_PTR, Cantera::int2str(), and OneDim::solve().
|
inherited |
Add a domain.
Domains are added left-to-right.
Definition at line 75 of file OneDim.cpp.
References OneDim::resize(), and Domain1D::setContainer().
Referenced by OneDim::OneDim().
|
inherited |
Return a reference to the Jacobian evaluator.
Definition at line 107 of file OneDim.cpp.
Referenced by Domain1D::needJacUpdate().
|
inherited |
Return a reference to the Newton iterator.
Definition at line 111 of file OneDim.cpp.
Referenced by OneDim::timeStep().
|
inherited |
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 235 of file OneDim.cpp.
References DATA_PTR, MultiJac::eval(), OneDim::eval(), Cantera::npos, and MultiNewton::solve().
Referenced by Sim1D::newtonSolve(), and OneDim::timeStep().
|
inlineinherited |
Number of domains.
Definition at line 52 of file OneDim.h.
References OneDim::m_nd.
Referenced by MultiNewton::boundStep(), MultiNewton::norm2(), and MultiNewton::step().
|
inlineinherited |
Return a reference to domain i.
Definition at line 57 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().
|
inlineinherited |
Check that the specified domain index is in range Throws an exception if n is greater than nDomains()-1.
Definition at line 65 of file OneDim.h.
References OneDim::m_nd.
|
inlineinherited |
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 74 of file OneDim.h.
References OneDim::m_nd.
|
inlineinherited |
The index of the start of domain i in the solution vector.
Definition at line 81 of file OneDim.h.
Referenced by MultiNewton::boundStep(), Sim1D::finalize(), MultiNewton::norm2(), Sim1D::refine(), Sim1D::showSolution(), Sim1D::Sim1D(), and MultiNewton::step().
|
inlineinherited |
Total solution vector length;.
Definition at line 86 of file OneDim.h.
Referenced by MultiJac::MultiJac(), MultiNewton::norm2(), OneDim::resize(), Sim1D::Sim1D(), and MultiNewton::step().
|
inlineinherited |
Pointer to left-most domain (first added).
Definition at line 91 of file OneDim.h.
Referenced by OneDim::init(), OneDim::initTimeInteg(), and OneDim::setSteadyMode().
|
inlineinherited |
Pointer to right-most domain (last added).
Definition at line 96 of file OneDim.h.
Referenced by OneDim::pointDomain().
|
inlineinherited |
Number of solution components at global point jg.
Definition at line 101 of file OneDim.h.
Referenced by MultiJac::eval().
|
inlineinherited |
Location in the solution vector of the first component of global point jg.
Definition at line 109 of file OneDim.h.
Referenced by MultiJac::eval(), OneDim::resize(), and Sim1D::restore().
|
inlineinherited |
|
inherited |
Initialize.
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 375 of file OneDim.cpp.
References Domain1D::init(), OneDim::left(), and Domain1D::right().
Referenced by OneDim::OneDim().
|
inlineinherited |
Total number of points.
Definition at line 122 of file OneDim.h.
Referenced by MultiJac::MultiJac().
|
inherited |
Steady-state max norm of the residual evaluated using solution x.
The 'infinity' (maximum magnitude) norm of the steady-state residual.
On return, array r contains the steady-state residual values.
Used only for diagnostic output.
Definition at line 317 of file OneDim.cpp.
References OneDim::eval(), ckr::max(), and Cantera::npos.
Referenced by MultiNewton::dampStep(), MultiNewton::solve(), and OneDim::timeStep().
|
inlineinherited |
Reciprocal of the time step.
Definition at line 133 of file OneDim.h.
Referenced by MultiNewton::solve().
|
inherited |
Prepare for time stepping beginning with solution x.
Prepare for time stepping with timestep dt.
Definition at line 331 of file OneDim.cpp.
References DATA_PTR, Domain1D::initTimeInteg(), OneDim::left(), Domain1D::right(), and Cantera::Tiny.
Referenced by OneDim::timeStep().
|
inlineinherited |
|
inherited |
Set steady mode.
Prepare to solve the steady-state problem.
After invoking this method, subsequent calls to solve() will solve the steady-state problem.
Set the reciprocal of the time step to zero, and, if it was previously non-zero, signal that a new Jacobian will be needed.
Definition at line 357 of file OneDim.cpp.
References DATA_PTR, OneDim::left(), Domain1D::right(), and Domain1D::setSteadyMode().
Referenced by OneDim::timeStep().
|
inherited |
Evaluate the multi-domain residual function.
Evaluate the multi-domain residual function, and return the result in array r.
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 283 of file OneDim.cpp.
References DATA_PTR.
Referenced by MultiJac::eval(), OneDim::solve(), MultiNewton::solve(), OneDim::ssnorm(), and MultiNewton::step().
|
inherited |
Pointer to the domain global point i belongs to.
Return a pointer to the domain that contains component i of the global solution vector.
The domains are scanned right-to-left, and the first one with starting location less or equal to i is returned.
8/26/02 changed '<' to '<=' DGG
Definition at line 266 of file OneDim.cpp.
References Domain1D::left(), Domain1D::loc(), and OneDim::right().
Referenced by MultiNewton::step().
|
inherited |
Call after one or more grids has been refined.
Definition at line 170 of file OneDim.cpp.
References Domain1D::bandwidth(), OneDim::loc(), 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().
|
inherited |
Take time steps using Backward Euler.
nsteps – number of steps dt – initial step size loglevel – controls amount of printed diagnostics
Definition at line 407 of file OneDim.cpp.
References OneDim::initTimeInteg(), OneDim::newton(), MultiNewton::setOptions(), OneDim::setSteadyMode(), OneDim::solve(), OneDim::ssnorm(), and Cantera::writelog().
|
inherited |
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 117 of file OneDim.cpp.
References Cantera::int2str(), OneDim::saveStats(), and Cantera::writelog().
|
inherited |
Save statistics on function and Jacobiab evaulation, 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 150 of file OneDim.cpp.
References MultiJac::elapsedTime(), and MultiJac::nEvals().
Referenced by Domain1D::needJacUpdate(), OneDim::resize(), and OneDim::writeStats().
|
protectedinherited |
number of domains
Definition at line 232 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().