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_CHILLER_H_
6 #define SIMGRID_PLUGINS_CHILLER_H_
8 #include <simgrid/kernel/resource/Model.hpp>
9 #include <simgrid/s4u/Activity.hpp>
10 #include <xbt/Extendable.hpp>
12 namespace simgrid::plugins {
14 /** @ingroup plugin_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);
21 class ChillerModel : public kernel::resource::Model {
22 std::vector<ChillerPtr> chillers_;
25 explicit ChillerModel();
27 void add_chiller(ChillerPtr b);
28 void update_actions_state(double now, double delta) override;
29 double next_occurring_event(double now) override;
37 static std::shared_ptr<ChillerModel> chiller_model_;
41 double specific_heat_j_per_kg_per_c_;
43 double cooling_efficiency_;
49 std::set<const s4u::Host*> hosts_ = {};
52 double energy_consumed_j_ = 0;
53 double last_updated_ = 0;
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);
58 static void init_plugin();
61 std::atomic_int_fast32_t refcount_{0};
63 friend void intrusive_ptr_release(Chiller* o)
65 if (o->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
66 std::atomic_thread_fence(std::memory_order_acquire);
70 friend void intrusive_ptr_add_ref(Chiller* o) { o->refcount_.fetch_add(1, std::memory_order_relaxed); }
73 static xbt::signal<void(Chiller*)> on_power_change;
74 xbt::signal<void(Chiller*)> on_this_power_change;
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);
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);
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();
106 } // namespace simgrid::plugins