bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
co_simulation.h
Go to the documentation of this file.
1#ifndef BITSIM_COSIM_CO_SIMULATION_H
2#define BITSIM_COSIM_CO_SIMULATION_H
3
8
9#include <boost/noncopyable.hpp>
10
11#include <string>
12#include <vector>
13
14namespace bitsim
15{
16namespace cosim
17{
18
36class CoSimulation : private boost::noncopyable
37{
38 public:
39 explicit CoSimulation(const CouplingConfig &config = CouplingConfig()) : config_(config) {}
40
44 void add(const std::string &name, CoSimSubsystem &subsystem);
45
46 void connect(const std::string &from, uint_t output, const std::string &to, uint_t input)
47 {
48 layout_.connect(from, output, to, input);
49 }
50
54 void initialise(real_t t0 = 0.0);
55
60
65 void set_pool(utils::concurrency::ThreadPool *pool) noexcept { pool_ = pool; }
66
67 real_t time() const noexcept { return t_; }
68
69 const CouplingLayout &layout() const noexcept { return layout_; }
70
71 const CouplingConfig &config() const noexcept { return config_; }
72
76 const std::vector<real_t> &inputs(const std::string &name) const;
77
81 uint_t total_iterations() const noexcept { return total_iterations_; }
82
86 uint_t n_not_converged() const noexcept { return n_not_converged_; }
87
88 private:
89 MacroStepResult gauss_seidel_(real_t H);
90
91 CouplingConfig config_;
92 CouplingLayout layout_;
93 std::vector<CoSimSubsystem *> subsystems_;
94 CouplingState state_;
95 utils::concurrency::ThreadPool *pool_{nullptr};
96 real_t t_{0.0};
97 bool initialised_{false};
98 uint_t total_iterations_{0};
99 uint_t n_not_converged_{0};
100};
101
102} // namespace cosim
103} // namespace bitsim
104
105#endif // BITSIM_COSIM_CO_SIMULATION_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
A part of a coupled system that a co-simulation steps on its own: a robot, a trailer,...
Definition cosim_subsystem.h:29
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 t...
Definition co_simulation.h:65
CoSimulation(const CouplingConfig &config=CouplingConfig())
Definition co_simulation.h:39
const CouplingConfig & config() const noexcept
Definition co_simulation.h:71
const std::vector< real_t > & inputs(const std::string &name) const
The inputs of subsystem name at the present time.
Definition co_simulation.cpp:43
uint_t n_not_converged() const noexcept
The macro steps that ended without converging.
Definition co_simulation.h:86
const CouplingLayout & layout() const noexcept
Definition co_simulation.h:69
void connect(const std::string &from, uint_t output, const std::string &to, uint_t input)
Definition co_simulation.h:46
real_t time() const noexcept
Definition co_simulation.h:67
void initialise(real_t t0=0.0)
Check the layout and find the inputs at time t0.
Definition co_simulation.cpp:21
uint_t total_iterations() const noexcept
The tries of all the macro steps so far.
Definition co_simulation.h:81
MacroStepResult step(real_t H)
Advance every subsystem by H.
Definition co_simulation.cpp:48
void add(const std::string &name, CoSimSubsystem &subsystem)
Add a subsystem; it must outlive this.
Definition co_simulation.cpp:11
The subsystems of a co-simulation, their sizes, and which output feeds which input.
Definition coupling.h:35
A fixed number of threads that run the tasks given to them, in the order given.
Definition thread_pool.h:33
Definition co_simulation.cpp:9
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20
How a co-simulation couples its subsystems.
Definition coupling.h:102
The inputs of every subsystem at the present time, and at the time before.
Definition coupling.h:118
What one macro step did.
Definition coupling.h:128