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