|
| 1 | +/** |
| 2 | + * \file |
| 3 | + * Defines the class for a ECCO (Energy-Conservation-based Co-Simulation) algorithm |
| 4 | + * |
| 5 | + * \copyright |
| 6 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 7 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 | + * file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | + */ |
| 10 | +#ifndef LIBCOSIM_ALGORITHM_ECCO_ALGORITHM_HPP |
| 11 | +#define LIBCOSIM_ALGORITHM_ECCO_ALGORITHM_HPP |
| 12 | + |
| 13 | +#include <cosim/algorithm/algorithm.hpp> |
| 14 | + |
| 15 | +namespace cosim |
| 16 | +{ |
| 17 | + |
| 18 | +struct ecco_algorithm_params |
| 19 | +{ |
| 20 | + double safety_factor; |
| 21 | + duration step_size; |
| 22 | + duration min_step_size; |
| 23 | + duration max_step_size; |
| 24 | + double min_change_rate; |
| 25 | + double max_change_rate; |
| 26 | + double abs_tolerance; |
| 27 | + double rel_tolerance; |
| 28 | + double p_gain; |
| 29 | + double i_gain; |
| 30 | +}; |
| 31 | + |
| 32 | +/** |
| 33 | + * A fixed-stepsize co-simulation algorithm. |
| 34 | + * |
| 35 | + * A simple implementation of `algorithm`. The simulation progresses |
| 36 | + * at a fixed base stepsize. Simulators are stepped in parallel at an optional |
| 37 | + * multiple of this base step size. |
| 38 | + */ |
| 39 | +class ecco_algorithm : public algorithm |
| 40 | +{ |
| 41 | +public: |
| 42 | + /** |
| 43 | + * Constructor. |
| 44 | + * |
| 45 | + * \param baseStepSize |
| 46 | + * The base communication interval length. |
| 47 | + * |
| 48 | + * \param workerThreadCount |
| 49 | + * The number of worker threads to spawn for running FMUs |
| 50 | + */ |
| 51 | + explicit ecco_algorithm(ecco_algorithm_params params, std::optional<unsigned int> workerThreadCount = std::nullopt); |
| 52 | + |
| 53 | + ~ecco_algorithm() noexcept; |
| 54 | + |
| 55 | + ecco_algorithm(const ecco_algorithm&) = delete; |
| 56 | + ecco_algorithm& operator=(const ecco_algorithm&) = delete; |
| 57 | + |
| 58 | + ecco_algorithm(ecco_algorithm&&) noexcept; |
| 59 | + ecco_algorithm& operator=(ecco_algorithm&&) noexcept; |
| 60 | + |
| 61 | + // `algorithm` methods |
| 62 | + void add_simulator(simulator_index i, simulator* s, duration stepSizeHint) override; |
| 63 | + void remove_simulator(simulator_index i) override; |
| 64 | + void add_function(function_index i, function* f) override; |
| 65 | + void connect_variables(variable_id output, variable_id input) override; |
| 66 | + void connect_variables(variable_id output, function_io_id input) override; |
| 67 | + void connect_variables(function_io_id output, variable_id input) override; |
| 68 | + void disconnect_variable(variable_id input) override; |
| 69 | + void disconnect_variable(function_io_id input) override; |
| 70 | + void setup(time_point startTime, std::optional<time_point> stopTime) override; |
| 71 | + void initialize() override; |
| 72 | + std::pair<duration, std::unordered_set<simulator_index>> do_step(time_point currentT) override; |
| 73 | + serialization::node export_current_state() const override; |
| 74 | + void import_state(const serialization::node& exportedState) override; |
| 75 | + |
| 76 | + /** |
| 77 | + * Adds a variable pair for the power residual calculation. |
| 78 | + * \param uVec |
| 79 | + * The index of the variable. |
| 80 | + */ |
| 81 | + void add_power_bond(cosim::variable_id input_a, cosim::variable_id output_a, cosim::variable_id input_b, cosim::variable_id output_b); |
| 82 | + |
| 83 | + /** |
| 84 | + * Retrieves the energies in the power bond for the given simulator index.add_variable_value |
| 85 | + * \param simulator_index |
| 86 | + * The index of the simulator. |
| 87 | + */ |
| 88 | + std::vector<double> get_powerbond_energies(cosim::simulator_index simulator_index); |
| 89 | + |
| 90 | +private: |
| 91 | + class impl; |
| 92 | + std::unique_ptr<impl> pimpl_; |
| 93 | +}; |
| 94 | + |
| 95 | +} // namespace cosim |
| 96 | + |
| 97 | +#endif |
0 commit comments