Cantera  4.0.0a1
Loading...
Searching...
No Matches
ReactorNet.h
Go to the documentation of this file.
1//! @file ReactorNet.h
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
6#ifndef CT_REACTORNET_H
7#define CT_REACTORNET_H
8
9#include "Reactor.h"
12
13namespace Cantera
14{
15
16class Array2D;
17class Integrator;
18class SystemJacobian;
19
20//! A class representing a network of connected reactors.
21/*!
22 * This class is used to integrate the governing equations for a network of reactors
23 * that are time dependent (Reactor, ConstPressureReactor) connected by various
24 * means, for example Wall, MassFlowController, Valve, or PressureController; or
25 * reactors dependent on a single spatial variable (FlowReactor).
26 *
27 * @ingroup zerodGroup
28 */
29class ReactorNet : public FuncEval
30{
31public:
32 //! Create reactor network containing single reactor.
33 //! @since New in %Cantera 3.2.
34 ReactorNet(shared_ptr<ReactorBase> reactor);
35 //! Create reactor network from multiple reactors.
36 //! @since New in %Cantera 3.2.
37 ReactorNet(span<shared_ptr<ReactorBase>> reactors);
38 ReactorNet(const ReactorNet&) = delete;
39 ReactorNet& operator=(const ReactorNet&) = delete;
41
42 //! @name Methods to set up a simulation
43 //! @{
44
45 //! Set the type of linear solver used in the integration.
46 //! @param linSolverType type of linear solver. Default type: "DENSE"
47 //! Other options include: "DIAG", "DENSE", "GMRES", "BAND"
48 void setLinearSolverType(const string& linSolverType="DENSE");
49
50 //! Set preconditioner used by the linear solver
51 //! @param preconditioner preconditioner object used for the linear solver
52 void setPreconditioner(shared_ptr<SystemJacobian> preconditioner);
53
54 //! Set the initial value of the independent variable (typically time).
55 //! Default = 0.0 s. Restarts integration from this value using the current mixture
56 //! state as the initial condition.
57 void setInitialTime(double time);
58
59 //! Get the initial value of the independent variable (typically time).
60 /*!
61 * @since New in %Cantera 3.0.
62 */
63 double getInitialTime() const {
64 return m_initial_time;
65 }
66
67 //! Get the maximum integrator step.
68 double maxTimeStep() const {
69 return m_maxstep;
70 }
71
72 //! Set the maximum integrator step.
73 void setMaxTimeStep(double maxstep);
74
75 //! Set the maximum number of error test failures permitted by the CVODES
76 //! integrator in a single step.
77 void setMaxErrTestFails(int nmax);
78
79 //! Set the relative tolerance for the integrator.
80 //!
81 //! @param rtol Relative tolerance for all state variables; must be positive.
82 //! @since New in %Cantera 4.0.
83 void setRelativeTolerance(double rtol);
84
85 //! Set the scalar absolute tolerance for the integrator.
86 //!
87 //! @param atol Scalar absolute tolerance for state variables without
88 //! reactor-specific absolute tolerances; must be positive. Superseded by
89 //! absolute tolerances set for individual reactors.
90 //! @see ReactorBase::setAbsoluteTolerances
91 //! @since New in %Cantera 4.0.
92 void setAbsoluteTolerance(double atol);
93
94 //! Clear the user-specified scalar absolute tolerance.
95 //!
96 //! Restores the default scalar absolute tolerance and enables
97 //! reactor-specific default scaling rules.
98 //! @see ReactorBase::updateDefaultTolerances
99 //! @since New in %Cantera 4.0.
101
102 //! Set the relative and scalar absolute tolerances for the integrator.
103 //!
104 //! @param rtol If positive, set the relative tolerance for all state variables;
105 //! ignored if negative.
106 //! @param atol If positive, set the scalar absolute tolerance for all state
107 //! variables; ignored if negative. Superseded by absolute tolerances set
108 //! for individual reactors.
109 //! @deprecated To be removed after %Cantera 4.0. Use setRelativeTolerance()
110 //! and setAbsoluteTolerance() instead.
111 void setTolerances(double rtol, double atol);
112
113 //! Set the relative and absolute tolerances for integrating the
114 //! sensitivity equations.
115 void setSensitivityTolerances(double rtol, double atol);
116
117 //! Current value of the simulation time [s], for reactor networks that are solved
118 //! in the time domain.
119 double time();
120
121 //! Current position [m] along the length of the reactor network, for reactors that
122 //! are solved as a function of space.
123 double distance();
124
125 //! Relative tolerance.
126 double rtol() {
127 return m_rtol;
128 }
129
130 //! Scalar absolute integration tolerance
131 double atol() {
132 return m_atols;
133 }
134
135 //! Relative sensitivity tolerance
136 double rtolSensitivity() const {
137 return m_rtolsens;
138 }
139
140 //! Absolute sensitivity tolerance
141 double atolSensitivity() const {
142 return m_atolsens;
143 }
144
145 //! Problem type of integrator
146 string linearSolverType() const;
147
148 //! Returns the maximum number of internal integration steps the
149 //! integrator will take before reaching the next output point
150 int maxSteps();
151
152 //! @}
153
154 /**
155 * Advance the state of all reactors in the independent variable (time or space).
156 * Take as many internal steps as necessary to reach *t*.
157 * @param t Time/distance to advance to (s or m).
158 */
159 void advance(double t);
160
161 /**
162 * Advance the state of all reactors in the independent variable (time or space).
163 * Take as many internal steps as necessary towards *t*. If *applylimit* is true,
164 * the advance step will be automatically reduced if needed to stay within limits
165 * (set by setAdvanceLimit).
166 * Returns the time/distance at the end of integration.
167 * @param t Time/distance to advance to (s or m).
168 * @param applylimit Limit advance step (boolean).
169 */
170 double advance(double t, bool applylimit);
171
172 //! Advance the state of all reactors with respect to the independent variable
173 //! (time or space). Returns the new value of the independent variable [s or m].
174 double step();
175
176 //! Solve directly for the steady-state solution.
177 //!
178 //! This approach is generally more efficient than time marching to the
179 //! steady-state, but imposes a few limitations:
180 //!
181 //! - The volume of control volume reactor types (such as Reactor and
182 //! IdealGasMoleReactor) must be constant; no moving walls can be used.
183 //! - The mass of constant pressure reactor types (such as ConstPressureReactor and
184 //! IdealGasConstPressureReactor) must be constant; if flow devices are used,
185 //! inlet and outlet flows must be balanced.
186 //! - Only ideal gas reactor types can be used for when the energy equation is
187 //! disabled (fixed temperature simulations).
188 //!
189 //! @param loglevel Print information about solver progress to aid in understanding
190 //! cases where the solver fails to converge. Higher levels are more verbose.
191 //! - 0: No logging.
192 //! - 1: Basic info about each steady-state attempt and round of time stepping.
193 //! - 2: Adds details about each time step and steady-state Newton iteration.
194 //! - 3: Adds details about Newton iterations for each time step.
195 //! - 4: Adds details about state variables that are limiting steady-state
196 //! Newton step sizes.
197 //! - 5: Adds details about state variables that are limiting time-stepping
198 //! Newton step sizes.
199 //! - 6: Print current state vector after different solver stages
200 //! - 7: Print current residual vector after different solver stages
201 //!
202 //! @see SteadyStateSystem, MultiNewton
203 //! @since New in %Cantera 3.2. Support for reacting surfaces added in %Cantera 4.0.
204 void solveSteady(int loglevel=0);
205
206 //! Get the Jacobian used by the steady-state solver.
207 //!
208 //! @param rdt Reciprocal of the pseudo-timestep [1/s]. Default of 0.0 returns the
209 //! steady-state Jacobian.
210 //! @since New in %Cantera 3.2.
211 Eigen::SparseMatrix<double> steadyJacobian(double rdt=0.0);
212
213 //! Calculate the semi-analytical preconditioner Jacobian for the entire network.
214 //!
215 //! Collects sparse Jacobian entries from each reactor's `getJacobianElements()`
216 //! implementation and assembles them into a single network-level matrix. Reactors
217 //! that do not implement `getJacobianElements()` contribute no entries. The
218 //! matrix uses global row and column indices for the full network state vector.
219 //!
220 //! @warning Depending on the particular implementation, this may return an
221 //! approximate Jacobian intended only for use in forming a preconditioner for
222 //! iterative solvers, excluding terms that would generate a fully-dense
223 //! Jacobian.
224 //!
225 //! @warning This method is an experimental part of the %Cantera API and may be
226 //! changed or removed without notice.
227 //! @since New in %Cantera 4.0.
228 Eigen::SparseMatrix<double> jacobian();
229
230 //! Calculate the system Jacobian for the reactor network using finite differences.
231 //!
232 //! Perturbs each element of the state vector and evaluates the network RHS to
233 //! estimate the full Jacobian. Uses the integrator tolerances to scale each
234 //! perturbation. This method is intended for debugging and validation of analytical
235 //! Jacobian implementations, including those added via {ct}`ExtensibleReactor`.
236 //!
237 //! @warning This method is an experimental part of the %Cantera API and may be
238 //! changed or removed without notice.
239 //! @since New in %Cantera 4.0.
240 Eigen::SparseMatrix<double> finiteDifferenceJacobian();
241
242 //! Return a reference to the *n*-th reactor in this network. The reactor
243 //! indices are determined by the order in which the reactors were added
244 //! to the reactor network.
246 return *m_reactors[n];
247 }
248
249 //! Returns `true` if verbose logging output is enabled.
250 bool verbose() const {
251 return m_verbose;
252 }
253
254 //! Enable or disable verbose logging while setting up and integrating the
255 //! reactor network.
256 void setVerbose(bool v = true) {
257 m_verbose = v;
258 suppressErrors(!m_verbose);
259 }
260
261 //! Return a reference to the integrator. Only valid after adding at least one
262 //! reactor to the network.
264
265 //! Update the state of all the reactors in the network to correspond to
266 //! the values in the solution vector *y*.
267 void updateState(span<const double> y);
268
269 //! Return the sensitivity of the *k*-th solution component with respect to
270 //! the *p*-th sensitivity parameter.
271 /*!
272 * The sensitivity coefficient @f$ S_{ki} @f$ of solution variable @f$ y_k
273 * @f$ with respect to sensitivity parameter @f$ p_i @f$ is defined as:
274 *
275 * @f[ S_{ki} = \frac{1}{y_k} \frac{\partial y_k}{\partial p_i} @f]
276 *
277 * For reaction sensitivities, the parameter is a multiplier on the forward
278 * rate constant (and implicitly on the reverse rate constant for
279 * reversible reactions) which has a nominal value of 1.0, and the
280 * sensitivity is nondimensional.
281 *
282 * For species enthalpy sensitivities, the parameter is a perturbation to
283 * the molar enthalpy of formation, such that the dimensions of the
284 * sensitivity are kmol/J.
285 */
286 double sensitivity(size_t k, size_t p);
287
288 //! Return the sensitivity of the component named *component* with respect to
289 //! the *p*-th sensitivity parameter.
290 //! @copydetails ReactorNet::sensitivity(size_t, size_t)
291 double sensitivity(const string& component, size_t p, int reactor=0) {
292 size_t k = globalComponentIndex(component, reactor);
293 return sensitivity(k, p);
294 }
295
296 //! Evaluate the Jacobian matrix for the reactor network.
297 /*!
298 * @param[in] t Time/distance at which to evaluate the Jacobian
299 * @param[in] y Global state vector at *t*
300 * @param[out] ydot Derivative of the state vector evaluated at *t*, with respect
301 * to *t*.
302 * @param[in] p sensitivity parameter vector (unused?)
303 * @param[out] j Jacobian matrix, size neq() by neq().
304 */
305 void evalJacobian(double t, span<double> y,
306 span<double> ydot, span<const double> p, Array2D* j);
307
308 // overloaded methods of class FuncEval
309 size_t neq() const override {
310 return m_nv;
311 }
312
313 size_t nReactors() const {
314 return m_reactors.size();
315 }
316
317 void eval(double t, span<const double> y, span<double> ydot,
318 span<const double> p) override;
319
320 //! Evaluate the governing equations adapted for the steady-state solver.
321 //!
322 //! @param[in] y Current state vector, length neq()
323 //! @param[out] residual For differential variables, this is the time derivative;
324 //! for algebraic variables, this is the residual of the governing equation.
325 //!
326 //! @since New in %Cantera 4.0.
327 void evalSteady(span<const double> y, span<double> residual);
328
329 //! eval coupling for IDA / DAEs
330 void evalDae(double t, span<const double> y, span<const double> ydot,
331 span<const double> p, span<double> residual) override;
332
333 void getState(span<double> y) override;
334 void getStateDae(span<double> y, span<double> ydot) override;
335
336 //! Return k-th derivative at the current state of the system
337 virtual void getDerivative(int k, span<double> dky);
338
339 void getConstraints(span<double> constraints) override;
340
341 size_t nparams() const override {
342 return m_sens_params.size();
343 }
344
345 //! Return the index corresponding to the component named *component* in the
346 //! reactor with index *reactor* in the global state vector for the
347 //! reactor network.
348 size_t globalComponentIndex(const string& component, size_t reactor=0);
349
350 //! Return the name of the i-th component of the global state vector. The
351 //! name returned includes both the name of the reactor and the specific
352 //! component, for example `'reactor1: CH4'`.
353 string componentName(size_t i) const;
354
355 //! Get the upper bound on the i-th component of the global state vector.
356 double upperBound(size_t i) const;
357
358 //! Get the lower bound on the i-th component of the global state vector.
359 double lowerBound(size_t i) const;
360
361 //! Reset physically or mathematically problematic values, such as negative species
362 //! concentrations.
363 //!
364 //! This method is used within solveSteady() if certain errors are encountered.
365 //!
366 //! @param[inout] y current state vector, to be updated; length neq()
367 void resetBadValues(span<double> y);
368
369 //! Used by Reactor and Wall objects to register the addition of
370 //! sensitivity parameters so that the ReactorNet can keep track of the
371 //! order in which sensitivity parameters are added.
372 //! @param name A name describing the parameter, for example the reaction string
373 //! @param value The nominal value of the parameter
374 //! @param scale A scaling factor to be applied to the sensitivity
375 //! coefficient
376 //! @returns the index of this parameter in the vector of sensitivity
377 //! parameters (global across all reactors)
378 size_t registerSensitivityParameter(const string& name, double value, double scale);
379
380 //! The name of the p-th sensitivity parameter added to this ReactorNet.
381 const string& sensitivityParameterName(size_t p) const {
382 return m_paramNames.at(p);
383 }
384
385 //! Initialize the reactor network. Called automatically the first time
386 //! advance or step is called.
387 void initialize();
388
389 //! Reinitialize the integrator. Used to solve a new problem (different
390 //! initial conditions) but with the same configuration of the reactor
391 //! network. Can be called manually, or automatically after calling
392 //! setInitialTime or modifying a reactor's contents.
393 void reinitialize();
394
395 //! Called to trigger integrator reinitialization before further
396 //! integration.
399 }
400
401 //! Set the maximum number of internal integration steps the
402 //! integrator will take before reaching the next output point
403 //! @param nmax The maximum number of steps, setting this value
404 //! to zero disables this option.
405 virtual void setMaxSteps(int nmax);
406
407 //! Set absolute step size limits during advance
408 void setAdvanceLimits(span<const double> limits);
409
410 //! Check whether ReactorNet object uses advance limits
411 bool hasAdvanceLimits() const;
412
413 //! Retrieve absolute step size limits during advance
414 bool getAdvanceLimits(span<double> limits) const;
415
416 void preconditionerSetup(double t, span<const double> y, double gamma) override;
417
418 void preconditionerSolve(span<const double> rhs, span<double> output) override;
419
420 //! Get solver stats from integrator
421 AnyMap solverStats() const;
422
423 //! Set derivative settings of all reactors
424 //! @param settings the settings map propagated to all reactors and kinetics objects
425 virtual void setDerivativeSettings(AnyMap& settings);
426
427 //! Root finding is enabled only while enforcing advance limits
428 size_t nRootFunctions() const override;
429
430 //! Evaluate the advance-limit root function used to stop integration once a limit
431 //! is met.
432 //!
433 //! When limits are active, this sets `gout[0]` to
434 //! `1 - max_i(|y[i]-y_base[i]| / limit[i])` so a zero indicates a component has
435 //! reached its limit; otherwise `gout[0]` is positive.
436 void evalRootFunctions(double t, span<const double> y,
437 span<double> gout) override;
438
439protected:
440 //! Check that preconditioning is supported by all reactors in the network
441 virtual void checkPreconditionerSupported() const;
442
443 //! Update the integrator tolerance vector from the current scalar settings,
444 //! reactor-specific user tolerances, and reactor-specific default scaling rules.
445 void updateTolerances();
446
447 void updatePreconditioner(double gamma) override;
448
449 //! Create reproducible names for reactors and walls/connectors.
450 void updateNames(ReactorBase& r);
451
452 //! Estimate a future state based on current derivatives.
453 //! The function is intended for internal use by ReactorNet::advance
454 //! and deliberately not exposed in external interfaces.
455 virtual void getEstimate(double time, int k, span<double> yest);
456
457 //! Returns the order used for last solution step of the ODE integrator
458 //! The function is intended for internal use by ReactorNet::advance
459 //! and deliberately not exposed in external interfaces.
460 virtual int lastOrder() const;
461
462 vector<shared_ptr<ReactorBase>> m_reactors;
463 vector<shared_ptr<Reactor>> m_bulkReactors;
464 vector<shared_ptr<ReactorBase>> m_surfaces;
465 vector<shared_ptr<ReactorBase>> m_reservoirs;
466 set<FlowDevice*> m_flowDevices;
467 set<WallBase*> m_walls;
468 map<string, int> m_counts; //!< Map used for default name generation
469 unique_ptr<Integrator> m_integ;
470
471 //! The independent variable in the system. May be either time or space depending
472 //! on the type of reactors in the network.
473 double m_time = 0.0;
474
475 //! The initial value of the independent variable in the system.
476 double m_initial_time = 0.0;
477
478 bool m_integratorInitialized = false; //!< True if the integrator has been initialized at least once
479 bool m_needIntegratorInit = true; //!< True if integrator needs to be (re)initialized
480 size_t m_nv = 0;
481
482 vector<double> m_atol;
483 double m_rtol = 1.0e-9;
484 double m_rtolsens = 1.0e-4;
485 double m_atols = 1.0e-15;
486 double m_atolsens = 1.0e-6;
487 //! True if scalar absolute tolerance was user-specified
489 shared_ptr<SystemJacobian> m_precon;
490 string m_linearSolverType;
491
492 //! Maximum integrator internal timestep. Default of 0.0 means infinity.
493 double m_maxstep = 0.0;
494
495 bool m_verbose = false;
496
497 //! Indicates whether time or space is the independent variable
499
500 //! Names corresponding to each sensitivity parameter
501 vector<string> m_paramNames;
502
503 vector<double> m_ydot;
504 vector<double> m_yest;
505 vector<double> m_advancelimits;
506 //! Base state used for evaluating advance limits during a single advance()
507 //! call when root-finding is enabled
508 vector<double> m_ybase;
509 //! Base time corresponding to #m_ybase
510 double m_ybase_time = 0.0;
511 //! Indicates whether the advance-limit root check is active for the
512 //! current call to `advance(t, applylimit=true)`
514 //! m_LHS is a vector representing the coefficients on the
515 //! "left hand side" of each governing equation
516 vector<double> m_LHS;
517 vector<double> m_RHS;
518};
519
520
521//! Adapter class to enable using the SteadyStateSystem solver with ReactorNet.
522//!
523//! @see ReactorNet::solveSteady
524//! @since New in %Cantera 3.2.
526{
527public:
528 SteadyReactorSolver(ReactorNet* net, span<const double> x0);
529 void eval(span<const double> x, span<double> r,
530 double rdt=-1.0, int count=1) override;
531 void initTimeInteg(double dt, span<const double> x) override;
532 void evalJacobian(span<const double> x0) override;
533 double weightedNorm(span<const double> step) const override;
534 string componentName(size_t i) const override;
535 double upperBound(size_t i) const override;
536 double lowerBound(size_t i) const override;
537 void resetBadValues(span<double> x) override;
538 void writeDebugInfo(const string& header_suffix, const string& message,
539 int loglevel, int attempt_counter) override;
540
541private:
542 ReactorNet* m_net = nullptr;
543
544 //! Initial value of each state variable
545 vector<double> m_initialState;
546};
547
548
549/**
550 * Create a reactor network containing one or more coupled reactors.
551 * Wall and FlowDevice objects should be installed prior to calling newReactorNet().
552 * @param[in] reactors A vector of shared pointers to the reactors to be linked
553 * together.
554 * @since New in %Cantera 3.2.
555 */
556shared_ptr<ReactorNet> newReactorNet(span<shared_ptr<ReactorBase>> reactors);
557
558}
559
560#endif
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:431
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition Array.h:32
Virtual base class for ODE/DAE right-hand-side function evaluators.
Definition FuncEval.h:32
bool suppressErrors() const
Get current state of error suppression.
Definition FuncEval.h:190
vector< double > m_sens_params
Values for the problem parameters for which sensitivities are computed This is the array which is per...
Definition FuncEval.h:205
Abstract base class for ODE system integrators.
Definition Integrator.h:44
Base class for reactor objects.
Definition ReactorBase.h:51
A class representing a network of connected reactors.
Definition ReactorNet.h:30
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.
Definition ReactorNet.h:381
double m_ybase_time
Base time corresponding to m_ybase.
Definition ReactorNet.h:510
size_t nparams() const override
Number of sensitivity parameters.
Definition ReactorNet.h:341
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.
Definition ReactorNet.h:309
ReactorBase & reactor(int n)
Return a reference to the n-th reactor in this network.
Definition ReactorNet.h:245
vector< double > m_LHS
m_LHS is a vector representing the coefficients on the "left hand side" of each governing equation
Definition ReactorNet.h:516
double m_initial_time
The initial value of the independent variable in the system.
Definition ReactorNet.h:476
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).
Definition ReactorNet.h:63
Eigen::SparseMatrix< double > finiteDifferenceJacobian()
Calculate the system Jacobian for the reactor network using finite differences.
void setNeedsReinit()
Called to trigger integrator reinitialization before further integration.
Definition ReactorNet.h:397
double m_time
The independent variable in the system.
Definition ReactorNet.h:473
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,...
Definition ReactorNet.h:513
map< string, int > m_counts
Map used for default name generation.
Definition ReactorNet.h:468
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.
Definition ReactorNet.h:478
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.
Definition ReactorNet.h:68
double m_maxstep
Maximum integrator internal timestep. Default of 0.0 means infinity.
Definition ReactorNet.h:493
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.
Definition ReactorNet.h:141
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.
Definition ReactorNet.h:479
void preconditionerSetup(double t, span< const double > y, double gamma) override
Evaluate the setup processes for the Jacobian preconditioner.
double rtol()
Relative tolerance.
Definition ReactorNet.h:126
bool verbose() const
Returns true if verbose logging output is enabled.
Definition ReactorNet.h:250
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.
Definition ReactorNet.h:498
double atol()
Scalar absolute integration tolerance.
Definition ReactorNet.h:131
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...
Definition ReactorNet.h:508
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...
Definition ReactorNet.h:291
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.
Definition ReactorNet.h:136
bool m_atolUserSpecified
True if scalar absolute tolerance was user-specified.
Definition ReactorNet.h:488
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.
Definition ReactorNet.h:256
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.
Definition ReactorNet.h:501
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.
Definition ReactorNet.h:526
double weightedNorm(span< const double > step) const override
Compute the weighted norm of step.
vector< double > m_initialState
Initial value of each state variable.
Definition ReactorNet.h:545
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.
Definition utilities.h:118
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
shared_ptr< ReactorNet > newReactorNet(span< shared_ptr< ReactorBase > > reactors)
Create a reactor network containing one or more coupled reactors.