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 {
15 using SolarPanelPtr = boost::intrusive_ptr<SolarPanel>;
16 XBT_PUBLIC void intrusive_ptr_release(SolarPanel* o);
17 XBT_PUBLIC void intrusive_ptr_add_ref(SolarPanel* o);
23 double conversion_efficiency_;
24 double solar_irradiance_w_per_m2_;
29 explicit SolarPanel(std::string name, double area_m2, double conversion_efficiency, double solar_irradiance_w_per_m2,
30 double min_power_w, double max_power_w);
33 std::atomic_int_fast32_t refcount_{0};
35 friend void intrusive_ptr_release(SolarPanel* o)
37 if (o->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
38 std::atomic_thread_fence(std::memory_order_acquire);
42 friend void intrusive_ptr_add_ref(SolarPanel* o) { o->refcount_.fetch_add(1, std::memory_order_relaxed); }
45 inline static xbt::signal<void(SolarPanel*)> on_power_change;
46 xbt::signal<void(SolarPanel*)> on_this_power_change;
49 static SolarPanelPtr init(const std::string& name, double area_m2, double conversion_efficiency,
50 double solar_irradiance_w_per_m2, double min_power_w, double max_power_w);
52 SolarPanelPtr set_name(std::string name);
53 SolarPanelPtr set_area(double area_m2);
54 SolarPanelPtr set_conversion_efficiency(double e);
55 SolarPanelPtr set_solar_irradiance(double solar_irradiance_w_per_m2);
56 SolarPanelPtr set_min_power(double power_w);
57 SolarPanelPtr set_max_power(double power_w);
59 std::string get_name() const { return name_; }
60 const char* get_cname() const { return name_.c_str(); }
61 double get_area() const { return area_m2_; }
62 double get_conversion_efficiency() const { return conversion_efficiency_; }
63 double get_solar_irradiance() const { return solar_irradiance_w_per_m2_; }
64 double get_min_power() const { return min_power_w_; }
65 double get_max_power() const { return max_power_w_; }
66 double get_power() const { return power_w_; }
68 /** Add a callback fired after this solar panel power changed. */
69 void on_this_power_change_cb(const std::function<void(SolarPanel*)>& func) { on_this_power_change.connect(func); };
70 /** Add a callback fired after a solar panel power changed.
71 * Triggered after the on_this_power_change function.**/
72 static void on_power_change_cb(const std::function<void(SolarPanel*)>& cb) { on_power_change.connect(cb); }
74 } // namespace simgrid::plugins