bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitsim::cosim::CoSimulation Class Reference

A co-simulation in one process: the master algorithm that steps coupled subsystems, each with its own solver, and passes the outputs of each to the inputs of the others. More...

#include <co_simulation.h>

Inheritance diagram for bitsim::cosim::CoSimulation:
Collaboration diagram for bitsim::cosim::CoSimulation:

Public Member Functions

 CoSimulation (const CouplingConfig &config=CouplingConfig())
void add (const std::string &name, CoSimSubsystem &subsystem)
 Add a subsystem; it must outlive this.
void connect (const std::string &from, uint_t output, const std::string &to, uint_t input)
void initialise (real_t t0=0.0)
 Check the layout and find the inputs at time t0.
MacroStepResult step (real_t H)
 Advance every subsystem by H.
void set_pool (utils::concurrency::ThreadPool *pool) noexcept
 Step the subsystems of a try on the threads of pool; nullptr steps them one after the other on this thread.
real_t time () const noexcept
const CouplingLayout & layout () const noexcept
const CouplingConfig & config () const noexcept
const std::vector< real_t > & inputs (const std::string &name) const
 The inputs of subsystem name at the present time.
uint_t total_iterations () const noexcept
 The tries of all the macro steps so far.
uint_t n_not_converged () const noexcept
 The macro steps that ended without converging.

Detailed Description

A co-simulation in one process: the master algorithm that steps coupled subsystems, each with its own solver, and passes the outputs of each to the inputs of the others.

The subsystems only meet every macro step H, so between two meetings each sees the others' outputs as a guess: held from the start of the step, or extrapolated. That is loose coupling, the Jacobi scheme with one try, and its error grows with H; with a stiff coupling, a stiff spring between two bodies for one, it can make the simulation unstable. Strong coupling repeats every macro step, with the inputs that the outputs of the last try gave, until they agree within a tolerance; it costs more tries per step, and allows much longer steps. Gauss-Seidel lets each subsystem use the new outputs of those before it.

In the Jacobi scheme the subsystems of a try step at the same time, on the threads of a pool if one is set, and the result does not depend on the threads. CoSimParticipant runs the same scheme with every subsystem in a process or on a machine of its own, and gives the same result to the last bit.

Constructor & Destructor Documentation

◆ CoSimulation()

bitsim::cosim::CoSimulation::CoSimulation ( const CouplingConfig & config = CouplingConfig())
inlineexplicit

Member Function Documentation

◆ add()

void bitsim::cosim::CoSimulation::add ( const std::string & name,
CoSimSubsystem & subsystem )

Add a subsystem; it must outlive this.

◆ config()

const CouplingConfig & bitsim::cosim::CoSimulation::config ( ) const
inlinenoexcept

◆ connect()

void bitsim::cosim::CoSimulation::connect ( const std::string & from,
uint_t output,
const std::string & to,
uint_t input )
inline

◆ initialise()

void bitsim::cosim::CoSimulation::initialise ( real_t t0 = 0.0)

Check the layout and find the inputs at time t0.

◆ inputs()

const std::vector< real_t > & bitsim::cosim::CoSimulation::inputs ( const std::string & name) const

The inputs of subsystem name at the present time.

◆ layout()

const CouplingLayout & bitsim::cosim::CoSimulation::layout ( ) const
inlinenoexcept

◆ n_not_converged()

uint_t bitsim::cosim::CoSimulation::n_not_converged ( ) const
inlinenoexcept

The macro steps that ended without converging.

◆ set_pool()

void bitsim::cosim::CoSimulation::set_pool ( utils::concurrency::ThreadPool * pool)
inlinenoexcept

Step the subsystems of a try on the threads of pool; nullptr steps them one after the other on this thread.

◆ step()

MacroStepResult bitsim::cosim::CoSimulation::step ( real_t H)

Advance every subsystem by H.

◆ time()

real_t bitsim::cosim::CoSimulation::time ( ) const
inlinenoexcept

◆ total_iterations()

uint_t bitsim::cosim::CoSimulation::total_iterations ( ) const
inlinenoexcept

The tries of all the macro steps so far.


The documentation for this class was generated from the following files: