MCPcopy Create free account
hub / github.com/Cantera/cantera / initialize

Method initialize

src/numerics/IdasIntegrator.cpp:232–326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

230}
231
232void IdasIntegrator::initialize(double t0, FuncEval& func)
233{
234 m_neq = func.neq();
235 m_t0 = t0;
236 m_time = t0;
237 m_tInteg = t0;
238 m_func = &func;
239 func.clearErrors();
240
241 if (m_y) {
242 N_VDestroy_Serial(m_y); // free solution vector if already allocated
243 }
244 m_y = newNVector(static_cast<sd_size_t>(m_neq), m_sundials_ctx);
245 N_VConst(0.0, m_y);
246
247 if (m_ydot) {
248 N_VDestroy_Serial(m_ydot); // free derivative vector if already allocated
249 }
250 m_ydot = newNVector(m_neq, m_sundials_ctx);
251 N_VConst(0.0, m_ydot);
252
253 // check abs tolerance array size
254 if (m_itol == IDA_SV && m_nabs < m_neq) {
255 throw CanteraError("IdasIntegrator::initialize",
256 "not enough absolute tolerance values specified.");
257 }
258
259 if (m_constraints) {
260 N_VDestroy_Serial(m_constraints);
261 }
262 m_constraints = newNVector(static_cast<sd_size_t>(m_neq), m_sundials_ctx);
263 // set the constraints
264 func.getConstraints(NV_DATA_S(m_constraints));
265
266 // get the initial conditions
267 func.getStateDae(NV_DATA_S(m_y), NV_DATA_S(m_ydot));
268
269 if (m_ida_mem) {
270 IDAFree(&m_ida_mem);
271 }
272
273 //! Create the IDA solver
274 #if SUNDIALS_VERSION_MAJOR >= 6
275 m_ida_mem = IDACreate(m_sundials_ctx.get());
276 #else
277 m_ida_mem = IDACreate();
278 #endif
279 if (!m_ida_mem) {
280 throw CanteraError("IdasIntegrator::initialize", "IDACreate failed.");
281 }
282
283 int flag = IDAInit(m_ida_mem, ida_rhs, m_t0, m_y, m_ydot);
284 if (flag != IDA_SUCCESS) {
285 if (flag == IDA_MEM_FAIL) {
286 throw CanteraError("IdasIntegrator::initialize",
287 "Memory allocation failed.");
288 } else if (flag == IDA_ILL_INPUT) {
289 throw CanteraError("IdasIntegrator::initialize",

Callers 2

resizeMethod · 0.45
setLinearSolverMethod · 0.45

Calls 8

CanteraErrorClass · 0.85
clearErrorsMethod · 0.80
newNVectorFunction · 0.70
neqMethod · 0.45
getConstraintsMethod · 0.45
getStateDaeMethod · 0.45
getMethod · 0.45
nparamsMethod · 0.45

Tested by

no test coverage detected