From: Adrien Gougeon Date: Thu, 2 Nov 2023 16:54:51 +0000 (+0100) Subject: better comments on examples X-Git-Tag: v3.35~89^2~25 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a8c66d7f0c38aed2cb5ff8bc017620f4ce647e2a better comments on examples --- diff --git a/examples/cpp/battery-chiller-solar/s4u-battery-chiller-solar.cpp b/examples/cpp/battery-chiller-solar/s4u-battery-chiller-solar.cpp index c428b32948..00fff065c0 100644 --- a/examples/cpp/battery-chiller-solar/s4u-battery-chiller-solar.cpp +++ b/examples/cpp/battery-chiller-solar/s4u-battery-chiller-solar.cpp @@ -82,6 +82,8 @@ int main(int argc, char* argv[]) chiller->add_host(myhost2); solar_panel->on_this_power_change_cb( [battery](sp::SolarPanel* s) { battery->set_load("Solar Panel", s->get_power() * -1); }); + + // These handlers connect/disconnect the solar panel and the hosts depending on the state of charge of the battery battery->schedule_handler(0.8, sp::Battery::CHARGE, sp::Battery::Handler::PERSISTANT, [battery]() { battery->set_load("Solar Panel", false); }); battery->schedule_handler(0.75, sp::Battery::DISCHARGE, sp::Battery::Handler::PERSISTANT, @@ -97,10 +99,17 @@ int main(int argc, char* argv[]) battery->connect_host(myhost2); }); + /* Handlers create simulation events preventing the simulation from finishing + To avoid this behaviour this actor sleeps for 2 days and then delete all handlers + */ + sg4::Actor::create("end_manager", myhost1, end_manager, battery); + + // This actor updates the solar irradiance of the solar panel sg4::Actor::create("irradiance_manager", myhost1, irradiance_manager, solar_panel)->daemonize(); + + // These actors start a job on a host for a specific duration sg4::Actor::create("host_job_manager", myhost1, host_job_manager, 12 * 60 * 60, 4 * 60 * 60); sg4::Actor::create("host_job_manager", myhost2, host_job_manager, 12 * 60 * 60, 4 * 60 * 60); - sg4::Actor::create("end_manager", myhost1, end_manager, battery); e.run(); XBT_INFO("State of charge of the battery: %0.1f%%", battery->get_state_of_charge() * 100); diff --git a/examples/cpp/battery-connector/s4u-battery-connector.cpp b/examples/cpp/battery-connector/s4u-battery-connector.cpp index b4d9434580..b3a8588b28 100644 --- a/examples/cpp/battery-connector/s4u-battery-connector.cpp +++ b/examples/cpp/battery-connector/s4u-battery-connector.cpp @@ -4,6 +4,8 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ /* This example shows how to use the battery as a connector. + A connector has no capacity and only delivers as much power as it receives + with a transfer efficiency of 100%. A solar panel is connected to the connector and power a host. */