Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove parameter depth of discharge from battery instanciation
[simgrid.git] / examples / cpp / battery-simple / s4u-battery-simple.cpp
1 /* Copyright (c) 2003-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/plugins/battery.hpp"
7 #include "simgrid/s4u.hpp"
8 #include <simgrid/s4u/Actor.hpp>
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(battery_simple, "Messages specific for this s4u example");
11
12 int main(int argc, char* argv[])
13 {
14   simgrid::s4u::Engine e(&argc, argv);
15   e.load_platform(argv[1]);
16
17   auto battery = simgrid::plugins::Battery::init("Battery", 0.8, 0.9, 0.9, 10, 1000);
18
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());
22
23   double load_w = 100;
24   battery->set_load("load", load_w);
25   XBT_INFO("Set load to %fW", load_w);
26
27   battery->create_event(0.2, simgrid::plugins::Battery::DISCHARGE, [battery, &load_w]() {
28     XBT_INFO("Discharged state: SoC: %f SoH: %f Energy stored: %fJ Energy provided: %fJ Energy consumed %fJ",
29              battery->get_state_of_charge(), battery->get_state_of_health(), battery->get_energy_stored(),
30              battery->get_energy_provided(), battery->get_energy_consumed());
31     battery->set_load("load", -load_w);
32     XBT_INFO("Set load to %fW", -load_w);
33   });
34
35   battery->create_event(0.8, simgrid::plugins::Battery::CHARGE, [battery]() {
36     XBT_INFO("Charged state: SoC: %f SoH: %f Energy stored: %fJ Energy provided: %fJ Energy consumed %fJ",
37              battery->get_state_of_charge(), battery->get_state_of_health(), battery->get_energy_stored(),
38              battery->get_energy_provided(), battery->get_energy_consumed());
39     XBT_INFO("Set load to %fW", 0.0);
40   });
41
42   e.run();
43   return 0;
44 }