Class IdaIntegrator#

Nested Relationships#

Nested Types#

Inheritance Relationships#

Base Type#

Class Documentation#

class IdaIntegrator : public Karana::Math::Integrator#

The IDA DAE integrator from the SUNDIALS suite.

Public Types

enum class NLSOLVER#

the nonlinear solver type to use

Values:

enumerator FIXEDPOINT#
enumerator NEWTON#
enum class METHOD#

the solver type to use

Values:

enumerator ADAMS#
enumerator BDF#

Public Functions

IdaIntegrator(size_t nstates, size_t nalgebraic, ResidualsFunction f, const IntegratorOptions *options = nullptr)#

Constructor.

Parameters:
  • nstates – The number of states to integrate.

  • nalgebraic – The number of algebraic states.

  • f – The derivative function to calculate the derivative of the states.

  • options – The integrator options.

~IdaIntegrator()#
virtual std::string_view typeString() const override#

Return the integrator type as a string.

Returns:

the integrator type

virtual void hardReset(size_t nstates) override#

Reset the state size.

Parameters:

nstates – the new state size

virtual void softReset(const Ktime &new_t, const Vec &new_x) override#

Reset the cached time and state and to the new values going forward.

Parameters:
  • new_t – the new time

  • new_x – the new state

virtual Ktime advanceTo(const Ktime &t_end) override#

Method to advance the system state to a specified time.

Parameters:

to_t – the desired end time

Returns:

the actual end time

virtual std::unique_ptr<Integrator::IntegratorOptions> getOptions() override#

Get the options associated with the integrator.

Returns:

The options associated with the integrator.

virtual IntegratorType getIntegratorType() const override#

Get the IntegratorType for this integrator.

Returns:

The IntegratorType for this integrator.

Vec getErrorContributions() const#

Get the error contribution for each state.

Returns:

A vector with the error contribution for each state.

Vec &residuals()#

Get the current integrator residuals.

Returns:

A reference to the current integrator residuals.

Protected Attributes

SUNContext _sunctx = nullptr#

The Sundials context object.

N_Vector _y = nullptr#

Buffer for the state. This combines continuous states followed by algebraic states.

N_Vector _ydot = nullptr#

Buffer for the state derivatives. This combines continuous states derivatives followed by algebraic state derivatives.

N_Vector _y_id#

Buffer for the SetID. This sets which states are algebraic vs differential.

Vec _iresiduals#

Buffer for residuals. This buffer is also used for initializing the setting the integrator’s “ydot” values when doing a soft reset. It is also used by the residuals callback to transfer the residual values to ida.

size_t _nalgebraic#

The number of algebraic states. nstates = sg.nQ() + sg.nU()

  • nalgebraic

SUNMatrix _a_mat = nullptr#

Matrix used in the linear solver.

SUNLinearSolver _ls = nullptr#

Linear solver.

SUNNonlinearSolver _nls = nullptr#

Nonlinear solver.

void *_ida_mem#

The IDA memory.

ResidualsFunction _residuals_fn = nullptr#

The residuals function.

Protected Static Functions

static int _ida_f(realtype t, N_Vector y, N_Vector yguess, N_Vector residual, void *user_data)#

Calculate the residuals using the user-provided residuals function.

Parameters:
  • t – The time to calculate the residuals at.

  • y – The state to calculate the residuals for.

  • yguess – The estimated derivative of the states.

  • residual – The vector to populate with the residual.

  • user_data – Extra data used to calculate the residuals.

Returns:

An error code indicated success or failure of the call.

struct IntegratorOptions : public Karana::Math::Integrator::IntegratorOptions#

Struct with options for this integrator

Public Functions

IntegratorOptions() = default#
IntegratorOptions(const IntegratorOptions &p)#

Copy constructor.

Parameters:

p – The IntegratorOptions to copy values from.

IntegratorOptions &operator=(const IntegratorOptions &p)#

Assignment operator.

Parameters:

p – The IntegratorOptions to copy values from.

Returns:

A reference to the newly assigned IntegratorOptions.

virtual ~IntegratorOptions()#

Public Members

double rtol = 1e-4#

The desired relative tolerance used to control the integrator error.

double atol = 1e-8#

The desired absolute tolerance used to control the integrator error.

Vec atol_vec#

The desired absolute tolerance vector used to control the integrator error. This can be used rather than a scalar tolerance to set different values for different states.

long max_num_steps = 1e6#

The maximum number of steps the solver can take before throwing a too much work error.

bool suppress_algebraric = false#

Whether to suppress the local error test for algebraic variables. Recommended to enable for index 2/3 DAEs, but not for index 1 DAEs.

unsigned int anderson_accel = 0#

Anderson acceleration used with the FixedPoint solver.

NLSOLVER nlsolver = NLSOLVER::FIXEDPOINT#

The Nonlinear solver type to use.

METHOD method = METHOD::ADAMS#

The solver method to use.