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 {
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);
19 class ChillerModel : public kernel::resource::Model {
20 std::vector<ChillerPtr> chillers_;
23 explicit ChillerModel();
25 void add_chiller(ChillerPtr b);
26 void update_actions_state(double now, double delta) override;
27 double next_occurring_event(double now) override;
35 static std::shared_ptr<ChillerModel> chiller_model_;
39 double specific_heat_j_per_kg_per_c_;
41 double cooling_efficiency_;
47 std::set<const s4u::Host*> hosts_ = {};
50 double energy_consumed_j_ = 0;
51 double last_updated_ = 0;
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);
56 static void init_plugin();
59 std::atomic_int_fast32_t refcount_{0};
61 friend void intrusive_ptr_release(Chiller* o)
63 if (o->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
64 std::atomic_thread_fence(std::memory_order_acquire);
68 friend void intrusive_ptr_add_ref(Chiller* o) { o->refcount_.fetch_add(1, std::memory_order_relaxed); }
71 inline static xbt::signal<void(Chiller*)> on_power_change;
72 xbt::signal<void(Chiller*)> on_this_power_change;
75 static ChillerPtr init(const std::string& name, double air_mass_kg, double specific_heat_j_per_kg_per_c, double alpha,
76 double cooling_efficiency, double initial_temp_c, double goal_temp_c, double max_power_w);
78 ChillerPtr set_name(std::string name);
79 ChillerPtr set_air_mass(double air_mass_kg);
80 ChillerPtr set_specific_heat(double specific_heat_j_per_kg_per_c);
81 ChillerPtr set_alpha(double alpha);
82 ChillerPtr set_cooling_efficiency(double cooling_efficiency);
83 ChillerPtr set_goal_temp(double goal_temp_c);
84 ChillerPtr set_max_power(double max_power_w);
85 ChillerPtr set_active(bool active);
86 ChillerPtr add_host(s4u::Host* host);
87 ChillerPtr remove_host(s4u::Host* host);
89 std::string get_name() { return name_; }
90 const char* get_cname() { return name_.c_str(); }
91 double get_air_mass() { return air_mass_kg_; }
92 double get_specific_heat() { return specific_heat_j_per_kg_per_c_; }
93 double get_alpha() { return alpha_; }
94 double get_cooling_efficiency() { return cooling_efficiency_; }
95 double get_goal_temp() { return goal_temp_c_; }
96 double get_max_power() { return max_power_w_; }
97 bool is_active() { return active_; }
98 double get_temp_in() { return temp_in_c_; }
99 double get_power() { return power_w_; }
100 double get_energy_consumed() { return energy_consumed_j_; }
101 double get_time_to_goal_temp();
104 } // namespace simgrid::plugins