| 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
6#include "cantera/numerics/IdasIntegrator.h"
7#include "cantera/base/stringUtils.h"
8
9#include "cantera/numerics/sundials_headers.h"
10
11 using namespace std;
12
13 namespace {
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
26 namespace Cantera
27{
28
29 extern "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*/
47 static 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.
56 static 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
66 IdasIntegrator::IdasIntegrator()
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
90 double& IdasIntegrator::solution(size_t k)
91{
92 return NV_Ith_S(m_y, k);
93}
94
95 double* IdasIntegrator::solution()
96{
97 return NV_DATA_S(m_y);
98}
99
100 void 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
116 void IdasIntegrator::setTolerances(double reltol, double abstol)
117{
118 m_itol = IDA_SS;
119 m_reltol = reltol;
120 m_abstols = abstol;
121}
122
123 void IdasIntegrator::setSensitivityTolerances(double reltol, double abstol)
124{
125 m_reltolsens = reltol;
126 m_abstolsens = abstol;
127}
128
129
130 void IdasIntegrator::setLinearSolverType(const string& linearSolverType)
131{
132 m_type = linearSolverType;
133}
134
135 void IdasIntegrator::setMaxOrder(int n)
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
144 void IdasIntegrator::setMaxStepSize(double hmax)
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
153 void IdasIntegrator::setMaxSteps(int nmax)
154{
155 m_maxsteps = nmax;
156 if (m_ida_mem) {
157 IDASetMaxNumSteps(m_ida_mem, m_maxsteps);
158 }
159}
160
161 int IdasIntegrator::maxSteps()
162{
163 return m_maxsteps;
164}
165
166 void IdasIntegrator::setMaxErrTestFails(int n)
167{
168 m_maxErrTestFails = n;
169 if (m_ida_mem) {
170 IDASetMaxErrTestFails(m_ida_mem, n);
171 }
172}
173
174 AnyMap IdasIntegrator::solverStats() const
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
198 void IdasIntegrator::setMaxNonlinIterations(int n)
199{
200 m_maxNonlinIters = n;
201 if (m_ida_mem) {
202 int flag = IDASetMaxNonlinIters(m_ida_mem, m_maxNonlinIters);
203 checkError(flag, "setMaxNonlinIterations", "IDASetMaxNonlinIters");
204 }
205}
206
207 void IdasIntegrator::setMaxNonlinConvFailures(int n)
208{
209 m_maxNonlinConvFails = n;
210 if (m_ida_mem) {
211 int flag = IDASetMaxConvFails(m_ida_mem, m_maxNonlinConvFails);
212 checkError(flag, "setMaxNonlinConvFailures", "IDASetMaxConvFails");
213 }
214}
215
216 void 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
225 void IdasIntegrator::initialize(double t0, FuncEval& func)
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
317 void 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
331 void IdasIntegrator::applyOptions()
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
413 void 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
452 void IdasIntegrator::integrate(double tout)
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
489 double 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 }
504 m_time = m_tInteg;
505 return m_time;
506}
507
508 double 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
531 string IdasIntegrator::getErrorInfo(int N)
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
555 void 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
571 void IdasIntegrator::setMethod(MethodType t)
572{
573 if (t != BDF_Method) {
574 // IDA only has the BDF method
575 throw CanteraError("IdasIntegrator::setMethod", "unknown method");
576 }
577}
578
579}
IdasIntegrator.h
Header file for class IdasIntegrator.
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::FuncEval
Virtual base class for ODE/DAE right-hand-side function evaluators.
Definition FuncEval.h:32
Cantera::FuncEval::getStateDae
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
Cantera::FuncEval::m_paramScales
vector< double > m_paramScales
Scaling factors for each sensitivity parameter.
Definition FuncEval.h:184
Cantera::FuncEval::evalDaeNoThrow
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
Cantera::FuncEval::clearErrors
void clearErrors()
Clear any previously-stored suppressed errors.
Definition FuncEval.h:174
Cantera::FuncEval::neq
virtual size_t neq() const =0
Number of equations.
Cantera::FuncEval::getConstraints
virtual void getConstraints(double *constraints)
Given a vector of length neq(), mark which variables should be considered algebraic constraints.
Definition FuncEval.h:63
Cantera::FuncEval::nparams
virtual size_t nparams() const
Number of sensitivity parameters.
Definition FuncEval.h:156
Cantera::FuncEval::getErrors
string getErrors() const
Return a string containing the text of any suppressed errors.
Definition FuncEval.cpp:71
Cantera::FuncEval::m_sens_params
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
Cantera::IdasIntegrator
Wrapper for Sundials IDAS solver.
Definition IdasIntegrator.h:26
Cantera::IdasIntegrator::step
double step(double tout) override
Integrate the system of equations.
Definition IdasIntegrator.cpp:489
Cantera::IdasIntegrator::setMaxStepSize
void setMaxStepSize(double hmax) override
Set the maximum step size.
Definition IdasIntegrator.cpp:144
Cantera::IdasIntegrator::solution
double * solution() override
The current value of the solution of the system of equations.
Definition IdasIntegrator.cpp:95
Cantera::IdasIntegrator::m_t0
double m_t0
The start time for the integrator.
Definition IdasIntegrator.h:109
Cantera::IdasIntegrator::m_y
N_Vector m_y
The current system state.
Definition IdasIntegrator.h:115
Cantera::IdasIntegrator::m_linsol
void * m_linsol
Sundials linear solver object.
Definition IdasIntegrator.h:102
Cantera::IdasIntegrator::m_maxNonlinConvFails
int m_maxNonlinConvFails
Maximum number of nonlinear convergence failures.
Definition IdasIntegrator.h:157
Cantera::IdasIntegrator::m_init_step
double m_init_step
Initial IDA step size.
Definition IdasIntegrator.h:163
Cantera::IdasIntegrator::checkError
void checkError(long flag, const string &ctMethod, const string &idaMethod) const
Check whether an IDAS method indicated an error.
Definition IdasIntegrator.cpp:555
Cantera::IdasIntegrator::m_abstolsens
double m_abstolsens
Scalar absolute tolerance for sensitivities.
Definition IdasIntegrator.h:128
Cantera::IdasIntegrator::m_nabs
size_t m_nabs
! Number of variables for which absolute tolerances were provided
Definition IdasIntegrator.h:131
Cantera::IdasIntegrator::setMaxOrder
void setMaxOrder(int n) override
Set the maximum integration order that will be used.
Definition IdasIntegrator.cpp:135
Cantera::IdasIntegrator::m_time
double m_time
The current integrator time, corresponding to m_y.
Definition IdasIntegrator.h:110
Cantera::IdasIntegrator::m_maxNonlinIters
int m_maxNonlinIters
Maximum number of nonlinear solver iterations at one solution.
Definition IdasIntegrator.h:154
Cantera::IdasIntegrator::m_sens_ok
bool m_sens_ok
Indicates whether the sensitivities stored in m_yS and m_ySdot have been updated for the current inte...
Definition IdasIntegrator.h:148
Cantera::IdasIntegrator::maxSteps
int maxSteps() override
Returns the maximum number of time-steps the integrator can take before reaching the next output time...
Definition IdasIntegrator.cpp:161
Cantera::IdasIntegrator::m_sundials_ctx
SundialsContext m_sundials_ctx
SUNContext object for Sundials>=6.0.
Definition IdasIntegrator.h:104
Cantera::IdasIntegrator::m_func
FuncEval * m_func
Object implementing the DAE residual function .
Definition IdasIntegrator.h:107
Cantera::IdasIntegrator::m_abstols
double m_abstols
Scalar absolute tolerance.
Definition IdasIntegrator.h:126
Cantera::IdasIntegrator::m_hmax
double m_hmax
Maximum time step size. Zero means infinity.
Definition IdasIntegrator.h:133
Cantera::IdasIntegrator::m_itol
int m_itol
Flag indicating whether scalar (IDA_SS) or vector (IDA_SV) absolute tolerances are being used.
Definition IdasIntegrator.h:122
Cantera::IdasIntegrator::m_maxErrTestFails
int m_maxErrTestFails
Maximum number of error test failures in attempting one step.
Definition IdasIntegrator.h:139
Cantera::IdasIntegrator::m_maxord
int m_maxord
Maximum order allowed for the BDF method.
Definition IdasIntegrator.h:124
Cantera::IdasIntegrator::setSensitivityTolerances
void setSensitivityTolerances(double reltol, double abstol) override
Set the sensitivity error tolerances.
Definition IdasIntegrator.cpp:123
Cantera::IdasIntegrator::applyOptions
void applyOptions()
Applies user-specified options to the underlying IDAS solver.
Definition IdasIntegrator.cpp:331
Cantera::IdasIntegrator::integrate
void integrate(double tout) override
Integrate the system of equations.
Definition IdasIntegrator.cpp:452
Cantera::IdasIntegrator::setTolerances
void setTolerances(double reltol, size_t n, double *abstol) override
Set error tolerances.
Definition IdasIntegrator.cpp:100
Cantera::IdasIntegrator::setLinearSolverType
void setLinearSolverType(const string &linearSolverType) override
Set the linear solver type.
Definition IdasIntegrator.cpp:130
Cantera::IdasIntegrator::m_reltol
double m_reltol
Relative tolerance for all state variables.
Definition IdasIntegrator.h:125
Cantera::IdasIntegrator::m_error_message
string m_error_message
Error message information provide by IDAS.
Definition IdasIntegrator.h:68
Cantera::IdasIntegrator::m_reltolsens
double m_reltolsens
Scalar relative tolerance for sensitivities.
Definition IdasIntegrator.h:127
Cantera::IdasIntegrator::m_yS
N_Vector * m_yS
Sensitivities of y, size m_np by m_neq.
Definition IdasIntegrator.h:142
Cantera::IdasIntegrator::setMaxErrTestFails
void setMaxErrTestFails(int n) override
Set the maximum permissible number of error test failures.
Definition IdasIntegrator.cpp:166
Cantera::IdasIntegrator::setMaxSteps
void setMaxSteps(int nmax) override
Set the maximum number of time-steps the integrator can take before reaching the next output time.
Definition IdasIntegrator.cpp:153
Cantera::IdasIntegrator::m_neq
size_t m_neq
Number of equations/variables in the system.
Definition IdasIntegrator.h:100
Cantera::IdasIntegrator::solverStats
AnyMap solverStats() const override
Get solver stats from integrator.
Definition IdasIntegrator.cpp:174
Cantera::IdasIntegrator::m_type
string m_type
The linear solver type.
Definition IdasIntegrator.h:118
Cantera::IdasIntegrator::m_np
size_t m_np
Number of sensitivity parameters.
Definition IdasIntegrator.h:141
Cantera::IdasIntegrator::m_linsol_matrix
void * m_linsol_matrix
matrix used by Sundials
Definition IdasIntegrator.h:103
Cantera::IdasIntegrator::m_ydot
N_Vector m_ydot
The time derivatives of the system state.
Definition IdasIntegrator.h:116
Cantera::IdasIntegrator::m_ySdot
N_Vector * m_ySdot
Sensitivities of ydot, size m_np by m_neq.
Definition IdasIntegrator.h:143
Cantera::IdasIntegrator::m_tInteg
double m_tInteg
The latest time reached by the integrator. May be greater than m_time.
Definition IdasIntegrator.h:113
Cantera::IdasIntegrator::initialize
void initialize(double t0, FuncEval &func) override
Initialize the integrator for a new problem.
Definition IdasIntegrator.cpp:225
Cantera::IdasIntegrator::m_maxsteps
int m_maxsteps
Maximum number of internal steps taken in a call to integrate()
Definition IdasIntegrator.h:136
Cantera::IdasIntegrator::getErrorInfo
string getErrorInfo(int N)
Returns a string listing the weighted error estimates associated with each solution component.
Definition IdasIntegrator.cpp:531
Cantera::IdasIntegrator::IdasIntegrator
IdasIntegrator()
Constructor.
Definition IdasIntegrator.cpp:66
Cantera::IdasIntegrator::setMethod
void setMethod(MethodType t) override
Set the solution method.
Definition IdasIntegrator.cpp:571
Cantera::IdasIntegrator::m_ida_mem
void * m_ida_mem
Pointer to the IDA memory for the problem.
Definition IdasIntegrator.h:101
Cantera::IdasIntegrator::m_setSuppressAlg
bool m_setSuppressAlg
If true, the algebraic variables don't contribute to error tolerances.
Definition IdasIntegrator.h:160
Cantera::IdasIntegrator::m_abstol
N_Vector m_abstol
Absolute tolerances for each state variable.
Definition IdasIntegrator.h:117
Cantera::Integrator::linearSolverType
virtual string linearSolverType() const
Return the integrator problem type.
Definition Integrator.h:152
Cantera::Integrator::lastOrder
virtual int lastOrder() const
Order used during the last solution step.
Definition Integrator.h:209
Cantera::SundialsContext
A wrapper for managing a SUNContext object, need for Sundials >= 6.0.
Definition SundialsContext.h:20
fmt_append
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
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::ida_err
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.
Definition IdasIntegrator.cpp:56
Cantera::MethodType
MethodType
Specifies the method used to integrate the system of equations.
Definition Integrator.h:30
Cantera::BDF_Method
@ BDF_Method
Backward Differentiation.
Definition Integrator.h:31
Cantera::ida_rhs
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.
Definition IdasIntegrator.cpp:47
stringUtils.h
Contains declarations for string manipulation functions within Cantera.