X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0958e84aeb993d9d89b53f2afd66af91be4112de..fe4080b8dd04acb2074ca72d36e3019acddea455:/include/simgrid/plugins/battery.hpp diff --git a/include/simgrid/plugins/battery.hpp b/include/simgrid/plugins/battery.hpp index b85cec6596..61937a91a6 100644 --- a/include/simgrid/plugins/battery.hpp +++ b/include/simgrid/plugins/battery.hpp @@ -6,6 +6,7 @@ #ifndef SIMGRID_PLUGINS_BATTERY_HPP_ #define SIMGRID_PLUGINS_BATTERY_HPP_ +#include #include #include #include @@ -36,73 +37,81 @@ class Battery { public: enum Flow { CHARGE, DISCHARGE }; - class Event { + class Handler { friend Battery; + public: + enum Persistancy { PERSISTANT, ONESHOT }; + private: double state_of_charge_; Flow flow_; double time_delta_ = -1; std::function callback_; - bool repeat_; + Persistancy persistancy_; public: - Event(double state_of_charge, Flow flow, std::function callback, bool repeat); - static std::shared_ptr init(double state_of_charge, Flow flow, std::function callback, bool repeat); + Handler(double state_of_charge, Flow flow, Persistancy p, std::function callback); + static std::shared_ptr init(double state_of_charge, Flow flow, Persistancy p, + std::function callback); /** @ingroup plugin_battery - * @return The state of charge at which the Event will happen. - * @note For Battery::Event objects + * @return The state of charge at which the Handler will happen. + * @note For Battery::Handler objects */ double get_state_of_charge() { return state_of_charge_; } /** @ingroup plugin_battery - * @return The flow in which the Event will happen, either when the Battery is charging or discharging. - * @note For Battery::Event objects + * @return The flow in which the Handler will happen, either when the Battery is charging or discharging. + * @note For Battery::Handler objects */ Flow get_flow() { return flow_; } /** @ingroup plugin_battery - * @return The time delta until the Event happen. + * @return The time delta until the Handler happen. -1 means that is will never happen with the current state the Battery, for instance when there is no load connected to the Battery. - * @note For Battery::Event objects + * @note For Battery::Handler objects */ double get_time_delta() { return time_delta_; } /** @ingroup plugin_battery - * @return The callback to trigger when the Event happen. - * @note For Battery::Event objects + * @return The callback to trigger when the Handler happen. + * @note For Battery::Handler objects */ std::function get_callback() { return callback_; } /** @ingroup plugin_battery - * @return true if its a recurrent Event. - * @note For Battery::Event objects + * @return true if its a recurrent Handler. + * @note For Battery::Handler objects */ - bool get_repeat() { return repeat_; } + Persistancy get_persistancy() { return persistancy_; } }; private: static std::shared_ptr battery_model_; std::string name_; - double charge_efficiency_; - double discharge_efficiency_; - double initial_capacity_wh_; - double energy_budget_j_; - - std::map host_loads_ = {}; - std::map named_loads_ = {}; - std::vector> events_; - - double capacity_wh_; - double energy_stored_j_; + double nominal_charge_power_w_ = -INFINITY; + double nominal_discharge_power_w_ = INFINITY; + double charge_efficiency_ = 1; + double discharge_efficiency_ = 1; + double initial_capacity_wh_ = 0; + double energy_budget_j_ = 0; + + std::map host_loads_ = {}; + std::map> named_loads_ = {}; + std::vector> handlers_; + + double capacity_wh_ = 0; + double energy_stored_j_ = 0; double energy_provided_j_ = 0; double energy_consumed_j_ = 0; double last_updated_ = 0; - explicit Battery(const std::string& name, double state_of_charge, double charge_efficiency, - double discharge_efficiency, double initial_capacity_wh, int cycles); + explicit Battery(); + explicit Battery(const std::string& name, double state_of_charge, double nominal_charge_power_w, + double nominal_discharge_power_w, double charge_efficiency, double discharge_efficiency, + double initial_capacity_wh, int cycles); static void init_plugin(); void update(); - double next_occurring_event(); + double next_occurring_handler(); std::atomic_int_fast32_t refcount_{0}; #ifndef DOXYGEN @@ -117,20 +126,24 @@ private: #endif public: - static BatteryPtr init(const std::string& name, double state_of_charge, double charge_efficiency, - double discharge_efficiency, double initial_capacity_wh, int cycles); + static BatteryPtr init(); + static BatteryPtr init(const std::string& name, double state_of_charge, double nominal_charge_power_w, + double nominal_discharge_power_w, double charge_efficiency, double discharge_efficiency, + double initial_capacity_wh, int cycles); void set_load(const std::string& name, double power_w); + void set_load(const std::string& name, bool active); void connect_host(s4u::Host* host, bool active = true); + std::string get_name() {return name_;} double get_state_of_charge(); double get_state_of_health(); double get_capacity(); double get_energy_provided(); double get_energy_consumed(); double get_energy_stored(std::string unit = "J"); - std::shared_ptr create_event(double state_of_charge, Flow flow, std::function callback, - bool repeat = false); - std::vector> get_events(); - void delete_event(std::shared_ptr event); + std::shared_ptr schedule_handler(double state_of_charge, Flow flow, Handler::Persistancy p, + std::function callback); + std::vector> get_handlers(); + void delete_handler(std::shared_ptr handler); }; } // namespace simgrid::plugins #endif \ No newline at end of file