Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'task-doc' into 'master'
[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,
48                       double min_power_w, double max_power_w);
49   static void init_plugin();
50   void update();
51
52   std::atomic_int_fast32_t refcount_{0};
53 #ifndef DOXYGEN
54   friend void intrusive_ptr_release(SolarPanel* o)
55   {
56     if (o->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
57       std::atomic_thread_fence(std::memory_order_acquire);
58       delete o;
59     }
60   }
61   friend void intrusive_ptr_add_ref(SolarPanel* o) { o->refcount_.fetch_add(1, std::memory_order_relaxed); }
62 #endif
63
64 public:
65   static SolarPanelPtr init(const std::string& name, double area_m2, double conversion_efficiency,
66                             double solar_irradiance_w_per_m2, double min_power_w, double max_power_w);
67
68   SolarPanelPtr set_name(std::string name);
69   SolarPanelPtr set_area(double area_m2);
70   SolarPanelPtr set_conversion_efficiency(double e);
71   SolarPanelPtr set_solar_irradiance(double solar_irradiance_w_per_m2);
72   SolarPanelPtr set_min_power(double power_w);
73   SolarPanelPtr set_max_power(double power_w);
74
75   std::string get_name() { return name_; }
76   const char* get_cname() { return name_.c_str(); }
77   double get_area() { return area_m2_; }
78   double get_conversion_efficiency() { return conversion_efficiency_; }
79   double get_solar_irradiance() { return solar_irradiance_w_per_m2_; }
80   double get_min_power() { return min_power_w_; }
81   double get_max_power() { return max_power_w_; }
82   double get_power() { return power_w_; }
83 };
84 } // namespace simgrid::plugins
85 #endif