Class Integrator#

Nested Relationships#

Nested Types#

Inheritance Relationships#

Base Type#

Derived Types#

Class Documentation#

class Integrator : public Karana::Core::BaseWithVars#

Base class for numerical integrators.

Subclassed by Karana::Integrators::EulerIntegrator, Karana::Integrators::IdaIntegrator, Karana::Integrators::NoopIntegrator, Karana::Integrators::RK4Integrator, Karana::Integrators::SundialsIntegrator

Public Functions

Integrator(const IntegratorType &integrator_type, size_t nstates, DerivativeFunction deriv_fn, const IntegratorOptions *options = nullptr)#

Constructor.

Parameters:
  • integrator_type – the type of this integrator

  • nstates – the length of the states vector

  • deriv_fn – the derivative function

  • options – options for the integrator

virtual ~Integrator()#

Destructor.

void _discard(kc::ks_ptr<kc::Base> &base) override#

Discard the Integrator.

Parameters:

base – A base pointer to the Integrator to discard.

virtual km::Ktime advanceTo(const km::Ktime &to_t) = 0#

Method to advance the system state to a specified time.

Parameters:

to_t – the desired end time

Returns:

the actual end time

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

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 void hardReset(size_t nstates)#

Reset the state size.

Parameters:

nstates – the new state size

const km::Vec &getX() const#

Return the current integrator state.

Returns:

the integrator state vector

km::Ktime getTime() const#

Return the current integrator time.

Returns:

the integrator state time

virtual const kc::ks_ptr<IntegratorOptions> getOptions() const#

Get the options associated with the integrator.

Returns:

The options associated with the integrator.

IntegratorType getIntegratorType() const#

Get the IntegratorType for this integrator.

Returns:

The IntegratorType for this integrator.

DerivativeFunction derivFunction() const#

Return the derivative function.

Returns:

the derivative function

virtual void updateJacobian(const km::Mat &mat)#

Update the stored Jacobian matrix with the provided one.

This is currently an experimental feature - and not all integrators support the use of Jacobians.

Parameters:

mat – the new Jacobian matrix

size_t nStates() const#

Return the state size.

Returns:

the integrator state size

virtual void setVerboseTracing(bool verbose)#

Tell the integrator to be very verbose; mostly used for debugging numerics in a brute-force approach.

Parameters:

verbose

Public Static Functions

static kc::ks_ptr<Integrator> create(const IntegratorType &integrator_type, size_t nstates, DerivativeFunction deriv_fn, const IntegratorOptions *options = nullptr)#

Factory method for creating an ODE Integrator instances.

Parameters:
  • integrator_type – the type of integrator to create

  • nstates – the length of the states vector

  • deriv_fn – the derivative function

  • options – options for the integrator

Returns:

a new ODE Integrator instance

static kc::ks_ptr<Integrator> create(const IntegratorType &integrator_type, size_t nstates, size_t nalgebraic, ResidualsFunction residuals_fn, const IntegratorOptions *options = nullptr)#

Factory method for creating a DAE Integrator instances.

Parameters:
  • integrator_type – the type of integrator to create

  • nstates – the length of the states vector (continuous+algebraic)

  • nalgebraic – the number of algebraic values

  • residuals_fn – the residuals function

  • options – options for the integrator

Returns:

a new DAE Integrator instance

Protected Attributes

bool _verbose_tracing#

Whether to log all integrator stats to a.

km::Ktime _t#

current time

km::Vec _x#

current state

size_t _nstates = 0#

The number of states the integrator has.

DerivativeFunction _deriv_fn = nullptr#

The derivative function used to calculate the derivative of the states.

IntegratorType _integrator_type#

The integrator type.

struct IntegratorOptions#

A struct with integrator options. This struct can be sub-classed by specialized classes to add custom options.

Subclassed by Karana::Integrators::IdaIntegrator::IntegratorOptions, Karana::Integrators::SundialsIntegrator::IntegratorOptions

Public Functions

IntegratorOptions() = default#

Constructor

IntegratorOptions(const IntegratorOptions&) = default#

Copy constructor

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

Assignment operator.

Parameters:

p – The IntegratorOptions to assign from.

Returns:

A reference to the IntegratorOptions assigned to.

virtual ~IntegratorOptions() = default#