Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix some more doc bugs
[simgrid.git] / include / simgrid / plugins / chiller.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_CHILLER_H_
6 #define SIMGRID_PLUGINS_CHILLER_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_chiller */
15 class Chiller;
16 /** @ingroup plugin_chiller */
17 using ChillerPtr = boost::intrusive_ptr<Chiller>;
18 XBT_PUBLIC void intrusive_ptr_release(Chiller* o);
19 XBT_PUBLIC void intrusive_ptr_add_ref(Chiller* o);
20
21 class ChillerModel : public kernel::resource::Model {
22   std::vector<ChillerPtr> chillers_;
23
24 public:
25   explicit ChillerModel();
26
27   void add_chiller(ChillerPtr b);
28   void update_actions_state(double now, double delta) override;
29   double next_occurring_event(double now) override;
30 };
31
32 class Chiller {
33
34   friend ChillerModel;
35
36 private:
37   static std::shared_ptr<ChillerModel> chiller_model_;
38
39   std::string name_;
40   double air_mass_kg_;
41   double specific_heat_j_per_kg_per_c_;
42   double alpha_;
43   double cooling_efficiency_;
44   double temp_in_c_;
45   double temp_out_c_;
46   double goal_temp_c_;
47   double max_power_w_;
48
49   std::set<const s4u::Host*> hosts_ = {};
50   bool active_                      = true;
51   double power_w_                   = 0;
52   double energy_consumed_j_         = 0;
53   double last_updated_              = 0;
54
55   explicit Chiller(const std::string& name, double air_mass_kg, double specific_heat_j_per_kg_per_c, double alpha,
56                    double cooling_efficiency, double initial_temp_c, double goal_temp_c, double max_power_w);
57
58   static void init_plugin();
59   void update();
60
61   std::atomic_int_fast32_t refcount_{0};
62 #ifndef DOXYGEN
63   friend void intrusive_ptr_release(Chiller* o)
64   {
65     if (o->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
66       std::atomic_thread_fence(std::memory_order_acquire);
67       delete o;
68     }
69   }
70   friend void intrusive_ptr_add_ref(Chiller* o) { o->refcount_.fetch_add(1, std::memory_order_relaxed); }
71 #endif
72
73   static xbt::signal<void(Chiller*)> on_power_change;
74   xbt::signal<void(Chiller*)> on_this_power_change;
75
76 public:
77   static ChillerPtr init(const std::string& name, double air_mass_kg, double specific_heat_j_per_kg_per_c, double alpha,
78                          double cooling_efficiency, double initial_temp_c, double goal_temp_c, double max_power_w);
79
80   ChillerPtr set_name(std::string name);
81   ChillerPtr set_air_mass(double air_mass_kg);
82   ChillerPtr set_specific_heat(double specific_heat_j_per_kg_per_c);
83   ChillerPtr set_alpha(double alpha);
84   ChillerPtr set_cooling_efficiency(double cooling_efficiency);
85   ChillerPtr set_goal_temp(double goal_temp_c);
86   ChillerPtr set_max_power(double max_power_w);
87   ChillerPtr set_active(bool active);
88   ChillerPtr add_host(simgrid::s4u::Host* host);
89   ChillerPtr remove_host(simgrid::s4u::Host* host);
90
91   std::string get_name() { return name_; }
92   const char* get_cname() { return name_.c_str(); }
93   double get_air_mass() { return air_mass_kg_; }
94   double get_specific_heat() { return specific_heat_j_per_kg_per_c_; }
95   double get_alpha() { return alpha_; }
96   double get_cooling_efficiency() { return cooling_efficiency_; }
97   double get_goal_temp() { return goal_temp_c_; }
98   double get_max_power() { return max_power_w_; }
99   bool is_active() { return active_; }
100   double get_temp_in() { return temp_in_c_; }
101   double get_power() { return power_w_; }
102   double get_energy_consumed() { return energy_consumed_j_; }
103   double get_time_to_goal_temp();
104 };
105
106 } // namespace simgrid::plugins
107 #endif