From 6da8d85344b45895e40e1e6befe1db2bfd3babf0 Mon Sep 17 00:00:00 2001 From: Adrien Gougeon Date: Mon, 18 Sep 2023 14:26:14 +0200 Subject: [PATCH] add chiller plugin with doc and an example --- ChangeLog | 2 + MANIFEST.in | 4 + docs/source/Plugins.rst | 5 + examples/cpp/CMakeLists.txt | 1 + .../cpp/chiller-simple/s4u-chiller-simple.cpp | 78 +++++ .../chiller-simple/s4u-chiller-simple.tesh | 24 ++ include/simgrid/plugins/chiller.hpp | 102 +++++++ src/plugins/chiller.cpp | 287 ++++++++++++++++++ tools/cmake/DefinePackages.cmake | 2 + 9 files changed, 505 insertions(+) create mode 100644 examples/cpp/chiller-simple/s4u-chiller-simple.cpp create mode 100644 examples/cpp/chiller-simple/s4u-chiller-simple.tesh create mode 100644 include/simgrid/plugins/chiller.hpp create mode 100644 src/plugins/chiller.cpp diff --git a/ChangeLog b/ChangeLog index 43e5acd31e..77b01a3071 100644 --- a/ChangeLog +++ b/ChangeLog @@ -27,6 +27,8 @@ C API: Plugins: - Revamp the battery plugin: rewrite completely the API, for a better usability. The examples were updated accordingly. + - Add chiller plugin: enable the management of chillers consuming electrical energy + to compensate heat generated by hosts. ---------------------------------------------------------------------------- diff --git a/MANIFEST.in b/MANIFEST.in index e0c96c2bed..7998d133ce 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -173,6 +173,8 @@ include examples/cpp/battery-energy/s4u-battery-energy.cpp include examples/cpp/battery-energy/s4u-battery-energy.tesh include examples/cpp/battery-simple/s4u-battery-simple.cpp include examples/cpp/battery-simple/s4u-battery-simple.tesh +include examples/cpp/chiller-simple/s4u-chiller-simple.cpp +include examples/cpp/chiller-simple/s4u-chiller-simple.tesh include examples/cpp/cloud-capping/s4u-cloud-capping.cpp include examples/cpp/cloud-capping/s4u-cloud-capping.tesh include examples/cpp/cloud-migration/s4u-cloud-migration.cpp @@ -1936,6 +1938,7 @@ include include/simgrid/modelchecker.h include include/simgrid/mutex.h include include/simgrid/plugins/ProducerConsumer.hpp include include/simgrid/plugins/battery.hpp +include include/simgrid/plugins/chiller.hpp include include/simgrid/plugins/dvfs.h include include/simgrid/plugins/energy.h include include/simgrid/plugins/file_system.h @@ -2312,6 +2315,7 @@ include src/mc/transition/TransitionSynchro.hpp include src/plugins/ProducerConsumer.cpp include src/plugins/battery.cpp include src/plugins/chaos_monkey.cpp +include src/plugins/chiller.cpp include src/plugins/file_system/s4u_FileSystem.cpp include src/plugins/host_dvfs.cpp include src/plugins/host_energy.cpp diff --git a/docs/source/Plugins.rst b/docs/source/Plugins.rst index 46b6c01dcd..87ba3a8220 100644 --- a/docs/source/Plugins.rst +++ b/docs/source/Plugins.rst @@ -231,4 +231,9 @@ Photovoltaic .. doxygengroup:: plugin_photovoltaic +Chiller +=========== + +.. doxygengroup:: plugin_chiller + .. LocalWords: SimGrid diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index 72e060f429..b0a2026034 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -158,6 +158,7 @@ foreach (example activityset-testany activityset-waitany activityset-waitall act actor-lifetime actor-migrate actor-suspend actor-yield actor-stacksize app-bittorrent app-chainsend app-token-ring battery-degradation battery-simple battery-energy + chiller-simple comm-pingpong comm-ready comm-suspend comm-wait comm-waituntil comm-dependent comm-host2host comm-failure comm-throttling cloud-capping cloud-migration cloud-simple diff --git a/examples/cpp/chiller-simple/s4u-chiller-simple.cpp b/examples/cpp/chiller-simple/s4u-chiller-simple.cpp new file mode 100644 index 0000000000..c5a45b3d16 --- /dev/null +++ b/examples/cpp/chiller-simple/s4u-chiller-simple.cpp @@ -0,0 +1,78 @@ +/* Copyright (c) 2017-2023. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "simgrid/plugins/chiller.hpp" +#include "simgrid/plugins/energy.h" +#include "simgrid/s4u.hpp" +#include + +XBT_LOG_NEW_DEFAULT_CATEGORY(chiller_simple, "Messages specific for this s4u example"); +namespace sg4 = simgrid::s4u; + +static void manager(simgrid::plugins::ChillerPtr c) +{ + XBT_INFO("Initial state: "); + XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(), + c->get_energy_consumed()); + + XBT_INFO("The machines slowly heat up the room."); + simgrid::s4u::this_actor::sleep_until(400); + XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(), + c->get_energy_consumed()); + simgrid::s4u::this_actor::sleep_until(800); + XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(), + c->get_energy_consumed()); + simgrid::s4u::this_actor::sleep_until(1000); + XBT_INFO("The Chiller now compensates the heat generated by the machines."); + XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(), + c->get_energy_consumed()); + simgrid::s4u::this_actor::sleep_until(1200); + XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(), + c->get_energy_consumed()); + + XBT_INFO("Let's compute something."); + sg4::this_actor::exec_async(1e10); + simgrid::s4u::this_actor::sleep_until(1250); + XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(), + c->get_energy_consumed()); + + simgrid::s4u::this_actor::sleep_until(1300); + XBT_INFO("Computation done."); + + simgrid::s4u::this_actor::sleep_until(1400); + XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(), + c->get_energy_consumed()); + + XBT_INFO("Now let's stress the chiller by decreasing the goal temperature to 23°C."); + c->set_goal_temp(23); + simgrid::s4u::this_actor::sleep_until(1600); + XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(), + c->get_energy_consumed()); + simgrid::s4u::this_actor::sleep_until(1800); + XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(), + c->get_energy_consumed()); + simgrid::s4u::this_actor::sleep_until(2000); + XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(), + c->get_energy_consumed()); + simgrid::s4u::this_actor::sleep_until(2200); + XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(), + c->get_energy_consumed()); +} + +int main(int argc, char* argv[]) +{ + sg4::Engine e(&argc, argv); + e.load_platform(argv[1]); + sg_host_energy_plugin_init(); + + auto chiller = simgrid::plugins::Chiller::init("Chiller", 294, 1006, 0.2, 0.9, 23, 24, 1000); + chiller->add_host(e.host_by_name("MyHost1")); + chiller->add_host(e.host_by_name("MyHost2")); + chiller->add_host(e.host_by_name("MyHost3")); + sg4::Actor::create("sender", e.host_by_name("MyHost1"), manager, chiller); + + e.run(); + return 0; +} diff --git a/examples/cpp/chiller-simple/s4u-chiller-simple.tesh b/examples/cpp/chiller-simple/s4u-chiller-simple.tesh new file mode 100644 index 0000000000..c1d4c27f46 --- /dev/null +++ b/examples/cpp/chiller-simple/s4u-chiller-simple.tesh @@ -0,0 +1,24 @@ +#!/usr/bin/env tesh + +$ ${bindir:=.}/s4u-chiller-simple ${platfdir}/energy_platform.xml +> [MyHost1:sender:(1) 0.000000] [chiller_simple/INFO] Initial state: +> [MyHost1:sender:(1) 0.000000] [chiller_simple/INFO] Chiller: Power: 0.000000W T_in: 23.000000°C Energy consumed: 0.000000J +> [MyHost1:sender:(1) 0.000000] [chiller_simple/INFO] The machines slowly heat up the room. +> [MyHost1:sender:(1) 400.000000] [chiller_simple/INFO] Chiller: Power: 0.000000W T_in: 23.486875°C Energy consumed: 0.000000J +> [MyHost1:sender:(1) 800.000000] [chiller_simple/INFO] Chiller: Power: 0.000000W T_in: 23.973749°C Energy consumed: 0.000000J +> [MyHost1:sender:(1) 1000.000000] [chiller_simple/INFO] The Chiller now compensates the heat generated by the machines. +> [MyHost1:sender:(1) 1000.000000] [chiller_simple/INFO] Chiller: Power: 356.866667W T_in: 24.000000°C Energy consumed: 71373.333333J +> [MyHost1:sender:(1) 1200.000000] [chiller_simple/INFO] Chiller: Power: 400.000000W T_in: 24.000000°C Energy consumed: 151373.333333J +> [MyHost1:sender:(1) 1200.000000] [chiller_simple/INFO] Let's compute something. +> [MyHost1:sender:(1) 1250.000000] [chiller_simple/INFO] Chiller: Power: 426.666667W T_in: 24.000000°C Energy consumed: 172706.666667J +> [MyHost1:sender:(1) 1300.000000] [chiller_simple/INFO] Computation done. +> [MyHost1:sender:(1) 1400.000000] [chiller_simple/INFO] Chiller: Power: 400.000000W T_in: 24.000000°C Energy consumed: 234040.000000J +> [MyHost1:sender:(1) 1400.000000] [chiller_simple/INFO] Now let's stress the chiller by decreasing the goal temperature to 23°C. +> [MyHost1:sender:(1) 1600.000000] [chiller_simple/INFO] Chiller: Power: 1000.000000W T_in: 23.634844°C Energy consumed: 434040.000000J +> [MyHost1:sender:(1) 1800.000000] [chiller_simple/INFO] Chiller: Power: 1000.000000W T_in: 23.269688°C Energy consumed: 634040.000000J +> [MyHost1:sender:(1) 2000.000000] [chiller_simple/INFO] Chiller: Power: 843.133333W T_in: 23.000000°C Energy consumed: 802666.666667J +> [MyHost1:sender:(1) 2200.000000] [chiller_simple/INFO] Chiller: Power: 400.000000W T_in: 23.000000°C Energy consumed: 882666.666667J +> [2200.000000] [host_energy/INFO] Total energy consumption: 662000.000000 Joules (used hosts: 222000.000000 Joules; unused/idle hosts: 440000.000000) +> [2200.000000] [host_energy/INFO] Energy consumption of host MyHost1: 222000.000000 Joules +> [2200.000000] [host_energy/INFO] Energy consumption of host MyHost2: 220000.000000 Joules +> [2200.000000] [host_energy/INFO] Energy consumption of host MyHost3: 220000.000000 Joules diff --git a/include/simgrid/plugins/chiller.hpp b/include/simgrid/plugins/chiller.hpp new file mode 100644 index 0000000000..0114b4d883 --- /dev/null +++ b/include/simgrid/plugins/chiller.hpp @@ -0,0 +1,102 @@ +/* Copyright (c) 2023. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ +#ifndef SIMGRID_PLUGINS_CHILLER_H_ +#define SIMGRID_PLUGINS_CHILLER_H_ + +#include +#include +#include + +namespace simgrid::plugins { + +class Chiller; +using ChillerPtr = boost::intrusive_ptr; +XBT_PUBLIC void intrusive_ptr_release(Chiller* o); +XBT_PUBLIC void intrusive_ptr_add_ref(Chiller* o); + +class ChillerModel : public kernel::resource::Model { + std::vector chillers_; + +public: + explicit ChillerModel(); + + void add_chiller(ChillerPtr b); + void update_actions_state(double now, double delta) override; + double next_occurring_event(double now) override; +}; + +class Chiller { + + friend ChillerModel; + +private: + static std::shared_ptr chiller_model_; + + std::string name_; + double air_mass_kg_; + double specific_heat_j_per_kg_per_c_; + double alpha_; + double cooling_efficiency_; + double goal_temp_c_; + double max_power_w_; + + std::set hosts_ = {}; + bool active_ = true; + double temp_in_c_; + double temp_out_c_; + double power_w_ = 0; + double energy_consumed_j_ = 0; + double last_updated_ = 0; + + explicit Chiller(const std::string& name, double air_mass_kg, double specific_heat_j_per_kg_per_c, double alpha, + double cooling_efficiency, double initial_temp_c, double goal_temp_c, double max_power_w); + + static void init_plugin(); + void update(); + + std::atomic_int_fast32_t refcount_{0}; +#ifndef DOXYGEN + friend void intrusive_ptr_release(Chiller* o) + { + if (o->refcount_.fetch_sub(1, std::memory_order_release) == 1) { + std::atomic_thread_fence(std::memory_order_acquire); + delete o; + } + } + friend void intrusive_ptr_add_ref(Chiller* o) { o->refcount_.fetch_add(1, std::memory_order_relaxed); } +#endif + +public: + static ChillerPtr init(const std::string& name, double air_mass_kg, double specific_heat_j_per_kg_per_c, double alpha, + double cooling_efficiency, double initial_temp_c, double goal_temp_c, double max_power_w); + + ChillerPtr set_name(std::string name); + ChillerPtr set_air_mass(double air_mass_kg); + ChillerPtr set_specific_heat(double specific_heat_j_per_kg_per_c); + ChillerPtr set_alpha(double alpha); + ChillerPtr set_cooling_efficiency(double cooling_efficiency); + ChillerPtr set_goal_temp(double goal_temp_c); + ChillerPtr set_max_power(double max_power_w); + ChillerPtr set_active(bool active); + ChillerPtr add_host(s4u::Host* host); + ChillerPtr remove_host(s4u::Host* host); + + std::string get_name() { return name_; } + const char* get_cname() { return name_.c_str(); } + double get_air_mass() { return air_mass_kg_; } + double get_specific_heat() { return specific_heat_j_per_kg_per_c_; } + double get_alpha() { return alpha_; } + double get_cooling_efficiency() { return cooling_efficiency_; } + double get_goal_temp() { return goal_temp_c_; } + double get_max_power() { return max_power_w_; } + bool is_active() { return active_; } + double get_temp_in() { return temp_in_c_; } + double get_temp_out() { return temp_out_c_; } + double get_power() { return power_w_; } + double get_energy_consumed() { return energy_consumed_j_; } +}; + +} // namespace simgrid::plugins +#endif diff --git a/src/plugins/chiller.cpp b/src/plugins/chiller.cpp new file mode 100644 index 0000000000..8000377a5a --- /dev/null +++ b/src/plugins/chiller.cpp @@ -0,0 +1,287 @@ +/* Copyright (c) 2023. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ +#include +#include +#include +#include +#include +#include + +#include "src/kernel/resource/CpuImpl.hpp" +#include "src/simgrid/module.hpp" + +SIMGRID_REGISTER_PLUGIN(chiller, "Chiller management", nullptr) + +/** @defgroup plugin_chiller Plugin Chiller + + @beginrst + +This is the chiller plugin, enabling management of chillers. + +Chiller +.................... + +A chiller is placed inside a room with several machines. The role of the chiller is to keep the temperature of the room +below a threshold. This plugin and its equations are based on the paper "Co-simulation of FMUs and Distributed +Applications with SimGrid" by Camus et al. (https://hal.science/hal-01762540). + +The heat generated inside the room :math:`Q_{room}` depends on the heat from the machines :math:`Q_{machines}` and +from the heat of the other devices, such as lighing, accounted using a factor :math:`\alpha` such as: + +.. math:: + + Q_{room} = (1 + \alpha) \times Q_{machines} + +This energy heats the input temperature :math:`T_{in}` and gives an output temperature :math:`T_{out}` based on the the +mass of air inside the room :math:`m_{air}` and its specific heat :math:`C_{p}`: + +.. math:: + + T_{out} = T_{in} + {Q_{room} \over m_{air} \times C_{p}} + +If the output temperature is above the goal temperature :math:`T_{goal}` the chiller compensates the excessive heat +using electrical energy :math:`Q_{cooling}` depending on its cooling efficiency :math:`\eta_{cooling}` : + +.. math:: + + Q_{cooling} = (T_{out} - T_{goal}) \times m_{air} \times C_{p} / \eta_{cooling} + +The chiller has a power threshold that cannot be exceeded. If the power needed is above this threshold, or if the +chiller is not active, the temperature of the room increases. + + @endrst + */ + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(Chiller, kernel, "Logging specific to the solar panel plugin"); + +namespace simgrid::plugins { + +/* ChillerModel */ + +ChillerModel::ChillerModel() : Model("ChillerModel") {} + +void ChillerModel::add_chiller(ChillerPtr c) +{ + chillers_.push_back(c); +} + +void ChillerModel::update_actions_state(double now, double delta) +{ + for (auto chiller : chillers_) + chiller->update(); +} + +double ChillerModel::next_occurring_event(double now) +{ + return -1; +} + +/* Chiller */ + +std::shared_ptr Chiller::chiller_model_; + +void Chiller::init_plugin() +{ + auto model = std::make_shared(); + simgrid::s4u::Engine::get_instance()->add_model(model); + Chiller::chiller_model_ = model; +} + +void Chiller::update() +{ + simgrid::kernel::actor::simcall_answered([this] { + double now = s4u::Engine::get_clock(); + double time_delta_s = now - last_updated_; + + if (time_delta_s <= 0) + return; + + double hosts_power_w = 0; + for (auto const& host : hosts_) + hosts_power_w += sg_host_get_current_consumption(host); + double heat_generated_j = hosts_power_w * (1 + alpha_) * time_delta_s; + temp_out_c_ = temp_in_c_ + heat_generated_j / (air_mass_kg_ * specific_heat_j_per_kg_per_c_); + double delta_temp_c = temp_out_c_ - goal_temp_c_; + + if (not active_ or delta_temp_c < 0) { + temp_in_c_ = temp_out_c_; + power_w_ = 0; + last_updated_ = now; + return; + } + + double cooling_demand_w = delta_temp_c * air_mass_kg_ * specific_heat_j_per_kg_per_c_ / time_delta_s; + if (cooling_demand_w / cooling_efficiency_ <= max_power_w_) { + power_w_ = cooling_demand_w / cooling_efficiency_; + temp_in_c_ = temp_out_c_ - + (power_w_ * time_delta_s * cooling_efficiency_) / (air_mass_kg_ * specific_heat_j_per_kg_per_c_); + } else { + power_w_ = max_power_w_; + temp_in_c_ = temp_out_c_ - + (power_w_ * time_delta_s * cooling_efficiency_) / (air_mass_kg_ * specific_heat_j_per_kg_per_c_); + } + + energy_consumed_j_ += power_w_ * time_delta_s; + last_updated_ = now; + }); +} + +Chiller::Chiller(const std::string& name, double air_mass_kg, double specific_heat_j_per_kg_per_c, double alpha, + double cooling_efficiency, double initial_temp_c, double goal_temp_c, double max_power_w) + : name_(name) + , air_mass_kg_(air_mass_kg) + , specific_heat_j_per_kg_per_c_(specific_heat_j_per_kg_per_c) + , alpha_(alpha) + , cooling_efficiency_(cooling_efficiency) + , temp_in_c_(initial_temp_c) + , temp_out_c_(initial_temp_c) + , goal_temp_c_(goal_temp_c) + , max_power_w_(max_power_w) +{ + xbt_assert(air_mass_kg > 0, ": air mass must be > 0 (provided: %f)", air_mass_kg); + xbt_assert(specific_heat_j_per_kg_per_c > 0, ": specific heat must be > 0 (provided: %f)", + specific_heat_j_per_kg_per_c); + xbt_assert(alpha >= 0, ": alpha must be >= 0 (provided: %f)", alpha); + xbt_assert(cooling_efficiency >= 0 and cooling_efficiency <= 1, + ": cooling efficiency must be in [0,1] (provided: %f)", cooling_efficiency); + xbt_assert(max_power_w >= 0, ": maximal power must be >=0 (provided: %f)", max_power_w); +} + +/** @ingroup plugin_chiller + * @param name The name of the Chiller. + * @param air_mass_kg The air mass of the room managed by the Chiller in kg (> 0). + * @param specific_heat_j_per_kg_per_c The specific heat of air in J per kg per °C (> 0). + * @param alpha The ratio of the other devices in the total heat dissipation (e.g. lighting, Power Distribution Unit) + * (>= 0). + * @param cooling_efficiency The cooling efficiency of the Chiller [0, 1]. + * @param initial_temp_c The initial temperature of the room managed by the Chiller. + * @param goal_temp_c The goal temperature of the room. The Chiller is idle below this temperature. + * @param max_power_w The maximal power delivered by the Chiller in W (> 0). If this power is reached the room + * temperature will raise above the goal temperature. + * @return A ChillerPtr pointing to the new Chiller. + */ +ChillerPtr Chiller::init(const std::string& name, double air_mass_kg, double specific_heat_j_per_kg_per_c, double alpha, + double cooling_efficiency, double initial_temp_c, double goal_temp_c, double max_power_w) +{ + static bool plugin_inited = false; + if (not plugin_inited) { + init_plugin(); + plugin_inited = true; + } + auto chiller = ChillerPtr(new Chiller(name, air_mass_kg, specific_heat_j_per_kg_per_c, alpha, cooling_efficiency, + initial_temp_c, goal_temp_c, max_power_w)); + chiller_model_->add_chiller(chiller); + return chiller; +} + +/** @ingroup plugin_chiller + * @param name The new name of the Chiller. + * @return A ChillerPtr pointing to the modified Chiller. + */ +ChillerPtr Chiller::set_name(std::string name) +{ + simgrid::kernel::actor::simcall_answered([this, name] { name_ = name; }); + return this; +} + +/** @ingroup plugin_chiller + * @param air_mass_kg The new air mass of the Chiller in kg. + * @return A ChillerPtr pointing to the modified Chiller. + */ +ChillerPtr Chiller::set_air_mass(double air_mass_kg) +{ + xbt_assert(air_mass_kg > 0, ": air mass must be > 0 (provided: %f)", air_mass_kg); + simgrid::kernel::actor::simcall_answered([this, air_mass_kg] { air_mass_kg_ = air_mass_kg; }); + return this; +} + +/** @ingroup plugin_chiller + * @param specific_heat_j_per_kg_per_c The specific heat of the Chiller in J per kg per °C. + * @return A ChillerPtr pointing to the modified Chiller. + */ +ChillerPtr Chiller::set_specific_heat(double specific_heat_j_per_kg_per_c) +{ + xbt_assert(specific_heat_j_per_kg_per_c > 0, ": specific heat must be > 0 (provided: %f)", + specific_heat_j_per_kg_per_c); + simgrid::kernel::actor::simcall_answered( + [this, specific_heat_j_per_kg_per_c] { specific_heat_j_per_kg_per_c_ = specific_heat_j_per_kg_per_c; }); + return this; +} + +/** @ingroup plugin_chiller + * @param alpha The new alpha of the Chiller. + * @return A ChillerPtr pointing to the modified Chiller. + */ +ChillerPtr Chiller::set_alpha(double alpha) +{ + xbt_assert(alpha >= 0, ": alpha must be >= 0 (provided: %f)", alpha); + simgrid::kernel::actor::simcall_answered([this, alpha] { alpha_ = alpha; }); + return this; +} + +/** @ingroup plugin_chiller + * @param cooling_efficiency The new coolingefficiency of the Chiller. + * @return A ChillerPtr pointing to the modified Chiller. + */ +ChillerPtr Chiller::set_cooling_efficiency(double cooling_efficiency) +{ + xbt_assert(cooling_efficiency >= 0 and cooling_efficiency <= 1, + ": cooling efficiency must be in [0,1] (provided: %f)", cooling_efficiency); + simgrid::kernel::actor::simcall_answered([this, cooling_efficiency] { cooling_efficiency_ = cooling_efficiency; }); + return this; +} + +/** @ingroup plugin_chiller + * @param goal_temp_c The new goal temperature of the Chiller in °C. + * @return A ChillerPtr pointing to the modified Chiller. + */ +ChillerPtr Chiller::set_goal_temp(double goal_temp_c) +{ + simgrid::kernel::actor::simcall_answered([this, goal_temp_c] { goal_temp_c_ = goal_temp_c; }); + return this; +} + +/** @ingroup plugin_chiller + * @param max_power_w The new maximal power of the Chiller in W. + * @return A ChillerPtr pointing to the modified Chiller. + */ +ChillerPtr Chiller::set_max_power(double max_power_w) +{ + xbt_assert(max_power_w >= 0, ": maximal power must be >=0 (provided: %f)", max_power_w); + simgrid::kernel::actor::simcall_answered([this, max_power_w] { max_power_w_ = max_power_w; }); + return this; +} + +/** @ingroup plugin_chiller + * @param active The new active status of the Chiller. + * @return A ChillerPtr pointing to the modified Chiller. + */ +ChillerPtr Chiller::set_active(bool active) +{ + simgrid::kernel::actor::simcall_answered([this, active] { active_ = active; }); + return this; +} + +/** @ingroup plugin_chiller + * @param host The host to add to the room managed by the Chiller. + * @return A ChillerPtr pointing to the modified Chiller. + */ +ChillerPtr Chiller::add_host(s4u::Host* host) +{ + simgrid::kernel::actor::simcall_answered([this, host] { hosts_.insert(host); }); + return this; +} + +/** @ingroup plugin_chiller + * @param host The host to remove from the room managed by the Chiller. + * @return A ChillerPtr pointing to the modified Chiller. + */ +ChillerPtr Chiller::remove_host(s4u::Host* host) +{ + simgrid::kernel::actor::simcall_answered([this, host] { hosts_.erase(host); }); + return this; +} + +} // namespace simgrid::plugins diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 8215478aec..59ef88e394 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -453,6 +453,7 @@ set(PLUGINS_SRC src/plugins/vm/VmLiveMigration.hpp src/plugins/vm/dirty_page_tracking.cpp src/plugins/battery.cpp + src/plugins/chiller.cpp src/plugins/photovoltaic.cpp ) @@ -657,6 +658,7 @@ set(headers_to_install include/simgrid/Exception.hpp include/simgrid/chrono.hpp include/simgrid/plugins/battery.hpp + include/simgrid/plugins/chiller.hpp include/simgrid/plugins/dvfs.h include/simgrid/plugins/energy.h include/simgrid/plugins/file_system.h -- 2.20.1