Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
photovoltaic plugin revamp, now called solar panel
[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 class SolarPanel;
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);
18
19 class SolarPanelModel : public kernel::resource::Model {
20   std::vector<SolarPanelPtr> solar_panels_;
21
22 public:
23   explicit SolarPanelModel();
24
25   void add_solar_panel(SolarPanelPtr b);
26   void update_actions_state(double now, double delta) override;
27   double next_occurring_event(double now) override;
28 };
29
30 class SolarPanel {
31
32   friend SolarPanelModel;
33
34 private:
35   static std::shared_ptr<SolarPanelModel> solar_panel_model_;
36
37   std::string name_;
38   double area_m2_;
39   double conversion_efficiency_;
40   double solar_irradiance_w_per_m2_ ;
41   double min_power_w_;
42   double max_power_w_;
43
44   double power_w_      = 0;
45   double last_updated_ = 0;
46
47   explicit SolarPanel(std::string name, double area_m2, double conversion_efficiency, double solar_irradiance_w_per_m2, double min_power_w, double max_power_w);
48   static void init_plugin();
49   void update();
50
51   std::atomic_int_fast32_t refcount_{0};
52 #ifndef DOXYGEN
53   friend void intrusive_ptr_release(SolarPanel* o)
54   {
55     if (o->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
56       std::atomic_thread_fence(std::memory_order_acquire);
57       delete o;
58     }
59   }
60   friend void intrusive_ptr_add_ref(SolarPanel* o) { o->refcount_.fetch_add(1, std::memory_order_relaxed); }
61 #endif
62
63 public:
64
65   static SolarPanelPtr init(const std::string& name, double area_m2, double conversion_efficiency, double solar_irradiance_w_per_m2, double min_power_w, double max_power_w);
66
67   SolarPanelPtr set_name(std::string name);
68   SolarPanelPtr set_area(double area_m2);
69   SolarPanelPtr set_conversion_efficiency(double e);
70   SolarPanelPtr set_solar_irradiance(double solar_irradiance_w_per_m2);
71   SolarPanelPtr set_min_power(double power_w);
72   SolarPanelPtr set_max_power(double power_w);
73
74   std::string get_name() { return name_; }
75   const char* get_cname() { return name_.c_str();}
76   double get_area() { return area_m2_;}
77   double get_conversion_efficiency() { return conversion_efficiency_; }
78   double get_solar_irradiance() { return solar_irradiance_w_per_m2_; }
79   double get_min_power() { return min_power_w_; }
80   double get_max_power() { return max_power_w_; }
81   double get_power() { return power_w_; }
82 };
83 } // namespace simgrid::plugins
84 #endif