Logo AND Algorithmique Numérique Distribuée

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