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);
19 class SolarPanelModel : public kernel::resource::Model {
20 std::vector<SolarPanelPtr> solar_panels_;
23 explicit SolarPanelModel();
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;
32 friend SolarPanelModel;
35 static std::shared_ptr<SolarPanelModel> solar_panel_model_;
39 double conversion_efficiency_;
40 double solar_irradiance_w_per_m2_;
45 double last_updated_ = 0;
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();
52 std::atomic_int_fast32_t refcount_{0};
54 friend void intrusive_ptr_release(SolarPanel* o)
56 if (o->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
57 std::atomic_thread_fence(std::memory_order_acquire);
61 friend void intrusive_ptr_add_ref(SolarPanel* o) { o->refcount_.fetch_add(1, std::memory_order_relaxed); }
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);
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);
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_; }
84 } // namespace simgrid::plugins