1 /* Copyright (c) 2003-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/plugins/battery.hpp"
7 #include "simgrid/s4u.hpp"
8 #include <simgrid/s4u/Actor.hpp>
10 XBT_LOG_NEW_DEFAULT_CATEGORY(battery_simple, "Messages specific for this s4u example");
12 int main(int argc, char* argv[])
14 simgrid::s4u::Engine e(&argc, argv);
15 e.load_platform(argv[1]);
17 auto battery = simgrid::plugins::Battery::init("Battery", 0.8, -100, 100, 0.9, 0.9, 10, 1000);
19 XBT_INFO("Initial state: SoC: %f SoH: %f Energy stored: %fJ Energy provided: %fJ Energy consumed %fJ",
20 battery->get_state_of_charge(), battery->get_state_of_health(), battery->get_energy_stored(),
21 battery->get_energy_provided(), battery->get_energy_consumed());
23 /* This power is beyond the nominal values of the battery
24 * see documentation for more info
27 battery->set_load("load", load_w);
28 XBT_INFO("Set load to %fW", load_w);
30 battery->create_event(0.2, simgrid::plugins::Battery::DISCHARGE, [battery, &load_w]() {
31 XBT_INFO("Discharged state: SoC: %f SoH: %f Energy stored: %fJ Energy provided: %fJ Energy consumed %fJ",
32 battery->get_state_of_charge(), battery->get_state_of_health(), battery->get_energy_stored(),
33 battery->get_energy_provided(), battery->get_energy_consumed());
34 battery->set_load("load", -load_w);
35 XBT_INFO("Set load to %fW", -load_w);
38 battery->create_event(0.8, simgrid::plugins::Battery::CHARGE, [battery]() {
39 XBT_INFO("Charged state: SoC: %f SoH: %f Energy stored: %fJ Energy provided: %fJ Energy consumed %fJ",
40 battery->get_state_of_charge(), battery->get_state_of_health(), battery->get_energy_stored(),
41 battery->get_energy_provided(), battery->get_energy_consumed());
42 XBT_INFO("Set load to %fW", 0.0);