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

Go to the source code of this file

LagrangianDS class - Second Order Non Linear Dynamical Systems.

class LagrangianDS : public SecondOrderDS
#include <LagrangianDS.hpp>

Lagrangian non linear dynamical systems - $$M(q,z) \dot v = F(v, q, t, z) + p$$.

This class defines and computes a generic ndof-dimensional Lagrangian Non Linear Dynamical System of the form :

$\begin{split}M(q,z) \dot v + F_{gyr}(v, q, z) + F_{int}(v , q , t, z) = F_{ext}(t, z) + p \\ \dot q = v\end{split}$

where

• $$q \in R^{ndof}$$ is the set of the generalized coordinates,

• $$\dot q =v \in R^{ndof}$$ the velocity, i. e. the time derivative of the generalized coordinates (Lagrangian systems).

• $$\ddot q =\dot v \in R^{ndof}$$ the acceleration, i. e. the second time derivative of the generalized coordinates.

• $$p \in R^{ndof}$$ the reaction forces due to the Non Smooth Interaction.

• $$M(q) \in R^{ndof \times ndof}$$ is the inertia term (access : mass() method).

• $$F_{gyr}(\dot q, q) \in R^{ndof}$$ is the non linear inertia term (access fGyr() method).

• $$F_{int}(\dot q , q , t) \in R^{ndof}$$ are the internal forces (access fInt() method).

• $$F_{ext}(t) \in R^{ndof}$$ are the external forces (access fExt() method).

• $$z \in R^{zSize}$$ is a vector of arbitrary algebraic variables, some sort of discrete state.

The equation of motion is also shortly denoted as $$M(q,z) \dot v = F(v, q, t, z) + p$$

where $$F(v, q, t, z) \in R^{ndof}$$ collects the total forces acting on the system, that is $$F(v, q, t, z) = F_{ext}(t, z) - F_{gyr}(v, q, z) + F_{int}(v, q , t, z)$$.

This vector is saved and may be accessed using forces() method.

q[i] is the derivative number i of q. Thus: q= $$q$$, global coordinates, q= $$\dot q$$, velocity, q= $$\ddot q$$, acceleration.

The following operators (and their jacobians) can be plugged, in the usual way (see User Guide, ‘User-defined plugins’)

If required (e.g. for Event-Driven like simulation), formulation as a first-order system is also available, and writes:

• $$n= 2 ndof$$

• $$x = \left[\begin{array}{c}q \\ \dot q\end{array}\right]$$

• rhs given by:

$\begin{split}\dot x = \left[\begin{array}{c} \dot q\\ \ddot q = M^{-1}(q)\left[F(v, q , t, z) + p \right]\\ \end{array}\right]\end{split}$

• jacobian of the rhs, with respect to x

$\begin{split}\nabla_{x}rhs(x,t) = \left[\begin{array}{cc} 0 & I \\ \nabla_{q}(M^{-1}(q)F(v, q , t, z)) & \nabla_{\dot q}(M^{-1}(q)F(v, q , t, z)) \\ \end{array}\right]\end{split}$

with the input due to the non smooth law:

$\begin{split}\left[\begin{array}{c} 0 \\ p \end{array}\right]\end{split}$

In that case, use the following methods:

Subclassed by LagrangianLinearDiagonalDS, LagrangianLinearTIDS

Right-hand side computation

void resetToInitialState()

reset the state to the initial state

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

virtual void computeJacobianRhsx(double time)

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

Parameters
• time: of interest

void resetAllNonSmoothParts()

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

p), for all ‘levels’

void resetNonSmoothPart(unsigned int level)

set nonsmooth part of the rhs (i.e.

p) to zero for a given level

Parameters
• level:

void setRhs(const SiconosVector &newValue)

set the value of the right-hand side, $$\dot x$$

Parameters

void setRhsPtr(SP::SiconosVector newPtr)

set right-hand side, $$\dot x$$ (pointer link)

Parameters
• newPtr: SP::SiconosVector

virtual void computeForces(double time, SP::SiconosVector q, SP::SiconosVector velocity)

function to compute $$F(v,q,t,z)$$ for the current state

Parameters
• time: the current timeCompute $$F(v,q,t,z)$$

• time: the current time

• q: SP::SiconosVector: pointers on q

• velocity: SP::SiconosVector: pointers on velocity

virtual void computeJacobianqForces(double time)

Compute $$\nabla_qF(v,q,t,z)$$ for current $$q,v$$ Default function to compute forces.

Parameters
• time: the current time

virtual void computeJacobianqDotForces(double time)

Compute $$\nabla_{\dot q}F(v,q,t,z)$$ for current $$q,v$$.

Parameters
• time: the current time

virtual void computeJacobianvForces(double time)

Compute $$\nabla_{\dot q}F(v,q,t,z)$$ for current $$q,v$$.

Parameters
• time: the current time

Attributes access

SP::SiconosVector q() const

generalized coordinates of the system (vector of size dimension())

Return

pointer on a SiconosVector

void setQ(const SiconosVector &newValue)

set value of generalized coordinates vector (copy)

Parameters
• newValue:

void setQPtr(SP::SiconosVector newPtr)

set value of generalized coordinates vector (pointer link)

Parameters
• newPtr:

void setQ0(const SiconosVector &newValue)

set initial state (copy)

Parameters
• newValue:

void setQ0Ptr(SP::SiconosVector newPtr)

Parameters
• newPtr:

SP::SiconosVector velocity() const

Return

pointer on a SiconosVector

void setVelocity(const SiconosVector &newValue)

set velocity vector (copy)

Parameters
• newValue:

void setVelocityPtr(SP::SiconosVector newPtr)

Parameters
• newPtr:

SP::SiconosVector velocity0() const

get initial velocity (pointer)

Return

pointer on a SiconosVector

void setVelocity0(const SiconosVector &newValue)

set initial velocity (copy)

Parameters
• newValue:

void setVelocity0Ptr(SP::SiconosVector newPtr)

Parameters
• newPtr:

SP::SiconosVector acceleration() const

Return

pointer on a SiconosVector

SP::SiconosVector fInt() const

get $F_{int}$ (pointer link)

Return

pointer on a plugged vector

void setFIntPtr(SP::SiconosVector newPtr)

set $F_{int}$ (pointer link)

Parameters
• newPtr: a SP to plugged vector

SP::SiconosVector fExt() const

get $$F_{ext}$$, (pointer link)

Return

pointer on a plugged vector

void setFExtPtr(SP::SiconosVector newPtr)

set $$F_{ext}$$, (pointer link)

Parameters
• newPtr: a SP to a Simple vector

SP::SiconosVector fGyr() const

get $$F_{gyr}$$, (pointer link)

Return

pointer on a plugged vector

void setFGyrPtr(SP::SiconosVector newPtr)

set $$F_{gyr}$$, (pointer link)

Parameters
• newPtr: a SP to plugged vector

SP::SiconosMatrix jacobianFIntq() const

get $$\nabla_qF_{int}$$, (pointer link)

Return

pointer on a SiconosMatrix

SP::SiconosMatrix jacobianFIntqDot() const

get $$\nabla_{\dot q}F_{int}$$, (pointer link)

Return

pointer on a SiconosMatrix

void allocateMass()
void allocateJacobianFIntq()
void allocateJacobianFIntqDot()
void allocateFInt()
void allocateFExt()
void setJacobianFIntqPtr(SP::SiconosMatrix newPtr)

set $$\nabla_{q}F_{int}$$, (pointer link)

Parameters

void setJacobianFIntqDotPtr(SP::SiconosMatrix newPtr)

set $$\nabla_{\dot q}F_{int}$$, (pointer link)

Parameters

SP::SiconosMatrix jacobianFGyrq() const

get $$\nabla_{q}F_{gyr}$$, (pointer link)

Return

pointer on a SiconosMatrix

SP::SiconosMatrix jacobianFGyrqDot() const

get $$\nabla_{\dot q}F_{gyr}$$, (pointer link)

Return

pointer on a SiconosMatrix

void setJacobianFGyrqPtr(SP::SiconosMatrix newPtr)

get $$\nabla_{q}F_{gyr}$$, (pointer link)

Parameters

void setJacobianFGyrqDotPtr(SP::SiconosMatrix newPtr)

get $$\nabla_{\dot q}F_{gyr}$$, (pointer link)

Parameters

SP::SiconosVector forces() const

get $$F(v,q,t,z)$$ (pointer link)

Return

pointer on a SiconosVector

virtual SP::SiconosMatrix jacobianqForces() const

get $$\nabla_qF(v,q,t,z)$$ (pointer link)

Return

pointer on a SiconosMatrix

virtual SP::SiconosMatrix jacobianvForces() const

get $$\nabla_{\dot q}F(v,q,t,z)$$ (pointer link)

Return

pointer on a SiconosMatrix

Memory vectors management

const SiconosMemory &qMemory()

get all the values of the state vector q stored in memory.

note: not const due to SchatzmanPaoliOSI::initializeWorkVectorsForDS

Return

a memory

const SiconosMemory &velocityMemory()

get all the values of the state vector velocity stored in memory.

note: not const due to SchatzmanPaoliOSI::initializeWorkVectorsForDS

Return

a memory

const SiconosMemory &pMemory(unsigned int level)

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

Return

a memory

Parameters
• level:

const SiconosMemory &forcesMemory()

get forces in memory buff

Return

pointer on a SiconosMemory

void initMemory(unsigned int size)

initialize the SiconosMemory objects with a positive size.

Parameters
• size: the size of the SiconosMemory. must be >= 0

void swapInMemory()

push the current values of x, q and r in the stored previous values xMemory, qMemory, rMemory,

Plugins management

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

allow to set a specified function to compute the mass

Parameters
• pluginPath: std::string : the complete path to the plugin

• functionName: std::string : the name of the function to use in this plugin

void setComputeMassFunction(FPtr7 fct)

set a specified function to compute Mass

Parameters
• fct: a pointer on the plugin function

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

allow to set a specified function to compute FInt

Parameters
• pluginPath: std::string : the complete path to the plugin

• functionName: std::string : the name of the function to use in this plugin

void setComputeFIntFunction(FPtr6 fct)

set a specified function to compute fInt

Parameters
• fct: a pointer on the plugin function

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

allow to set a specified function to compute Fext

Parameters
• pluginPath: std::string : the complete path to the plugin

• functionName: std::string : the name of the function to use in this plugin

void setComputeFExtFunction(VectorFunctionOfTime fct)

set a specified function to compute fExt

Parameters
• fct: a pointer on the plugin function

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

allow to set a specified function to compute the inertia

Parameters
• pluginPath: std::string : the complete path to the plugin

• functionName: std::string : the name of the function to use in this plugin

void setComputeFGyrFunction(FPtr5 fct)

set a specified function to compute FGyr

Parameters
• fct: a pointer on the plugin function

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

allow to set a specified function to compute the jacobian w.r.t q of the internal forces

Parameters
• pluginPath: std::string : the complete path to the plugin

• functionName: std::string : the name of the function to use in this plugin

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

allow to set a specified function to compute the jacobian following qDot of the internal forces w.r.t.

Parameters
• pluginPath: std::string : the complete path to the plugin

• functionName: std::string : the name of the function to use in this plugin

void setComputeJacobianFIntqFunction(FPtr6 fct)

set a specified function to compute jacobian following q of the FInt

Parameters
• fct: a pointer on the plugin function

void setComputeJacobianFIntqDotFunction(FPtr6 fct)

set a specified function to compute jacobian following qDot of the FInt

Parameters
• fct: a pointer on the plugin function

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

allow to set a specified function to compute the jacobian w.r.t q of the the external forces

Parameters
• pluginPath: std::string : the complete path to the plugin

• functionName: std::string : the name of the function to use in this plugin

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

allow to set a specified function to compute the jacobian w.r.t qDot of the the external strength

Parameters
• pluginPath: std::string : the complete path to the plugin

• functionName: std::string : the name of the function to use in this plugin

void setComputeJacobianFGyrqFunction(FPtr5 fct)

set a specified function to compute the jacobian following q of FGyr

Parameters
• fct: a pointer on the plugin function

void setComputeJacobianFGyrqDotFunction(FPtr5 fct)

set a specified function to compute the jacobian following qDot of FGyr

Parameters
• fct: a pointer on the plugin function

virtual void computeMass()

default function to compute the mass

virtual void computeMass(SP::SiconosVector position)

function to compute the mass

Parameters
• position: value used to evaluate the mass matrix

virtual void computeFInt(double time)

default function to compute the internal strengths

Parameters
• time: the current time

virtual void computeFInt(double time, SP::SiconosVector position, SP::SiconosVector velocity)

function to compute the internal strengths with some specific values for position and velocity (ie not those of the current state).

Parameters
• time: the current time,

• position: value used to evaluate the internal forces

• velocity: value used to evaluate the internal forces

virtual void computeFExt(double time)

default function to compute the external strengths

Parameters
• time: the current time

virtual void computeFGyr()

default function to compute the inertia

virtual void computeFGyr(SP::SiconosVector position, SP::SiconosVector velocity)

function to compute the inertia with some specific values for q and velocity (ie not those of the current state).

Parameters
• position: value used to evaluate the inertia forces

• velocity: value used to evaluate the inertia forces

virtual void computeJacobianFIntq(double time)

To compute the jacobian w.r.t q of the internal forces.

Parameters
• time: the current time

virtual void computeJacobianFIntqDot(double time)

To compute the jacobian w.r.t qDot of the internal forces.

Parameters
• time: the current time

virtual void computeJacobianFIntq(double time, SP::SiconosVector position, SP::SiconosVector velocity)

To compute the jacobian w.r.t q of the internal forces.

Parameters
• time: the current time

• position: value used to evaluate the jacobian

• velocity: value used to evaluate the jacobian

virtual void computeJacobianFIntqDot(double time, SP::SiconosVector position, SP::SiconosVector velocity)

To compute the jacobian w.r.t.

qDot of the internal forces

Parameters
• time: the current time

• position: value used to evaluate the jacobian

• velocity: value used to evaluate the jacobian

virtual void computeJacobianFGyrq()

function to compute the jacobian w.r.t.

q of the inertia forces

virtual void computeJacobianFGyrqDot()

function to compute the jacobian w.r.t.

qDot of the inertia forces

virtual void computeJacobianFGyrq(SP::SiconosVector position, SP::SiconosVector velocity)

function to compute the jacobian w.r.t.

q of the inertia forces

Parameters
• position: value used to evaluate the jacobian

• velocity: value used to evaluate the jacobian

virtual void computeJacobianFGyrqDot(SP::SiconosVector position, SP::SiconosVector velocity)

function to compute the jacobian w.r.t.

qDot of the inertia forces

Parameters
• position: value used to evaluate the jacobian

• velocity: value used to evaluate the jacobian

virtual void updatePlugins(double time)

default function to update the plugins functions using a new time:

Parameters
• time: the current time

Miscellaneous public methods

double computeKineticEnergy()

To compute the kinetic energy.

void display(bool brief = true) const

print the data of the dynamical system on the standard output

void computePostImpactVelocity()

Computes post-impact velocity, using pre-impact velocity and impulse (p) value.

void init_generalized_coordinates(unsigned int level)

Allocate memory for q[level], level > 1 Useful for some integrators that need q or other coordinates vectors.

Parameters
• level: the required level

void init_inverse_mass()

Allocate memory for the lu factorization of the mass of the system.

Useful for some integrators with system inversion involving the mass

void update_inverse_mass()

Update the content of the lu factorization of the mass of the system, if required.

void init_forces()

Allocate memory for forces and its jacobian.

Public Functions

LagrangianDS(SP::SiconosVector position, SP::SiconosVector velocity)

constructor from initial state only, $$dv = p$$

Parameters

LagrangianDS(SP::SiconosVector position, SP::SiconosVector velocity, SP::SiconosMatrix mass)

constructor from initial state and mass, $$Mdv = p$$

Parameters

LagrangianDS(SP::SiconosVector position, SP::SiconosVector velocity, const std::string &plugin)

constructor from initial state and mass (plugin) $$Mdv = p$$

Parameters

virtual ~LagrangianDS()

destructor

ACCEPT_STD_VISITORS()

Protected Types

enum LagrangianDSRhsMatrices

Values:

jacobianXBloc10
jacobianXBloc11
zeroMatrix
idMatrix
numberOfRhsMatrices

Protected Functions

LagrangianDS()

Default constructor.

void _init(SP::SiconosVector position, SP::SiconosVector velocity)

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

Parameters
• position: vector of initial positions

• velocity: vector of initial velocities

void _zeroPlugin()

build all _plugin…

ACCEPT_SERIALIZATION(LagrangianDS)

Protected Attributes

SP::SiconosVector _fExt

external forces applied to the system

SP::SiconosVector _fGyr

non-linear inertia term of the system

SP::SiconosVector _fInt

internal forces applied to the system

SP::SiconosVector _forces

forces(q,q,t)= fExt - fInt -FGyr

SiconosMemory _forcesMemory

memory of previous forces of the system

bool _hasConstantFExt

boolean if _fext is constant (set thanks to setFExtPtr for instance) false by default

SP::SiconosMatrix _jacobianFGyrq

jacobian_q FGyrq

SP::SiconosMatrix _jacobianFGyrqDot

jacobian_{qDot} FGyrq

SP::SiconosMatrix _jacobianFIntq

jacobian_q FInt

SP::SiconosMatrix _jacobianFIntqDot

jacobian_{qDot} FInt

SP::SiconosMatrix _jacobianqDotForces

jacobian_{qDot} forces

SP::SiconosMatrix _jacobianqForces

jacobian_q forces

SP::PluggedObject _pluginFExt

LagrangianDS plug-in to compute external forces $$F_{Ext}(t)$$, id = “fExt”.

Parameters
• time: : current time

• sizeOfq: : size of vector q

• [inout] fExt: : pointer to the first element of fExt

• size: of vector z

• [inout] z: : a vector of user-defined parameters

SP::PluggedObject _pluginFGyr

LagrangianDS plug-in to compute $$FGyr(\dot q, q)$$, id = “FGyr”.

Parameters
• sizeOfq: : size of vector q

• q: : pointer to the first element of q

• velocity: : pointer to the first element of velocity

• [inout] FGyr: : pointer to the first element of FGyr

• size: of vector z

• [inout] z: : a vector of user-defined parameters

SP::PluggedObject _pluginFInt

LagrangianDS plug-in to compute internal forces $$F_{int}(t,q,\dot q)$$ - id = “fInt”.

Parameters
• time: : current time

• sizeOfq: : size of vector q

• q: : pointer to the first element of q

• velocity: : pointer to the first element of velocity

• [inout] fInt: : pointer to the first element of fInt

• size: of vector z

• [inout] z: : a vector of user-defined parameters

SP::PluggedObject _pluginJacqDotFGyr

LagrangianDS plug-in to compute $$\nabla_{\dot q}FGyr(\dot q, q)$$, id = “jacobianFGyrqDot”.

Parameters
• sizeOfq: : size of vector q

• q: : pointer to the first element of q

• velocity: : pointer to the first element of velocity

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

• size: of vector z

• [inout] z: : a vector of user-defined parameters

SP::PluggedObject _pluginJacqDotFInt

LagrangianDS plug-in to compute $$\nabla_{\dot q}F_{Int}(\dot q, q, t)$$, id = “jacobianFIntqDot”.

Parameters
• time: : current time

• sizeOfq: : size of vector q

• q: : pointer to the first element of q

• velocity: : pointer to the first element of velocity

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

• size: of vector z

• [inout] z: : a vector of user-defined parameters

SP::PluggedObject _pluginJacqFGyr

LagrangianDS plug-in to compute $$\nabla_qFGyr(\dot q, q)$$, id = “jacobianFGyrq”.

Parameters
• sizeOfq: : size of vector q

• q: : pointer to the first element of q

• velocity: : pointer to the first element of velocity

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

• size: of vector z

• [inout] z: : a vector of user-defined parameters

SP::PluggedObject _pluginJacqFInt

LagrangianDS plug-in to compute $$\nabla_qF_{Int}(\dot q, q, t)$$, id = “jacobianFIntq”.

Parameters
• time: : current time

• sizeOfq: : size of vector q

• q: : pointer to the first element of q

• velocity: : pointer to the first element of velocity

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

• size: of vector z

• [inout] z: : a vector of user-defined parameters

SP::PluggedObject _pluginMass

LagrangianDS plug-in to compute mass(q,t) - id = “mass”.

Parameters
• sizeOfq: : size of vector q

• q: : pointer to the first element of q

• [inout] mass: : pointer to the first element of mass

• size: of vector z

• [inout] z: : a vector of user-defined parameters

VectorOfVectors _q

state of the system.

See details on top of page.

SiconosMemory _qMemory

memory of previous coordinates of the system

VectorOfSMatrices _rhsMatrices

A container of matrices to save matrices that are involed in first order from of LagrangianDS system values (jacobianXBloc10, jacobianXBloc11, zeroMatrix, idMatrix) No get-set functions at the time.

Only used as a protected member.

SP::SiconosVector _velocity0

initial velocity of the system

SiconosMemory _velocityMemory

memory of previous velocities of the system