Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / include / simgrid / plugins / solar_panel.hpp
1 /* Copyright (c) 2023. The SimGrid Team. All rights reserved.          */
2
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_
7
8 #include <simgrid/kernel/resource/Model.hpp>
9 #include <simgrid/s4u/Activity.hpp>
10 #include <xbt/Extendable.hpp>
11
12 namespace simgrid::plugins {
13
14 /** @ingroup plugin_solar_panel */
15 class SolarPanel;
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);
20
21 class SolarPanel {
22
23   std::string name_;
24   double area_m2_;
25   double conversion_efficiency_;
26   double solar_irradiance_w_per_m2_;
27   double min_power_w_;
28   double max_power_w_;
29   double power_w_ = -1;
30
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);
33   void update();
34
35   std::atomic_int_fast32_t refcount_{0};
36 #ifndef DOXYGEN
37   friend void intrusive_ptr_release(SolarPanel* o)
38   {
39     if (o->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
40       std::atomic_thread_fence(std::memory_order_acquire);
41       delete o;
42     }
43   }
44   friend void intrusive_ptr_add_ref(SolarPanel* o) { o->refcount_.fetch_add(1, std::memory_order_relaxed); }
45 #endif
46
47   static xbt::signal<void(SolarPanel*)> on_power_change;
48   xbt::signal<void(SolarPanel*)> on_this_power_change;
49
50 public:
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);
53
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);
60
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_; }
69
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); }
75 };
76 } // namespace simgrid::plugins
77 #endif