Class Simulation

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

class Simulation : public std11::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

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

virtual ~Simulation()

destructor

virtual void advanceToEvent() = 0

step from current event to next event of EventsManager

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

associate an OSI with a DS

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

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.

int computeOneStepNSProblem(int nb)

computes a one step NS problem

Return
information about the solver convergence.
Parameters

double currentTimeStep() const

returns current timestep

SP::EventsManager eventsManager() const

returns a pointer to the EventsManager

bool getPrintStat() const

get printStat value

Return
true if stats are activated

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
Return
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
Return
a double. If the simulation is near the end (t_{k+2} > T), it returns NaN.

bool hasNextEvent() const

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

SP::InteractionsGraph indexSet(unsigned int i)

get a pointer to indexSets[i]

Return
a graph of interactions
Parameters
  • i: number of the required index set

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.

virtual void initOSNS() = 0

initialisation for OneStepNSProblem.

virtual void insertIntegrator(SP::OneStepIntegrator osi)

insert an Integrator into the simulation list of integrators

Parameters

void insertInteractionManager(SP::InteractionManager manager)

Set an object to automatically manage interactions during the simulation.

Parameters
  • manager:

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

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

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

Return
a SP::SiconosVector that contains the concatenated value
Parameters
  • level: lambda min order to be computed
  • coor: the coordinate of interest

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

const std::string name() const

get the name of the Simulation

Return
std::string : the name of the Simulation

double nextTime() const

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

Return
a double.

SP::NonSmoothDynamicalSystem nonSmoothDynamicalSystem() const

get the NonSmoothDynamicalSystem

Return
NonSmoothDynamicalSystem

unsigned int numberOfOSI() const

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

Return
an unsigned int

unsigned int numberOfOSNSProblems() const

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

Return
an unsigned int

const SP::OSISet oneStepIntegrators() const

get all the Integrators of the Simulation

Return
an OSISset

SP::OneStepNSProblem oneStepNSProblem(int id)

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

Return
a pointer to OneStepNSProblem
Parameters
  • id: number of the required osnspb

const SP::OneStepNSProblems oneStepNSProblems() const

get allNSProblems

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

void processEvents()

call eventsManager processEvents.

bool relativeConvergenceCriterionHeld()

Return
true if the relative convergence criterion held.

double relativeConvergenceTol()

Return
the relative convergence tolerence.

virtual void run()

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

void setName(const std::string &newName)

set the name of the Simulation

Parameters
  • newName: the new name

void setNonSmoothDynamicalSystemPtr(SP::NonSmoothDynamicalSystem newPtr)

set the NonSmoothDynamicalSystem of the Simulation

Parameters

void setPrintStat(const bool &newVal)

set printStat value: if true, print solver stats.

Parameters
  • newVal: true to activate stats

void setRelativeConvergenceCriterionHeld(bool newVal)

Parameters
  • newVal: a new relative convergence criterion

void setRelativeConvergenceTol(double v)

Set the relative convergence tolerance.

Parameters
  • v: tolerance value

void setStaticLevels(bool b)

set staticLevels

Parameters
  • b: decides whether levels should be computed at each iteration

void setTolerance(double inputVal)

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

Parameters
  • inputVal: new tolerance

double startingTime() const

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

Return
a double.

double timeStep() const

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

Return
a double.

double tolerance() const

get tolerance

Return
a double

void unlink(SP::Interaction inter)

Remove an Interaction from the simulation.

Parameters
  • inter: the SP::Interaction to remove

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 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

void updateIndexSets()

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

virtual void updateInput(unsigned int level = 0)

update 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 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

virtual void updateState(unsigned int level = 0)

update state of each dynamical system

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

bool useRelativeConvergenceCriteron()

Return
true if the relative convergence criterion is activated.

VIRTUAL_ACCEPT_VISITORS(Simulation)

visitors hook

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

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

Return
a SP::SiconosVector that contains the concatenated value
Parameters
  • level: y min order to be computed
  • coor: the coordinate of interest