37 ReactorNet(span<shared_ptr<ReactorBase>> reactors);
139 double advance(
double t,
bool applylimit);
186 return *m_reactors[n];
246 span<double> ydot, span<const double> p,
Array2D* j);
249 size_t neq()
const override {
253 size_t nReactors()
const {
254 return m_reactors.size();
257 void eval(
double t, span<const double> y, span<double> ydot,
258 span<const double> p)
override;
267 void evalSteady(span<const double> y, span<double> residual);
270 void evalDae(
double t, span<const double> y, span<const double> ydot,
271 span<const double> p, span<double> residual)
override;
273 void getState(span<double> y)
override;
274 void getStateDae(span<double> y, span<double> ydot)
override;
377 span<double> gout)
override;
398 vector<shared_ptr<ReactorBase>> m_reactors;
399 vector<shared_ptr<Reactor>> m_bulkReactors;
400 vector<shared_ptr<ReactorBase>> m_surfaces;
401 vector<shared_ptr<ReactorBase>> m_reservoirs;
402 set<FlowDevice*> m_flowDevices;
403 set<WallBase*> m_walls;
405 unique_ptr<Integrator> m_integ;
418 vector<double> m_atol;
419 double m_rtol = 1.0e-9;
420 double m_rtolsens = 1.0e-4;
421 double m_atols = 1.0e-15;
422 double m_atolsens = 1.0e-6;
423 shared_ptr<SystemJacobian> m_precon;
424 string m_linearSolverType;
429 bool m_verbose =
false;
437 vector<double> m_ydot;
438 vector<double> m_yest;
439 vector<double> m_advancelimits;
451 vector<double> m_RHS;
463 void eval(span<const double> x, span<double> r,
464 double rdt=-1.0,
int count=1)
override;
465 void initTimeInteg(
double dt, span<const double> x)
override;
467 double weightedNorm(span<const double> step)
const override;
472 void writeDebugInfo(
const string& header_suffix,
const string& message,
473 int loglevel,
int attempt_counter)
override;
490shared_ptr<ReactorNet>
newReactorNet(span<shared_ptr<ReactorBase>> reactors);
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.
Virtual base class for ODE/DAE right-hand-side function evaluators.
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...
Abstract base class for ODE system integrators.
Base class for reactor objects.
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...
const string & sensitivityParameterName(size_t p) const
The name of the p-th sensitivity parameter added to this ReactorNet.
double m_ybase_time
Base time corresponding to m_ybase.
size_t nparams() const override
Number of sensitivity parameters.
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.
double getInitialTime() const
Get the initial value of the independent variable (typically time).
void setNeedsReinit()
Called to trigger integrator reinitialization before further integration.
double m_time
The independent variable in the system.
AnyMap solverStats() const
Get solver stats from integrator.
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
Root finding is enabled only while enforcing 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 maxTimeStep() const
Get the maximum integrator step.
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.
double atolSensitivity() const
Absolute sensitivity tolerance.
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.
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.
bool verbose() const
Returns true if verbose logging output is enabled.
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()
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...
double sensitivity(const string &component, size_t p, int reactor=0)
Return the sensitivity of the component named component with respect to the p-th sensitivity paramete...
void setMaxTimeStep(double maxstep)
Set the maximum integrator step.
void setAdvanceLimits(span< const double > limits)
Set absolute step size limits during advance.
double rtolSensitivity() const
Relative sensitivity tolerance.
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.
void setVerbose(bool v=true)
Enable or disable verbose logging while setting up and integrating the reactor network.
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 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 absolute tolerances 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.
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.
Base class for representing a system of differential-algebraic equations and solving for its steady-s...
double rdt() const
Reciprocal of the time step.
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Namespace for the Cantera kernel.
shared_ptr< ReactorNet > newReactorNet(span< shared_ptr< ReactorBase > > reactors)
Create a reactor network containing one or more coupled reactors.