Template Class KModel#

Inheritance Relationships#

Base Type#

Class Documentation#

template<class T, class P = NoParams, class Sc = NoScratch, class S = NoDiscreteStates, class C = NoContinuousStates>
class KModel : public Karana::Models::BaseKModel#

KModel<T,P,Sc,S,C> uses the curiously recurring template pattern (CRTP) to determine what methods the derived class has, and make the appropriate calls. All C++ models should derive from this. Python models will have a different class to derive from. See the KModel component models section for more discussion about the KModel class.

Public Functions

inline virtual bool isReady() const override#

Checks whether the model is ready.

Returns:

bool - Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.

inline virtual std::optional<km::Ktime> getNextModelStepTime(const km::Ktime &t) final#

Get the model’s next time step after t.

Parameters:

t – The t to use when calculating the next time step.

Returns:

The model’s next time step.

inline virtual km::Ktime getPeriod() final override#

Get the model’s period.

Returns:

The model’s period.

inline virtual void setPeriod(const km::Ktime &t) override#

Set the model’s period.

Parameters:

t – - The value to set the model’s period to.

BaseKModel(std::string_view name, const kc::ks_ptr<kd::ModelManager> &mm)#

BaseKModel constructor. The constructor is not meant to be called directly. Please use the create(…) method instead to create an instance.

Parameters:
  • name – - The name of the model

  • mm – - The ModelManager associated with the model.

Public Members

kc::ks_ptr<P> params = nullptr#

The parameters for the model.

kc::ks_ptr<Sc> scratch = nullptr#

The scratch for the model.

kc::ks_ptr<S> discrete_states = nullptr#

The discrete states for the model.

kc::ks_ptr<C> continuous_states = nullptr#

The continuous states for the model.

Protected Functions

inline virtual void _registerModel() override#

Register this model instance with the state propagator. See the.

Registering and unregistering models for details.

inline virtual void _unregisterModel() override#

Unregister this model instance from the state propagator. See the.

Registering and unregistering models for details.

inline virtual const Eigen::Ref<const km::Vec> _getContinuousStates() const override#

Get model continuous states. Overridden by KModel if appropriate.

Returns:

The model’s continuous states.

inline virtual const Eigen::Ref<const km::Vec> _getContinuousStatesDeriv() override#

Get the derivative of the continuous states. Overridden by KModel if appropriate.

Returns:

The model’s continuous states’ derivatives.

inline virtual void _setContinuousStates(const Eigen::Ref<const km::Vec> x) override#

Set the continuous model states.

Parameters:

x – The new continuous model states.

inline std::string dumpString(std::string_view prefix = "", const Base::DumpOptions* = nullptr) const override#