28ReactorNet::~ReactorNet()
39 if (reactors.empty()) {
40 throw CanteraError(
"ReactorNet::ReactorNet",
"No reactors in network!");
48 map<Solution*, set<string>> solutions;
52 std::deque<shared_ptr<ReactorBase>> reactorQueue(reactors.begin(), reactors.end());
53 std::set<shared_ptr<ReactorBase>> visited;
55 while (!reactorQueue.empty()) {
56 auto R = reactorQueue.front();
57 reactorQueue.pop_front();
59 if (visited.find(R) != visited.end()) {
64 if (
auto bulk = std::dynamic_pointer_cast<Reactor>(R)) {
65 m_bulkReactors.push_back(bulk);
66 m_reactors.push_back(R);
67 }
else if (
auto surf = std::dynamic_pointer_cast<ReactorSurface>(R)) {
68 m_surfaces.push_back(surf);
69 m_reactors.push_back(R);
70 for (
size_t i = 0; i < surf->nAdjacent(); i++) {
71 reactorQueue.push_back(surf->adjacent(i));
73 }
else if (
auto res = std::dynamic_pointer_cast<Reservoir>(R)) {
74 m_reservoirs.push_back(res);
78 for (
size_t i = 0; i < R->nInlets(); i++) {
79 auto& inlet = R->inlet(i);
80 m_flowDevices.insert(&inlet);
81 reactorQueue.push_back(inlet.in().shared_from_this());
83 for (
size_t i = 0; i < R->nOutlets(); i++) {
84 auto& outlet = R->outlet(i);
85 m_flowDevices.insert(&outlet);
86 reactorQueue.push_back(outlet.out().shared_from_this());
88 for (
size_t i = 0; i < R->nWalls(); i++) {
89 auto& wall = R->wall(i);
90 m_walls.insert(&wall);
91 reactorQueue.push_back(wall.left().shared_from_this());
92 reactorQueue.push_back(wall.right().shared_from_this());
95 auto phase = R->phase();
96 for (
size_t i = 0; i < R->nSurfs(); i++) {
97 if (R->surface(i)->phase()->adjacent(phase->name()) != phase) {
99 "Bulk phase '{}' used by interface '{}' must be the same object\n"
100 "as the contents of the adjacent reactor '{}'.",
101 phase->name(), R->surface(i)->name(), R->name());
103 reactorQueue.push_back(R->surface(i)->shared_from_this());
107 solutions[phase.get()].insert(R->name());
110 for (
auto& R : m_bulkReactors) {
111 if (R->type() ==
"FlowReactor" && m_bulkReactors.size() > 1) {
113 "FlowReactors must be used alone.");
119 size_t nv = R->neq();
122 for (
auto current : m_bulkReactors) {
123 if (current->isOde() != R->isOde()) {
125 "Cannot mix Reactor types using both ODEs and DAEs ({} and {})",
126 current->type(), R->type());
128 if (current->timeIsIndependent() != R->timeIsIndependent()) {
130 "Cannot mix Reactor types using time and space as independent variables"
131 "\n({} and {})", current->type(), R->type());
136 for (
auto surf : m_surfaces) {
137 surf->setOffset(m_nv);
140 solutions[surf->phase().get()].insert(surf->name());
143 for (
auto& [soln, reactors] : solutions) {
144 if (reactors.size() > 1) {
146 for (
auto r : reactors) {
147 if (r != *reactors.begin()) {
150 shared += fmt::format(
"'{}'", r);
152 throw CanteraError(
"ReactorNet::initialize",
"The following reactors /"
153 " reactor surfaces are using the same Solution object: {}. Use"
154 " independent Solution objects or set the 'clone' argument to 'true'"
155 " when creating the Reactor or ReactorSurface objects.", shared);
159 m_ydot.resize(m_nv, 0.0);
160 m_yest.resize(m_nv, 0.0);
161 m_advancelimits.resize(m_nv, -1.0);
168 m_integ->setLinearSolverType(
"DENSE");
194 "Relative tolerance must be positive; got {}.",
rtol);
204 "Absolute tolerance must be positive; got {}.",
atol);
221 "Use setRelativeTolerance and setAbsoluteTolerance instead."
222 " To be removed after Cantera 4.0.");
235 fill(m_atol.begin(), m_atol.end(), m_atols);
236 for (
auto& R : m_reactors) {
237 auto localAtol = span<double>(m_atol.data() + R->offset(), R->neq());
238 if (R->hasUserTolerances()) {
239 R->getAbsoluteTolerances(localAtol);
241 R->updateDefaultTolerances(localAtol, m_atols);
244 m_integ->setTolerances(m_rtol, m_atol);
255 m_integ->setSensitivityTolerances(m_rtolsens, m_atolsens);
262 throw CanteraError(
"ReactorNet::time",
"Time is not the independent variable"
263 " for this reactor network.");
271 throw CanteraError(
"ReactorNet::distance",
"Distance is not the independent"
272 " variable for this reactor network.");
284 if (!m_linearSolverType.empty()) {
285 m_integ->setLinearSolverType(m_linearSolverType);
288 m_integ->setPreconditioner(m_precon);
290 for (
auto&
reactor : m_reactors) {
291 reactor->updateConnected(
true);
294 m_integ->initialize(
m_time, *
this);
299 if (m_integ->preconditionerSide() != PreconditionerSide::NO_PRECONDITION) {
309 debuglog(
"Re-initializing reactor network.\n", m_verbose);
310 for (
auto&
reactor : m_reactors) {
311 reactor->updateConnected(
true);
314 m_integ->reinitialize(
m_time, *
this);
315 if (m_integ->preconditionerSide() != PreconditionerSide::NO_PRECONDITION) {
326 m_linearSolverType = linSolverType;
332 m_precon = preconditioner;
334 settings[
"skip-nonideal"] =
true;
335 settings[
"skip-connector-composition-dependence"] =
true;
336 settings[
"skip-connector-pressure-composition-dependence"] =
true;
354 m_integ->integrate(
time);
355 m_time = m_integ->currentTime();
378 m_integ->integrate(
time);
383 m_time = m_integ->currentTime();
396 if (m_advancelimits.size() != m_nv) {
397 m_advancelimits.assign(m_nv, -1.0);
400 auto ycurr = m_integ->solution();
402 double max_ratio = -1.0;
403 double best_limit = 0.0;
404 for (
size_t j = 0; j < m_nv; j++) {
405 double lim = m_advancelimits[j];
407 double delta = std::abs(ycurr[j] -
m_ybase[j]);
408 double ratio = delta / lim;
409 if (ratio > max_ratio) {
418 double y_start =
m_ybase[jmax];
419 double y_end = ycurr[jmax];
420 double delta = y_end - y_start;
421 writelog(
" Advance limit triggered for component {:d} (dt = {:9.4g}):"
422 " y_start = {:11.6g}, y_end = {:11.6g},"
423 " delta = {:11.6g}, limit = {:9.4g}\n",
424 jmax, dt, y_start, y_end, delta, best_limit);
443 vector<double> y(
neq());
447 solver.
solve(loglevel);
455 vector<double> y0(
neq());
456 vector<double> y1(
neq());
463 return std::dynamic_pointer_cast<EigenSparseJacobian>(solver.
linearSolver())->jacobian();
469 SparseTriplets trips;
470 for (
auto& r : m_reactors) {
471 r->getJacobianElements(trips);
473 Eigen::SparseMatrix<double> jac(m_nv, m_nv);
474 jac.setFromTriplets(trips.begin(), trips.end());
481 vector<double> yCurrent(m_nv);
483 vector<double> yPerturbed(m_nv);
484 vector<double> ydotPlus(m_nv), ydotMinus(m_nv);
486 SparseTriplets trips;
487 for (
size_t j = 0; j < m_nv; j++) {
488 double dy = m_atol[j] + std::abs(yCurrent[j]) * m_rtol;
489 std::copy(yCurrent.begin(), yCurrent.end(), yPerturbed.begin());
492 yPerturbed[j] = yCurrent[j] - dy;
494 for (
size_t i = 0; i < m_nv; i++) {
495 double val = (ydotPlus[i] - ydotMinus[i]) / (2.0 * dy);
497 trips.emplace_back(
static_cast<int>(i),
static_cast<int>(j), val);
503 Eigen::SparseMatrix<double> jac(m_nv, m_nv);
504 jac.setFromTriplets(trips.begin(), trips.end());
511 auto cvode_dky = m_integ->solution();
512 std::copy(cvode_dky.begin(), cvode_dky.end(), yest.begin());
517 for (
int n = 1; n <= k; n++) {
518 factor *= deltat / n;
519 cvode_dky = m_integ->derivative(
m_time, n);
520 for (
size_t j = 0; j < m_nv; j++) {
521 yest[j] += factor * cvode_dky[j];
529 return m_integ->lastOrder();
547 if (m_advancelimits.size() != m_nv) {
548 m_advancelimits.assign(m_nv, -1.0);
552 double max_ratio = 0.0;
553 for (
size_t i = 0; i < m_nv; i++) {
554 double lim = m_advancelimits[i];
556 double delta = std::abs(y[i] -
m_ybase[i]);
557 double ratio = delta / lim;
558 if (ratio > max_ratio) {
574 for (
size_t i=0; i<r.
nWalls(); i++) {
577 if (w.left().type() ==
"Reservoir") {
580 if (w.right().type() ==
"Reservoir") {
585 for (
size_t i=0; i<r.
nInlets(); i++) {
586 auto& in = r.
inlet(i);
588 if (in.in().type() ==
"Reservoir") {
593 for (
size_t i=0; i<r.
nOutlets(); i++) {
596 if (out.out().type() ==
"Reservoir") {
601 for (
size_t i=0; i<r.
nSurfs(); i++) {
607 if (m_integ ==
nullptr) {
609 "Integrator has not been instantiated. Add one or more reactors first.");
615 span<const double> p)
619 m_LHS.assign(m_nv, 1);
620 m_RHS.assign(m_nv, 0);
621 for (
auto& R : m_reactors) {
622 size_t offset = R->offset();
623 R->applySensitivity(p);
624 R->eval(t, span<double>(
m_LHS.data() +
offset, R->neq()),
625 span<double>(m_RHS.data() +
offset, R->neq()));
627 ydot[i] = m_RHS[i] /
m_LHS[i];
629 R->resetSensitivity(p);
637 m_LHS.assign(m_nv, 1);
638 m_RHS.assign(m_nv, 0);
639 for (
auto& R : m_reactors) {
640 size_t offset = R->offset();
642 span<double>(m_RHS.data() +
offset, R->neq()));
644 residual[i] = m_RHS[i] /
m_LHS[i];
651 span<const double> p, span<double> residual)
655 for (
auto& R : m_reactors) {
656 size_t offset = R->offset();
657 R->applySensitivity(p);
658 R->evalDae(t, y.subspan(
offset, R->neq()),
659 ydot.subspan(
offset, R->neq()),
660 residual.subspan(
offset, R->neq()));
661 R->resetSensitivity(p);
668 for (
auto& R : m_reactors) {
669 R->getConstraints(constraints.subspan(R->offset(), R->neq()));
680 double denom = m_integ->solution(k);
684 return m_integ->sensitivity(k, p) / denom;
688 span<const double> p,
Array2D* j)
692 for (
size_t n = 0; n < m_nv; n++) {
695 double dy = m_atol[n] + fabs(ysave)*m_rtol;
700 eval(t, y, m_ydot, p);
703 for (
size_t m = 0; m < m_nv; m++) {
704 j->
value(m,n) = (m_ydot[m] - ydot[m])/dy;
713 for (
auto& R : m_reactors) {
714 R->updateState(y.subspan(R->offset(), R->neq()));
721 auto cvode_dky = m_integ->derivative(
m_time, k);
722 std::copy(cvode_dky.begin(), cvode_dky.end(), dky.begin());
728 for (
auto& R : m_bulkReactors) {
729 R->setAdvanceLimits(limits.subspan(R->offset(), R->neq()));
735 bool has_limit =
false;
736 for (
size_t n = 0; n < m_bulkReactors.size(); n++) {
737 has_limit |= m_bulkReactors[n]->hasAdvanceLimits();
744 bool has_limit =
false;
745 for (
auto& R : m_bulkReactors) {
746 has_limit |= R->getAdvanceLimits(limits.subspan(R->offset(), R->neq()));
753 for (
auto& R : m_reactors) {
754 R->getState(y.subspan(R->offset(), R->neq()));
764 for (
size_t n = m_reactors.size(); n != 0 ; n--) {
765 auto& R = m_reactors[n-1];
766 R->getStateDae(y.subspan(R->offset(), R->neq()),
767 ydot.subspan(R->offset(), R->neq()));
774 return m_reactors[
reactor]->offset()
775 + m_reactors[
reactor]->componentIndex(component);
782 for (
auto r : m_reactors) {
784 return r->name() +
": " + r->componentName(i);
790 throw IndexError(
"ReactorNet::componentName",
"component", i0, iTot);
797 for (
auto r : m_reactors) {
799 return r->upperBound(i);
805 throw IndexError(
"ReactorNet::upperBound",
"upperBound", i0, iTot);
812 for (
auto r : m_reactors) {
814 return r->lowerBound(i);
820 throw IndexError(
"ReactorNet::lowerBound",
"lowerBound", i0, iTot);
824 for (
auto& R : m_reactors) {
825 R->resetBadValues(y.subspan(R->offset(), R->neq()));
830 const string& name,
double value,
double scale)
833 throw CanteraError(
"ReactorNet::registerSensitivityParameter",
834 "Sensitivity parameters cannot be added after the"
835 "integrator has been initialized.");
846 for (
auto& R : m_bulkReactors) {
847 R->setDerivativeSettings(settings);
854 return m_integ->solverStats();
863 return m_integ->linearSolverType();
873 "Must only be called after ReactorNet is initialized.");
875 m_integ->preconditionerSolve(rhs, output);
883 auto precon = std::dynamic_pointer_cast<EigenSparseJacobian>(
884 m_integ->preconditioner());
888 precon->setGamma(gamma);
890 vector<double> yCopy(m_nv);
894 precon->stateAdjustment(yCopy);
898 vector<Eigen::Triplet<double>> trips;
899 for (
auto& R : m_reactors) {
900 R->getJacobianElements(trips);
902 precon->setFromTriplets(trips);
904 precon->updatePreconditioner();
911 "Must only be called after ReactorNet is initialized.");
913 auto precon = m_integ->preconditioner();
914 precon->setGamma(gamma);
915 precon->updatePreconditioner();
920 for (
auto reactor : m_bulkReactors) {
921 if (!
reactor->preconditionerSupported()) {
922 throw CanteraError(
"ReactorNet::checkPreconditionerSupported",
923 "Preconditioning is only supported for type *MoleReactor,\n"
924 "Reactor type given: '{}'.",
930SteadyReactorSolver::SteadyReactorSolver(
ReactorNet* net, span<const double> x0)
933 m_size = m_net->neq();
936 m_initialState.assign(x0.begin(), x0.end());
938 setJacobianPerturbation(m_jacobianRelPerturb, 1000 * m_net->atol(),
939 m_jacobianThreshold);
940 m_mask.assign(m_size, 1);
942 for (
size_t i = 0; i < net->nReactors(); i++) {
945 auto algebraic = R.initializeSteady();
946 for (
auto& m : algebraic) {
947 m_mask[start + m] = 0;
954 double rdt,
int count)
959 m_net->evalSteady(x, r);
960 for (
size_t i = 0; i <
size(); i++) {
974 clock_t t0 = clock();
976 m_work2.resize(
size());
978 vector<double> perturbed(x0.begin(), x0.end());
979 for (
size_t j = 0; j <
size(); j++) {
981 double xsave = x0[j];
986 perturbed[j] = xsave + dx;
987 double rdx = 1.0 / (perturbed[j] - xsave);
990 eval(perturbed, m_work2, 0.0, 0);
993 for (
size_t i = 0; i <
size(); i++) {
994 double delta = m_work2[i] -
m_work1[i];
996 m_jac->setValue(i, j, delta * rdx);
999 perturbed[j] = xsave;
1002 m_net->updateState(x0);
1004 m_jac->updateElapsed(
double(clock() - t0) / CLOCKS_PER_SEC);
1005 m_jac->incrementEvals();
1012 const double* x =
m_state->data();
1013 for (
size_t i = 0; i <
size(); i++) {
1014 double ewt = m_net->rtol()*fabs(x[i]) + m_net->atol();
1015 double f = step[i] / ewt;
1018 return sqrt(sum /
size());
1023 return m_net->componentName(i);
1028 return m_net->upperBound(i);
1033 return m_net->lowerBound(i);
1038 m_net->resetBadValues(x);
1042 const string& message,
int loglevel,
int attempt_counter)
1044 if (loglevel >= 6 && !
m_state->empty()) {
1046 writelog(
"Current state ({}):\n[", header_suffix);
1047 for (
size_t i = 0; i < state.size() - 1; i++) {
1052 if (loglevel >= 7 && !
m_xnew.empty()) {
1053 writelog(
"Current residual ({}):\n[", header_suffix);
1054 for (
size_t i = 0; i <
m_xnew.size() - 1; i++) {
1063 return make_shared<ReactorNet>(reactors);
Header file for class Cantera::Array2D.
Header file for class ReactorSurface.
Header file for base class WallBase.
A map of string keys to values whose type can vary at runtime.
A class for 2D arrays stored in column-major (Fortran-compatible) form.
double & value(size_t i, size_t j)
Returns a changeable reference to position in the matrix.
Base class for exceptions thrown by Cantera classes.
void setDefaultName(map< string, int > &counts)
Set the default name of a connector. Returns false if it was previously set.
vector< double > m_paramScales
Scaling factors for each sensitivity parameter.
bool suppressErrors() const
Get current state of error suppression.
vector< double > m_sens_params
Values for the problem parameters for which sensitivities are computed This is the array which is per...
An array index is out of range.
Abstract base class for ODE system integrators.
virtual void setMaxStepSize(double hmax)
Set the maximum step size.
virtual void setMaxSteps(int nmax)
Set the maximum number of time-steps the integrator can take before reaching the next output time.
virtual int maxSteps()
Returns the maximum number of time-steps the integrator can take before reaching the next output time...
virtual void setMaxErrTestFails(int n)
Set the maximum permissible number of error test failures.
Base class for reactor objects.
FlowDevice & outlet(size_t n=0)
Return a reference to the n-th outlet FlowDevice connected to this reactor.
size_t nWalls()
Return the number of Wall objects connected to this reactor.
WallBase & wall(size_t n)
Return a reference to the n-th Wall connected to this reactor.
bool setDefaultName(map< string, int > &counts)
Set the default name of a reactor. Returns false if it was previously set.
virtual void updateState(span< const double > y)
Set the state of the reactor to correspond to the state vector y.
virtual size_t nSurfs() const
Return the number of surfaces in a reactor.
FlowDevice & inlet(size_t n=0)
Return a reference to the n-th inlet FlowDevice connected to this reactor.
size_t nOutlets()
Return the number of outlet FlowDevice objects connected to this reactor.
size_t nInlets()
Return the number of inlet FlowDevice objects connected to this reactor.
ReactorSurface * surface(size_t n)
Return a reference to the n-th ReactorSurface connected to this reactor.
A class representing a network of connected reactors.
virtual void getDerivative(int k, span< double > dky)
Return k-th derivative at the current state of the system.
void setLinearSolverType(const string &linSolverType="DENSE")
Set the type of linear solver used in the integration.
bool getAdvanceLimits(span< double > limits) const
Retrieve absolute step size limits during advance.
double step()
Advance the state of all reactors with respect to the independent variable (time or space).
virtual int lastOrder() const
Returns the order used for last solution step of the ODE integrator The function is intended for inte...
double m_ybase_time
Base time corresponding to m_ybase.
void initialize()
Initialize the reactor network.
void evalDae(double t, span< const double > y, span< const double > ydot, span< const double > p, span< double > residual) override
eval coupling for IDA / DAEs
void advance(double t)
Advance the state of all reactors in the independent variable (time or space).
size_t neq() const override
Number of equations.
ReactorBase & reactor(int n)
Return a reference to the n-th reactor in this network.
vector< double > m_LHS
m_LHS is a vector representing the coefficients on the "left hand side" of each governing equation
double m_initial_time
The initial value of the independent variable in the system.
double time()
Current value of the simulation time [s], for reactor networks that are solved in the time domain.
void updateNames(ReactorBase &r)
Create reproducible names for reactors and walls/connectors.
Eigen::SparseMatrix< double > finiteDifferenceJacobian()
Calculate the system Jacobian for the reactor network using finite differences.
double m_time
The independent variable in the system.
Eigen::SparseMatrix< double > jacobian()
Calculate the semi-analytical preconditioner Jacobian for the entire network.
AnyMap solverStats() const
Get solver stats from integrator.
void updateTolerances()
Update the integrator tolerance vector from the current scalar settings, reactor-specific user tolera...
bool m_limit_check_active
Indicates whether the advance-limit root check is active for the current call to advance(t,...
map< string, int > m_counts
Map used for default name generation.
double upperBound(size_t i) const
Get the upper bound on the i-th component of the global state vector.
virtual void setMaxSteps(int nmax)
Set the maximum number of internal integration steps the integrator will take before reaching the nex...
bool m_integratorInitialized
True if the integrator has been initialized at least once.
string componentName(size_t i) const
Return the name of the i-th component of the global state vector.
virtual void getEstimate(double time, int k, span< double > yest)
Estimate a future state based on current derivatives.
size_t nRootFunctions() const override
The advance-limit root function is registered whenever any reactor has advance limits,...
void evalRootFunctions(double t, span< const double > y, span< double > gout) override
Evaluate the advance-limit root function used to stop integration once a limit is met.
void setInitialTime(double time)
Set the initial value of the independent variable (typically time).
void setMaxErrTestFails(int nmax)
Set the maximum number of error test failures permitted by the CVODES integrator in a single step.
size_t registerSensitivityParameter(const string &name, double value, double scale)
Used by Reactor and Wall objects to register the addition of sensitivity parameters so that the React...
void getConstraints(span< double > constraints) override
Given a vector of length neq(), mark which variables should be considered algebraic constraints.
double m_maxstep
Maximum integrator internal timestep. Default of 0.0 means infinity.
double distance()
Current position [m] along the length of the reactor network, for reactors that are solved as a funct...
void evalSteady(span< const double > y, span< double > residual)
Evaluate the governing equations adapted for the steady-state solver.
void setSensitivityTolerances(double rtol, double atol)
Set the relative and absolute tolerances for integrating the sensitivity equations.
int maxSteps()
Returns the maximum number of internal integration steps the integrator will take before reaching the...
virtual void setDerivativeSettings(AnyMap &settings)
Set derivative settings of all reactors.
ReactorNet(shared_ptr< ReactorBase > reactor)
Create reactor network containing single reactor.
double sensitivity(size_t k, size_t p)
Return the sensitivity of the k-th solution component with respect to the p-th sensitivity parameter.
void evalJacobian(double t, span< double > y, span< double > ydot, span< const double > p, Array2D *j)
Evaluate the Jacobian matrix for the reactor network.
void updateState(span< const double > y)
Update the state of all the reactors in the network to correspond to the values in the solution vecto...
void preconditionerSolve(span< const double > rhs, span< double > output) override
Evaluate the linear system Ax=b where A is the preconditioner.
bool m_needIntegratorInit
True if integrator needs to be (re)initialized.
void preconditionerSetup(double t, span< const double > y, double gamma) override
Evaluate the setup processes for the Jacobian preconditioner.
double rtol()
Relative tolerance.
size_t globalComponentIndex(const string &component, size_t reactor=0)
Return the index corresponding to the component named component in the reactor with index reactor in ...
void resetBadValues(span< double > y)
Reset physically or mathematically problematic values, such as negative species concentrations.
void solveSteady(int loglevel=0)
Solve directly for the steady-state solution.
bool m_timeIsIndependent
Indicates whether time or space is the independent variable.
double atol()
Scalar absolute integration tolerance.
bool hasAdvanceLimits() const
Check whether ReactorNet object uses advance limits.
vector< double > m_ybase
Base state used for evaluating advance limits during a single advance() call when root-finding is ena...
void setMaxTimeStep(double maxstep)
Set the maximum integrator step.
void setAdvanceLimits(span< const double > limits)
Set absolute step size limits during advance.
bool m_atolUserSpecified
True if scalar absolute tolerance was user-specified.
double lowerBound(size_t i) const
Get the lower bound on the i-th component of the global state vector.
virtual void checkPreconditionerSupported() const
Check that preconditioning is supported by all reactors in the network.
void reinitialize()
Reinitialize the integrator.
Integrator & integrator()
Return a reference to the integrator.
Eigen::SparseMatrix< double > steadyJacobian(double rdt=0.0)
Get the Jacobian used by the steady-state solver.
string linearSolverType() const
Problem type of integrator.
void updatePreconditioner(double gamma) override
Update the preconditioner based on already computed jacobian values.
void setPreconditioner(shared_ptr< SystemJacobian > preconditioner)
Set preconditioner used by the linear solver.
void getState(span< double > y) override
Fill in the vector y with the current state of the system.
vector< string > m_paramNames
Names corresponding to each sensitivity parameter.
void clearAbsoluteTolerance()
Clear the user-specified scalar absolute tolerance.
void getStateDae(span< double > y, span< double > ydot) override
Fill in the vectors y and ydot with the current state of the system.
void setTolerances(double rtol, double atol)
Set the relative and scalar absolute tolerances for the integrator.
void setRelativeTolerance(double rtol)
Set the relative tolerance for the integrator.
void eval(double t, span< const double > y, span< double > ydot, span< const double > p) override
Evaluate the right-hand-side ODE function.
void setAbsoluteTolerance(double atol)
Set the scalar absolute tolerance for the integrator.
Adapter class to enable using the SteadyStateSystem solver with ReactorNet.
double weightedNorm(span< const double > step) const override
Compute the weighted norm of step.
vector< double > m_initialState
Initial value of each state variable.
string componentName(size_t i) const override
Get the name of the i-th component of the state vector.
void initTimeInteg(double dt, span< const double > x) override
Prepare for time stepping beginning with solution x and timestep dt.
double upperBound(size_t i) const override
Get the upper bound for global component i in the state vector.
void evalJacobian(span< const double > x0) override
Evaluates the Jacobian at x0 using finite differences.
void writeDebugInfo(const string &header_suffix, const string &message, int loglevel, int attempt_counter) override
Write solver debugging based on the specified log level.
void resetBadValues(span< double > x) override
Reset values such as negative species concentrations.
void eval(span< const double > x, span< double > r, double rdt=-1.0, int count=1) override
Evaluate the residual function.
double lowerBound(size_t i) const override
Get the lower bound for global component i in the state vector.
virtual void resize()
Call to set the size of internal data structures after first defining the system or if the problem si...
shared_ptr< SystemJacobian > linearSolver() const
Get the the linear solver being used to hold the Jacobian matrix and solve linear systems as part of ...
vector< double > m_xnew
Work array used to hold the residual or the new solution.
void getState(span< double > x) const
Get the converged steady-state solution after calling solve().
double m_jacobianAbsPerturb
Absolute perturbation of each component in finite difference Jacobian.
size_t size() const
Total solution vector length;.
vector< int > & transientMask()
Access the vector indicating which equations contain a transient term.
double rdt() const
Reciprocal of the time step.
virtual void initTimeInteg(double dt, span< const double > x)
Prepare for time stepping beginning with solution x and timestep dt.
double m_rdt
Reciprocal of time step.
double m_jacobianThreshold
Threshold for ignoring small elements in Jacobian.
shared_ptr< SystemJacobian > m_jac
Jacobian evaluator.
shared_ptr< vector< double > > m_state
Solution vector.
vector< int > m_mask
Transient mask.
void setMaxTimeStepCount(int nmax)
Set the maximum number of timeteps allowed before successful steady-state solve.
void solve(int loglevel=0)
Solve the steady-state problem, taking internal timesteps as necessary until the Newton solver can co...
double m_jacobianRelPerturb
Relative perturbation of each component in finite difference Jacobian.
vector< double > m_work1
Work arrays used during Jacobian evaluation.
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
void debuglog(const string &msg, int loglevel)
Write a message to the log only if loglevel > 0.
void writelog(const string &fmt, const Args &... args)
Write a formatted message to the screen.
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Integrator * newIntegrator(const string &itype)
Create new Integrator object.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
void checkFinite(const double tmp)
Check to see that a number is finite (not NaN, +Inf or -Inf).
shared_ptr< ReactorNet > newReactorNet(span< shared_ptr< ReactorBase > > reactors)
Create a reactor network containing one or more coupled reactors.
@ BDF_Method
Backward Differentiation.
shared_ptr< SystemJacobian > newSystemJacobian(const string &type)
Create a SystemJacobian object of the specified type.
const double SmallNumber
smallest number to compare to zero.
offset
Offsets of solution components in the 1D solution array.
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...