1#ifndef BITSIM_COSIM_COUPLING_H
2#define BITSIM_COSIM_COUPLING_H
53 const std::string &
name(
uint_t i)
const {
return names_.at(i); }
59 const std::vector<Connection> &
connections() const noexcept {
return connections_; }
64 std::vector<std::vector<real_t>>
65 inputs_from(
const std::vector<std::vector<real_t>> &outputs)
const;
70 std::vector<std::vector<real_t>>
zero_inputs()
const;
73 std::vector<std::string> names_;
74 std::vector<uint_t> n_inputs_;
75 std::vector<uint_t> n_outputs_;
76 std::map<std::string, uint_t> index_;
77 std::vector<Connection> connections_;
139 uint_t iteration,
const std::vector<std::vector<real_t>> &begin,
140 const std::vector<std::vector<real_t>> &end)>;
159 const std::function<std::vector<std::vector<real_t>>(
const std::vector<std::vector<real_t>> &)>
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
The subsystems of a co-simulation, their sizes, and which output feeds which input.
Definition coupling.h:35
uint_t index(const std::string &name) const
Definition coupling.cpp:26
uint_t add(const std::string &name, uint_t n_inputs, uint_t n_outputs)
Add a subsystem; its index is the number of subsystems before it.
Definition coupling.cpp:12
uint_t size() const noexcept
Definition coupling.h:49
void connect(const std::string &from, uint_t output, const std::string &to, uint_t input)
Definition coupling.cpp:36
std::vector< std::vector< real_t > > zero_inputs() const
Every subsystem's inputs, all 0.
Definition coupling.cpp:72
uint_t n_outputs(uint_t i) const
Definition coupling.h:57
const std::vector< Connection > & connections() const noexcept
Definition coupling.h:59
void validate() const
Definition coupling.cpp:48
std::vector< std::vector< real_t > > inputs_from(const std::vector< std::vector< real_t > > &outputs) const
The inputs of every subsystem that the outputs of every subsystem give.
Definition coupling.cpp:83
uint_t n_inputs(uint_t i) const
Definition coupling.h:55
const std::string & name(uint_t i) const
Definition coupling.h:53
Definition co_simulation.cpp:9
std::vector< std::vector< real_t > > resolve_inputs(const CouplingLayout &layout, const std::function< std::vector< std::vector< real_t > >(const std::vector< std::vector< real_t > > &)> &outputs_of)
The inputs at the start: outputs_of(inputs) gives the outputs of every subsystem for the inputs,...
Definition coupling.cpp:147
CouplingScheme
The order in which the subsystems of a macro step take their inputs.
Definition coupling.h:84
@ JACOBI
Definition coupling.h:90
@ GAUSS_SEIDEL
Definition coupling.h:95
MacroStepResult jacobi_step(const CouplingLayout &layout, const CouplingConfig &config, CouplingState &state, const try_step_type &try_step)
One macro step of the Jacobi scheme, with as many tries as config allows.
Definition coupling.cpp:93
std::function< std::vector< std::vector< real_t > >( uint_t iteration, const std::vector< std::vector< real_t > > &begin, const std::vector< std::vector< real_t > > &end)> try_step_type
The outputs of every subsystem at the end of try iteration of a macro step, the subsystems having ste...
Definition coupling.h:138
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
Output output of subsystem from feeds input input of subsystem to.
Definition coupling.h:20
std::string from
Definition coupling.h:21
std::string to
Definition coupling.h:23
uint_t output
Definition coupling.h:22
uint_t input
Definition coupling.h:24
How a co-simulation couples its subsystems.
Definition coupling.h:102
uint_t max_iterations
JACOBI: the most tries of a macro step; 1 couples loosely.
Definition coupling.h:104
CouplingScheme scheme
Definition coupling.h:103
real_t tolerance
JACOBI: done when no input moves by more than this.
Definition coupling.h:105
bool extrapolate
Definition coupling.h:111
real_t relaxation
Definition coupling.h:106
The inputs of every subsystem at the present time, and at the time before.
Definition coupling.h:118
std::vector< std::vector< real_t > > previous
Definition coupling.h:120
bool has_previous
Definition coupling.h:121
std::vector< std::vector< real_t > > inputs
Definition coupling.h:119
What one macro step did.
Definition coupling.h:128
bool converged
the residual is within the tolerance; always true for one try
Definition coupling.h:131
real_t residual
the largest change of an input in the last try
Definition coupling.h:130
uint_t iterations
the tries of the step
Definition coupling.h:129