Container class for multiple-domain 1D problems. More...
#include <OneDim.h>
Container class for multiple-domain 1D problems.
Each domain is represented by an instance of Domain1D.
Public Member Functions | |
OneDim () | |
Default constructor. | |
OneDim (vector< shared_ptr< Domain1D > > &domains) | |
Construct a OneDim container for the domains in the list domains. | |
OneDim (const OneDim &)=delete | |
OneDim & | operator= (const OneDim &)=delete |
void | addDomain (shared_ptr< Domain1D > d) |
Add a domain. Domains are added left-to-right. | |
MultiJac & | jacobian () |
Return a reference to the Jacobian evaluator of an OneDim object. | |
MultiNewton & | newton () |
Return a reference to the Newton iterator. | |
int | solve (double *x0, double *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 (const string &name) |
Get the index of the domain named name . | |
void | checkDomainIndex (size_t n) const |
Check that the specified domain index is in range. | |
void | checkDomainArraySize (size_t nn) const |
Check that an array size is at least 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 . | |
std::tuple< string, size_t, string > | component (size_t i) |
Return the domain, local point index, and component name for the i-th component of the global solution vector. | |
size_t | bandwidth () const |
Jacobian bandwidth. | |
void | init () |
Initialize all domains. | |
size_t | points () |
Total number of points. | |
double | ssnorm (double *x, double *r) |
Steady-state max norm (infinity norm) of the residual evaluated using solution x. | |
double | rdt () const |
Reciprocal of the time step. | |
void | initTimeInteg (double dt, double *x) |
Prepare for time stepping beginning with solution x and timestep dt. | |
bool | transient () const |
True if transient mode. | |
bool | steady () const |
True if steady mode. | |
void | setSteadyMode () |
Prepare to solve the steady-state problem. | |
void | eval (size_t j, double *x, double *r, double rdt=-1.0, int count=1) |
Evaluate the multi-domain residual function. | |
Domain1D * | pointDomain (size_t i) |
Return a pointer to the domain global point i belongs to. | |
virtual void | resize () |
Call after one or more grids has changed size, for example after being refined. | |
vector< int > & | transientMask () |
Access the vector indicating which equations contain a transient term. | |
double | timeStep (int nsteps, double dt, double *x, double *r, int loglevel) |
Take time steps using Backward Euler. | |
void | resetBadValues (double *x) |
Reset values such as negative species concentrations in each domain. | |
void | writeStats (int printTime=1) |
Write statistics about the number of iterations and Jacobians at each grid level. | |
void | setJacAge (int ss_age, int ts_age=-1) |
Set the maximum number of steps that can be taken using the same Jacobian before it must be re-evaluated. | |
void | saveStats () |
Save statistics on function and Jacobian evaluation, and reset the counters. | |
void | clearStats () |
Clear saved statistics. | |
const vector< size_t > & | gridSizeStats () |
Return total grid size in each call to solve() | |
const vector< double > & | jacobianTimeStats () |
Return CPU time spent evaluating Jacobians in each call to solve() | |
const vector< double > & | evalTimeStats () |
Return CPU time spent on non-Jacobian function evaluations in each call to solve() | |
const vector< int > & | jacobianCountStats () |
Return number of Jacobian evaluations made in each call to solve() | |
const vector< int > & | evalCountStats () |
Return number of non-Jacobian function evaluations made in each call to solve() | |
const vector< int > & | timeStepStats () |
Return number of time steps taken in each call to solve() | |
void | setInterrupt (Func1 *interrupt) |
Set a function that will be called every time eval is called. | |
void | setTimeStepCallback (Func1 *callback) |
Set a function that will be called after each successful timestep. | |
Options | |
void | setMinTimeStep (double tmin) |
Set the minimum time step allowed during time stepping. | |
void | setMaxTimeStep (double tmax) |
Set the maximum time step allowed during time stepping. | |
void | setTimeStepFactor (double tfactor) |
Sets a factor by which the time step is reduced if the time stepping fails. | |
void | setMaxTimeStepCount (int nmax) |
Set the maximum number of timeteps allowed before successful steady-state solve. | |
int | maxTimeStepCount () const |
Return the maximum number of timeteps allowed before successful steady-state solve. | |
Protected Member Functions | |
void | evalSSJacobian (double *x, double *rsd) |
Evaluate the steady-state Jacobian, accessible via jacobian() | |
Protected Attributes | |
double | m_tmin = 1e-16 |
minimum timestep size | |
double | m_tmax = 1e+08 |
maximum timestep size | |
double | m_tfactor = 0.5 |
factor time step is multiplied by if time stepping fails ( < 1 ) | |
shared_ptr< vector< double > > | m_state |
Solution vector. | |
unique_ptr< MultiJac > | m_jac |
Jacobian evaluator. | |
unique_ptr< MultiNewton > | m_newt |
Newton iterator. | |
double | m_rdt = 0.0 |
reciprocal of time step | |
bool | m_jac_ok = false |
if true, Jacobian is current | |
size_t | m_bw = 0 |
Jacobian bandwidth. | |
size_t | m_size = 0 |
solution vector size | |
vector< shared_ptr< Domain1D > > | m_dom |
All domains comprising the system. | |
vector< shared_ptr< Domain1D > > | m_connect |
All connector and boundary domains. | |
vector< shared_ptr< Domain1D > > | m_bulk |
All bulk/flow domains. | |
bool | m_init = false |
Indicates whether one-time initialization for each domain has been completed. | |
vector< size_t > | m_nvars |
Number of variables at each point, across all domains. | |
vector< size_t > | m_loc |
Location in the state vector of the first component of each point, across all domains. | |
vector< int > | m_mask |
Transient mask. See transientMask(). | |
size_t | m_pts = 0 |
Total number of points. | |
int | m_ss_jac_age = 20 |
Maximum age of the Jacobian in steady-state mode. | |
int | m_ts_jac_age = 20 |
Maximum age of the Jacobian in time-stepping mode. | |
Func1 * | m_interrupt = nullptr |
Function called at the start of every call to eval. | |
Func1 * | m_time_step_callback = nullptr |
User-supplied function called after each successful timestep. | |
int | m_nsteps = 0 |
Number of time steps taken in the current call to solve() | |
int | m_nsteps_max = 500 |
Maximum number of timesteps allowed per call to solve() | |
Private Attributes | |
Statistics | |
Solver stats are collected after successfully solving on a particular grid. | |
int | m_nevals = 0 |
Number of calls to eval() | |
double | m_evaltime = 0 |
Total time [s] spent in eval() | |
vector< size_t > | m_gridpts |
Number of grid points in this grid. | |
vector< int > | m_jacEvals |
Number of Jacobian evaluations on this grid. | |
vector< double > | m_jacElapsed |
Time [s] spent evaluating Jacobians on this grid. | |
vector< int > | m_funcEvals |
Number of residual function evaluations on this grid (not counting evaluations used to construct Jacobians). | |
vector< double > | m_funcElapsed |
Time [s] spent on residual function evaluations on this grid (not counting evaluations used to construct Jacobians). | |
vector< int > | m_timeSteps |
Number of time steps taken in each call to solve() (for example, for each successive grid refinement) | |
OneDim | ( | ) |
Default constructor.
Definition at line 19 of file OneDim.cpp.
Construct a OneDim container for the domains in the list domains.
Definition at line 24 of file OneDim.cpp.
|
virtual |
Definition at line 36 of file OneDim.cpp.
void addDomain | ( | shared_ptr< Domain1D > | d | ) |
Add a domain. Domains are added left-to-right.
Definition at line 64 of file OneDim.cpp.
MultiNewton & newton | ( | ) |
Return a reference to the Newton iterator.
Definition at line 91 of file OneDim.cpp.
int solve | ( | double * | x0, |
double * | 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 208 of file OneDim.cpp.
|
inline |
size_t domainIndex | ( | const string & | name | ) |
Get the index of the domain named name
.
Definition at line 40 of file OneDim.cpp.
|
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 |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
std::tuple< string, size_t, 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 50 of file OneDim.cpp.
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 319 of file OneDim.cpp.
double ssnorm | ( | double * | x, |
double * | 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 273 of file OneDim.cpp.
void initTimeInteg | ( | double | dt, |
double * | x | ||
) |
Prepare for time stepping beginning with solution x and timestep dt.
Definition at line 283 of file OneDim.cpp.
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 302 of file OneDim.cpp.
void eval | ( | size_t | j, |
double * | x, | ||
double * | r, | ||
double | 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 241 of file OneDim.cpp.
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 229 of file OneDim.cpp.
|
virtual |
Call after one or more grids has changed size, for example after being refined.
Reimplemented in Sim1D.
Definition at line 154 of file OneDim.cpp.
|
inline |
double 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 331 of file OneDim.cpp.
void resetBadValues | ( | double * | x | ) |
Reset values such as negative species concentrations in each domain.
Definition at line 425 of file OneDim.cpp.
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 106 of file OneDim.cpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void setJacAge | ( | int | ss_age, |
int | ts_age = -1 |
||
) |
Set the maximum number of steps that can be taken using the same Jacobian before it must be re-evaluated.
ss_age | Age limit during steady-state mode |
ts_age | Age limit during time stepping mode. If not specified, the steady-state age is also used during time stepping. |
Definition at line 96 of file OneDim.cpp.
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 123 of file OneDim.cpp.
void clearStats | ( | ) |
Clear saved statistics.
Definition at line 141 of file OneDim.cpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
protected |
Evaluate the steady-state Jacobian, accessible via jacobian()
Definition at line 219 of file OneDim.cpp.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Transient mask. See transientMask().
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |