-Batteries properties
-....................
-
-Properties of the batteries are defined as properties of hosts in the platform XML file.
-
-Here is an example of XML declaration:
-
-.. code-block:: xml
-
- <host id="Host" speed="100.0Mf" core="1">
- <prop id="battery_active" value="1" />
- <prop id="battery_capacity" value="10" />
- <prop id="battery_cycles" value="200" />
- <prop id="battery_state_of_charge" value="0.8" />
- </host>
-
-The different properties are:
-
-- ``battery_active``: Set the battery as active if set to 1 (default=0)
-- ``battery_power``: Set the initial power of the battery in W (default=0). A negative value indicates that the battery
-act as a load and charge. A positive value indicates that the battery act as a generator and discharge
-- ``battery_state_of_charge``: Set the initial state of charge of the battery (default=0)
-- ``battery_state_of_charge_min``: Set the minimal state of charge of the battery (default=0.2)
-- ``battery_state_of_charge_max``: Set the maximal state of charge of the battery (default=0.8)
-- ``battery_capacity``: Set the initial capacity of the battery in Wh (default=0)
-- ``battery_usable_capacity``: Set the ratio of usable capacity of the battery (default=0.8)
-- ``battery_depth_of_discharge``: Set the depth of discharge of the battery (default=0.9)
-- ``battery_charge_efficiency``: Set the charge efficiency of the battery (default=1)
-- ``battery_discharge_efficiency``: Set the charge efficiency of the battery (default=1)
-- ``battery_cycles``: Set the number of cycle of the battery (default=1)
-- ``battery_depth_of_discharge``: Set the number of cycle of the battery (default=1)
-- ``battery_eval_cost``: Evaluate the cost of the battery during the simulation if set to 1 (defaulf=0)
-- ``battery_investment_cost``: Set the investment cost of the battery (default=0)
-- ``battery_static_maintenance_cost``: Set the static maintenance cost of the battery (default=0)
-- ``battery_variable_maintenance_cost``: Set the variable maintenance cost of the battery (default=0)
-
- @endrst
- */
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(battery, kernel, "Logging specific to the battery plugin");
-
-namespace simgrid::plugin {
-class Battery {
-private:
- simgrid::s4u::Host* host_ = nullptr;
-
- double state_of_charge_min_ = 0.2;
- double state_of_charge_max_ = 0.8;
- double charge_efficiency_ = 1;
- double discharge_efficiency_ = 1;
- double initial_capacity_wh_ = 0;
- double cycles_ = 1; // total complete cycles (charge + discharge) the battery can do before complete depletion.
- double depth_of_discharge_ = 0.9;
- double usable_capacity_ = 0.8;
- double energy_budget_j_ = 0;
-
- bool active_ = false;
- double power_w_ = 0; // NEGATIVE when charging (consumes power) POSITIVE when discharging (generates power)
- double state_of_charge_ = 0;
- double capacity_wh_ = 0;
- double next_event_ = -1;
- double energy_exchanged_j_ = 0;
- double last_updated_ = 0;
-
- // Calculation of costs from Bei Li thesis (link :https://tel.archives-ouvertes.fr/tel-02077668/document) (chapter 4)
- bool eval_cost_ = false;
- double cumulative_cost_ = 0;
- double investment_cost_per_wh_ = 0;
- double static_maintenance_cost_per_wh_times_h_ = 0;
- double variable_maintenance_cost_per_wh_ = 0;
-
- void init_battery_params();
- void init_cost_params();
- void update();
-
- void set_state_of_charge(double soc);
- void set_state_of_charge_min(double soc);
- void set_state_of_charge_max(double soc);
- void set_capacity(double c);
- void set_initial_capacity(double c);
- void set_cycles(int c);
- void set_depth_of_discharge(double d);
- void set_usable_capacity(double c);
- void set_charge_efficiency(double e);
- void set_discharge_efficiency(double e);
- void set_eval_cost(bool eval);
- void set_investment_cost(double c);
- void set_static_maintenance_cost(double c);
- void set_variable_maintenance_cost(double c);
-
- bool is_charging();
-
-public:
- static simgrid::xbt::Extension<simgrid::s4u::Host, Battery> EXTENSION_ID;
-
- explicit Battery(simgrid::s4u::Host* host);
- ~Battery();
-
- void set_state(bool state);
- void set_power(const double power);
-
- bool is_active() const;
- double get_power();
- double get_state_of_charge();
- double get_state_of_charge_min();
- double get_state_of_charge_max();
- double get_state_of_health();
- double get_capacity();
- double get_cumulative_cost();
- double get_next_event_date();
-};
-
-simgrid::xbt::Extension<simgrid::s4u::Host, Battery> Battery::EXTENSION_ID;
-
-void Battery::set_power(const double p)
-{
- update();
- xbt_assert(p == 0 or (p > 0 and state_of_charge_ > state_of_charge_min_) or
- (p < 0 and state_of_charge_ < state_of_charge_max_),
- "Incoherent power and state of charge. A battery cannot charge(discharge) past its maximal(minimal) state "
- "of charge.");
- xbt_assert(p == 0 or energy_exchanged_j_ < energy_budget_j_, "Cannot set power of a fully used battery.");
- simgrid::kernel::actor::simcall_answered([this, p] {
- power_w_ = p;
- if (power_w_ == 0) {
- next_event_ = -1;
- return;
- }
- double soc_shutdown;
- double soh_shutdown;
- if (power_w_ > 0) {
- soc_shutdown = capacity_wh_ * 3600 * (state_of_charge_ - state_of_charge_min_) / (power_w_ * charge_efficiency_);
- soh_shutdown = (energy_budget_j_ - energy_exchanged_j_) / (power_w_ * charge_efficiency_);
- } else { // power_w_ < 0
- soc_shutdown =
- capacity_wh_ * 3600 * (state_of_charge_max_ - state_of_charge_) / (abs(power_w_) / discharge_efficiency_);
- soh_shutdown = (energy_budget_j_ - energy_exchanged_j_) / (abs(power_w_) / discharge_efficiency_);
- }
- if (soh_shutdown <= 0)
- next_event_ = simgrid::s4u::Engine::get_clock() + soc_shutdown;
- else
- next_event_ = simgrid::s4u::Engine::get_clock() + std::min(soc_shutdown, soh_shutdown);
- });
-}
-
-void Battery::set_state(bool state)
-{
- update();
- simgrid::kernel::actor::simcall_answered([this, state] { active_ = state; });
-}