A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
rv-battery-model.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
7 */
8
9#ifndef RV_BATTERY_MODEL_H
10#define RV_BATTERY_MODEL_H
11
12#include "energy-source.h"
13
14#include "ns3/event-id.h"
15#include "ns3/nstime.h"
16#include "ns3/traced-value.h"
17
18namespace ns3
19{
20namespace energy
21{
22
23/**
24 * \ingroup energy
25 * \brief Rakhmatov Vrudhula non-linear battery model.
26 *
27 * This (energy source) model implements an analytical non-linear battery model.
28 * It is capable of capturing load capacity and recovery effects of batteries.
29 * Batteries are characterized by 2 parameters, alpha and beta, which can both
30 * be obtained from the discharge curve of the batteries.
31 *
32 * The model is developed by Daler Rakhmatov & Sarma Vrudhula in: "Battery
33 * Lifetime Prediction for Energy-Aware Computing" and "An Analytical High-Level
34 * Battery Model for Use in Energy Management of Portable Electronic Systems".
35 *
36 * The real-time algorithm is developed by Matthias Handy & Dirk Timmermann in:
37 * "Simulation of Mobile Wireless Networks with Accurate Modeling of non-linear
38 * battery effects". The real-time algorithm is modified by the authors of this
39 * code for improved accuracy and reduced computation (sampling) overhead.
40 *
41 */
43{
44 public:
45 /**
46 * \brief Get the type ID.
47 * \return The object TypeId.
48 */
49 static TypeId GetTypeId();
51 ~RvBatteryModel() override;
52
53 /**
54 * \return Initial energy stored (theoretical capacity) in the battery, in Joules.
55 *
56 * Implements GetInitialEnergy.
57 */
58 double GetInitialEnergy() const override;
59
60 /**
61 * \returns Supply voltage at the energy source.
62 *
63 * Implements GetSupplyVoltage.
64 */
65 double GetSupplyVoltage() const override;
66
67 /**
68 * \return Remaining energy in energy source, in Joules
69 *
70 * Implements GetRemainingEnergy.
71 */
72 double GetRemainingEnergy() override;
73
74 /**
75 * \returns Energy fraction.
76 *
77 * Implements GetEnergyFraction. For the RV battery model, energy fraction is
78 * equivalent to battery level.
79 */
80 double GetEnergyFraction() override;
81
82 /**
83 * Implements UpdateEnergySource. This function samples the total load (total
84 * current) from all devices to discharge the battery.
85 */
86 void UpdateEnergySource() override;
87
88 /**
89 * \param interval Energy update interval.
90 *
91 * This function sets the interval between each energy update.
92 */
93 void SetSamplingInterval(Time interval);
94
95 /**
96 * \returns The interval between each energy update.
97 */
99
100 /**
101 * \brief Sets open circuit voltage of battery.
102 *
103 * \param voltage Open circuit voltage.
104 */
105 void SetOpenCircuitVoltage(double voltage);
106
107 /**
108 * \return Open circuit voltage of battery.
109 */
110 double GetOpenCircuitVoltage() const;
111
112 /**
113 * \brief Sets cutoff voltage of battery.
114 *
115 * \param voltage Cutoff voltage.
116 */
117 void SetCutoffVoltage(double voltage);
118
119 /**
120 * \returns Cutoff voltage of battery.
121 */
122 double GetCutoffVoltage() const;
123
124 /**
125 * \brief Sets the alpha value for the battery model.
126 *
127 * \param alpha Alpha.
128 */
129 void SetAlpha(double alpha);
130
131 /**
132 * \returns The alpha value used by the battery model.
133 */
134 double GetAlpha() const;
135
136 /**
137 * \brief Sets the beta value for the battery model.
138 *
139 * \param beta Beta.
140 */
141 void SetBeta(double beta);
142
143 /**
144 * \returns The beta value used by the battery model.
145 */
146 double GetBeta() const;
147
148 /**
149 * \returns Battery level [0, 1].
150 */
151 double GetBatteryLevel();
152
153 /**
154 * \returns Lifetime of the battery.
155 */
156 Time GetLifetime() const;
157
158 /**
159 * \brief Sets the number of terms of the infinite sum for estimating battery
160 * level.
161 *
162 * \param num Number of terms.
163 */
164 void SetNumOfTerms(int num);
165
166 /**
167 * \returns The number of terms of the infinite sum for estimating battery
168 * level.
169 */
170 int GetNumOfTerms() const;
171
172 private:
173 /// Defined in ns3::Object
174 void DoInitialize() override;
175
176 /// Defined in ns3::Object
177 void DoDispose() override;
178
179 /**
180 * Handles the remaining energy going to zero event. This function notifies
181 * all the energy models aggregated to the node about the energy being
182 * depleted. Each energy model is then responsible for its own handler.
183 */
185
186 /**
187 * \brief Discharges the battery.
188 *
189 * \param load Load value (total current form devices, in mA).
190 * \param t Time stamp of the load value.
191 * \returns Calculated alpha value.
192 *
193 * Discharge function calculates a value which is then compared to the alpha
194 * value to determine if the battery is dead. It will also update the battery
195 * level.
196 *
197 * Note that the load value passed to Discharge has to be in mA.
198 */
199 double Discharge(double load, Time t);
200
201 /**
202 * \brief RV model A function.
203 *
204 * \param t Current time.
205 * \param sk Time stamp in array position k
206 * \param sk_1 Time stamp in array position k-1
207 * \param beta Beta value used by the battery model.
208 * \returns Result of A function.
209 *
210 * This function computes alpha value using the recorded load profile.
211 */
212 double RvModelAFunction(Time t, Time sk, Time sk_1, double beta);
213
214 private:
215 double m_openCircuitVoltage; //!< Open circuit voltage (in Volts)
216 double m_cutoffVoltage; //!< Cutoff voltage (in Volts)
217 double m_alpha; //!< alpha value of RV model, in Coulomb
218 double m_beta; //!< beta value of RV model, in second^-1
219
220 double m_previousLoad; //!< load value (total current) of previous sampling
221 std::vector<double> m_load; //!< load profile
222 std::vector<Time> m_timeStamps; //!< time stamps of load profile
223 Time m_lastSampleTime; //!< Last sample time
224
225 int m_numOfTerms; //!< Number# of terms for infinite sum in battery level estimation
226
227 /**
228 * Battery level is defined as: output of Discharge function / alpha value
229 *
230 * The output of Discharge function is an estimated charge consumption of the
231 * battery.
232 *
233 * The alpha value is the amount of charges stored in the battery, or battery
234 * capacity (in Coulomb).
235 *
236 * When the battery is fully charged (no charge is consumed from the battery)
237 * the battery level is 1. When the battery is fully discharged, the battery
238 * level is 0.
239 *
240 * NOTE Note that the definition in Timmermann's paper is the inverse of this
241 * definition. In the paper, battery level = 1 when the battery is drained.
242 */
244
245 double m_lowBatteryTh; //!< low battery threshold, as a fraction of the initial energy
246
247 /**
248 * Sampling interval.
249 * (1 / sampling interval) = sampling frequency
250 */
252 EventId m_currentSampleEvent; //!< Current sample event
253
254 TracedValue<Time> m_lifetime; //!< time of death of the battery
255};
256
257} // namespace energy
258} // namespace ns3
259
260#endif /* RV_BATTERY_MODEL_H */
An identifier for simulation events.
Definition event-id.h:45
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Trace classes with value semantics.
a unique identifier for an interface.
Definition type-id.h:48
Energy source base class.
Rakhmatov Vrudhula non-linear battery model.
double m_beta
beta value of RV model, in second^-1
double RvModelAFunction(Time t, Time sk, Time sk_1, double beta)
RV model A function.
static TypeId GetTypeId()
Get the type ID.
TracedValue< Time > m_lifetime
time of death of the battery
TracedValue< double > m_batteryLevel
Battery level is defined as: output of Discharge function / alpha value.
Time m_lastSampleTime
Last sample time.
double GetRemainingEnergy() override
EventId m_currentSampleEvent
Current sample event.
void DoDispose() override
Defined in ns3::Object.
double GetInitialEnergy() const override
double GetSupplyVoltage() const override
std::vector< double > m_load
load profile
void UpdateEnergySource() override
Implements UpdateEnergySource.
double Discharge(double load, Time t)
Discharges the battery.
void SetNumOfTerms(int num)
Sets the number of terms of the infinite sum for estimating battery level.
void HandleEnergyDrainedEvent()
Handles the remaining energy going to zero event.
double m_alpha
alpha value of RV model, in Coulomb
double m_lowBatteryTh
low battery threshold, as a fraction of the initial energy
int m_numOfTerms
Number# of terms for infinite sum in battery level estimation.
void SetBeta(double beta)
Sets the beta value for the battery model.
double m_openCircuitVoltage
Open circuit voltage (in Volts)
std::vector< Time > m_timeStamps
time stamps of load profile
void DoInitialize() override
Defined in ns3::Object.
void SetCutoffVoltage(double voltage)
Sets cutoff voltage of battery.
void SetAlpha(double alpha)
Sets the alpha value for the battery model.
double m_previousLoad
load value (total current) of previous sampling
double GetEnergyFraction() override
void SetSamplingInterval(Time interval)
double m_cutoffVoltage
Cutoff voltage (in Volts)
Time m_samplingInterval
Sampling interval.
void SetOpenCircuitVoltage(double voltage)
Sets open circuit voltage of battery.
Every class exported by the ns3 library is enclosed in the ns3 namespace.