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 #ifndef SIMGRID_PLUGINS_SOLAR_PANEL_H_
6 #define SIMGRID_PLUGINS_SOLAR_PANEL_H_
8 #include <simgrid/kernel/resource/Model.hpp>
9 #include <simgrid/s4u/Activity.hpp>
10 #include <xbt/Extendable.hpp>
12 namespace simgrid::plugins {
14 /** @ingroup plugin_solar_panel */
16 /** @ingroup plugin_solar_panel */
17 using SolarPanelPtr = boost::intrusive_ptr<SolarPanel>;
18 XBT_PUBLIC void intrusive_ptr_release(SolarPanel* o);
19 XBT_PUBLIC void intrusive_ptr_add_ref(SolarPanel* o);
25 double conversion_efficiency_;
26 double solar_irradiance_w_per_m2_;
31 explicit SolarPanel(std::string name, double area_m2, double conversion_efficiency, double solar_irradiance_w_per_m2,
32 double min_power_w, double max_power_w);
35 std::atomic_int_fast32_t refcount_{0};
37 friend void intrusive_ptr_release(SolarPanel* o)
39 if (o->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
40 std::atomic_thread_fence(std::memory_order_acquire);
44 friend void intrusive_ptr_add_ref(SolarPanel* o) { o->refcount_.fetch_add(1, std::memory_order_relaxed); }
47 static xbt::signal<void(SolarPanel*)> on_power_change;
48 xbt::signal<void(SolarPanel*)> on_this_power_change;
51 static SolarPanelPtr init(const std::string& name, double area_m2, double conversion_efficiency,
52 double solar_irradiance_w_per_m2, double min_power_w, double max_power_w);
54 SolarPanelPtr set_name(std::string name);
55 SolarPanelPtr set_area(double area_m2);
56 SolarPanelPtr set_conversion_efficiency(double e);
57 SolarPanelPtr set_solar_irradiance(double solar_irradiance_w_per_m2);
58 SolarPanelPtr set_min_power(double power_w);
59 SolarPanelPtr set_max_power(double power_w);
61 std::string get_name() const { return name_; }
62 const char* get_cname() const { return name_.c_str(); }
63 double get_area() const { return area_m2_; }
64 double get_conversion_efficiency() const { return conversion_efficiency_; }
65 double get_solar_irradiance() const { return solar_irradiance_w_per_m2_; }
66 double get_min_power() const { return min_power_w_; }
67 double get_max_power() const { return max_power_w_; }
68 double get_power() const { return power_w_; }
70 /** Add a callback fired after this solar panel power changed. */
71 void on_this_power_change_cb(const std::function<void(SolarPanel*)>& func) { on_this_power_change.connect(func); };
72 /** Add a callback fired after a solar panel power changed.
73 * Triggered after the on_this_power_change function.**/
74 static void on_power_change_cb(const std::function<void(SolarPanel*)>& cb) { on_power_change.connect(cb); }
76 } // namespace simgrid::plugins