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 {
48 void SolarPanel::update()
50 simgrid::kernel::actor::simcall_answered([this] {
51 double power_w = conversion_efficiency_ * area_m2_ * solar_irradiance_w_per_m2_;
52 if (power_w < min_power_w_)
54 if (power_w > max_power_w_)
55 power_w = max_power_w_;
56 auto previous_power_w = power_w_;
58 if (previous_power_w != power_w_) {
59 on_this_power_change(this);
60 on_power_change(this);
65 SolarPanel::SolarPanel(std::string name, double area_m2, double conversion_efficiency, double solar_irradiance_w_per_m2,
66 double min_power_w, double max_power_w)
69 , conversion_efficiency_(conversion_efficiency)
70 , solar_irradiance_w_per_m2_(solar_irradiance_w_per_m2)
71 , min_power_w_(min_power_w)
72 , max_power_w_(max_power_w)
74 xbt_assert(area_m2 >= 0, " : area must be >= 0 (provided: %f)", area_m2);
75 xbt_assert(conversion_efficiency >= 0 and conversion_efficiency <= 1,
76 " : conversion efficiency must be in [0,1] (provided: %f)", conversion_efficiency);
77 xbt_assert(solar_irradiance_w_per_m2 >= 0, " : solar irradiance must be >= 0 (provided: %f)",
78 solar_irradiance_w_per_m2);
79 xbt_assert(min_power_w >= 0, " : minimal power must be >= 0 (provided: %f)", min_power_w);
80 xbt_assert(max_power_w > 0, " : maximal power must be > 0 (provided: %f)", max_power_w);
81 xbt_assert(max_power_w > min_power_w, " : maximal power must be above minimal power (provided: %f, %f)", max_power_w,
85 /** @ingroup plugin_solar_panel
86 * @param name The name of the Solar Panel.
87 * @param area_m2 The area of the Solar Panel in m² (> 0).
88 * @param conversion_efficiency The conversion efficiency of the Solar Panel [0,1].
89 * @param solar_irradiance_w_per_m2 The solar irradiance of the Solar Panel in W/m² (> 0).
90 * @param min_power_w The minimal power delivered by the Solar Panel in W (> 0 and < max_power_w).
91 * @param max_power_w The maximal power delivered by the Solar Panel in W (> 0 and > min_power_w).
92 * @return A SolarPanelPtr pointing to the new SolarPanel.
94 SolarPanelPtr SolarPanel::init(const std::string& name, double area_m2, double conversion_efficiency,
95 double solar_irradiance_w_per_m2, double min_power_w, double max_power_w)
97 auto solar_panel = SolarPanelPtr(
98 new SolarPanel(name, area_m2, conversion_efficiency, solar_irradiance_w_per_m2, min_power_w, max_power_w));
99 solar_panel->update();
103 /** @ingroup plugin_solar_panel
104 * @param name The new name of the Solar Panel.
105 * @return A SolarPanelPtr pointing to the modified SolarPanel.
107 SolarPanelPtr SolarPanel::set_name(std::string name)
109 kernel::actor::simcall_answered([this, name] { name_ = name; });
113 /** @ingroup plugin_solar_panel
114 * @param area_m2 The new area of the Solar Panel in m².
115 * @return A SolarPanelPtr pointing to the modified SolarPanel.
117 SolarPanelPtr SolarPanel::set_area(double area_m2)
119 xbt_assert(area_m2 >= 0, " : area must be > 0 (provided: %f)", area_m2);
120 kernel::actor::simcall_answered([this, area_m2] { area_m2_ = area_m2; });
125 /** @ingroup plugin_solar_panel
126 * @param e The new convesion efficiency of the Solar Panel.
127 * @return A SolarPanelPtr pointing to the modified SolarPanel.
129 SolarPanelPtr SolarPanel::set_conversion_efficiency(double e)
131 xbt_assert(e >= 0 and e <= 1, " : conversion efficiency must be in [0,1] (provided: %f)", e);
132 kernel::actor::simcall_answered([this, e] { conversion_efficiency_ = e; });
137 /** @ingroup plugin_solar_panel
138 * @param solar_irradiance_w_per_m2 The new solar irradiance of the Solar Panel in W/m².
139 * @return A SolarPanelPtr pointing to the modified SolarPanel.
141 SolarPanelPtr SolarPanel::set_solar_irradiance(double solar_irradiance_w_per_m2)
143 xbt_assert(solar_irradiance_w_per_m2 >= 0, " : solar irradiance must be >= 0 (provided: %f)",
144 solar_irradiance_w_per_m2);
145 kernel::actor::simcall_answered(
146 [this, solar_irradiance_w_per_m2] { solar_irradiance_w_per_m2_ = solar_irradiance_w_per_m2; });
151 /** @ingroup plugin_solar_panel
152 * @param power_w The new minimal power of the Solar Panel in W.
153 * @return A SolarPanelPtr pointing to the modified SolarPanel.
155 SolarPanelPtr SolarPanel::set_min_power(double power_w)
157 xbt_assert(power_w >= 0, " : minimal power must be >= 0 (provided: %f)", power_w);
158 xbt_assert(max_power_w_ > power_w, " : maximal power must be above minimal power (provided: %f, max: %f)", power_w,
160 kernel::actor::simcall_answered([this, power_w] { min_power_w_ = power_w; });
165 /** @ingroup plugin_solar_panel
166 * @param power_w The new maximal power of the Solar Panel in W.
167 * @return A SolarPanelPtr pointing to the modified SolarPanel.
169 SolarPanelPtr SolarPanel::set_max_power(double power_w)
171 xbt_assert(power_w > 0, " : maximal power must be > 0 (provided: %f)", power_w);
172 xbt_assert(min_power_w_ < power_w, " : maximal power must be above minimal power (provided: %f, min: %f)", power_w,
174 kernel::actor::simcall_answered([this, power_w] { max_power_w_ = power_w; });
179 } // namespace simgrid::plugins