1 /* Copyright (c) 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. */
5 #include <simgrid/Exception.hpp>
6 #include <simgrid/plugins/solar_panel.hpp>
7 #include <simgrid/simix.hpp>
8 #include <xbt/asserts.h>
11 #include "src/kernel/resource/CpuImpl.hpp"
12 #include "src/simgrid/module.hpp"
14 SIMGRID_REGISTER_PLUGIN(solar_panel, "Solar Panel management", nullptr)
16 /** @defgroup plugin_solar_panel Plugin Solar Panel
20 This is the solar panel plugin, enabling management of solar panels on hosts.
22 This plugin allows the use of solar panels to generate power during simulation depending on size, solar
23 irradiance and conversion factor.
25 The power model is taken from the paper `"Reinforcement Learning Based Load Balancing for
26 Geographically Distributed Data Centres" <https://dro.dur.ac.uk/33395/1/33395.pdf?DDD280+kkgc95+vbdv77>`_ by Max Mackie
32 A solar panel has an area :math:`A` in m², a conversion efficiency :math:`\eta` and a solar irradiance :math:`S` in
33 W/m². The power generated :math:`P` in W by a solar panel is given by the following equation:
37 P = A \times \eta \times S
42 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(SolarPanel, kernel, "Logging specific to the solar panel plugin");
44 namespace simgrid::plugins {
46 xbt::signal<void(SolarPanel*)> SolarPanel::on_power_change;
50 void SolarPanel::update()
52 simgrid::kernel::actor::simcall_answered([this] {
53 double power_w = conversion_efficiency_ * area_m2_ * solar_irradiance_w_per_m2_;
54 if (power_w < min_power_w_)
56 if (power_w > max_power_w_)
57 power_w = max_power_w_;
58 auto previous_power_w = power_w_;
60 if (previous_power_w != power_w_) {
61 on_this_power_change(this);
62 on_power_change(this);
67 SolarPanel::SolarPanel(std::string name, double area_m2, double conversion_efficiency, double solar_irradiance_w_per_m2,
68 double min_power_w, double max_power_w)
71 , conversion_efficiency_(conversion_efficiency)
72 , solar_irradiance_w_per_m2_(solar_irradiance_w_per_m2)
73 , min_power_w_(min_power_w)
74 , max_power_w_(max_power_w)
76 xbt_assert(area_m2 >= 0, " : area must be >= 0 (provided: %f)", area_m2);
77 xbt_assert(conversion_efficiency >= 0 and conversion_efficiency <= 1,
78 " : conversion efficiency must be in [0,1] (provided: %f)", conversion_efficiency);
79 xbt_assert(solar_irradiance_w_per_m2 >= 0, " : solar irradiance must be >= 0 (provided: %f)",
80 solar_irradiance_w_per_m2);
81 xbt_assert(min_power_w >= 0, " : minimal power must be >= 0 (provided: %f)", min_power_w);
82 xbt_assert(max_power_w > 0, " : maximal power must be > 0 (provided: %f)", max_power_w);
83 xbt_assert(max_power_w > min_power_w, " : maximal power must be above minimal power (provided: %f, %f)", max_power_w,
87 /** @ingroup plugin_solar_panel
88 * @param name The name of the Solar Panel.
89 * @param area_m2 The area of the Solar Panel in m² (> 0).
90 * @param conversion_efficiency The conversion efficiency of the Solar Panel [0,1].
91 * @param solar_irradiance_w_per_m2 The solar irradiance of the Solar Panel in W/m² (> 0).
92 * @param min_power_w The minimal power delivered by the Solar Panel in W (> 0 and < max_power_w).
93 * @param max_power_w The maximal power delivered by the Solar Panel in W (> 0 and > min_power_w).
94 * @return A SolarPanelPtr pointing to the new SolarPanel.
96 SolarPanelPtr SolarPanel::init(const std::string& name, double area_m2, double conversion_efficiency,
97 double solar_irradiance_w_per_m2, double min_power_w, double max_power_w)
99 auto solar_panel = SolarPanelPtr(
100 new SolarPanel(name, area_m2, conversion_efficiency, solar_irradiance_w_per_m2, min_power_w, max_power_w));
101 solar_panel->update();
105 /** @ingroup plugin_solar_panel
106 * @param name The new name of the Solar Panel.
107 * @return A SolarPanelPtr pointing to the modified SolarPanel.
109 SolarPanelPtr SolarPanel::set_name(std::string name)
111 kernel::actor::simcall_answered([this, name] { name_ = name; });
115 /** @ingroup plugin_solar_panel
116 * @param area_m2 The new area of the Solar Panel in m².
117 * @return A SolarPanelPtr pointing to the modified SolarPanel.
119 SolarPanelPtr SolarPanel::set_area(double area_m2)
121 xbt_assert(area_m2 >= 0, " : area must be > 0 (provided: %f)", area_m2);
122 kernel::actor::simcall_answered([this, area_m2] { area_m2_ = area_m2; });
127 /** @ingroup plugin_solar_panel
128 * @param e The new convesion efficiency of the Solar Panel.
129 * @return A SolarPanelPtr pointing to the modified SolarPanel.
131 SolarPanelPtr SolarPanel::set_conversion_efficiency(double e)
133 xbt_assert(e >= 0 and e <= 1, " : conversion efficiency must be in [0,1] (provided: %f)", e);
134 kernel::actor::simcall_answered([this, e] { conversion_efficiency_ = e; });
139 /** @ingroup plugin_solar_panel
140 * @param solar_irradiance_w_per_m2 The new solar irradiance of the Solar Panel in W/m².
141 * @return A SolarPanelPtr pointing to the modified SolarPanel.
143 SolarPanelPtr SolarPanel::set_solar_irradiance(double solar_irradiance_w_per_m2)
145 xbt_assert(solar_irradiance_w_per_m2 >= 0, " : solar irradiance must be >= 0 (provided: %f)",
146 solar_irradiance_w_per_m2);
147 kernel::actor::simcall_answered(
148 [this, solar_irradiance_w_per_m2] { solar_irradiance_w_per_m2_ = solar_irradiance_w_per_m2; });
153 /** @ingroup plugin_solar_panel
154 * @param power_w The new minimal power of the Solar Panel in W.
155 * @return A SolarPanelPtr pointing to the modified SolarPanel.
157 SolarPanelPtr SolarPanel::set_min_power(double power_w)
159 xbt_assert(power_w >= 0, " : minimal power must be >= 0 (provided: %f)", power_w);
160 xbt_assert(max_power_w_ > power_w, " : maximal power must be above minimal power (provided: %f, max: %f)", power_w,
162 kernel::actor::simcall_answered([this, power_w] { min_power_w_ = power_w; });
167 /** @ingroup plugin_solar_panel
168 * @param power_w The new maximal power of the Solar Panel in W.
169 * @return A SolarPanelPtr pointing to the modified SolarPanel.
171 SolarPanelPtr SolarPanel::set_max_power(double power_w)
173 xbt_assert(power_w > 0, " : maximal power must be > 0 (provided: %f)", power_w);
174 xbt_assert(min_power_w_ < power_w, " : maximal power must be above minimal power (provided: %f, min: %f)", power_w,
176 kernel::actor::simcall_answered([this, power_w] { max_power_w_ = power_w; });
181 } // namespace simgrid::plugins