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