Class Simulation

Contents

Class Simulation#

Defined in Program listing for file kernel/src/simulationTools/Simulation.hpp

class Simulation : public std::enable_shared_from_this<Simulation>#

Description of the simulation process (integrators, time discretisation and so on).

This is an abstract class.

The available simulations are TimeStepping, EventDriven and TimeSteppingD1Minus.

Subclassed by EventDriven, TimeStepping, TimeSteppingD1Minus

Public Functions

inline Simulation()#

default constructor, for serialization

Simulation(SP::NonSmoothDynamicalSystem nsds, SP::TimeDiscretisation td)#

default constructor

Parameters:
  • nsds – current nonsmooth dynamical system

  • td – the timeDiscretisation for this Simulation

Simulation(SP::TimeDiscretisation td)#

constructor with only a TimeDiscretisation

Parameters:

td – the timeDiscretisation for this Simulation

virtual ~Simulation()#

destructor

void clear()#

clear all maps.

This function should not exist, but there is a cycle with the shared_ptr: the OneStepIntegrator and OneStepNSProblem have both a link to the Simulation, and here we have all the OneStepIntegrator and OneStepNSProblem in maps. Then the memory is never freed. The clumsy way to deal with it is to call this function from the Model destructor to free the maps and then the cycle is broken

Warning

do not call this yourself, it is meant to be called from the desctructor of the Model

inline const std::string name() const#

get the name of the Simulation

Returns:

std::string : the name of the Simulation

inline void setName(const std::string &newName)#

set the name of the Simulation

Parameters:

newName – the new name

double getTk() const#

returns time instant k of the time discretisation

double getTkp1() const#

get time instant k+1 of the time discretisation

Warning

: this instant may be different from nextTime(), if for example some non-smooth events or some sensor events are present

Returns:

a double. If the simulation is near the end (t_{k+1} > T), it returns NaN.

double getTkp2() const#

get time instant k+2 of the time discretisation

Warning

: this instant may be different from nextTime(), if for example some non-smooth events or some sensor events are present

Returns:

a double. If the simulation is near the end (t_{k+2} > T), it returns NaN.

double currentTimeStep() const#

returns current timestep

inline SP::EventsManager eventsManager() const#

returns a pointer to the EventsManager

double startingTime() const#

get “current time” (ie starting point for current integration, time of currentEvent of eventsManager.)

Returns:

a double.

double nextTime() const#

get “next time” (ie ending point for current integration, time of nextEvent of eventsManager.)

Returns:

a double.

inline double timeStep() const#

get the current time step size (“next time”-“current time”)

Returns:

a double.

bool hasNextEvent() const#

true if a future event is to be treated or not (ie if some events remain in the eventsManager).

inline const SP::OSISet oneStepIntegrators() const#

get all the Integrators of the Simulation

Returns:

an OSISset

inline size_t numberOfOSI() const#

get the number of OSIs in the Simulation (ie the size of allOSI)

Returns:

an unsigned int

virtual void insertIntegrator(SP::OneStepIntegrator osi)#

insert an Integrator into the simulation list of integrators

Parameters:

osi – the OneStepIntegrator to add

void associate(SP::OneStepIntegrator osi, SP::DynamicalSystem ds)#

associate an OSI with a DS

SP::InteractionsGraph indexSet(unsigned int i)#

get a pointer to indexSets[i]

Parameters:

i – number of the required index set

Returns:

a graph of interactions

inline const SP::OneStepNSProblems oneStepNSProblems() const#

get allNSProblems

Returns:

a pointer to OneStepNSProblems object (container of SP::OneStepNSProblem)

inline size_t numberOfOSNSProblems() const#

get the number of OSNSP in the Simulation (ie the size of allNSProblems)

Returns:

an unsigned int

SP::OneStepNSProblem oneStepNSProblem(int id)#

get a OneStep nonsmooth problem of the simulation, identify with its number.

Parameters:

id – number of the required osnspb

Returns:

a pointer to OneStepNSProblem

virtual void insertNonSmoothProblem(SP::OneStepNSProblem osns, int Id = SICONOS_OSNSP_DEFAULT)#

add a OneStepNSProblem in the Simulation

Parameters:
  • osns – the OneStepNSProblem to insert

  • Id – its id: default is SICONOS_OSNSP_DEFAULT, at impact level SICONOS_OSNSP_ED_IMPACT, at acceleration level SICONOS_OSNSP_ED_ACCELERATION

inline SP::NonSmoothDynamicalSystem nonSmoothDynamicalSystem() const#

get the NonSmoothDynamicalSystem

Returns:

NonSmoothDynamicalSystem

inline void setNonSmoothDynamicalSystemPtr(SP::NonSmoothDynamicalSystem newPtr)#

set the NonSmoothDynamicalSystem of the Simulation

Parameters:

newPtr – a pointer on NonSmoothDynamicalSystem

inline double tolerance() const#

get tolerance

Returns:

a double

inline void setTolerance(double inputVal)#

set the value of offset for q dof vector in dynamical systems (to avoid events accumulation)

Parameters:

inputVal – new tolerance

inline void setPrintStat(const bool &newVal)#

set printStat value: if true, print solver stats.

Parameters:

newVal – true to activate stats

inline bool getPrintStat() const#
Returns:

true if stats are activated

void updateIndexSets()#

update all index sets of the topology, using current y and lambda values of Interactions

virtual void updateIndexSet(unsigned int level) = 0#

update indexSets[i] of the topology, using current y and lambda values of Interactions.

Parameters:

level – the number of the set to be updated

virtual void initialize()#

Complete initialisation of the Simulation (OneStepIntegrators, OneStepNSProblem, TImediscretisation).

virtual void initializeInteraction(double time, SP::Interaction inter)#

Initialize a single Interaction for this Simulation, used for dynamic topology updates.

inline void insertInteractionManager(SP::InteractionManager manager)#

Set an object to automatically manage interactions during the simulation.

Parameters:

manager

void computeResidu()#

Compute the residu of all OSI.

int computeOneStepNSProblem(int nb)#

computes a one step NS problem

Parameters:

nb – the id of the OneStepNSProblem to be computed

Returns:

information about the solver convergence.

virtual void updateDSPlugins(double time)#

update the plugins of the DS

Parameters:

time – to be used for plugins

virtual void updateInput(unsigned int level)#

update input

Parameters:

level – lambda order used to compute input

virtual void updateAllInput()#

update all input terms

virtual void updateState(unsigned int level = 0)#

update state of each dynamical system

virtual void updateOutput(unsigned int level = 0)#

update output

Parameters:

level – lambda order used to compute output level is set to 0 by default since in all time-stepping schemes we update all the state

inline void update(unsigned int level = 0)#

update output, state, and input

Parameters:

level – lambda order used to compute input level is set to 0 by default since in all time-stepping schemes we update all the state

virtual void run()#

run the simulation, from t0 to T with default parameters if any particular settings has been done

virtual void initializeOneStepNSProblem() = 0#

initialisation for OneStepNSProblem.

virtual void advanceToEvent() = 0#

step from current event to next event of EventsManager

void clearNSDSChangeLog()#

clear the NSDS changelog up to current position.

If you have a particularly dynamic simulation (DS and Interactions created and destroyed frequently), then it is important to call this periodically.

inline void setUseRelativeConvergenceCriteron(bool use)#

Set the option to specify if a relative convergence criterion must be used to stop the Newton iterations.

Parameters:

use – true if relative critarion activated

inline bool useRelativeConvergenceCriteron()#
Returns:

true if the relative convergence criterion is activated.

inline void setRelativeConvergenceTol(double v)#

Set the relative convergence tolerance.

Parameters:

v – tolerance value

inline double relativeConvergenceTol()#
Returns:

the relative convergence tolerence.

inline void setRelativeConvergenceCriterionHeld(bool newVal)#
Parameters:

newVal – a new relative convergence criterion

inline bool relativeConvergenceCriterionHeld()#
Returns:

true if the relative convergence criterion held.

SP::SiconosVector lambda(unsigned int level = 0, unsigned int coor = 0)#

return input lambda[level](coor) for all the interactions

Parameters:
  • level – lambda min order to be computed

  • coor – the coordinate of interest

Returns:

a SP::SiconosVector that contains the concatenated value

SP::SiconosVector y(unsigned int level = 0, unsigned int coor = 0)#

return output y[level](coor) for all the interactions

Parameters:
  • level – y min order to be computed

  • coor – the coordinate of interest

Returns:

a SP::SiconosVector that contains the concatenated value

void processEvents()#

call eventsManager processEvents.

inline void setStaticLevels(bool b)#

set staticLevels

Parameters:

b – decides whether levels should be computed at each iteration

void updateT(double T)#

This updates the end of the Simulation.

Warning

this should be called only from the Model, to synchronise the 2 values

Parameters:

T – the new final time

void link(SP::Interaction inter, SP::DynamicalSystem ds1, SP::DynamicalSystem ds2 = SP::DynamicalSystem())#

Add a new Interaction between one or a pair of DSs.

Parameters:
  • inter – the SP::Interaction to add

  • ds1 – the first SP::DynamicalSystem in the Interaction

  • ds2 – the second SP::DynamicalSystem in the Interaction, if any

void unlink(SP::Interaction inter)#

Remove an Interaction from the simulation.

Parameters:

inter – the SP::Interaction to remove

void updateInteractions()#

Call the interaction manager one if is registered, otherwise do nothing.

void initializeOSIAssociations()#

initialize OSI-DS links in the NSDS graph.

void initializeNSDSChangelog()#

initialize objects (DSs and Interations) found in the NSDS Changelog and update the changelog iterator.

void initializeIndexSets()#

initialize index sets for OSIs

virtual void firstInitialize()#

Complete initialisation of the Simulation (OneStepIntegrators, OneStepNSProblem, TImediscretisation).