# File kernel/src/modelingTools/FirstOrderNonLinearDS.hpp¶

Go to the source code of this file

First Order Non Linear Dynamical Systems.

class FirstOrderNonLinearDS : public DynamicalSystem
#include <FirstOrderNonLinearDS.hpp>

General First Order Non Linear Dynamical Systems - $$M(t) \dot{x} = f(x,t,z) + r, \quad x(t_0) = x_0$$.

This class defines and computes a generic n-dimensional dynamical system of the form :

$$M \dot x = f(x,t,z) + r, \quad x(t_0) = x_0$$

where

• $$x \in R^{n}$$ is the state.

• $$M \in R^{n\times n}$$ a “mass matrix”

• $$r \in R^{n}$$ the input due to the Non Smooth Interaction.

• $$z \in R^{zSize}$$ is a vector of arbitrary algebraic variables, some sort of discret state. For example, z may be used to set some perturbation parameters, to control the system (z set by actuators) and so on.

• $$f : R^{n} \times R \mapsto R^{n}$$ the vector field.

By default, the DynamicalSystem is considered to be an Initial Value Problem (IVP) and the initial conditions are given by $$x(t_0)=x_0$$ To define a Boundary Value Problem, a pointer on a BoundaryCondition must be set.

The right-hand side and its jacobian (from base classe) are defined as

$\begin{split}rhs &=& \dot x = M^{-1}(f(x,t,z)+ r) \\ jacobianRhsx &=& \nabla_x rhs(x,t,z) = M^{-1}\nabla_x f(x,t,z)\end{split}$

The following operators can be plugged, in the usual way (see User Guide)

• $$f(x,t,z)$$

• $$\nabla_x f(x,t,z)$$

• $$M(t)$$

Subclassed by FirstOrderLinearDS

Right-hand side computation

virtual void initRhs(double time)

allocate (if needed) and compute rhs and its jacobian.

Parameters
• time: of initialization

void initializeNonSmoothInput(unsigned int level)

set nonsmooth input to zero

Parameters
• level: input-level to be initialized.

virtual void computeRhs(double time)

update right-hand side for the current state

Parameters
• time: of interest

void computeJacobianRhsx(double time)

update $$\nabla_x rhs$$ for the current state

Parameters
• time: of interest

virtual void resetAllNonSmoothParts()

reset non-smooth part of the rhs (i.e.

r), for all ‘levels’

virtual void resetNonSmoothPart(unsigned int level)

set nonsmooth part of the rhs (i.e.

r) to zero for a given level

Parameters
• level:

Attributes access

SP::SiconosMatrix M() const

returns a pointer to M, matrix coeff.

on left-hand side

void setMPtr(SP::SiconosMatrix newM)

set M, matrix coeff of left-hand side (pointer link)

Parameters
• newM: the new M matrix

const SimpleMatrix getInvM() const

get a copy of the LU factorisation of M operator

Return

SP::SiconosMatrix invM() const

get the inverse of LU fact.

Return

pointer to a SiconosMatrix

SP::SiconosVector f() const

void setFPtr(SP::SiconosVector newPtr)

Parameters
• newPtr: a SP::SiconosVector

virtual SP::SiconosMatrix jacobianfx() const

get jacobian of f(x,t,z) with respect to x (pointer link)

Return

SP::SiconosMatrix

void setJacobianfxPtr(SP::SiconosMatrix newPtr)

set jacobian of f(x,t,z) with respect to x (pointer link)

Parameters
• newPtr: the new value

Memory vectors management

const SiconosMemory &rMemory() const

get all the values of the state vector r stored in memory

Return

a memory vector

SP::SiconosVector fold() const

returns previous value of rhs >OSI Related!!

void initMemory(unsigned int steps)

initialize the SiconosMemory objects: reserve memory for i vectors in memory and reset all to zero.

Parameters
• steps: the size of the SiconosMemory (i)

void swapInMemory()

push the current values of x and r in memory (index 0 of memory is the last inserted vector) xMemory and rMemory,

Plugins management

virtual void updatePlugins(double time)

Call all plugged-function to initialize plugged-object values.

Parameters
• time: value

void setComputeMFunction(const std::string &pluginPath, const std::string &functionName)

to set a specified function to compute M

Parameters
• pluginPath: the complete path to the plugin

• functionName: function name to use in this library

Exceptions
• SiconosSharedLibraryException:

void setComputeMFunction(FPtr1 fct)

set a specified function to compute M

Parameters
• fct: a pointer on the plugin function

void setComputeFFunction(const std::string &pluginPath, const std::string &functionName)

to set a specified function to compute f(x,t)

Parameters
• pluginPath: the complete path to the plugin

• functionName: the function name to use in this library

Exceptions
• SiconosSharedLibraryException:

void setComputeFFunction(FPtr1 fct)

set a specified function to compute the vector f

Parameters
• fct: a pointer on the plugin function

void setComputeJacobianfxFunction(const std::string &pluginPath, const std::string &functionName)

to set a specified function to compute jacobianfx

Parameters
• pluginPath: the complete path to the plugin

• functionName: function name to use in this library

Exceptions
• SiconosSharedLibraryException:

void setComputeJacobianfxFunction(FPtr1 fct)

set a specified function to compute jacobianfx

Parameters
• fct: a pointer on the plugin function

void computeM(double time)

Default function to compute $$M: (x,t)$$.

Parameters
• time: time instant used in the computations

virtual void computef(double time, SP::SiconosVector state)

Default function to compute $$f: (x,t)$$.

Parameters
• time: time instant used in the computations function to compute $$f: (x,t)$$

• time: time instant used in the computations

• state: x value

virtual void computeJacobianfx(double time, SP::SiconosVector state)

Default function to compute $$\nabla_x f: (x,t) \in R^{n} \times R \mapsto R^{n \times n}$$ with x different from current saved state.

Parameters
• time: instant used in the computations

• state: a SiconosVector to store the resuting value

SP::PluggedObject getPluginF() const

Get _pluginf.

Return

a SP::PluggedObject

SP::PluggedObject getPluginJacxf() const

Get _pluginJacxf.

Return

a SP::PluggedObject

SP::PluggedObject getPluginM() const

Get _pluginM.

Return

a SP::PluggedObject

Miscellaneous public methods

void display(bool brief = true) const

print the data of the dynamical system on the standard output

Public Functions

FirstOrderNonLinearDS(SP::SiconosVector newX0)

constructor from initial state, leads to $$\dot x = r$$

Warning

you need to set explicitely the plugin for f and its jacobian if needed (e.g. if used with an EventDriven scheme)

Parameters
• newX0: initial state

FirstOrderNonLinearDS(SP::SiconosVector newX0, const std::string &fPlugin, const std::string &jacobianfxPlugin)

constructor from initial state and f (plugins), $$\dot x = f(x, t, z) + r$$

Parameters
• newX0: initial state

• fPlugin: name of the plugin function to be used for f(x,t,z)

• jacobianfxPlugin: name of the plugin to be used for the jacobian of f(x,t,z)

FirstOrderNonLinearDS(const FirstOrderNonLinearDS &FONLDS)

Copy constructor.

Parameters

virtual ~FirstOrderNonLinearDS()

destructor

ACCEPT_STD_VISITORS()

Protected Functions

FirstOrderNonLinearDS()

default constructor

void _init(SP::SiconosVector initial_state)

Common code for constructors should be replaced in C++11 by delegating constructors.

Parameters
• initial_state: vector of initial values for state

virtual void _zeroPlugin()

Reset the PluggedObjects.

ACCEPT_SERIALIZATION(FirstOrderNonLinearDS)

Protected Attributes

SP::SiconosVector _f

value of f(x,t,z)

SP::SiconosVector _fold

to store f(x_k,t_k,z_k)

SP::SiconosMatrix _invM

Copy of M Matrix, LU-factorized, used to solve systems like Mx = b with LU-factorization.

(Warning: may not exist, used if we need to avoid factorization in place of M)

SP::SiconosMatrix _jacobianfx

Gradient of $$f(x,t,z)$$ with respect to $$x$$.

SP::SiconosMatrix _M

Matrix coefficient of $$\dot x$$.

SP::PluggedObject _pluginf

DynamicalSystem plug-in to compute f(x,t,z)

Parameters
• current: time

• size: of the vector _x

• [inout] pointer: to the first element of the vector _x

• [inout] the: pointer to the first element of the vector _f

• the: size of the vector _z

• a: vector of parameters _z

SP::PluggedObject _pluginJacxf

DynamicalSystem plug-in to compute the gradient of f(x,t,z) with respect to the state: $$\nabla_x f: (x,t,z) \in R^{n} \times R \mapsto R^{n \times n}$$.

Parameters
• time: current time

• sizeOfX: size of vector x

• x: pointer to the first element of x

• [inout] jacob: pointer to the first element of jacobianfx matrix

• the: size of the vector z

• [inout] a: vector of parameters, z

SP::PluggedObject _pluginM
SiconosMemory _rMemory

the previous r vectors

Private Types

typedef void (*FNLDSPtrfct)(double, unsigned int, const double *, double *, unsigned int, double *)

plugin signature