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"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(battery_simple, "Messages specific for this s4u example");
13 auto battery = simgrid::s4u::Engine::get_instance()->host_by_name("battery");
14 double consumption_w = 200;
16 XBT_INFO("Initial Battery: SoC: %f SoH: %f Capacity (Total): %fWh Capacity (Usable): %fWh P: %f",
17 sg_battery_get_state_of_charge(battery), sg_battery_get_state_of_health(battery),
18 sg_battery_get_capacity(battery),
19 sg_battery_get_capacity(battery) *
20 (sg_battery_get_state_of_charge_max(battery) - sg_battery_get_state_of_charge_min(battery)),
21 sg_battery_get_power(battery));
22 double start = simgrid::s4u::Engine::get_clock();
23 sg_battery_set_power(battery, consumption_w);
24 XBT_INFO("Battery power set to: %fW", consumption_w);
25 double end = sg_battery_get_next_event_date(battery);
26 XBT_INFO("The battery will be depleted at: %f", end);
27 simgrid::s4u::this_actor::sleep_until(end);
28 XBT_INFO("Energy consumed : %fJ (%fWh)", (end - start) * consumption_w, (end - start) * consumption_w / 3600);
31 int main(int argc, char* argv[])
33 simgrid::s4u::Engine e(&argc, argv);
34 e.load_platform(argv[1]);
36 sg_battery_plugin_init();
38 simgrid::s4u::Actor::create("manager", e.host_by_name("host1"), manager);