Cantera  3.0.0
Loading...
Searching...
No Matches
IdasIntegrator.cpp
Go to the documentation of this file.
1//! @file IdasIntegrator.cpp
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at http://www.cantera.org/license.txt for license and copyright information.
5
8
9#include "cantera/numerics/sundials_headers.h"
10
11using namespace std;
12
13namespace {
14
15N_Vector newNVector(size_t N, Cantera::SundialsContext& context)
16{
17#if CT_SUNDIALS_VERSION >= 60
18 return N_VNew_Serial(static_cast<sd_size_t>(N), context.get());
19#else
20 return N_VNew_Serial(static_cast<sd_size_t>(N));
21#endif
22}
23
24} // end anonymous namespace
25
26namespace Cantera
27{
28
29extern "C" {
30
31//! Function called by IDA to evaluate the residual, given y and ydot.
32/*!
33* IDA allows passing in a void* pointer to access external data. Instead of requiring
34* the user to provide a residual function directly to IDA (which would require using the
35* Sundials data types N_Vector, etc.), we define this function as the single function
36* that IDA always calls. The real evaluation of the residual is done by an instance of a
37* subclass of ResidEval, passed in to this function as a pointer in the parameters.
38*
39* FROM IDA WRITEUP -> What the IDA solver expects as a return flag from its
40* residual routines:
41*
42* A IDAResFn res should return a value of 0 if successful, a positive value if a
43* recoverable error occurred (e.g. yy has an illegal value), or a negative value if a
44* nonrecoverable error occurred. In the latter case, the program halts. If a recoverable
45* error occurred, the integrator will attempt to correct and retry.
46*/
47static int ida_rhs(realtype t, N_Vector y, N_Vector ydot, N_Vector r, void* f_data)
48{
49 FuncEval* f = (FuncEval*) f_data;
50 return f->evalDaeNoThrow(t, NV_DATA_S(y), NV_DATA_S(ydot), NV_DATA_S(r));
51}
52
53//! Function called by IDA when an error is encountered instead of writing to stdout.
54//! Here, save the error message provided by IDA so that it can be included in the
55//! subsequently raised CanteraError.
56static void ida_err(int error_code, const char* module,
57 const char* function, char* msg, void* eh_data)
58{
59 IdasIntegrator* integrator = (IdasIntegrator*) eh_data;
60 integrator->m_error_message = msg;
61 integrator->m_error_message += "\n";
62}
63
64}
65
67 : m_itol(IDA_SS)
68{
69}
70
71IdasIntegrator::~IdasIntegrator()
72{
73 if (m_ida_mem) {
74 IDAFree(&m_ida_mem);
75 }
76 if (m_y) {
77 N_VDestroy_Serial(m_y);
78 }
79 if (m_ydot) {
80 N_VDestroy_Serial(m_ydot);
81 }
82 if (m_abstol) {
83 N_VDestroy_Serial(m_abstol);
84 }
85 if (m_constraints) {
86 N_VDestroy_Serial(m_constraints);
87 }
88}
89
90double& IdasIntegrator::solution(size_t k)
91{
92 return NV_Ith_S(m_y, k);
93}
94
96{
97 return NV_DATA_S(m_y);
98}
99
100void IdasIntegrator::setTolerances(double reltol, size_t n, double* abstol)
101{
102 m_itol = IDA_SV;
103 if (n != m_nabs) {
104 m_nabs = n;
105 if (m_abstol) {
106 N_VDestroy_Serial(m_abstol);
107 }
108 m_abstol = newNVector(static_cast<sd_size_t>(n), m_sundials_ctx);
109 }
110 for (size_t i=0; i<n; i++) {
111 NV_Ith_S(m_abstol, i) = abstol[i];
112 }
113 m_reltol = reltol;
114}
115
116void IdasIntegrator::setTolerances(double reltol, double abstol)
117{
118 m_itol = IDA_SS;
119 m_reltol = reltol;
120 m_abstols = abstol;
121}
122
123void IdasIntegrator::setSensitivityTolerances(double reltol, double abstol)
124{
125 m_reltolsens = reltol;
126 m_abstolsens = abstol;
127}
128
129
130void IdasIntegrator::setLinearSolverType(const string& linearSolverType)
131{
133}
134
136{
137 if (m_ida_mem) {
138 int flag = IDASetMaxOrd(m_ida_mem, n);
139 checkError(flag, "setMaxOrder", "IDASetMaxOrd");
140 }
141 m_maxord = n;
142}
143
145{
146 m_hmax = hmax;
147 if (m_ida_mem) {
148 int flag = IDASetMaxStep(m_ida_mem, hmax);
149 checkError(flag, "setMaxStepSize", "IDASetMaxStep");
150 }
151}
152
154{
155 m_maxsteps = nmax;
156 if (m_ida_mem) {
157 IDASetMaxNumSteps(m_ida_mem, m_maxsteps);
158 }
159}
160
162{
163 return m_maxsteps;
164}
165
167{
169 if (m_ida_mem) {
170 IDASetMaxErrTestFails(m_ida_mem, n);
171 }
172}
173
175{
176 AnyMap stats;
177 long int val;
178 int lastOrder;
179
180 int flag = IDAGetNumSteps(m_ida_mem, &val);
181 checkError(flag, "solverStats", "IDAGetNumSteps");
182 stats["steps"] = val;
183 IDAGetNumResEvals(m_ida_mem, &val);
184 stats["res_evals"] = val;
185 IDAGetNumLinSolvSetups(m_ida_mem, &val);
186 stats["lin_solve_setups"] = val;
187 IDAGetNumErrTestFails(m_ida_mem, &val);
188 stats["err_tests_fails"] = val;
189 IDAGetLastOrder(m_ida_mem, &lastOrder);
190 stats["last_order"] = lastOrder;
191 IDAGetNumNonlinSolvIters(m_ida_mem, &val);
192 stats["nonlinear_iters"] = val;
193 IDAGetNumNonlinSolvConvFails(m_ida_mem, &val);
194 stats["nonlinear_conv_fails"] = val;
195 return stats;
196}
197
198void IdasIntegrator::setMaxNonlinIterations(int n)
199{
201 if (m_ida_mem) {
202 int flag = IDASetMaxNonlinIters(m_ida_mem, m_maxNonlinIters);
203 checkError(flag, "setMaxNonlinIterations", "IDASetMaxNonlinIters");
204 }
205}
206
207void IdasIntegrator::setMaxNonlinConvFailures(int n)
208{
210 if (m_ida_mem) {
211 int flag = IDASetMaxConvFails(m_ida_mem, m_maxNonlinConvFails);
212 checkError(flag, "setMaxNonlinConvFailures", "IDASetMaxConvFails");
213 }
214}
215
216void IdasIntegrator::includeAlgebraicInErrorTest(bool yesno)
217{
218 m_setSuppressAlg = !yesno;
219 if (m_ida_mem) {
220 int flag = IDASetSuppressAlg(m_ida_mem, m_setSuppressAlg);
221 checkError(flag, "inclAlgebraicInErrorTest", "IDASetSuppressAlg");
222 }
223}
224
226{
227 m_neq = func.neq();
228 m_t0 = t0;
229 m_time = t0;
230 m_tInteg = t0;
231 m_func = &func;
232 func.clearErrors();
233
234 if (m_y) {
235 N_VDestroy_Serial(m_y); // free solution vector if already allocated
236 }
237 m_y = newNVector(static_cast<sd_size_t>(m_neq), m_sundials_ctx);
238 N_VConst(0.0, m_y);
239
240 if (m_ydot) {
241 N_VDestroy_Serial(m_ydot); // free derivative vector if already allocated
242 }
243 m_ydot = newNVector(m_neq, m_sundials_ctx);
244 N_VConst(0.0, m_ydot);
245
246 // check abs tolerance array size
247 if (m_itol == IDA_SV && m_nabs < m_neq) {
248 throw CanteraError("IdasIntegrator::initialize",
249 "not enough absolute tolerance values specified.");
250 }
251
252 if (m_constraints) {
253 N_VDestroy_Serial(m_constraints);
254 }
255 m_constraints = newNVector(static_cast<sd_size_t>(m_neq), m_sundials_ctx);
256 // set the constraints
257 func.getConstraints(NV_DATA_S(m_constraints));
258
259 // get the initial conditions
260 func.getStateDae(NV_DATA_S(m_y), NV_DATA_S(m_ydot));
261
262 if (m_ida_mem) {
263 IDAFree(&m_ida_mem);
264 }
265
266 //! Create the IDA solver
267 #if CT_SUNDIALS_VERSION >= 60
268 m_ida_mem = IDACreate(m_sundials_ctx.get());
269 #else
270 m_ida_mem = IDACreate();
271 #endif
272 if (!m_ida_mem) {
273 throw CanteraError("IdasIntegrator::initialize", "IDACreate failed.");
274 }
275
276 int flag = IDAInit(m_ida_mem, ida_rhs, m_t0, m_y, m_ydot);
277 if (flag != IDA_SUCCESS) {
278 if (flag == IDA_MEM_FAIL) {
279 throw CanteraError("IdasIntegrator::initialize",
280 "Memory allocation failed.");
281 } else if (flag == IDA_ILL_INPUT) {
282 throw CanteraError("IdasIntegrator::initialize",
283 "Illegal value for IDAInit input argument.");
284 } else {
285 throw CanteraError("IdasIntegrator::initialize", "IDAInit failed.");
286 }
287 }
288
289 flag = IDASetErrHandlerFn(m_ida_mem, &ida_err, this);
290
291 // set constraints
292 flag = IDASetId(m_ida_mem, m_constraints);
293 checkError(flag, "initialize", "IDASetId");
294
295 if (m_itol == IDA_SV) {
296 flag = IDASVtolerances(m_ida_mem, m_reltol, m_abstol);
297 checkError(flag, "initialize", "IDASVtolerances");
298 } else {
299 flag = IDASStolerances(m_ida_mem, m_reltol, m_abstols);
300 checkError(flag, "initialize", "IDASStolerances");
301 }
302
303 flag = IDASetUserData(m_ida_mem, &func);
304 checkError(flag, "initialize", "IDASetUserData");
305
306 if (func.nparams() > 0) {
307 throw CanteraError("IdasIntegrator::initialize", "Sensitivity analysis "
308 "for DAE systems is not fully implemented");
309 sensInit(t0, func);
310 flag = IDASetSensParams(m_ida_mem, func.m_sens_params.data(),
311 func.m_paramScales.data(), NULL);
312 checkError(flag, "initialize", "IDASetSensParams");
313 }
314 applyOptions();
315}
316
317void IdasIntegrator::reinitialize(double t0, FuncEval& func)
318{
319 m_t0 = t0;
320 m_time = t0;
321 m_tInteg = t0;
322 func.getStateDae(NV_DATA_S(m_y), NV_DATA_S(m_ydot));
323 m_func = &func;
324 func.clearErrors();
325
326 int result = IDAReInit(m_ida_mem, m_t0, m_y, m_ydot);
327 checkError(result, "reinitialize", "IDAReInit");
328 applyOptions();
329}
330
332{
333 if (m_type == "DENSE") {
334 sd_size_t N = static_cast<sd_size_t>(m_neq);
335 SUNLinSolFree((SUNLinearSolver) m_linsol);
336 SUNMatDestroy((SUNMatrix) m_linsol_matrix);
337 #if CT_SUNDIALS_VERSION >= 60
338 m_linsol_matrix = SUNDenseMatrix(N, N, m_sundials_ctx.get());
339 #else
340 m_linsol_matrix = SUNDenseMatrix(N, N);
341 #endif
342 #if CT_SUNDIALS_VERSION >= 60
343 m_linsol_matrix = SUNDenseMatrix(N, N, m_sundials_ctx.get());
344 #else
345 m_linsol_matrix = SUNDenseMatrix(N, N);
346 #endif
347 #if CT_SUNDIALS_USE_LAPACK
348 #if CT_SUNDIALS_VERSION >= 60
349 m_linsol = SUNLinSol_LapackDense(m_y, (SUNMatrix) m_linsol_matrix,
350 m_sundials_ctx.get());
351 #else
352 m_linsol = SUNLapackDense(m_y, (SUNMatrix) m_linsol_matrix);
353 #endif
354 #else
355 #if CT_SUNDIALS_VERSION >= 60
356 m_linsol = SUNLinSol_Dense(m_y, (SUNMatrix) m_linsol_matrix,
357 m_sundials_ctx.get());
358 #else
359 m_linsol = SUNLinSol_Dense(m_y, (SUNMatrix) m_linsol_matrix);
360 #endif
361 #endif
362 #if CT_SUNDIALS_VERSION >= 60
363 IDASetLinearSolver(m_ida_mem, (SUNLinearSolver) m_linsol,
364 (SUNMatrix) m_linsol_matrix);
365 #else
366 IDADlsSetLinearSolver(m_ida_mem, (SUNLinearSolver) m_linsol,
367 (SUNMatrix) m_linsol_matrix);
368 #endif
369 } else if (m_type == "GMRES") {
370 #if CT_SUNDIALS_VERSION >= 60
371 m_linsol = SUNLinSol_SPGMR(m_y, PREC_NONE, 0, m_sundials_ctx.get());
372 IDASetLinearSolver(m_ida_mem, (SUNLinearSolver) m_linsol, nullptr);
373 #elif CT_SUNDIALS_VERSION >= 40
374 m_linsol = SUNLinSol_SPGMR(m_y, PREC_NONE, 0);
375 IDASpilsSetLinearSolver(m_ida_mem, (SUNLinearSolver) m_linsol);
376 #else
377 m_linsol = SUNSPGMR(m_y, PREC_NONE, 0);
378 IDASpilsSetLinearSolver(m_ida_mem, (SUNLinearSolver) m_linsol);
379 #endif
380 } else {
381 throw CanteraError("IdasIntegrator::applyOptions",
382 "unsupported linear solver flag '{}'", m_type);
383 }
384
385 if (m_init_step > 0) {
386 IDASetInitStep(m_ida_mem, m_init_step);
387 }
388
389 if (m_maxord > 0) {
390 int flag = IDASetMaxOrd(m_ida_mem, m_maxord);
391 checkError(flag, "applyOptions", "IDASetMaxOrd");
392 }
393 if (m_maxsteps > 0) {
394 IDASetMaxNumSteps(m_ida_mem, m_maxsteps);
395 }
396 if (m_hmax > 0) {
397 IDASetMaxStep(m_ida_mem, m_hmax);
398 }
399 if (m_maxNonlinIters > 0) {
400 int flag = IDASetMaxNonlinIters(m_ida_mem, m_maxNonlinIters);
401 checkError(flag, "applyOptions", "IDASetMaxNonlinIters");
402 }
403 if (m_maxNonlinConvFails > 0) {
404 int flag = IDASetMaxConvFails(m_ida_mem, m_maxNonlinConvFails);
405 checkError(flag, "applyOptions", "IDASetMaxConvFails");
406 }
407 if (m_setSuppressAlg != 0) {
408 int flag = IDASetSuppressAlg(m_ida_mem, m_setSuppressAlg);
409 checkError(flag, "applyOptions", "IDASetSuppressAlg");
410 }
411}
412
413void IdasIntegrator::sensInit(double t0, FuncEval& func)
414{
415 m_np = func.nparams();
416 m_sens_ok = false;
417
418 N_Vector y = newNVector(static_cast<sd_size_t>(func.neq()), m_sundials_ctx);
419 #if CT_SUNDIALS_VERSION >= 60
420 m_yS = N_VCloneVectorArray(static_cast<int>(m_np), y);
421 #else
422 m_yS = N_VCloneVectorArray_Serial(static_cast<int>(m_np), y);
423 #endif
424 for (size_t n = 0; n < m_np; n++) {
425 N_VConst(0.0, m_yS[n]);
426 }
427 N_VDestroy_Serial(y);
428 N_Vector ydot = newNVector(static_cast<sd_size_t>(func.neq()), m_sundials_ctx);
429 #if CT_SUNDIALS_VERSION >= 60
430 m_ySdot = N_VCloneVectorArray(static_cast<int>(m_np), ydot);
431 #else
432 m_ySdot = N_VCloneVectorArray_Serial(static_cast<int>(m_np), ydot);
433 #endif
434 for (size_t n = 0; n < m_np; n++) {
435 N_VConst(0.0, m_ySdot[n]);
436 }
437
438 int flag = IDASensInit(m_ida_mem, static_cast<sd_size_t>(m_np),
439 IDA_STAGGERED, IDASensResFn(0), m_yS, m_ySdot);
440 checkError(flag, "sensInit", "IDASensInit");
441
442 vector<double> atol(m_np);
443 for (size_t n = 0; n < m_np; n++) {
444 // This scaling factor is tuned so that reaction and species enthalpy
445 // sensitivities can be computed simultaneously with the same abstol.
446 atol[n] = m_abstolsens / func.m_paramScales[n];
447 }
448 flag = IDASensSStolerances(m_ida_mem, m_reltolsens, atol.data());
449 checkError(flag, "sensInit", "IDASensSStolerances");
450}
451
453{
454 if (tout == m_time) {
455 return;
456 } else if (tout < m_time) {
457 throw CanteraError("IdasIntegrator::integrate",
458 "Cannot integrate backwards in time.\n"
459 "Requested time {} < current time {}",
460 tout, m_time);
461 }
462 int nsteps = 0;
463 while (m_tInteg < tout) {
464 if (nsteps >= m_maxsteps) {
465 throw CanteraError("IdasIntegrator::integrate",
466 "Maximum number of timesteps ({}) taken without reaching output "
467 "time ({}).\nCurrent integrator time: {}",
468 nsteps, tout, m_time);
469 }
470 int flag = IDASolve(m_ida_mem, tout, &m_tInteg, m_y, m_ydot, IDA_ONE_STEP);
471 if (flag != IDA_SUCCESS) {
472 string f_errs = m_func->getErrors();
473 if (!f_errs.empty()) {
474 f_errs = "Exceptions caught during RHS evaluation:\n" + f_errs;
475 }
476 throw CanteraError("IdasIntegrator::integrate",
477 "IDA error encountered. Error code: {}\n{}\n"
478 "{}"
479 "Components with largest weighted error estimates:\n{}",
480 flag, m_error_message, f_errs, getErrorInfo(10));
481 }
482 nsteps++;
483 }
484 int flag = IDAGetDky(m_ida_mem, tout, 0, m_y);
485 checkError(flag, "integrate", "IDAGetDky");
486 m_time = tout;
487}
488
489double IdasIntegrator::step(double tout)
490{
491 int flag = IDASolve(m_ida_mem, tout, &m_tInteg, m_y, m_ydot, IDA_ONE_STEP);
492 if (flag != IDA_SUCCESS) {
493 string f_errs = m_func->getErrors();
494 if (!f_errs.empty()) {
495 f_errs = "Exceptions caught during RHS evaluation:\n" + f_errs;
496 }
497 throw CanteraError("IdasIntegrator::step",
498 "IDA error encountered. Error code: {}\n{}\n"
499 "{}"
500 "Components with largest weighted error estimates:\n{}",
501 flag, f_errs, m_error_message, getErrorInfo(10));
502
503 }
505 return m_time;
506}
507
508double IdasIntegrator::sensitivity(size_t k, size_t p)
509{
510 if (m_time == m_t0) {
511 // calls to IDAGetSens are only allowed after a successful time step.
512 return 0.0;
513 }
514 if (!m_sens_ok && m_np) {
515 int flag = IDAGetSensDky(m_ida_mem, m_time, 0, m_yS);
516 checkError(flag, "sensitivity", "IDAGetSens");
517 m_sens_ok = true;
518 }
519
520 if (k >= m_neq) {
521 throw CanteraError("IdasIntegrator::sensitivity",
522 "sensitivity: k out of range ({})", k);
523 }
524 if (p >= m_np) {
525 throw CanteraError("IdasIntegrator::sensitivity",
526 "sensitivity: p out of range ({})", p);
527 }
528 return NV_Ith_S(m_yS[p],k);
529}
530
532{
533 N_Vector errs = newNVector(static_cast<sd_size_t>(m_neq), m_sundials_ctx);
534 N_Vector errw = newNVector(static_cast<sd_size_t>(m_neq), m_sundials_ctx);
535 IDAGetErrWeights(m_ida_mem, errw);
536 IDAGetEstLocalErrors(m_ida_mem, errs);
537
538 vector<tuple<double, double, size_t>> weightedErrors;
539 for (size_t i=0; i<m_neq; i++) {
540 double err = NV_Ith_S(errs, i) * NV_Ith_S(errw, i);
541 weightedErrors.emplace_back(-abs(err), err, i);
542 }
543 N_VDestroy(errs);
544 N_VDestroy(errw);
545
546 N = std::min(N, static_cast<int>(m_neq));
547 sort(weightedErrors.begin(), weightedErrors.end());
548 fmt::memory_buffer s;
549 for (int i=0; i<N; i++) {
550 fmt_append(s, "{}: {}\n", get<2>(weightedErrors[i]), get<1>(weightedErrors[i]));
551 }
552 return to_string(s);
553}
554
555void IdasIntegrator::checkError(long flag, const string& ctMethod,
556 const string& idaMethod) const
557{
558 if (flag == IDA_SUCCESS) {
559 return;
560 } else if (flag == IDA_MEM_NULL) {
561 throw CanteraError("IdasIntegrator::" + ctMethod,
562 "IDAS integrator is not initialized");
563 } else {
564 const char* flagname = IDAGetReturnFlagName(flag);
565 throw CanteraError("IdasIntegrator::" + ctMethod,
566 "{} returned error code {} ({}):\n{}",
567 idaMethod, flag, flagname, m_error_message);
568 }
569}
570
572{
573 if (t != BDF_Method) {
574 // IDA only has the BDF method
575 throw CanteraError("IdasIntegrator::setMethod", "unknown method");
576 }
577}
578
579}
Header file for class IdasIntegrator.
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
Base class for exceptions thrown by Cantera classes.
Virtual base class for ODE/DAE right-hand-side function evaluators.
Definition FuncEval.h:32
virtual void getStateDae(double *y, double *ydot)
Fill in the vectors y and ydot with the current state of the system.
Definition FuncEval.h:148
vector< double > m_paramScales
Scaling factors for each sensitivity parameter.
Definition FuncEval.h:184
int evalDaeNoThrow(double t, double *y, double *ydot, double *residual)
Evaluate the right-hand side using return code to indicate status.
Definition FuncEval.cpp:39
void clearErrors()
Clear any previously-stored suppressed errors.
Definition FuncEval.h:174
virtual size_t neq() const =0
Number of equations.
virtual void getConstraints(double *constraints)
Given a vector of length neq(), mark which variables should be considered algebraic constraints.
Definition FuncEval.h:63
virtual size_t nparams() const
Number of sensitivity parameters.
Definition FuncEval.h:156
string getErrors() const
Return a string containing the text of any suppressed errors.
Definition FuncEval.cpp:71
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:181
Wrapper for Sundials IDAS solver.
double step(double tout) override
Integrate the system of equations.
void setMaxStepSize(double hmax) override
Set the maximum step size.
double * solution() override
The current value of the solution of the system of equations.
double m_t0
The start time for the integrator.
N_Vector m_y
The current system state.
void * m_linsol
Sundials linear solver object.
int m_maxNonlinConvFails
Maximum number of nonlinear convergence failures.
double m_init_step
Initial IDA step size.
void checkError(long flag, const string &ctMethod, const string &idaMethod) const
Check whether an IDAS method indicated an error.
double m_abstolsens
Scalar absolute tolerance for sensitivities.
size_t m_nabs
! Number of variables for which absolute tolerances were provided
void setMaxOrder(int n) override
Set the maximum integration order that will be used.
double m_time
The current integrator time, corresponding to m_y.
int m_maxNonlinIters
Maximum number of nonlinear solver iterations at one solution.
bool m_sens_ok
Indicates whether the sensitivities stored in m_yS and m_ySdot have been updated for the current inte...
int maxSteps() override
Returns the maximum number of time-steps the integrator can take before reaching the next output time...
SundialsContext m_sundials_ctx
SUNContext object for Sundials>=6.0.
FuncEval * m_func
Object implementing the DAE residual function .
double m_abstols
Scalar absolute tolerance.
double m_hmax
Maximum time step size. Zero means infinity.
int m_itol
Flag indicating whether scalar (IDA_SS) or vector (IDA_SV) absolute tolerances are being used.
int m_maxErrTestFails
Maximum number of error test failures in attempting one step.
int m_maxord
Maximum order allowed for the BDF method.
void setSensitivityTolerances(double reltol, double abstol) override
Set the sensitivity error tolerances.
void applyOptions()
Applies user-specified options to the underlying IDAS solver.
void integrate(double tout) override
Integrate the system of equations.
void setTolerances(double reltol, size_t n, double *abstol) override
Set error tolerances.
void setLinearSolverType(const string &linearSolverType) override
Set the linear solver type.
double m_reltol
Relative tolerance for all state variables.
string m_error_message
Error message information provide by IDAS.
double m_reltolsens
Scalar relative tolerance for sensitivities.
N_Vector * m_yS
Sensitivities of y, size m_np by m_neq.
void setMaxErrTestFails(int n) override
Set the maximum permissible number of error test failures.
void setMaxSteps(int nmax) override
Set the maximum number of time-steps the integrator can take before reaching the next output time.
size_t m_neq
Number of equations/variables in the system.
AnyMap solverStats() const override
Get solver stats from integrator.
string m_type
The linear solver type.
size_t m_np
Number of sensitivity parameters.
void * m_linsol_matrix
matrix used by Sundials
N_Vector m_ydot
The time derivatives of the system state.
N_Vector * m_ySdot
Sensitivities of ydot, size m_np by m_neq.
double m_tInteg
The latest time reached by the integrator. May be greater than m_time.
void initialize(double t0, FuncEval &func) override
Initialize the integrator for a new problem.
int m_maxsteps
Maximum number of internal steps taken in a call to integrate()
string getErrorInfo(int N)
Returns a string listing the weighted error estimates associated with each solution component.
void setMethod(MethodType t) override
Set the solution method.
void * m_ida_mem
Pointer to the IDA memory for the problem.
bool m_setSuppressAlg
If true, the algebraic variables don't contribute to error tolerances.
N_Vector m_abstol
Absolute tolerances for each state variable.
virtual string linearSolverType() const
Return the integrator problem type.
Definition Integrator.h:152
virtual int lastOrder() const
Order used during the last solution step.
Definition Integrator.h:209
A wrapper for managing a SUNContext object, need for Sundials >= 6.0.
void fmt_append(fmt::memory_buffer &b, Args... args)
Versions 6.2.0 and 6.2.1 of fmtlib do not include this define before they include windows....
Definition fmt.h:29
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
static void ida_err(int error_code, const char *module, const char *function, char *msg, void *eh_data)
Function called by IDA when an error is encountered instead of writing to stdout.
MethodType
Specifies the method used to integrate the system of equations.
Definition Integrator.h:30
@ BDF_Method
Backward Differentiation.
Definition Integrator.h:31
static int ida_rhs(realtype t, N_Vector y, N_Vector ydot, N_Vector r, void *f_data)
Function called by IDA to evaluate the residual, given y and ydot.
Contains declarations for string manipulation functions within Cantera.