Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Various sonar cleanups
[simgrid.git] / include / simgrid / plugins / battery.hpp
index 7f0c361..fc39505 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef SIMGRID_PLUGINS_BATTERY_HPP_
 #define SIMGRID_PLUGINS_BATTERY_HPP_
 
+#include <cmath>
 #include <memory>
 #include <simgrid/kernel/resource/Model.hpp>
 #include <simgrid/s4u/Activity.hpp>
@@ -87,23 +88,24 @@ private:
   static std::shared_ptr<BatteryModel> battery_model_;
 
   std::string name_;
-  double nominal_charge_power_w_;
-  double nominal_discharge_power_w_;
-  double charge_efficiency_;
-  double discharge_efficiency_;
-  double initial_capacity_wh_;
-  double energy_budget_j_;
-
-  std::map<const s4u::Host*, bool> host_loads_     = {};
-  std::map<const std::string, double> named_loads_ = {};
+  double nominal_charge_power_w_    = -INFINITY;
+  double nominal_discharge_power_w_ = INFINITY;
+  double charge_efficiency_         = 1;
+  double discharge_efficiency_      = 1;
+  double initial_capacity_wh_       = 0;
+  double energy_budget_j_           = 0;
+
+  std::map<const s4u::Host*, bool> host_loads_                      = {};
+  std::map<const std::string, std::pair<bool, double>> named_loads_ = {};
   std::vector<std::shared_ptr<Handler>> handlers_;
 
-  double capacity_wh_;
-  double energy_stored_j_;
+  double capacity_wh_       = 0;
+  double energy_stored_j_   = 0;
   double energy_provided_j_ = 0;
   double energy_consumed_j_ = 0;
   double last_updated_      = 0;
 
+  explicit Battery() = default;
   explicit Battery(const std::string& name, double state_of_charge, double nominal_charge_power_w,
                    double nominal_discharge_power_w, double charge_efficiency, double discharge_efficiency,
                    double initial_capacity_wh, int cycles);
@@ -124,11 +126,14 @@ private:
 #endif
 
 public:
+  static BatteryPtr init();
   static BatteryPtr init(const std::string& name, double state_of_charge, double nominal_charge_power_w,
                          double nominal_discharge_power_w, double charge_efficiency, double discharge_efficiency,
                          double initial_capacity_wh, int cycles);
   void set_load(const std::string& name, double power_w);
+  void set_load(const std::string& name, bool active);
   void connect_host(s4u::Host* host, bool active = true);
+  std::string get_name() const { return name_; }
   double get_state_of_charge();
   double get_state_of_health();
   double get_capacity();